This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtl.cpp
161 lines (143 loc) · 3.33 KB
/
tl.cpp
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
#include "telegramstream.h"
#include "tlschema.h"
#include <QDebug>
using namespace TLType;
QVariant getPeerId(TObject obj)
{
switch (ID(obj)) {
case PeerUser:
return obj["user_id"];
case PeerChat:
return obj["chat_id"];
case PeerChannel:
return obj["channel_id"];
case InputUserEmpty:
return 0;
case InputUserSelf:
return 0; //TODO: current account ID
case InputUser:
return obj["user_id"];
case InputUserFromMessage:
return obj["user_id"];
case InputPeerEmpty:
return 0;
case InputPeerSelf:
return 0; //TODO: current account ID
case InputPeerChat:
return obj["chat_id"];
case InputPeerUser:
return obj["user_id"];
case InputPeerChannel:
return obj["channel_id"];
case InputPeerUserFromMessage:
return obj["user_id"];
case InputPeerChannelFromMessage:
return obj["channel_id"];
case TLType::User:
return obj["id"];
case UserEmpty:
return obj["id"];
case Chat:
return obj["id"];
case ChatEmpty:
return obj["id"];
case ChatForbidden:
return obj["id"];
case Channel:
return obj["id"];
case ChannelForbidden:
return obj["id"];
default:
qWarning() << "[getPeerId] Invalid object." << ID(obj);
return QVariant();
}
}
TObject getInputPeer(TObject obj)
{
switch (ID(obj)) {
case ChatEmpty:
case Chat:
case ChatForbidden:
{
TOBJECT(v, InputPeerChat);
v["chat_id"] = obj["id"];
return v;
}
case Channel:
case ChannelForbidden:
{
TOBJECT(v, InputPeerChannel);
v["channel_id"] = obj["id"];
v["access_hash"] = obj["access_hash"];
return v;
}
case TLType::User:
case UserEmpty:
{
TOBJECT(v, InputPeerUser);
v["user_id"] = obj["id"];
v["access_hash"] = obj["access_hash"];
return v;
}
default:
{
qWarning() << "[getInputPeer] Empty object." << ID(obj);
TOBJECT(v, InputPeerEmpty);
return v;
}
}
}
TObject getInputMessage(TObject obj)
{
switch (ID(obj)) {
case MessageEmpty:
case Message:
case MessageService:
{
TOBJECT(v, InputMessageID);
v["id"] = obj["id"];
return v;
}
case MessageReplyHeader:
{
TOBJECT(v, InputMessageReplyTo);
v["id"] = obj["id"];
return v;
}
default:
qWarning() << "[getInputMessage] Invalid object." << ID(obj);
return TObject();
}
}
qint32 commonPeerType(TObject peer)
{
switch (ID(peer)) {
case InputUserEmpty:
case InputUserSelf:
case InputUser:
case InputUserFromMessage:
case TLType::User:
case UserEmpty:
case PeerUser:
case InputPeerEmpty:
case InputPeerSelf:
case InputPeerUser:
case InputPeerUserFromMessage:
return TLType::User;
case Chat:
case ChatEmpty:
case ChatForbidden:
case Channel:
case ChannelForbidden:
case PeerChat:
case PeerChannel:
case InputPeerChat:
case InputPeerChannel:
case InputPeerChannelFromMessage:
return Chat;
}
}
bool peersEqual(TObject peer1, TObject peer2)
{
return commonPeerType(peer1) == commonPeerType(peer2) && getPeerId(peer1) == getPeerId(peer2);
}