-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwbot_model.pas
987 lines (852 loc) · 25.7 KB
/
wbot_model.pas
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
{
_ _ _ _____
| | | || | |_ _| /|
| | | || |___ ___ | | / |__
| |/\| || _ |/ _ \| | /_ /
| / \ || (_) | (_) | | | /
|__/\__||_____|\___/|_| |/
}
unit WBot_Model;
{$i wbot.inc}
interface
uses
Classes, SysUtils, Graphics, Contnrs, fpjson;
type
TActionType = (
atNone,
// Response
atGetAllChats, atGetAllContacts, atGetAllGroups, atGetBatteryLevel,
atGetQrCode, atGetUnreadMessages,
// Connection
atConnected, atConnecting, atDisconnected, atDisconnecting, atDestroy,
atDestroying, atInitializing, atInitialized
);
TNotificationEvent = procedure(const ASender: TObject;
const AAction: TActionType; const AData: string) of object;
TErrorEvent = procedure(const ASender: TObject; const AError: string;
const AAdditionalInformation: string) of object;
EWBot = Exception;
{ TModel }
TModel = class
private
FName: string;
public
constructor Create;
function ActionType: TActionType;
procedure LoadJSON(const AJSON: string); virtual;
function SaveJSON(const ABeautiful: boolean = False): string; virtual;
published
property Name: string read FName write FName;
end;
TModelClass = class of TModel;
{ TModelList }
TModelList = class(TModel)
private
FItems: TObjectList;
function GetItem(const AIndex: NativeInt): TModel;
public
destructor Destroy; override;
procedure AfterConstruction; override;
procedure Add(const AItem: TModel);
procedure Clear;
function Count: NativeInt;
function ItemClass: TModelClass; virtual; abstract;
property Items[const AIndex: NativeInt]: TModel read GetItem; default;
end;
{ TGModelList }
generic TGModelList<T: class> = class(TModelList)
private
type
TGModelListEnumerator = class
private
FList: TGModelList;
FPosition: NativeInt;
function GetCurrent: T;
public
constructor Create(const AList: TGModelList);
function MoveNext: boolean;
public
property Current: T read GetCurrent;
end;
private
function GetItem(const AIndex: NativeInt): T;
public
procedure Add(const AItem: T);
function GetEnumerator: TGModelListEnumerator;
function ItemClass: TModelClass; override;
property Items[const AIndex: NativeInt]: T read GetItem; default;
end;
{ TResponsel }
TResponse = class(TModel)
private
FResult: string;
published
property Result: string read FResult write FResult;
end;
{ TQrCode }
TQrCode = class(TModel)
private
FQrCode: string;
FQrCodeImage: TPicture;
protected
procedure ProcessQRCodeImage;
public
destructor Destroy; override;
procedure AfterConstruction; override;
property QrCodeImage: TPicture read FQrCodeImage;
published
property _QrCode: string read FQrCode write FQrCode;
end;
{ TResponseQrCode }
TResponseQrCode = class(TModel)
private
FResult: TQrCode;
public
destructor Destroy; override;
procedure AfterConstruction; override;
procedure LoadJSON(const AJSON: string); reintroduce;
published
property Result: TQrCode read FResult;
end;
{ TResponseConsole }
TResponseConsole = class(TResponse)
end;
{ TResponseBattery }
TResponseBattery = class(TResponse)
end;
{ TResponseGroups }
TResponseGroups = class(TModel)
private
FResult: TStringList;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property Result: TStringList read FResult;
end;
{ TContact}
TContact = class(TModel)
private
FFormattedName: string;
FId: string;
FIsMe: boolean;
FIsMyContact: boolean;
FIsPSA: boolean;
FIsUser: boolean;
FIsWAContact: boolean;
FLabels: TStrings;
FMsgs: string;
FPushname: string;
FSectionHeader: string;
FStatusMute: boolean;
FType: String;
FVerifiedName: string;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property FormattedName: string read FFormattedName write FFormattedName;
property SectionHeader: string read FSectionHeader write FSectionHeader;
property Id: string read FId write FId;
property Name: string read FName write FName;
property Pushname: string read FPushname write FPushname;
property VerifiedName: string read FVerifiedName write FVerifiedName;
property IsUser: boolean read FIsUser write FIsUser;
property StatusMute: boolean read FStatusMute write FStatusMute;
property Labels: TStrings read FLabels;
property IsMe: boolean read FIsMe write FIsMe;
property IsMyContact: boolean read FIsMyContact write FIsMyContact;
property IsPSA: boolean read FIsPSA write FIsPSA;
property IsWAContact: boolean read FIsWAContact write FIsWAContact;
property Msgs: string read FMsgs write FMsgs;
property &type: String read FType write FType;
end;
{ TContactList }
TContactList = class(specialize TGModelList<TContact>)
end;
{ TResponseContact }
TResponseContact = class(TModel)
private
FResult: TContactList;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property Result: TContactList read FResult;
end;
// Forward
TChat = class;
{ TLastReceivedKey }
TLastReceivedKey = class(TModel)
private
FFromMe: boolean;
FId: string;
FRemote: string;
FSerialized: string;
published
property _Serialized: string read FSerialized write FSerialized;
property FromMe: boolean read FFromMe write FFromMe;
property Id: string read FId write FId;
property Remote: string read FRemote write FRemote;
end;
{ TProfilePicThumbObj }
TProfilePicThumbObj = class(TModel)
private
FEurl: string;
FId: string;
FImg: string;
FImgFull: string;
FTag: string;
published
property EUrl: string read FEurl write FEUrl;
property Id: string read FId write FId;
property Img: string read FImg write FImg;
property ImgFull: string read FImgFull write FImgFull;
property Tag: string read FTag write FTag;
end;
{ TSender }
TSender = class(TModel)
private
FFormattedName: string;
FId: string;
FIsBusiness: boolean;
FIsEnterprise: boolean;
FIsMe: boolean;
FIsMyContact: boolean;
FIsPSA: boolean;
FIsUser: boolean;
FIsWAContact: boolean;
FLabels: TStrings;
FProfilePicThumbObj: TProfilePicThumbObj;
FPushname: string;
FStatusMute: boolean;
FType: String;
FVerifiedName: string;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property ProfilePicThumbObj: TProfilePicThumbObj read FProfilePicThumbObj;
property FormattedName: string read FFormattedName write FFormattedName;
property Id: string read FId write FId;
property IsBusiness: boolean read FIsBusiness write FIsBusiness;
property IsEnterprise: boolean read FIsEnterprise write FIsEnterprise;
property IsMe: boolean read FIsMe write FIsMe;
property IsMyContact: boolean read FIsMyContact write FIsMyContact;
property IsPSA: boolean read FIsPSA write FIsPSA;
property IsUser: boolean read FIsUser write FIsUser;
property IsWAContact: boolean read FIsWAContact write FIsWAContact;
property Labels: TStrings read FLabels;
property Pushname: string read FPushname write FPushname;
property StatusMute: boolean read FStatusMute write FStatusMute;
property Name: string read FName write FName;
property VerifiedName: string read FVerifiedName write FVerifiedName;
property &Type: String read FType write FType;
end;
{ TMediaDataPreview }
TMediaDataPreview = class(TModel)
private
FBody: string;
Freleased: boolean;
F_B64: string;
F_inAutoreleasePool: boolean;
F_retainCount: NativeInt;
published
property _RetainCount: NativeInt read F_retainCount write F_RetainCount;
property _InAutoreleasePool: boolean
read F_inAutoreleasePool write F_InAutoreleasePool;
property Released: boolean read Freleased write Freleased;
property Body: string read FBody write Fbody;
property _B64: string read F_B64 write F_B64;
end;
{ TMediaData_Blob }
TMediaData_Blob = class(TModel)
private
F_Mimetype: string;
F_Url: string;
published
property _Url: string read F_Url write F_Url;
property _Mimetype: string read F_Mimetype write F_Mimetype;
end;
{ TMediaDataBlob }
TMediaDataBlob = class(TModel)
private
FReleased: boolean;
F_Blob: TMediaData_Blob;
F_InAutoreleasePool: boolean;
F_RetainCount: NativeInt;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property _RetainCount: NativeInt read F_RetainCount Write F_RetainCount;
property _InAutoreleasePool: boolean
read F_InAutoreleasePool write F_InAutoreleasePool;
property Released: boolean read FReleased write Freleased;
property _Blob: TMediaData_Blob Read F_Blob;
end;
{ TMediaData }
TMediaData = class(TModel)
private
FanimatedAsNewMsg: boolean;
FanimationDuration: extended;
FAspectRatio: extended;
FFilehash: string;
FFullHeight: NativeInt;
FfullWidth: NativeInt;
FMediaBlob: string;
FMediaStage: string;
FMimetype: string;
FPreview: TMediaDataPreview;
FSize: extended;
FType: string;
F_ListeningToSwSupport: boolean;
F_SwStreamingSupported: boolean;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property &Type: string read FType write FType;
property MediaStage: string read FMediaStage write FMediaStage;
property Size: extended read FSize write FSize;
property Filehash: string read FFilehash write FFilehash;
property Mimetype: string read FMimetype write FMimetype;
property MediaBlob: string read FMediaBlob write FMediaBlob;
property FullHeight: NativeInt read FFullHeight write FFullHeight;
property FullWidth : NativeInt read FfullWidth write FFullWidth;
property AspectRatio: extended read FAspectRatio write FaspectRatio;
property AnimationDuration: extended
read FanimationDuration write FanimationDuration;
property AnimatedAsNewMsg: boolean
read FanimatedAsNewMsg write FanimatedAsNewMsg;
property _SwStreamingSupported: boolean
read F_SwStreamingSupported write F_SwStreamingSupported;
property _ListeningToSwSupport: boolean
read F_ListeningToSwSupport write F_ListeningToSwSupport;
property Preview: TMediaDataPreview Read FPreview write FPreview;
end;
{ TMessage }
TMessage = class(TModel)
private
FAck: extended;
FBody: string;
FBroadcast: Boolean;
FCaption: string;
FChat: TChat;
FChatId: string;
FClientUrl: string;
FContent: string;
FDirectPath: string;
FFilehash: string;
FFilename: string;
FFrom: string;
FId: string;
FInvis: boolean;
FIsForwarded: boolean;
FIsGroupMsg: boolean;
FIsMedia: boolean;
FIsMMS: boolean;
FIsNewMsg: boolean;
FIsNotification: Boolean;
FIsPSA: boolean;
FLabels: TStrings;
FLat: extended;
FLng: extended;
FMediaData: TMediaData;
FMediaKey: string;
FMediaKeyTimestamp: extended;
FMentionedJidList: TStrings;
FMimetype: string;
FNotifyName: string;
FPageCount: extended;
FQuotedMsgObj: string;
FRecvFresh: boolean;
FSelf: string;
FSender: TSender;
FSize: extended;
FStar: boolean;
FSubType: string;
FT: extended;
FTimestamp: extended;
FTo: string;
FType: string;
FUploadhash: string;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property Ack: extended read FAck write FAck;
property Body: string read FBody write FBody;
property Broadcast: Boolean read FBroadcast write FBroadcast;
property Chat: TChat read FChat;
property ChatId: string read FChatId write FChatId;
property Caption: string read FCaption write FCaption;
property Content: string read FContent write FContent;
property From: string read FFrom write FFrom;
property Id: string read FId write FId;
property Invis: boolean read FInvis write FInvis;
property IsForwarded: boolean read FIsForwarded write FIsForwarded;
property IsGroupMsg: boolean read FIsGroupMsg write FIsGroupMsg;
property IsMMS: boolean read FIsMMS write FIsMMS;
property IsMedia: boolean read FIsMedia write FIsMedia;
property IsNewMsg: boolean read FIsNewMsg write FIsNewMsg;
property Lat: extended read FLat write FLat;
property Lng: extended read FLng write FLng;
property SubType: string read FSubType write FSubType;
property IsNotification: Boolean read FIsNotification write FIsNotification;
property IsPSA: boolean read FIsPSA write FIsPSA;
property Labels: TStrings read FLabels;
property MediaData: TMediaData read FMediaData;
property MentionedJidList: TStrings read FMentionedJidList;
property NotifyName: string read FNotifyName write FNotifyName;
property RecvFresh: boolean read FRecvFresh write FRecvFresh;
property Self: string read FSelf write FSelf;
property Mimetype: string read FMimetype write FMimetype;
property Filename: string read FFilename write Ffilename;
property ClientUrl: string read FClientUrl write FClientUrl;
property DirectPath: string read FDirectPath write FDirectPath;
property Filehash: string read FFilehash write FFilehash;
property Uploadhash: string read FUploadhash write FUploadhash;
property Size: extended read FSize write FSize;
property MediaKey: string read FMediaKey write FMediaKey;
property MediaKeyTimestamp: extended
read FMediaKeyTimestamp write FMediaKeyTimestamp;
property PageCount: extended read FPageCount write FPageCount;
property QuotedMsgObj: string read FQuotedMsgObj write FQuotedMsgObj;
property Sender: TSender read FSender;
property Star: boolean read FStar write FStar;
property T: extended read FT write FT;
property Timestamp: extended read FTimestamp write FTimestamp;
property &To: string read FTo write FTo;
property &Type: string read FType write FType;
end;
{ TMessageList }
TMessageList = class(specialize TGModelList<TMessage>)
end;
{ TChatStates }
TChatStates = class(TModel)
private
FTeste: string;
published
property Teste: string read FTeste write FTeste;
end;
{ TChatStatesList }
TChatStatesList = class(specialize TGModelList<TChatStates>)
end;
{ TPresence }
TPresence = class(TModel)
private
FChatstates: TChatStatesList;
FId: string;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property Chatstates: TChatStatesList read FChatstates write FChatstates;
property Id: string read FId write FId;
end;
{ TParticipants }
TParticipants = class(TModel)
private
FId: string;
FIsAdmin: boolean;
FIsSuperAdmin: boolean;
published
property Id: string read FId write FId;
property IsAdmin: boolean read FIsAdmin write FIsAdmin;
property IsSuperAdmin: boolean read FIsSuperAdmin write FIsSuperAdmin;
end;
{ TParticipantsList }
TParticipantsList = class(specialize TGModelList<TParticipants>)
end;
{ TGroupMetadata }
TGroupMetadata = class(TModel)
private
FCreation: extended;
FDesc: string;
FDescId: string;
FDescOwner: string;
FDescTime: extended;
FId: string;
FOwner: string;
FParticipants: TParticipantsList;
FPendingParticipants: TParticipantsList;
FRestrict: boolean;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property Creation: extended read FCreation write FCreation;
property Desc: string read FDesc write FDesc;
property DescId: string read FDescId write FDescId;
property DescOwner: string read FDescOwner write FDescOwner;
property DescTime: extended read FDescTime write FDescTime;
property Id: string read FId write FId;
property Owner: string read FOwner write FOwner;
property Restrict: boolean read FRestrict write FRestrict;
property Participants: TParticipantsList read FParticipants;
property PendingParticipants: TParticipantsList read FPendingParticipants;
end;
{ TChat }
TChat = class(TModel)
private
FArchive: boolean;
FContact: TContact;
FGroupMetadata: TGroupMetadata;
FId: string;
FIsAnnounceGrpRestrict: boolean;
FIsGroup: boolean;
FIsReadOnly: boolean;
FKind: String;
FKindTypeNumber: string;
FLastReceivedKey: TLastReceivedKey;
FMessages: TMessageList;
FModifyTag: Extended;
FMsgs: String;
FMuteExpiration: Extended;
FNotSpam: Boolean;
FPendingMsgs: Boolean;
FPin: Extended;
FPresence: TPresence;
FT: Extended;
FUnreadCount: Extended;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property IsAnnounceGrpRestrict: boolean
read FIsAnnounceGrpRestrict write FIsAnnounceGrpRestrict;
property GroupMetadata: TGroupMetadata read FGroupMetadata;
property Archive: boolean read FArchive write FArchive;
property Contact: TContact read FContact;
property Id: string read FId write FId;
property IsGroup: boolean read FIsGroup write FIsGroup;
property IsReadOnly: boolean read FIsReadOnly write FIsReadOnly;
property kind: string read FKind write FKind;
property KindTypeNumber: string read FKindTypeNumber write FKindTypeNumber;
property LastReceivedKey: TLastReceivedKey read FLastReceivedKey;
property Messages: TMessageList read FMessages write FMessages;
property ModifyTag: Extended read FModifyTag write FModifyTag;
property MuteExpiration: Extended read FMuteExpiration write FMuteExpiration;
property NotSpam: Boolean read FNotSpam write FNotSpam;
property PendingMsgs: Boolean read FPendingMsgs write FPendingMsgs;
property Msgs: String read FMsgs Write FMsgs;
property Pin: Extended read FPin write FPin;
property Presence: TPresence read FPresence write FPresence;
property T: Extended read FT write FT;
property UnreadCount: Extended read FUnreadCount write FUnreadCount;
end;
{ TChatList }
TChatList = class(specialize TGModelList<TChat>)
end;
{ TResponseChat }
TResponseChat = class(TModel)
private
FResult: TChatList;
public
destructor Destroy; override;
procedure AfterConstruction; override;
published
property Result: TChatList read FResult;
end;
implementation
uses
// WBot
WBot_Utils;
{ TModel }
constructor TModel.Create;
begin
inherited Create;
FName := EmptyStr;
end;
function TModel.ActionType: TActionType;
begin
Result := StringToActionType(FName);
end;
procedure TModel.LoadJSON(const AJSON: string);
var
VJSON: TJSONData;
begin
VJSON := JSONParse(AJSON);
if (Assigned(VJSON)) then
begin
try
JSONToObject(VJSON, Self);
finally
FreeAndNil(VJSON);
end;
end;
end;
function TModel.SaveJSON(const ABeautiful: boolean): string;
var
VJSON: TJSONData;
begin
Result := EmptyStr;
VJSON := ObjectToJSON(Self);
if (Assigned(VJSON)) then
begin
try
if (ABeautiful) then
begin
Result := VJSON.FormatJSON();
end
else
begin
Result := VJSON.FormatJSON(AsCompressedJSON);
end;
finally
FreeAndNil(VJSON);
end;
end;
end;
{ TModelList }
function TModelList.GetItem(const AIndex: NativeInt): TModel;
begin
Result := TModel(FItems[AIndex]);
end;
destructor TModelList.Destroy;
begin
FreeAndNil(FItems);
inherited Destroy;
end;
procedure TModelList.AfterConstruction;
begin
inherited AfterConstruction;
FItems := TObjectList.Create(True);
end;
procedure TModelList.Add(const AItem: TModel);
begin
FItems.Add(AItem);
end;
procedure TModelList.Clear;
begin
FItems.Clear;
end;
function TModelList.Count: NativeInt;
begin
Result := FItems.Count;
end;
{ TGModelList.TGModelListEnumerator }
function TGModelList.TGModelListEnumerator.GetCurrent: T;
begin
Result := FList[FPosition];
end;
constructor TGModelList.TGModelListEnumerator.Create(const AList: TGModelList);
begin
inherited Create;
FList := AList;
FPosition := -1;
end;
function TGModelList.TGModelListEnumerator.MoveNext: boolean;
begin
Inc(FPosition);
Result := FPosition < FList.Count;
end;
{ TGModelList }
function TGModelList.GetItem(const AIndex: NativeInt): T;
begin
Result := T(inherited Items[AIndex]);
end;
procedure TGModelList.Add(const AItem: T);
begin
inherited Add(AItem);
end;
function TGModelList.GetEnumerator: TGModelListEnumerator;
begin
Result := TGModelListEnumerator.Create(Self);
end;
function TGModelList.ItemClass: TModelClass;
begin
Result := T;
end;
{ TQrCode }
procedure TQrCode.ProcessQRCodeImage;
var
VStream: TMemoryStream;
begin
VStream := TMemoryStream.Create;
try
FQrCodeImage.Clear;
try
Base64ToStream(Copy(FQrCode, 23, Length(FQrCode)), VStream);
// Minimum size of an image
if (VStream.Size > 3000) then
begin
VStream.Position := 0;
FQrCodeImage.LoadFromStream(VStream);
end;
except
end;
finally
FreeAndNil(VStream);
end;
end;
destructor TQrCode.Destroy;
begin
FreeAndNil(FQrCodeImage);
inherited Destroy;
end;
procedure TQrCode.AfterConstruction;
begin
inherited AfterConstruction;
FQrCode := EmptyStr;
FQrCodeImage := TPicture.Create;
end;
{ TResponseQrCode }
destructor TResponseQrCode.Destroy;
begin
FreeAndNil(FResult);
inherited Destroy;
end;
procedure TResponseQrCode.AfterConstruction;
begin
inherited AfterConstruction;
FResult := TQrCode.Create;
end;
procedure TResponseQrCode.LoadJSON(const AJSON: string);
begin
inherited LoadJSON(AJSON);
FResult.ProcessQRCodeImage;
end;
{ TResponseGroups }
destructor TResponseGroups.Destroy;
begin
FreeAndNil(FResult);
inherited Destroy;
end;
procedure TResponseGroups.AfterConstruction;
begin
inherited AfterConstruction;
FResult := TStringList.Create;
end;
{ TContact }
destructor TContact.Destroy;
begin
FreeAndNil(FLabels);
inherited Destroy;
end;
procedure TContact.AfterConstruction;
begin
inherited AfterConstruction;
FLabels := TStringList.Create;
end;
{ TResponseContact }
destructor TResponseContact.Destroy;
begin
FreeAndNil(FResult);
inherited Destroy;
end;
procedure TResponseContact.AfterConstruction;
begin
inherited AfterConstruction;
FResult := TContactList.Create;
end;
{ TSender }
destructor TSender.Destroy;
begin
FreeAndNil(FLabels);
FreeAndNil(FProfilePicThumbObj);
inherited Destroy;
end;
procedure TSender.AfterConstruction;
begin
inherited AfterConstruction;
FLabels := TStringList.Create;
FProfilePicThumbObj := TProfilePicThumbObj.Create;
end;
{ TMediaDataBlob }
destructor TMediaDataBlob.Destroy;
begin
FreeAndNil(F_Blob);
inherited Destroy;
end;
procedure TMediaDataBlob.AfterConstruction;
begin
inherited AfterConstruction;
F_Blob := TMediaData_Blob.Create;
end;
{ TMediaData }
destructor TMediaData.Destroy;
begin
FreeAndNil(FPreview);
inherited Destroy;
end;
procedure TMediaData.AfterConstruction;
begin
inherited AfterConstruction;
FPreview := TMediaDataPreview.Create;
end;
{ TMessage }
destructor TMessage.Destroy;
begin
FreeAndNil(FChat);
FreeAndNil(FLabels);
FreeAndNil(FMentionedJidList);
FreeAndNil(FSender);
FreeAndNil(FMediaData);
inherited Destroy;
end;
procedure TMessage.AfterConstruction;
begin
inherited AfterConstruction;
FChat := TChat.Create;
FLabels := TStringList.Create;
FMentionedJidList:= TStringList.Create;
FSender := TSender.Create;
FMediaData := TMediaData.Create;
end;
{ TPresence }
destructor TPresence.Destroy;
begin
FreeAndNil(FChatstates);
inherited Destroy;
end;
procedure TPresence.AfterConstruction;
begin
inherited AfterConstruction;
FChatstates := TChatStatesList.Create;
end;
{ TGroupMetadata }
destructor TGroupMetadata.Destroy;
begin
FreeAndNil(FParticipants);
FreeAndNil(FPendingParticipants);
inherited Destroy;
end;
procedure TGroupMetadata.AfterConstruction;
begin
inherited AfterConstruction;
FParticipants := TParticipantsList.Create;
FPendingParticipants := TParticipantsList.Create;
end;
{ TChat }
destructor TChat.Destroy;
begin
FreeAndNil(FContact);
FreeAndNil(FMessages);
FreeAndNil(FLastReceivedKey);
FreeAndNil(FPresence);
FreeAndNil(FGroupMetadata);
inherited Destroy;
end;
procedure TChat.AfterConstruction;
begin
inherited AfterConstruction;
FContact := TContact.Create;
FMessages := TMessageList.Create;
FLastReceivedKey := TLastReceivedKey.Create;
FPresence := TPresence.Create;
FGroupMetadata := TGroupMetadata.Create;
end;
{ TResponseChat }
destructor TResponseChat.Destroy;
begin
FreeAndNil(FResult);
inherited Destroy;
end;
procedure TResponseChat.AfterConstruction;
begin
inherited AfterConstruction;
FResult := TChatList.Create;
end;
end.