-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChatFMX.Frame.Message.pas
1206 lines (1111 loc) · 36.5 KB
/
ChatFMX.Frame.Message.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
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit ChatFMX.Frame.Message;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, FMX.Objects, FMX.Controls.Presentation, FMX.Memo.Types,
FMX.ScrollBox, FMX.Memo, VK.Entity.Message, VK.Entity.PushSettings, VK.API,
VK.Entity.Conversation, FMX.Memo.Style, System.Messaging, FMX.Ani,
VK.Entity.Media, VK.Types, ChatFMX.Frame.Attachment.AudioMessage,
ChatFMX.Frame.Attachment.Audio, ChatFMX.Frame.Attachment.Document,
VK.Entity.Geo, ChatFMX.Frame.Attachment.Geo,
ChatFMX.Frame.Attachment.ReplyMessage, VK.Entity.Common.ExtendedList,
VK.Entity.Keyboard, ChatFMX.Classes, System.Threading,
ChatFMX.Frame.Message.Base;
type
TMessageSubType = (stNone, stGift, stMoneyTransfer, stMoneyRequest);
TFrameMessage = class(TFrameMessageBase)
LayoutLeft: TLayout;
RectangleBG: TRectangle;
LayoutLeftTop: TLayout;
CircleAvatar: TCircle;
LayoutRight: TLayout;
PathSelected: TPath;
LayoutClient: TLayout;
LayoutFrom: TLayout;
LabelFrom: TLabel;
LabelTime: TLabel;
MemoText: TMemo;
LayoutRightTop: TLayout;
RectangleUnread: TRectangle;
LayoutContent: TLayout;
FlowLayoutMedia: TFlowLayout;
LayoutSelectedIcon: TLayout;
LayoutUpdated: TLayout;
LabelUpdated: TLabel;
LabelMessageType: TLabel;
RectangleGiftBG: TRectangle;
LayoutFwdMessages: TLayout;
LayoutDeleted: TLayout;
LabelMesDeleted: TLabel;
LabelRestoreMessage: TLabel;
RectangleFlash: TRectangle;
ButtonFavorite: TButton;
ButtonEdit: TButton;
ButtonReply: TButton;
procedure MemoTextChange(Sender: TObject);
procedure MemoTextResize(Sender: TObject);
procedure FrameResize(Sender: TObject);
procedure FrameMouseEnter(Sender: TObject);
procedure FrameMouseLeave(Sender: TObject);
procedure LabelFromMouseEnter(Sender: TObject);
procedure LabelFromMouseLeave(Sender: TObject);
procedure FrameMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure MemoTextMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure MemoTextExit(Sender: TObject);
procedure MemoTextMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
procedure FlowLayoutMediaResize(Sender: TObject);
procedure LayoutFwdMessagesResize(Sender: TObject);
procedure LabelRestoreMessageClick(Sender: TObject);
procedure ButtonFavoriteClick(Sender: TObject);
private
FText: string;
FFromText: string;
FImageUrl: string;
FImageFile: string;
FMouseFrame: Boolean;
FIsSelfMessage: Boolean;
FIsCanEdit: Boolean;
FIsUnread: Boolean;
FIsImportant: Boolean;
FIsSelected: Boolean;
FWasSelectedText: Boolean;
FOnSelectedChanged: TNotifyEvent;
FUpdateTime: TDateTime;
FIsGift: Boolean;
FCanAnswer: Boolean;
FFromSex: TVkSex;
FMessageSubType: TMessageSubType;
FChatInfo: TChatInfo;
FIsPinned: Boolean;
FIsDeleted: Boolean;
FConversationMessageId: Int64;
FOnReplyMessageClick: TNotifyEvent;
procedure FOnAttachSelect(Sender: TObject);
procedure SetText(const Value: string);
procedure SetFromText(const Value: string);
procedure SetImageUrl(const Value: string);
procedure FOnReadyImage(const Sender: TObject; const M: TMessage);
procedure SetMouseFrame(const Value: Boolean);
procedure SetIsSelfMessage(const Value: Boolean);
procedure SetIsCanEdit(const Value: Boolean);
procedure SetIsUnread(const Value: Boolean);
procedure SetIsImportant(const Value: Boolean);
procedure SetIsSelected(const Value: Boolean);
procedure SetOnSelectedChanged(const Value: TNotifyEvent);
procedure CreatePhotos(Items: TVkAttachmentArray);
procedure ClearMedia;
procedure RecalcMedia;
procedure CreateAutioMessages(Items: TVkAttachmentArray; Msg: TVkMessage);
procedure CreateSticker(Items: TVkAttachmentArray);
procedure CreateVideos(Items: TVkAttachmentArray);
procedure CreateAudios(Items: TVkAttachmentArray);
procedure CreateDocs(Items: TVkAttachmentArray);
procedure CreateGeo(Value: TVkGeo);
procedure SetUpdateTime(const Value: TDateTime);
procedure CreateReplyMessage(Item: TVkMessage; Data: TVkEntityExtendedList<TVkMessage>);
procedure SetIsGift(const Value: Boolean);
procedure CreateGift(Items: TVkAttachmentArray; Msg: TVkMessage);
procedure SetCanAnswer(const Value: Boolean);
procedure CreateFwdMessages(Items: TArray<TVkMessage>; Data: TVkEntityExtendedList<TVkMessage>);
procedure CreateLinks(Items: TVkAttachmentArray);
procedure CreatePosts(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
procedure SetFromSex(const Value: TVkSex);
procedure CreateCalls(Items: TVkAttachmentArray);
procedure BroadcastVisible(const Value: Boolean);
procedure CreateAlbums(Items: TVkAttachmentArray);
procedure CreateMarket(Items: TVkAttachmentArray);
procedure CreateMoney(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
procedure SetMessageSubType(const Value: TMessageSubType);
procedure UpdateSubType;
procedure UpdateImportant;
procedure FOnPhotosClick(Sender: TObject);
{$IFDEF ADAPTIVE}
procedure FOnPhotosTap(Sender: TObject; const Point: TPointF);
{$ENDIF}
function CollectPhotosFrom(const PhotoId: string; out Items: TArray<string>; out Index: Integer): Boolean;
procedure CreateGraffiti(Items: TVkAttachmentArray);
procedure CreatePoll(Items: TVkAttachmentArray);
procedure SetChatInfo(const Value: TChatInfo);
procedure CreateAudioPlaylists(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
procedure CreateKeyborad(Keyboard: TVkKeyboard);
procedure SetIsPinned(const Value: Boolean);
procedure SetIsDeleted(const Value: Boolean);
procedure CreateStories(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
procedure FOnReplyMessageAttachClick(Sender: TObject);
procedure SetOnReplyMessageClick(const Value: TNotifyEvent);
procedure ClearAttachments;
procedure UpdateMessageActions;
protected
procedure SetVisibility(const Value: Boolean); override;
procedure SetDate(const Value: TDateTime); override;
public
constructor Create(AOwner: TComponent; AVK: TCustomVK); override;
destructor Destroy; override;
procedure Fill(Item: TVkMessage; Data: TVkEntityExtendedList<TVkMessage>; AChatInfo: TChatInfo);
property Text: string read FText write SetText;
property FromText: string read FFromText write SetFromText;
property ImageUrl: string read FImageUrl write SetImageUrl;
property MouseFrame: Boolean read FMouseFrame write SetMouseFrame;
property IsSelfMessage: Boolean read FIsSelfMessage write SetIsSelfMessage;
property IsCanEdit: Boolean read FIsCanEdit write SetIsCanEdit;
property IsUnread: Boolean read FIsUnread write SetIsUnread;
property IsImportant: Boolean read FIsImportant write SetIsImportant;
property IsSelected: Boolean read FIsSelected write SetIsSelected;
property OnSelectedChanged: TNotifyEvent read FOnSelectedChanged write SetOnSelectedChanged;
property UpdateTime: TDateTime read FUpdateTime write SetUpdateTime;
property IsGift: Boolean read FIsGift write SetIsGift;
property ChatCanAnswer: Boolean read FCanAnswer write SetCanAnswer;
property FromSex: TVkSex read FFromSex write SetFromSex;
property MessageSubType: TMessageSubType read FMessageSubType write SetMessageSubType;
property ChatInfo: TChatInfo read FChatInfo write SetChatInfo;
property IsPinned: Boolean read FIsPinned write SetIsPinned;
property ConversationMessageId: Int64 read FConversationMessageId;
property IsDeleted: Boolean read FIsDeleted write SetIsDeleted;
procedure UpdateFlags(ChangeType: TVkFlagsChangeType; Flags: TVkMessageFlags);
property OnReplyMessageClick: TNotifyEvent read FOnReplyMessageClick write SetOnReplyMessageClick;
procedure UpdateVisibility;
procedure Flash; override;
end;
implementation
uses
System.Math, System.DateUtils, VK.Entity.Profile, VK.Entity.Group,
ChatFMX.PreviewManager, ChatFMX.Frame.Attachment.Photo, ChatFMX.Utils,
ChatFMX.Frame.Attachment.Sticker, ChatFMX.Frame.Attachment.Video,
ChatFMX.Frame.Attachment.Gift, ChatFMX.Frame.Attachment.Message,
ChatFMX.Frame.Attachment.Link, ChatFMX.Frame.Attachment.Wall,
ChatFMX.Frame.Attachment.Call, ChatFMX.Frame.Attachment,
ChatFMX.Frame.Attachment.Album, ChatFMX.Frame.Attachment.Market,
ChatFMX.Frame.Attachment.Money, ChatFMX.Frame.Window.Photo,
ChatFMX.Frame.Attachment.Graffiti, ChatFMX.Frame.Attachment.Poll,
ChatFMX.Frame.Attachment.AudioPlaylist, ChatFMX.Frame.Attachment.Keyboard,
ChatFMX.Frame.Attachment.Story;
{$R *.fmx}
procedure TFrameMessage.BroadcastVisible(const Value: Boolean);
begin
for var Control in LayoutClient.Controls do
if Control is TFrameAttachment then
(Control as TFrameAttachment).SetVisibility(Value);
for var Control in FlowLayoutMedia.Controls do
if Control is TFrameAttachment then
(Control as TFrameAttachment).SetVisibility(Value);
for var Control in LayoutFwdMessages.Controls do
if Control is TFrameAttachment then
(Control as TFrameAttachment).SetVisibility(Value);
end;
procedure TFrameMessage.ClearMedia;
begin
FlowLayoutMedia.BeginUpdate;
try
while FlowLayoutMedia.ControlsCount > 0 do
FlowLayoutMedia.Controls[0].Free;
finally
FlowLayoutMedia.EndUpdate;
end;
RecalcMedia;
end;
procedure TFrameMessage.RecalcMedia;
begin
var H: Single := 0;
if ((FlowLayoutMedia.ControlsCount = 1) and (
(FlowLayoutMedia.Controls[0] is TFrameAttachmentPhoto) or
(FlowLayoutMedia.Controls[0] is TFrameAttachmentVideo))) then
begin
var Control := FlowLayoutMedia.Controls[0];
var D := Control.Height / Control.Width;
var DH := Control.Width / Control.Height;
Control.Width := Min(347, FlowLayoutMedia.Width);
Control.Height := Control.Width * D;
if (Control is TFrameAttachmentVideo) then
begin
if (Control as TFrameAttachmentVideo).IsCircle then
begin
Control.Width := Min(216, FlowLayoutMedia.Width);
Control.Height := Min(216, FlowLayoutMedia.Width);
end
else if not (Control as TFrameAttachmentVideo).ShowCaption then
begin
(Control as TFrameAttachmentVideo).ShowCaption := True;
Control.Height := Control.Width * D +
(Control as TFrameAttachmentVideo).LayoutCaption.Height;
end;
end;
if Control.Height > 300 then
begin
Control.Height := 300;
Control.Width := Control.Height * DH;
end;
H := Max(Control.Position.Y + Control.Height, H);
end
else
for var Control in FlowLayoutMedia.Controls do
begin
if Control.Width > FlowLayoutMedia.Width then
begin
var D := Control.Height / Control.Width;
Control.Width := FlowLayoutMedia.Width;
Control.Height := Control.Width * D;
end;
H := Max(Control.Position.Y + Control.Height, H);
end;
if FlowLayoutMedia.Height <> H then
begin
FlowLayoutMedia.Height := H;
FrameResize(nil);
end;
end;
constructor TFrameMessage.Create(AOwner: TComponent; AVK: TCustomVK);
begin
inherited Create(AOwner, AVK);
MessageSubType := stNone;
{$IFDEF ADAPTIVE}
LayoutSelectedIcon.Visible := False;
LayoutLeft.Width := 51;
LayoutRight.Visible := False;
RectangleUnread.Margins.Left := 54;
RectangleUnread.Margins.Right := 0;
CircleAvatar.Margins.Right := 7;
MemoText.HitTest := False;
{$ENDIF}
RectangleBG.Visible := False;
RectangleUnread.Visible := False;
PathSelected.Visible := False;
MemoText.DisableDisappear := True;
MouseFrame := False;
IsSelected := False;
Text := '';
IsGift := False;
FIsDeleted := False;
LayoutDeleted.Visible := False;
LayoutFwdMessages.Visible := False;
ClearMedia;
end;
destructor TFrameMessage.Destroy;
begin
TPreview.Instance.Unsubscribe(FOnReadyImage);
inherited;
end;
procedure TFrameMessage.ButtonFavoriteClick(Sender: TObject);
begin
var MsgId: Int64;
var Mark: Boolean := not IsImportant;
TTask.Run(
procedure
begin
VK.Messages.MarkAsImportant(MsgId, MessageId, Mark);
end);
end;
procedure TFrameMessage.ClearAttachments;
begin
LayoutClient.BeginUpdate;
try
for var i := Pred(LayoutClient.ControlsCount) to 0 do
if LayoutClient.Controls[i] is TFrameAttachment then
LayoutClient.Controls[i].Free;
finally
LayoutClient.EndUpdate;
end;
end;
procedure TFrameMessage.Fill(Item: TVkMessage; Data: TVkEntityExtendedList<TVkMessage>; AChatInfo: TChatInfo);
begin
MessageId := Item.Id;
TagFloat := MessageId;
FConversationMessageId := Item.ConversationMessageId;
IsPinned := Item.PinnedAt <> 0;
ChatInfo := AChatInfo;
ChatCanAnswer := ChatInfo.IsCanWrite;
Text := Item.Text;
Date := Item.Date;
ImageUrl := '';
IsSelfMessage := Item.FromId = VK.UserId;
IsCanEdit := HoursBetween(Now, Item.Date) < 24;
IsImportant := Item.Important;
IsUnread := False;
UpdateTime := Item.UpdateTime;
IsGift := False;
//Clear
ClearMedia;
ClearAttachments;
LayoutFwdMessages.Visible := False;
LayoutFwdMessages.Tag := 0;
var P2P := ChatInfo.IsP2P;
IsUnread := Item.Id > ChatInfo.OutRead;
if PeerIdIsUser(Item.FromId) then
begin
var User: TVkProfile;
if Data.GetProfileById(Item.FromId, User) then
begin
if P2P then
FromText := User.FirstName
else
FromText := User.FullName;
FromSex := User.Sex;
ImageUrl := User.Photo50;
end;
end
else
begin
var Group: TVkGroup;
if Data.GetGroupById(Item.FromId, Group) then
begin
FromText := Group.Name;
ImageUrl := Group.Photo50;
end;
end;
// BeginUpdate;
try
if Assigned(Item.ReplyMessage) then
CreateReplyMessage(Item.ReplyMessage, Data);
if Length(Item.Attachments) > 0 then
begin
CreatePhotos(Item.Attachments);
CreateVideos(Item.Attachments);
CreateAudios(Item.Attachments);
CreateAlbums(Item.Attachments);
CreateDocs(Item.Attachments);
CreateAutioMessages(Item.Attachments, Item);
CreateSticker(Item.Attachments);
CreateGift(Item.Attachments, Item);
CreateLinks(Item.Attachments);
CreatePosts(Item.Attachments, Data);
CreateCalls(Item.Attachments);
CreateMarket(Item.Attachments);
CreateMoney(Item.Attachments, Data);
CreateGraffiti(Item.Attachments);
CreatePoll(Item.Attachments);
CreateAudioPlaylists(Item.Attachments, Data);
CreateStories(Item.Attachments, Data);
RecalcMedia;
end;
if Assigned(Item.Geo) then
CreateGeo(Item.Geo);
if Length(Item.FwdMessages) > 0 then
CreateFwdMessages(Item.FwdMessages, Data);
if Assigned(Item.Keyboard) then
CreateKeyborad(Item.Keyboard);
except
// EndUpdate;
end;
RecalcSize;
end;
procedure TFrameMessage.CreateKeyborad(Keyboard: TVkKeyboard);
begin
var Frame := TFrameAttachmentKeyboard.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Keyboard);
Frame.PeerId := ChatInfo.PeerId;
end;
procedure TFrameMessage.CreatePosts(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Wall then
begin
var Frame := TFrameAttachmentWall.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Wall, Data);
end;
end;
procedure TFrameMessage.CreateAudioPlaylists(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.AudioPlaylist then
begin
var Frame := TFrameAttachmentAudioPlaylist.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.AudioPlaylist, Data);
end;
end;
procedure TFrameMessage.CreateStories(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Story then
begin
var Frame := TFrameAttachmentStory.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Story, Data);
end;
end;
procedure TFrameMessage.CreateAlbums(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Album then
begin
var Frame := TFrameAttachmentAlbum.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Album);
end;
end;
procedure TFrameMessage.CreateMarket(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Market then
begin
var Frame := TFrameAttachmentMarket.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Market);
end;
end;
procedure TFrameMessage.CreateGraffiti(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Graffiti then
begin
var Frame := TFrameAttachmentGraffiti.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Graffiti);
end;
end;
procedure TFrameMessage.CreatePoll(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Poll then
begin
var Frame := TFrameAttachmentPoll.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Poll);
end;
end;
procedure TFrameMessage.CreateMoney(Items: TVkAttachmentArray; Data: TVkEntityExtendedList<TVkMessage>);
begin
for var Item in Items do
if Item.&Type in [TVkAttachmentType.MoneyTransfer, TVkAttachmentType.MoneyRequest] then
begin
var Frame := TFrameAttachmentMoney.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
case Item.&Type of
TVkAttachmentType.MoneyTransfer:
begin
Frame.Fill(Item.MoneyTransfer, Data);
MessageSubType := stMoneyTransfer;
end;
TVkAttachmentType.MoneyRequest:
begin
Frame.Fill(Item.MoneyRequest, Data);
MessageSubType := stMoneyRequest;
end;
end;
end;
end;
procedure TFrameMessage.CreateFwdMessages(Items: TArray<TVkMessage>; Data: TVkEntityExtendedList<TVkMessage>);
begin
for var Item in Items do
begin
var Frame := TFrameAttachmentMessage.Create(LayoutFwdMessages, VK);
Frame.OnSelect := FOnAttachSelect;
Frame.Parent := LayoutFwdMessages;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item, Data, ChatInfo, True);
end;
LayoutFwdMessages.Visible := True;
LayoutFwdMessages.Tag := 1;
LayoutFwdMessages.RecalcSize;
end;
procedure TFrameMessage.CreateReplyMessage(Item: TVkMessage; Data: TVkEntityExtendedList<TVkMessage>);
begin
var Frame := TFrameAttachmentReplyMessage.Create(LayoutClient, VK);
Frame.OnSelect := FOnAttachSelect;
Frame.Parent := LayoutClient;
Frame.Align := TAlignLayout.MostTop;
Frame.Fill(Item, Data);
Frame.OnClick := FOnReplyMessageAttachClick;
end;
procedure TFrameMessage.FOnReplyMessageAttachClick(Sender: TObject);
begin
if Assigned(FOnReplyMessageClick) then
FOnReplyMessageClick(Sender);
end;
procedure TFrameMessage.Flash;
begin
RectangleFlash.Opacity := 1;
TAnimator.AnimateFloatDelay(RectangleFlash, 'Opacity', 0, 0.1, 3);
end;
procedure TFrameMessage.FlowLayoutMediaResize(Sender: TObject);
begin
RecalcMedia;
end;
procedure TFrameMessage.CreateGeo(Value: TVkGeo);
begin
var Frame := TFrameAttachmentGeo.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Value);
end;
function TFrameMessage.CollectPhotosFrom(const PhotoId: string; out Items: TArray<string>; out Index: Integer): Boolean;
begin
SetLength(Items, FlowLayoutMedia.ControlsCount);
Index := 0;
if Length(Items) <= 0 then
Exit(False);
var i := 0;
for var Control in FlowLayoutMedia.Controls do
if Control is TFrameAttachmentPhoto then
begin
var Id := (Control as TFrameAttachmentPhoto).Id;
Items[i] := Id;
if Id = PhotoId then
Index := i;
Inc(i);
end;
SetLength(Items, i);
Result := True;
end;
procedure TFrameMessage.FOnPhotosClick(Sender: TObject);
var
Frame: TFrameAttachmentPhoto absolute Sender;
begin
if not (Sender is TFrameAttachmentPhoto) then
Exit;
var Items: TArray<string>;
var CurrentIndex: Integer;
if CollectPhotosFrom(Frame.Id, Items, CurrentIndex) then
begin
var Form := Application.MainForm;
with TFrameWindowPhoto.Create(Form, VK) do
begin
Parent := Form;
Align := TAlignLayout.Contents;
Fill(Items, CurrentIndex);
ShowFrame;
end;
end;
end;
{$IFDEF ADAPTIVE}
procedure TFrameMessage.FOnPhotosTap(Sender: TObject; const Point: TPointF);
begin
FOnPhotosClick(Sender);
end;
{$ENDIF}
procedure TFrameMessage.CreatePhotos(Items: TVkAttachmentArray);
begin
for var Item in Items do
begin
if Item.&Type = TVkAttachmentType.Photo then
begin
var Frame := TFrameAttachmentPhoto.Create(FlowLayoutMedia, VK);
Frame.Parent := FlowLayoutMedia;
{$IFDEF ADAPTIVE}
Frame.OnTap := FOnPhotosTap;
{$ELSE}
Frame.OnClick := FOnPhotosClick;
{$ENDIF}
Frame.Fill(Item.Photo);
end;
if (Item.&Type = TVkAttachmentType.Doc) and (Assigned(Item.Doc.Preview)) then
begin
var Frame := TFrameAttachmentDocument.Create(FlowLayoutMedia, VK);
Frame.Parent := FlowLayoutMedia;
Frame.Fill(Item.Doc, True);
end;
end;
end;
procedure TFrameMessage.CreateVideos(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Video then
begin
var Frame := TFrameAttachmentVideo.Create(FlowLayoutMedia, VK);
Frame.Parent := FlowLayoutMedia;
Frame.Fill(Item.Video);
end;
end;
procedure TFrameMessage.CreateGift(Items: TVkAttachmentArray; Msg: TVkMessage);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Gift then
begin
IsGift := True;
var Frame := TFrameAttachmentGift.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Gift, Msg, ChatCanAnswer);
end;
end;
procedure TFrameMessage.CreateSticker(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Sticker then
begin
var Frame := TFrameAttachmentSticker.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Sticker);
end;
end;
procedure TFrameMessage.CreateAutioMessages(Items: TVkAttachmentArray; Msg: TVkMessage);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.AudioMessage then
begin
var Frame := TFrameAttachmentAudioMessage.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.AudioMessage, Msg.WasListened);
end;
end;
procedure TFrameMessage.CreateAudios(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Audio then
begin
var Frame := TFrameAttachmentAudio.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Audio);
end;
end;
procedure TFrameMessage.CreateLinks(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Link then
begin
var Frame := TFrameAttachmentLink.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Link);
end;
end;
procedure TFrameMessage.CreateDocs(Items: TVkAttachmentArray);
begin
for var Item in Items do
if (Item.&Type = TVkAttachmentType.Doc) and (not Assigned(Item.Doc.Preview)) then
begin
var Frame := TFrameAttachmentDocument.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Doc, False);
end;
end;
procedure TFrameMessage.CreateCalls(Items: TVkAttachmentArray);
begin
for var Item in Items do
if Item.&Type = TVkAttachmentType.Call then
begin
var Frame := TFrameAttachmentCall.Create(LayoutClient, VK);
Frame.Parent := LayoutClient;
Frame.Position.Y := 10000;
Frame.Align := TAlignLayout.Top;
Frame.Fill(Item.Call);
end;
end;
procedure TFrameMessage.FrameMouseEnter(Sender: TObject);
begin
MouseFrame := True;
end;
procedure TFrameMessage.FrameMouseLeave(Sender: TObject);
begin
MouseFrame := False;
end;
procedure TFrameMessage.FrameMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
{$IFNDEF ADAPTIVE}
MemoText.SelLength := 0;
IsSelected := not IsSelected;
{$ENDIF}
end;
procedure TFrameMessage.FrameResize(Sender: TObject);
begin
if IsUpdating then
Exit;
var H: Single := LayoutContent.Padding.Top + LayoutContent.Padding.Bottom;
RecalcMedia;
for var Control in LayoutClient.Controls do
if Control.IsVisible then
H := H + Control.Height + Control.Margins.Top + Control.Margins.Bottom;
H := Floor(Max(H, 52));
if Height <> H then
begin
Height := H;
if Assigned(ParentControl) then
ParentControl.RecalcSize;
end;
end;
procedure TFrameMessage.LabelFromMouseEnter(Sender: TObject);
var
Control: TLabel absolute Sender;
begin
Control.TextSettings.Font.Style := Control.TextSettings.Font.Style + [TFontStyle.fsUnderline];
end;
procedure TFrameMessage.LabelFromMouseLeave(Sender: TObject);
var
Control: TLabel absolute Sender;
begin
Control.TextSettings.Font.Style := Control.TextSettings.Font.Style - [TFontStyle.fsUnderline];
end;
procedure TFrameMessage.LabelRestoreMessageClick(Sender: TObject);
begin
TTask.Run(
procedure
begin
VK.Messages.Restore(MessageId);
end);
end;
procedure TFrameMessage.LayoutFwdMessagesResize(Sender: TObject);
begin
var H: Single := 0;
for var Control in LayoutFwdMessages.Controls do
H := Max(Control.Position.Y + Control.Height, H);
LayoutFwdMessages.Height := H;
FrameResize(nil);
end;
procedure TFrameMessage.MemoTextChange(Sender: TObject);
begin
MemoText.Height := MemoText.ContentSize.Size.Height + 1;
FrameResize(nil);
end;
procedure TFrameMessage.MemoTextExit(Sender: TObject);
begin
MemoText.SelLength := 0;
end;
procedure TFrameMessage.MemoTextMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
FWasSelectedText := MemoText.SelLength > 0;
end;
procedure TFrameMessage.MemoTextMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
if (MemoText.SelLength > 0) or FWasSelectedText then
Exit;
{$IFNDEF ADAPTIVE}
//IsSelected := not IsSelected;
FrameMouseUp(Sender, Button, Shift, X, Y);
{$ENDIF}
end;
procedure TFrameMessage.MemoTextResize(Sender: TObject);
begin
MemoTextChange(Sender);
end;
procedure TFrameMessage.SetCanAnswer(const Value: Boolean);
begin
FCanAnswer := Value;
end;
procedure TFrameMessage.SetChatInfo(const Value: TChatInfo);
begin
FChatInfo := Value;
end;
procedure TFrameMessage.SetDate(const Value: TDateTime);
begin
inherited;
LabelTime.Text := FormatDateTime('HH:nn', Date);
LabelTime.Hint := FormatDateTime('c', Date);
end;
procedure TFrameMessage.SetFromSex(const Value: TVkSex);
begin
FFromSex := Value;
UpdateSubType;
end;
procedure TFrameMessage.SetFromText(const Value: string);
begin
FFromText := Value;
LabelFrom.Text := FFromText;
end;
procedure TFrameMessage.SetImageUrl(const Value: string);
begin
FImageUrl := Value;
if not FImageUrl.IsEmpty then
TPreview.Instance.Subscribe(FImageUrl, FOnReadyImage)
else
CircleAvatar.Fill.Kind := TBrushKind.Solid;
end;
procedure TFrameMessage.SetIsCanEdit(const Value: Boolean);
begin
FIsCanEdit := Value;
end;
procedure TFrameMessage.SetIsDeleted(const Value: Boolean);
begin
FIsDeleted := Value;
LayoutDeleted.Visible := FIsDeleted;
LabelMesDeleted.Text := 'Сообщение удалено.';
if FIsDeleted then
begin
IsSelected := False;
MouseFrame := False;
end;
for var Control in LayoutClient.Controls do
if (Control <> LayoutFrom) and (Control <> LayoutDeleted) then
if FIsDeleted then
begin
if Control.Visible then
Control.Tag := 1;
Control.Visible := False;
end
else
begin
Control.Visible := Control.Tag = 1;
end;
RecalcSize;
end;
procedure TFrameMessage.SetIsGift(const Value: Boolean);
begin
FIsGift := Value;
MemoText.Visible := not FIsGift;
if FIsGift then
begin
MessageSubType := stGift;
PathSelected.Fill.Color := $FFe3d3ac;
LabelFrom.FontColor := TAlphaColorRec.White;
LabelTime.FontColor := $FFE3D3AC;
ButtonFavorite.StyleLookup := 'buttonstyle_msg_star_gift';
ButtonEdit.StyleLookup := 'buttonstyle_msg_edit_gift';
ButtonReply.StyleLookup := 'buttonstyle_msg_reply_gift';
end
else
begin
PathSelected.Fill.Color := $FF71AAEB;
LabelFrom.FontColor := $FF71AAEB;
LabelTime.FontColor := $FF828282;
ButtonFavorite.StyleLookup := 'buttonstyle_msg_star';
ButtonEdit.StyleLookup := 'buttonstyle_msg_edit';
ButtonReply.StyleLookup := 'buttonstyle_msg_reply';
end;
RectangleGiftBG.Visible := FIsGift;
UpdateImportant;
end;
procedure TFrameMessage.UpdateFlags(ChangeType: TVkFlagsChangeType; Flags: TVkMessageFlags);
begin
case ChangeType of
TVkFlagsChangeType.Replace:
begin
if (TVkMessageFlag.Deleted in Flags) or (TVkMessageFlag.DeleteForAll in Flags) then
IsDeleted := True;
if TVkMessageFlag.Spam in Flags then
begin
IsDeleted := True;
LabelMesDeleted.Text := 'Сообщение помечено как спам и удалено.';
end;
if TVkMessageFlag.Important in Flags then
IsImportant := True;
if TVkMessageFlag.Unread in Flags then
IsUnread := True;
end;
TVkFlagsChangeType.set:
begin
if (TVkMessageFlag.Deleted in Flags) or (TVkMessageFlag.DeleteForAll in Flags) then
IsDeleted := True;
if TVkMessageFlag.Spam in Flags then
begin
IsDeleted := True;
LabelMesDeleted.Text := 'Сообщение помечено как спам и удалено.';
end;
if TVkMessageFlag.Important in Flags then
IsImportant := True;
if TVkMessageFlag.Unread in Flags then
IsUnread := True;
end;
TVkFlagsChangeType.Reset:
begin
if (TVkMessageFlag.Deleted in Flags) or (TVkMessageFlag.DeleteForAll in Flags) then
IsDeleted := False;
if TVkMessageFlag.Spam in Flags then
IsDeleted := False;
if TVkMessageFlag.Important in Flags then