-
Notifications
You must be signed in to change notification settings - Fork 7
/
ChatFMX.Frame.MessageAction.pas
96 lines (82 loc) · 2.51 KB
/
ChatFMX.Frame.MessageAction.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
unit ChatFMX.Frame.MessageAction;
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.Objects, FMX.Controls.Presentation, VK.Entity.Message, VK.API,
VK.Entity.Conversation, VK.Entity.Common.ExtendedList, ChatFMX.Frame.Chat,
ChatFMX.Classes, ChatFMX.Frame.Message.Base;
type
TFrameMessageAction = class(TFrameMessageBase)
LabelText: TLabel;
procedure LabelTextResize(Sender: TObject);
private
FText: string;
FFromText, FMemberText: string;
procedure SetText(const Value: string);
public
procedure Fill(Item: TVkMessage; Data: TVkEntityExtendedList<TVkMessage>; ChatInfo: TChatInfo);
property Text: string read FText write SetText;
end;
implementation
uses
VK.Types, VK.Entity.Group, ChatFMX.Utils, VK.Entity.Profile;
{$R *.fmx}
procedure TFrameMessageAction.Fill(Item: TVkMessage; Data: TVkEntityExtendedList<TVkMessage>; ChatInfo: TChatInfo);
begin
MessageId := Item.Id;
TagFloat := MessageId;
FFromText := 'Кто-то';
FMemberText := '';
var P2P := ChatInfo.IsP2P;
if PeerIdIsUser(Item.FromId) then
begin
var User: TVkProfile;
if Data.GetProfileById(Abs(Item.FromId), User) then
if P2P then
FFromText := User.FirstName
else
FFromText := User.FullName;
end
else
begin
var Group: TVkGroup;
if Data.GetGroupById(Abs(Item.FromId), Group) then
FFromText := Group.Name;
end;
if PeerIdIsUser(Item.Action.MemberId) then
begin
var User: TVkProfile;
if Data.GetProfileById(Abs(Item.Action.MemberId), User) then
if P2P then
if User.FirstNameAcc.IsEmpty then
FMemberText := User.FirstName
else
FMemberText := User.FirstNameAcc
else if User.FirstNameAcc.IsEmpty then
FMemberText := User.FullName
else
FMemberText := User.FullNameAcc;
end
else
begin
var Group: TVkGroup;
if Data.GetGroupById(Abs(Item.Action.MemberId), Group) then
FMemberText := Group.Name;
end;
Text := MessageActionToText(Item.Action, Item.FromId, FFromText, FMemberText);
if Text.IsEmpty then
Text := Item.Action.Text;
end;
procedure TFrameMessageAction.LabelTextResize(Sender: TObject);
begin
Height := LabelText.Height + Padding.Top + Padding.Bottom;
end;
procedure TFrameMessageAction.SetText(const Value: string);
begin
FText := Value;
LabelText.Text := FText;
LabelText.AutoSize := False;
LabelText.AutoSize := True;
end;
end.