package tg
import (
"context"
"errors"
"fmt"
"sort"
"strings"
"go.uber.org/multierr"
"github.com/gotd/td/bin"
"github.com/gotd/td/tdjson"
"github.com/gotd/td/tdp"
"github.com/gotd/td/tgerr"
)
var (
_ = bin .Buffer {}
_ = context .Background ()
_ = fmt .Stringer (nil )
_ = strings .Builder {}
_ = errors .Is
_ = multierr .AppendInto
_ = sort .Ints
_ = tdp .Format
_ = tgerr .Error {}
_ = tdjson .Encoder {}
)
type MessagesSaveDraftRequest struct {
Flags bin .Fields
NoWebpage bool
InvertMedia bool
ReplyTo InputReplyToClass
Peer InputPeerClass
Message string
Entities []MessageEntityClass
Media InputMediaClass
}
const MessagesSaveDraftRequestTypeID = 0x7ff3b806
var (
_ bin .Encoder = &MessagesSaveDraftRequest {}
_ bin .Decoder = &MessagesSaveDraftRequest {}
_ bin .BareEncoder = &MessagesSaveDraftRequest {}
_ bin .BareDecoder = &MessagesSaveDraftRequest {}
)
func (s *MessagesSaveDraftRequest ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .NoWebpage == false ) {
return false
}
if !(s .InvertMedia == false ) {
return false
}
if !(s .ReplyTo == nil ) {
return false
}
if !(s .Peer == nil ) {
return false
}
if !(s .Message == "" ) {
return false
}
if !(s .Entities == nil ) {
return false
}
if !(s .Media == nil ) {
return false
}
return true
}
func (s *MessagesSaveDraftRequest ) String () string {
if s == nil {
return "MessagesSaveDraftRequest(nil)"
}
type Alias MessagesSaveDraftRequest
return fmt .Sprintf ("MessagesSaveDraftRequest%+v" , Alias (*s ))
}
func (s *MessagesSaveDraftRequest ) FillFrom (from interface {
GetNoWebpage () (value bool )
GetInvertMedia () (value bool )
GetReplyTo () (value InputReplyToClass , ok bool )
GetPeer () (value InputPeerClass )
GetMessage () (value string )
GetEntities () (value []MessageEntityClass , ok bool )
GetMedia () (value InputMediaClass , ok bool )
}) {
s .NoWebpage = from .GetNoWebpage ()
s .InvertMedia = from .GetInvertMedia ()
if val , ok := from .GetReplyTo (); ok {
s .ReplyTo = val
}
s .Peer = from .GetPeer ()
s .Message = from .GetMessage ()
if val , ok := from .GetEntities (); ok {
s .Entities = val
}
if val , ok := from .GetMedia (); ok {
s .Media = val
}
}
func (*MessagesSaveDraftRequest ) TypeID () uint32 {
return MessagesSaveDraftRequestTypeID
}
func (*MessagesSaveDraftRequest ) TypeName () string {
return "messages.saveDraft"
}
func (s *MessagesSaveDraftRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.saveDraft" ,
ID : MessagesSaveDraftRequestTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "NoWebpage" ,
SchemaName : "no_webpage" ,
Null : !s .Flags .Has (1 ),
},
{
Name : "InvertMedia" ,
SchemaName : "invert_media" ,
Null : !s .Flags .Has (6 ),
},
{
Name : "ReplyTo" ,
SchemaName : "reply_to" ,
Null : !s .Flags .Has (4 ),
},
{
Name : "Peer" ,
SchemaName : "peer" ,
},
{
Name : "Message" ,
SchemaName : "message" ,
},
{
Name : "Entities" ,
SchemaName : "entities" ,
Null : !s .Flags .Has (3 ),
},
{
Name : "Media" ,
SchemaName : "media" ,
Null : !s .Flags .Has (5 ),
},
}
return typ
}
func (s *MessagesSaveDraftRequest ) SetFlags () {
if !(s .NoWebpage == false ) {
s .Flags .Set (1 )
}
if !(s .InvertMedia == false ) {
s .Flags .Set (6 )
}
if !(s .ReplyTo == nil ) {
s .Flags .Set (4 )
}
if !(s .Entities == nil ) {
s .Flags .Set (3 )
}
if !(s .Media == nil ) {
s .Flags .Set (5 )
}
}
func (s *MessagesSaveDraftRequest ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.saveDraft#7ff3b806 as nil" )
}
b .PutID (MessagesSaveDraftRequestTypeID )
return s .EncodeBare (b )
}
func (s *MessagesSaveDraftRequest ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.saveDraft#7ff3b806 as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field flags: %w" , err )
}
if s .Flags .Has (4 ) {
if s .ReplyTo == nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field reply_to is nil" )
}
if err := s .ReplyTo .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field reply_to: %w" , err )
}
}
if s .Peer == nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field peer is nil" )
}
if err := s .Peer .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field peer: %w" , err )
}
b .PutString (s .Message )
if s .Flags .Has (3 ) {
b .PutVectorHeader (len (s .Entities ))
for idx , v := range s .Entities {
if v == nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field entities element with index %d is nil" , idx )
}
if err := v .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field entities element with index %d: %w" , idx , err )
}
}
}
if s .Flags .Has (5 ) {
if s .Media == nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field media is nil" )
}
if err := s .Media .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.saveDraft#7ff3b806: field media: %w" , err )
}
}
return nil
}
func (s *MessagesSaveDraftRequest ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.saveDraft#7ff3b806 to nil" )
}
if err := b .ConsumeID (MessagesSaveDraftRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: %w" , err )
}
return s .DecodeBare (b )
}
func (s *MessagesSaveDraftRequest ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.saveDraft#7ff3b806 to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field flags: %w" , err )
}
}
s .NoWebpage = s .Flags .Has (1 )
s .InvertMedia = s .Flags .Has (6 )
if s .Flags .Has (4 ) {
value , err := DecodeInputReplyTo (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field reply_to: %w" , err )
}
s .ReplyTo = value
}
{
value , err := DecodeInputPeer (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field peer: %w" , err )
}
s .Peer = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field message: %w" , err )
}
s .Message = value
}
if s .Flags .Has (3 ) {
headerLen , err := b .VectorHeader ()
if err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field entities: %w" , err )
}
if headerLen > 0 {
s .Entities = make ([]MessageEntityClass , 0 , headerLen %bin .PreallocateLimit )
}
for idx := 0 ; idx < headerLen ; idx ++ {
value , err := DecodeMessageEntity (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field entities: %w" , err )
}
s .Entities = append (s .Entities , value )
}
}
if s .Flags .Has (5 ) {
value , err := DecodeInputMedia (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.saveDraft#7ff3b806: field media: %w" , err )
}
s .Media = value
}
return nil
}
func (s *MessagesSaveDraftRequest ) SetNoWebpage (value bool ) {
if value {
s .Flags .Set (1 )
s .NoWebpage = true
} else {
s .Flags .Unset (1 )
s .NoWebpage = false
}
}
func (s *MessagesSaveDraftRequest ) GetNoWebpage () (value bool ) {
if s == nil {
return
}
return s .Flags .Has (1 )
}
func (s *MessagesSaveDraftRequest ) SetInvertMedia (value bool ) {
if value {
s .Flags .Set (6 )
s .InvertMedia = true
} else {
s .Flags .Unset (6 )
s .InvertMedia = false
}
}
func (s *MessagesSaveDraftRequest ) GetInvertMedia () (value bool ) {
if s == nil {
return
}
return s .Flags .Has (6 )
}
func (s *MessagesSaveDraftRequest ) SetReplyTo (value InputReplyToClass ) {
s .Flags .Set (4 )
s .ReplyTo = value
}
func (s *MessagesSaveDraftRequest ) GetReplyTo () (value InputReplyToClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (4 ) {
return value , false
}
return s .ReplyTo , true
}
func (s *MessagesSaveDraftRequest ) GetPeer () (value InputPeerClass ) {
if s == nil {
return
}
return s .Peer
}
func (s *MessagesSaveDraftRequest ) GetMessage () (value string ) {
if s == nil {
return
}
return s .Message
}
func (s *MessagesSaveDraftRequest ) SetEntities (value []MessageEntityClass ) {
s .Flags .Set (3 )
s .Entities = value
}
func (s *MessagesSaveDraftRequest ) GetEntities () (value []MessageEntityClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (3 ) {
return value , false
}
return s .Entities , true
}
func (s *MessagesSaveDraftRequest ) SetMedia (value InputMediaClass ) {
s .Flags .Set (5 )
s .Media = value
}
func (s *MessagesSaveDraftRequest ) GetMedia () (value InputMediaClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (5 ) {
return value , false
}
return s .Media , true
}
func (s *MessagesSaveDraftRequest ) MapEntities () (value MessageEntityClassArray , ok bool ) {
if !s .Flags .Has (3 ) {
return value , false
}
return MessageEntityClassArray (s .Entities ), true
}
func (c *Client ) MessagesSaveDraft (ctx context .Context , request *MessagesSaveDraftRequest ) (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
}
The pages are generated with Golds v0.6.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .