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 MessagesSearchRequest struct {
Flags bin .Fields
Peer InputPeerClass
Q string
FromID InputPeerClass
TopMsgID int
Filter MessagesFilterClass
MinDate int
MaxDate int
OffsetID int
AddOffset int
Limit int
MaxID int
MinID int
Hash int64
}
const MessagesSearchRequestTypeID = 0xa0fda762
var (
_ bin .Encoder = &MessagesSearchRequest {}
_ bin .Decoder = &MessagesSearchRequest {}
_ bin .BareEncoder = &MessagesSearchRequest {}
_ bin .BareDecoder = &MessagesSearchRequest {}
)
func (s *MessagesSearchRequest ) Zero () bool {
if s == nil {
return true
}
if !(s .Flags .Zero ()) {
return false
}
if !(s .Peer == nil ) {
return false
}
if !(s .Q == "" ) {
return false
}
if !(s .FromID == nil ) {
return false
}
if !(s .TopMsgID == 0 ) {
return false
}
if !(s .Filter == nil ) {
return false
}
if !(s .MinDate == 0 ) {
return false
}
if !(s .MaxDate == 0 ) {
return false
}
if !(s .OffsetID == 0 ) {
return false
}
if !(s .AddOffset == 0 ) {
return false
}
if !(s .Limit == 0 ) {
return false
}
if !(s .MaxID == 0 ) {
return false
}
if !(s .MinID == 0 ) {
return false
}
if !(s .Hash == 0 ) {
return false
}
return true
}
func (s *MessagesSearchRequest ) String () string {
if s == nil {
return "MessagesSearchRequest(nil)"
}
type Alias MessagesSearchRequest
return fmt .Sprintf ("MessagesSearchRequest%+v" , Alias (*s ))
}
func (s *MessagesSearchRequest ) FillFrom (from interface {
GetPeer () (value InputPeerClass )
GetQ () (value string )
GetFromID () (value InputPeerClass , ok bool )
GetTopMsgID () (value int , ok bool )
GetFilter () (value MessagesFilterClass )
GetMinDate () (value int )
GetMaxDate () (value int )
GetOffsetID () (value int )
GetAddOffset () (value int )
GetLimit () (value int )
GetMaxID () (value int )
GetMinID () (value int )
GetHash () (value int64 )
}) {
s .Peer = from .GetPeer ()
s .Q = from .GetQ ()
if val , ok := from .GetFromID (); ok {
s .FromID = val
}
if val , ok := from .GetTopMsgID (); ok {
s .TopMsgID = val
}
s .Filter = from .GetFilter ()
s .MinDate = from .GetMinDate ()
s .MaxDate = from .GetMaxDate ()
s .OffsetID = from .GetOffsetID ()
s .AddOffset = from .GetAddOffset ()
s .Limit = from .GetLimit ()
s .MaxID = from .GetMaxID ()
s .MinID = from .GetMinID ()
s .Hash = from .GetHash ()
}
func (*MessagesSearchRequest ) TypeID () uint32 {
return MessagesSearchRequestTypeID
}
func (*MessagesSearchRequest ) TypeName () string {
return "messages.search"
}
func (s *MessagesSearchRequest ) TypeInfo () tdp .Type {
typ := tdp .Type {
Name : "messages.search" ,
ID : MessagesSearchRequestTypeID ,
}
if s == nil {
typ .Null = true
return typ
}
typ .Fields = []tdp .Field {
{
Name : "Peer" ,
SchemaName : "peer" ,
},
{
Name : "Q" ,
SchemaName : "q" ,
},
{
Name : "FromID" ,
SchemaName : "from_id" ,
Null : !s .Flags .Has (0 ),
},
{
Name : "TopMsgID" ,
SchemaName : "top_msg_id" ,
Null : !s .Flags .Has (1 ),
},
{
Name : "Filter" ,
SchemaName : "filter" ,
},
{
Name : "MinDate" ,
SchemaName : "min_date" ,
},
{
Name : "MaxDate" ,
SchemaName : "max_date" ,
},
{
Name : "OffsetID" ,
SchemaName : "offset_id" ,
},
{
Name : "AddOffset" ,
SchemaName : "add_offset" ,
},
{
Name : "Limit" ,
SchemaName : "limit" ,
},
{
Name : "MaxID" ,
SchemaName : "max_id" ,
},
{
Name : "MinID" ,
SchemaName : "min_id" ,
},
{
Name : "Hash" ,
SchemaName : "hash" ,
},
}
return typ
}
func (s *MessagesSearchRequest ) SetFlags () {
if !(s .FromID == nil ) {
s .Flags .Set (0 )
}
if !(s .TopMsgID == 0 ) {
s .Flags .Set (1 )
}
}
func (s *MessagesSearchRequest ) Encode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.search#a0fda762 as nil" )
}
b .PutID (MessagesSearchRequestTypeID )
return s .EncodeBare (b )
}
func (s *MessagesSearchRequest ) EncodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't encode messages.search#a0fda762 as nil" )
}
s .SetFlags ()
if err := s .Flags .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field flags: %w" , err )
}
if s .Peer == nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field peer is nil" )
}
if err := s .Peer .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field peer: %w" , err )
}
b .PutString (s .Q )
if s .Flags .Has (0 ) {
if s .FromID == nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field from_id is nil" )
}
if err := s .FromID .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field from_id: %w" , err )
}
}
if s .Flags .Has (1 ) {
b .PutInt (s .TopMsgID )
}
if s .Filter == nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field filter is nil" )
}
if err := s .Filter .Encode (b ); err != nil {
return fmt .Errorf ("unable to encode messages.search#a0fda762: field filter: %w" , err )
}
b .PutInt (s .MinDate )
b .PutInt (s .MaxDate )
b .PutInt (s .OffsetID )
b .PutInt (s .AddOffset )
b .PutInt (s .Limit )
b .PutInt (s .MaxID )
b .PutInt (s .MinID )
b .PutLong (s .Hash )
return nil
}
func (s *MessagesSearchRequest ) Decode (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.search#a0fda762 to nil" )
}
if err := b .ConsumeID (MessagesSearchRequestTypeID ); err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: %w" , err )
}
return s .DecodeBare (b )
}
func (s *MessagesSearchRequest ) DecodeBare (b *bin .Buffer ) error {
if s == nil {
return fmt .Errorf ("can't decode messages.search#a0fda762 to nil" )
}
{
if err := s .Flags .Decode (b ); err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field flags: %w" , err )
}
}
{
value , err := DecodeInputPeer (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field peer: %w" , err )
}
s .Peer = value
}
{
value , err := b .String ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field q: %w" , err )
}
s .Q = value
}
if s .Flags .Has (0 ) {
value , err := DecodeInputPeer (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field from_id: %w" , err )
}
s .FromID = value
}
if s .Flags .Has (1 ) {
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field top_msg_id: %w" , err )
}
s .TopMsgID = value
}
{
value , err := DecodeMessagesFilter (b )
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field filter: %w" , err )
}
s .Filter = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field min_date: %w" , err )
}
s .MinDate = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field max_date: %w" , err )
}
s .MaxDate = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field offset_id: %w" , err )
}
s .OffsetID = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field add_offset: %w" , err )
}
s .AddOffset = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field limit: %w" , err )
}
s .Limit = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field max_id: %w" , err )
}
s .MaxID = value
}
{
value , err := b .Int ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field min_id: %w" , err )
}
s .MinID = value
}
{
value , err := b .Long ()
if err != nil {
return fmt .Errorf ("unable to decode messages.search#a0fda762: field hash: %w" , err )
}
s .Hash = value
}
return nil
}
func (s *MessagesSearchRequest ) GetPeer () (value InputPeerClass ) {
if s == nil {
return
}
return s .Peer
}
func (s *MessagesSearchRequest ) GetQ () (value string ) {
if s == nil {
return
}
return s .Q
}
func (s *MessagesSearchRequest ) SetFromID (value InputPeerClass ) {
s .Flags .Set (0 )
s .FromID = value
}
func (s *MessagesSearchRequest ) GetFromID () (value InputPeerClass , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (0 ) {
return value , false
}
return s .FromID , true
}
func (s *MessagesSearchRequest ) SetTopMsgID (value int ) {
s .Flags .Set (1 )
s .TopMsgID = value
}
func (s *MessagesSearchRequest ) GetTopMsgID () (value int , ok bool ) {
if s == nil {
return
}
if !s .Flags .Has (1 ) {
return value , false
}
return s .TopMsgID , true
}
func (s *MessagesSearchRequest ) GetFilter () (value MessagesFilterClass ) {
if s == nil {
return
}
return s .Filter
}
func (s *MessagesSearchRequest ) GetMinDate () (value int ) {
if s == nil {
return
}
return s .MinDate
}
func (s *MessagesSearchRequest ) GetMaxDate () (value int ) {
if s == nil {
return
}
return s .MaxDate
}
func (s *MessagesSearchRequest ) GetOffsetID () (value int ) {
if s == nil {
return
}
return s .OffsetID
}
func (s *MessagesSearchRequest ) GetAddOffset () (value int ) {
if s == nil {
return
}
return s .AddOffset
}
func (s *MessagesSearchRequest ) GetLimit () (value int ) {
if s == nil {
return
}
return s .Limit
}
func (s *MessagesSearchRequest ) GetMaxID () (value int ) {
if s == nil {
return
}
return s .MaxID
}
func (s *MessagesSearchRequest ) GetMinID () (value int ) {
if s == nil {
return
}
return s .MinID
}
func (s *MessagesSearchRequest ) GetHash () (value int64 ) {
if s == nil {
return
}
return s .Hash
}
func (c *Client ) MessagesSearch (ctx context .Context , request *MessagesSearchRequest ) (MessagesMessagesClass , error ) {
var result MessagesMessagesBox
if err := c .rpc .Invoke (ctx , request , &result ); err != nil {
return nil , err
}
return result .Messages , 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 .