7a04f298d2
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
218 lines
5.4 KiB
Go
218 lines
5.4 KiB
Go
// Code generated by gotdgen, DO NOT EDIT.
|
|
|
|
package tg
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"go.uber.org/multierr"
|
|
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/bin"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tdjson"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tdp"
|
|
"go.mau.fi/mautrix-telegram/pkg/gotd/tgerr"
|
|
)
|
|
|
|
// No-op definition for keeping imports.
|
|
var (
|
|
_ = bin.Buffer{}
|
|
_ = context.Background()
|
|
_ = fmt.Stringer(nil)
|
|
_ = strings.Builder{}
|
|
_ = errors.Is
|
|
_ = multierr.AppendInto
|
|
_ = sort.Ints
|
|
_ = tdp.Format
|
|
_ = tgerr.Error{}
|
|
_ = tdjson.Encoder{}
|
|
)
|
|
|
|
// AccountToggleUsernameRequest represents TL type `account.toggleUsername#58d6b376`.
|
|
// Activate or deactivate a purchased fragment.com¹ username associated to the currently
|
|
// logged-in user.
|
|
//
|
|
// Links:
|
|
// 1. https://fragment.com
|
|
//
|
|
// See https://core.telegram.org/method/account.toggleUsername for reference.
|
|
type AccountToggleUsernameRequest struct {
|
|
// Username
|
|
Username string
|
|
// Whether to activate or deactivate it
|
|
Active bool
|
|
}
|
|
|
|
// AccountToggleUsernameRequestTypeID is TL type id of AccountToggleUsernameRequest.
|
|
const AccountToggleUsernameRequestTypeID = 0x58d6b376
|
|
|
|
// Ensuring interfaces in compile-time for AccountToggleUsernameRequest.
|
|
var (
|
|
_ bin.Encoder = &AccountToggleUsernameRequest{}
|
|
_ bin.Decoder = &AccountToggleUsernameRequest{}
|
|
_ bin.BareEncoder = &AccountToggleUsernameRequest{}
|
|
_ bin.BareDecoder = &AccountToggleUsernameRequest{}
|
|
)
|
|
|
|
func (t *AccountToggleUsernameRequest) Zero() bool {
|
|
if t == nil {
|
|
return true
|
|
}
|
|
if !(t.Username == "") {
|
|
return false
|
|
}
|
|
if !(t.Active == false) {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|
|
|
|
// String implements fmt.Stringer.
|
|
func (t *AccountToggleUsernameRequest) String() string {
|
|
if t == nil {
|
|
return "AccountToggleUsernameRequest(nil)"
|
|
}
|
|
type Alias AccountToggleUsernameRequest
|
|
return fmt.Sprintf("AccountToggleUsernameRequest%+v", Alias(*t))
|
|
}
|
|
|
|
// FillFrom fills AccountToggleUsernameRequest from given interface.
|
|
func (t *AccountToggleUsernameRequest) FillFrom(from interface {
|
|
GetUsername() (value string)
|
|
GetActive() (value bool)
|
|
}) {
|
|
t.Username = from.GetUsername()
|
|
t.Active = from.GetActive()
|
|
}
|
|
|
|
// TypeID returns type id in TL schema.
|
|
//
|
|
// See https://core.telegram.org/mtproto/TL-tl#remarks.
|
|
func (*AccountToggleUsernameRequest) TypeID() uint32 {
|
|
return AccountToggleUsernameRequestTypeID
|
|
}
|
|
|
|
// TypeName returns name of type in TL schema.
|
|
func (*AccountToggleUsernameRequest) TypeName() string {
|
|
return "account.toggleUsername"
|
|
}
|
|
|
|
// TypeInfo returns info about TL type.
|
|
func (t *AccountToggleUsernameRequest) TypeInfo() tdp.Type {
|
|
typ := tdp.Type{
|
|
Name: "account.toggleUsername",
|
|
ID: AccountToggleUsernameRequestTypeID,
|
|
}
|
|
if t == nil {
|
|
typ.Null = true
|
|
return typ
|
|
}
|
|
typ.Fields = []tdp.Field{
|
|
{
|
|
Name: "Username",
|
|
SchemaName: "username",
|
|
},
|
|
{
|
|
Name: "Active",
|
|
SchemaName: "active",
|
|
},
|
|
}
|
|
return typ
|
|
}
|
|
|
|
// Encode implements bin.Encoder.
|
|
func (t *AccountToggleUsernameRequest) Encode(b *bin.Buffer) error {
|
|
if t == nil {
|
|
return fmt.Errorf("can't encode account.toggleUsername#58d6b376 as nil")
|
|
}
|
|
b.PutID(AccountToggleUsernameRequestTypeID)
|
|
return t.EncodeBare(b)
|
|
}
|
|
|
|
// EncodeBare implements bin.BareEncoder.
|
|
func (t *AccountToggleUsernameRequest) EncodeBare(b *bin.Buffer) error {
|
|
if t == nil {
|
|
return fmt.Errorf("can't encode account.toggleUsername#58d6b376 as nil")
|
|
}
|
|
b.PutString(t.Username)
|
|
b.PutBool(t.Active)
|
|
return nil
|
|
}
|
|
|
|
// Decode implements bin.Decoder.
|
|
func (t *AccountToggleUsernameRequest) Decode(b *bin.Buffer) error {
|
|
if t == nil {
|
|
return fmt.Errorf("can't decode account.toggleUsername#58d6b376 to nil")
|
|
}
|
|
if err := b.ConsumeID(AccountToggleUsernameRequestTypeID); err != nil {
|
|
return fmt.Errorf("unable to decode account.toggleUsername#58d6b376: %w", err)
|
|
}
|
|
return t.DecodeBare(b)
|
|
}
|
|
|
|
// DecodeBare implements bin.BareDecoder.
|
|
func (t *AccountToggleUsernameRequest) DecodeBare(b *bin.Buffer) error {
|
|
if t == nil {
|
|
return fmt.Errorf("can't decode account.toggleUsername#58d6b376 to nil")
|
|
}
|
|
{
|
|
value, err := b.String()
|
|
if err != nil {
|
|
return fmt.Errorf("unable to decode account.toggleUsername#58d6b376: field username: %w", err)
|
|
}
|
|
t.Username = value
|
|
}
|
|
{
|
|
value, err := b.Bool()
|
|
if err != nil {
|
|
return fmt.Errorf("unable to decode account.toggleUsername#58d6b376: field active: %w", err)
|
|
}
|
|
t.Active = value
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetUsername returns value of Username field.
|
|
func (t *AccountToggleUsernameRequest) GetUsername() (value string) {
|
|
if t == nil {
|
|
return
|
|
}
|
|
return t.Username
|
|
}
|
|
|
|
// GetActive returns value of Active field.
|
|
func (t *AccountToggleUsernameRequest) GetActive() (value bool) {
|
|
if t == nil {
|
|
return
|
|
}
|
|
return t.Active
|
|
}
|
|
|
|
// AccountToggleUsername invokes method account.toggleUsername#58d6b376 returning error if any.
|
|
// Activate or deactivate a purchased fragment.com¹ username associated to the currently
|
|
// logged-in user.
|
|
//
|
|
// Links:
|
|
// 1. https://fragment.com
|
|
//
|
|
// Possible errors:
|
|
//
|
|
// 400 USERNAMES_ACTIVE_TOO_MUCH: The maximum number of active usernames was reached.
|
|
// 400 USERNAME_INVALID: The provided username is not valid.
|
|
// 400 USERNAME_NOT_MODIFIED: The username was not modified.
|
|
//
|
|
// See https://core.telegram.org/method/account.toggleUsername for reference.
|
|
func (c *Client) AccountToggleUsername(ctx context.Context, request *AccountToggleUsernameRequest) (bool, error) {
|
|
var result BoolBox
|
|
|
|
if err := c.rpc.Invoke(ctx, request, &result); err != nil {
|
|
return false, err
|
|
}
|
|
_, ok := result.Bool.(*BoolTrue)
|
|
return ok, nil
|
|
}
|