-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
tl_message_fwd_header_gen.go
570 lines (526 loc) · 13 KB
/
tl_message_fwd_header_gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
// Code generated by gotdgen, DO NOT EDIT.
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"
)
// 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{}
)
// MessageFwdHeader represents TL type `messageFwdHeader#5f777dce`.
// Info about a forwarded message
//
// See https://core.telegram.org/constructor/messageFwdHeader for reference.
type MessageFwdHeader struct {
// Flags, see TL conditional fields¹
//
// Links:
// 1) https://core.telegram.org/mtproto/TL-combinators#conditional-fields
Flags bin.Fields
// Whether this message was imported from a foreign chat service, click here for more
// info »¹
//
// Links:
// 1) https://core.telegram.org/api/import
Imported bool
// The ID of the user that originally sent the message
//
// Use SetFromID and GetFromID helpers.
FromID PeerClass
// The name of the user that originally sent the message
//
// Use SetFromName and GetFromName helpers.
FromName string
// When was the message originally sent
Date int
// ID of the channel message that was forwarded
//
// Use SetChannelPost and GetChannelPost helpers.
ChannelPost int
// For channels and if signatures are enabled, author of the channel message
//
// Use SetPostAuthor and GetPostAuthor helpers.
PostAuthor string
// Only for messages forwarded to the current user (inputPeerSelf), full info about the
// user/channel that originally sent the message
//
// Use SetSavedFromPeer and GetSavedFromPeer helpers.
SavedFromPeer PeerClass
// Only for messages forwarded to the current user (inputPeerSelf), ID of the message
// that was forwarded from the original user/channel
//
// Use SetSavedFromMsgID and GetSavedFromMsgID helpers.
SavedFromMsgID int
// PSA type
//
// Use SetPsaType and GetPsaType helpers.
PsaType string
}
// MessageFwdHeaderTypeID is TL type id of MessageFwdHeader.
const MessageFwdHeaderTypeID = 0x5f777dce
// Ensuring interfaces in compile-time for MessageFwdHeader.
var (
_ bin.Encoder = &MessageFwdHeader{}
_ bin.Decoder = &MessageFwdHeader{}
_ bin.BareEncoder = &MessageFwdHeader{}
_ bin.BareDecoder = &MessageFwdHeader{}
)
func (m *MessageFwdHeader) Zero() bool {
if m == nil {
return true
}
if !(m.Flags.Zero()) {
return false
}
if !(m.Imported == false) {
return false
}
if !(m.FromID == nil) {
return false
}
if !(m.FromName == "") {
return false
}
if !(m.Date == 0) {
return false
}
if !(m.ChannelPost == 0) {
return false
}
if !(m.PostAuthor == "") {
return false
}
if !(m.SavedFromPeer == nil) {
return false
}
if !(m.SavedFromMsgID == 0) {
return false
}
if !(m.PsaType == "") {
return false
}
return true
}
// String implements fmt.Stringer.
func (m *MessageFwdHeader) String() string {
if m == nil {
return "MessageFwdHeader(nil)"
}
type Alias MessageFwdHeader
return fmt.Sprintf("MessageFwdHeader%+v", Alias(*m))
}
// FillFrom fills MessageFwdHeader from given interface.
func (m *MessageFwdHeader) FillFrom(from interface {
GetImported() (value bool)
GetFromID() (value PeerClass, ok bool)
GetFromName() (value string, ok bool)
GetDate() (value int)
GetChannelPost() (value int, ok bool)
GetPostAuthor() (value string, ok bool)
GetSavedFromPeer() (value PeerClass, ok bool)
GetSavedFromMsgID() (value int, ok bool)
GetPsaType() (value string, ok bool)
}) {
m.Imported = from.GetImported()
if val, ok := from.GetFromID(); ok {
m.FromID = val
}
if val, ok := from.GetFromName(); ok {
m.FromName = val
}
m.Date = from.GetDate()
if val, ok := from.GetChannelPost(); ok {
m.ChannelPost = val
}
if val, ok := from.GetPostAuthor(); ok {
m.PostAuthor = val
}
if val, ok := from.GetSavedFromPeer(); ok {
m.SavedFromPeer = val
}
if val, ok := from.GetSavedFromMsgID(); ok {
m.SavedFromMsgID = val
}
if val, ok := from.GetPsaType(); ok {
m.PsaType = val
}
}
// TypeID returns type id in TL schema.
//
// See https://core.telegram.org/mtproto/TL-tl#remarks.
func (*MessageFwdHeader) TypeID() uint32 {
return MessageFwdHeaderTypeID
}
// TypeName returns name of type in TL schema.
func (*MessageFwdHeader) TypeName() string {
return "messageFwdHeader"
}
// TypeInfo returns info about TL type.
func (m *MessageFwdHeader) TypeInfo() tdp.Type {
typ := tdp.Type{
Name: "messageFwdHeader",
ID: MessageFwdHeaderTypeID,
}
if m == nil {
typ.Null = true
return typ
}
typ.Fields = []tdp.Field{
{
Name: "Imported",
SchemaName: "imported",
Null: !m.Flags.Has(7),
},
{
Name: "FromID",
SchemaName: "from_id",
Null: !m.Flags.Has(0),
},
{
Name: "FromName",
SchemaName: "from_name",
Null: !m.Flags.Has(5),
},
{
Name: "Date",
SchemaName: "date",
},
{
Name: "ChannelPost",
SchemaName: "channel_post",
Null: !m.Flags.Has(2),
},
{
Name: "PostAuthor",
SchemaName: "post_author",
Null: !m.Flags.Has(3),
},
{
Name: "SavedFromPeer",
SchemaName: "saved_from_peer",
Null: !m.Flags.Has(4),
},
{
Name: "SavedFromMsgID",
SchemaName: "saved_from_msg_id",
Null: !m.Flags.Has(4),
},
{
Name: "PsaType",
SchemaName: "psa_type",
Null: !m.Flags.Has(6),
},
}
return typ
}
// SetFlags sets flags for non-zero fields.
func (m *MessageFwdHeader) SetFlags() {
if !(m.Imported == false) {
m.Flags.Set(7)
}
if !(m.FromID == nil) {
m.Flags.Set(0)
}
if !(m.FromName == "") {
m.Flags.Set(5)
}
if !(m.ChannelPost == 0) {
m.Flags.Set(2)
}
if !(m.PostAuthor == "") {
m.Flags.Set(3)
}
if !(m.SavedFromPeer == nil) {
m.Flags.Set(4)
}
if !(m.SavedFromMsgID == 0) {
m.Flags.Set(4)
}
if !(m.PsaType == "") {
m.Flags.Set(6)
}
}
// Encode implements bin.Encoder.
func (m *MessageFwdHeader) Encode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageFwdHeader#5f777dce as nil")
}
b.PutID(MessageFwdHeaderTypeID)
return m.EncodeBare(b)
}
// EncodeBare implements bin.BareEncoder.
func (m *MessageFwdHeader) EncodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't encode messageFwdHeader#5f777dce as nil")
}
m.SetFlags()
if err := m.Flags.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field flags: %w", err)
}
if m.Flags.Has(0) {
if m.FromID == nil {
return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field from_id is nil")
}
if err := m.FromID.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field from_id: %w", err)
}
}
if m.Flags.Has(5) {
b.PutString(m.FromName)
}
b.PutInt(m.Date)
if m.Flags.Has(2) {
b.PutInt(m.ChannelPost)
}
if m.Flags.Has(3) {
b.PutString(m.PostAuthor)
}
if m.Flags.Has(4) {
if m.SavedFromPeer == nil {
return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field saved_from_peer is nil")
}
if err := m.SavedFromPeer.Encode(b); err != nil {
return fmt.Errorf("unable to encode messageFwdHeader#5f777dce: field saved_from_peer: %w", err)
}
}
if m.Flags.Has(4) {
b.PutInt(m.SavedFromMsgID)
}
if m.Flags.Has(6) {
b.PutString(m.PsaType)
}
return nil
}
// Decode implements bin.Decoder.
func (m *MessageFwdHeader) Decode(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageFwdHeader#5f777dce to nil")
}
if err := b.ConsumeID(MessageFwdHeaderTypeID); err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: %w", err)
}
return m.DecodeBare(b)
}
// DecodeBare implements bin.BareDecoder.
func (m *MessageFwdHeader) DecodeBare(b *bin.Buffer) error {
if m == nil {
return fmt.Errorf("can't decode messageFwdHeader#5f777dce to nil")
}
{
if err := m.Flags.Decode(b); err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field flags: %w", err)
}
}
m.Imported = m.Flags.Has(7)
if m.Flags.Has(0) {
value, err := DecodePeer(b)
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field from_id: %w", err)
}
m.FromID = value
}
if m.Flags.Has(5) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field from_name: %w", err)
}
m.FromName = value
}
{
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field date: %w", err)
}
m.Date = value
}
if m.Flags.Has(2) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field channel_post: %w", err)
}
m.ChannelPost = value
}
if m.Flags.Has(3) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field post_author: %w", err)
}
m.PostAuthor = value
}
if m.Flags.Has(4) {
value, err := DecodePeer(b)
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field saved_from_peer: %w", err)
}
m.SavedFromPeer = value
}
if m.Flags.Has(4) {
value, err := b.Int()
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field saved_from_msg_id: %w", err)
}
m.SavedFromMsgID = value
}
if m.Flags.Has(6) {
value, err := b.String()
if err != nil {
return fmt.Errorf("unable to decode messageFwdHeader#5f777dce: field psa_type: %w", err)
}
m.PsaType = value
}
return nil
}
// SetImported sets value of Imported conditional field.
func (m *MessageFwdHeader) SetImported(value bool) {
if value {
m.Flags.Set(7)
m.Imported = true
} else {
m.Flags.Unset(7)
m.Imported = false
}
}
// GetImported returns value of Imported conditional field.
func (m *MessageFwdHeader) GetImported() (value bool) {
if m == nil {
return
}
return m.Flags.Has(7)
}
// SetFromID sets value of FromID conditional field.
func (m *MessageFwdHeader) SetFromID(value PeerClass) {
m.Flags.Set(0)
m.FromID = value
}
// GetFromID returns value of FromID conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetFromID() (value PeerClass, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(0) {
return value, false
}
return m.FromID, true
}
// SetFromName sets value of FromName conditional field.
func (m *MessageFwdHeader) SetFromName(value string) {
m.Flags.Set(5)
m.FromName = value
}
// GetFromName returns value of FromName conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetFromName() (value string, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(5) {
return value, false
}
return m.FromName, true
}
// GetDate returns value of Date field.
func (m *MessageFwdHeader) GetDate() (value int) {
if m == nil {
return
}
return m.Date
}
// SetChannelPost sets value of ChannelPost conditional field.
func (m *MessageFwdHeader) SetChannelPost(value int) {
m.Flags.Set(2)
m.ChannelPost = value
}
// GetChannelPost returns value of ChannelPost conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetChannelPost() (value int, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(2) {
return value, false
}
return m.ChannelPost, true
}
// SetPostAuthor sets value of PostAuthor conditional field.
func (m *MessageFwdHeader) SetPostAuthor(value string) {
m.Flags.Set(3)
m.PostAuthor = value
}
// GetPostAuthor returns value of PostAuthor conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetPostAuthor() (value string, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(3) {
return value, false
}
return m.PostAuthor, true
}
// SetSavedFromPeer sets value of SavedFromPeer conditional field.
func (m *MessageFwdHeader) SetSavedFromPeer(value PeerClass) {
m.Flags.Set(4)
m.SavedFromPeer = value
}
// GetSavedFromPeer returns value of SavedFromPeer conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetSavedFromPeer() (value PeerClass, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(4) {
return value, false
}
return m.SavedFromPeer, true
}
// SetSavedFromMsgID sets value of SavedFromMsgID conditional field.
func (m *MessageFwdHeader) SetSavedFromMsgID(value int) {
m.Flags.Set(4)
m.SavedFromMsgID = value
}
// GetSavedFromMsgID returns value of SavedFromMsgID conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetSavedFromMsgID() (value int, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(4) {
return value, false
}
return m.SavedFromMsgID, true
}
// SetPsaType sets value of PsaType conditional field.
func (m *MessageFwdHeader) SetPsaType(value string) {
m.Flags.Set(6)
m.PsaType = value
}
// GetPsaType returns value of PsaType conditional field and
// boolean which is true if field was set.
func (m *MessageFwdHeader) GetPsaType() (value string, ok bool) {
if m == nil {
return
}
if !m.Flags.Has(6) {
return value, false
}
return m.PsaType, true
}