@overpod/mcp-telegram 1.26.0 → 1.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -1
- package/dist/rate-limiter.d.ts +1 -1
- package/dist/rate-limiter.js +8 -8
- package/dist/telegram-client.d.ts +6 -470
- package/dist/telegram-client.js +17 -874
- package/dist/telegram-helpers.d.ts +470 -0
- package/dist/telegram-helpers.js +870 -0
- package/dist/tools/account.js +7 -7
- package/dist/tools/boosts.js +4 -4
- package/dist/tools/chats.js +7 -7
- package/dist/tools/contacts.js +3 -3
- package/dist/tools/extras.js +3 -3
- package/dist/tools/group-calls.js +3 -3
- package/dist/tools/messages.js +17 -17
- package/dist/tools/quick-replies.js +3 -3
- package/dist/tools/reactions.js +2 -2
- package/dist/tools/shared.d.ts +3 -3
- package/dist/tools/shared.js +8 -7
- package/dist/tools/stars.js +3 -3
- package/dist/tools/stickers.js +5 -5
- package/dist/tools/stories.js +5 -5
- package/package.json +1 -1
- package/dist/__tests__/admin-log.test.d.ts +0 -1
- package/dist/__tests__/admin-log.test.js +0 -41
- package/dist/__tests__/approve-join-request.test.d.ts +0 -1
- package/dist/__tests__/approve-join-request.test.js +0 -107
- package/dist/__tests__/boosts.test.d.ts +0 -1
- package/dist/__tests__/boosts.test.js +0 -310
- package/dist/__tests__/broadcast-stats.test.d.ts +0 -1
- package/dist/__tests__/broadcast-stats.test.js +0 -172
- package/dist/__tests__/business-chat-links.test.d.ts +0 -1
- package/dist/__tests__/business-chat-links.test.js +0 -102
- package/dist/__tests__/get-message-buttons.test.d.ts +0 -1
- package/dist/__tests__/get-message-buttons.test.js +0 -122
- package/dist/__tests__/group-calls.test.d.ts +0 -1
- package/dist/__tests__/group-calls.test.js +0 -503
- package/dist/__tests__/inline-query-send.test.d.ts +0 -1
- package/dist/__tests__/inline-query-send.test.js +0 -94
- package/dist/__tests__/inline-query.test.d.ts +0 -1
- package/dist/__tests__/inline-query.test.js +0 -115
- package/dist/__tests__/megagroup-stats.test.d.ts +0 -1
- package/dist/__tests__/megagroup-stats.test.js +0 -166
- package/dist/__tests__/press-button.test.d.ts +0 -1
- package/dist/__tests__/press-button.test.js +0 -123
- package/dist/__tests__/quick-replies.test.d.ts +0 -1
- package/dist/__tests__/quick-replies.test.js +0 -245
- package/dist/__tests__/rate-limiter.test.d.ts +0 -1
- package/dist/__tests__/rate-limiter.test.js +0 -81
- package/dist/__tests__/reactions.test.d.ts +0 -1
- package/dist/__tests__/reactions.test.js +0 -23
- package/dist/__tests__/set-chat-permissions-merge.test.d.ts +0 -1
- package/dist/__tests__/set-chat-permissions-merge.test.js +0 -107
- package/dist/__tests__/set-chat-reactions.test.d.ts +0 -1
- package/dist/__tests__/set-chat-reactions.test.js +0 -129
- package/dist/__tests__/stars-status.test.d.ts +0 -1
- package/dist/__tests__/stars-status.test.js +0 -205
- package/dist/__tests__/stars-transactions.test.d.ts +0 -1
- package/dist/__tests__/stars-transactions.test.js +0 -82
- package/dist/__tests__/stories.test.d.ts +0 -1
- package/dist/__tests__/stories.test.js +0 -361
- package/dist/__tests__/toggle-anti-spam.test.d.ts +0 -1
- package/dist/__tests__/toggle-anti-spam.test.js +0 -80
- package/dist/__tests__/toggle-channel-signatures.test.d.ts +0 -1
- package/dist/__tests__/toggle-channel-signatures.test.js +0 -80
- package/dist/__tests__/toggle-forum-mode.test.d.ts +0 -1
- package/dist/__tests__/toggle-forum-mode.test.js +0 -80
- package/dist/__tests__/toggle-prehistory-hidden.test.d.ts +0 -1
- package/dist/__tests__/toggle-prehistory-hidden.test.js +0 -80
- package/dist/__tests__/tools/shared.test.d.ts +0 -1
- package/dist/__tests__/tools/shared.test.js +0 -110
- package/dist/__tests__/updates.test.d.ts +0 -1
- package/dist/__tests__/updates.test.js +0 -221
|
@@ -0,0 +1,870 @@
|
|
|
1
|
+
import { Api } from "telegram/tl/index.js";
|
|
2
|
+
export function describeAdminLogAction(action) {
|
|
3
|
+
const prefix = "ChannelAdminLogEventAction";
|
|
4
|
+
const raw = action.className.startsWith(prefix) ? action.className.slice(prefix.length) : action.className;
|
|
5
|
+
return raw
|
|
6
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
7
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
8
|
+
.toLowerCase();
|
|
9
|
+
}
|
|
10
|
+
export function describeAdminLogDetails(action, describeUser) {
|
|
11
|
+
if (action instanceof Api.ChannelAdminLogEventActionChangeTitle) {
|
|
12
|
+
return `"${action.prevValue}" → "${action.newValue}"`;
|
|
13
|
+
}
|
|
14
|
+
if (action instanceof Api.ChannelAdminLogEventActionChangeAbout) {
|
|
15
|
+
return `description changed`;
|
|
16
|
+
}
|
|
17
|
+
if (action instanceof Api.ChannelAdminLogEventActionChangeUsername) {
|
|
18
|
+
return `@${action.prevValue || "-"} → @${action.newValue || "-"}`;
|
|
19
|
+
}
|
|
20
|
+
if (action instanceof Api.ChannelAdminLogEventActionUpdatePinned) {
|
|
21
|
+
return `message #${action.message instanceof Api.Message ? action.message.id : "?"}`;
|
|
22
|
+
}
|
|
23
|
+
if (action instanceof Api.ChannelAdminLogEventActionEditMessage) {
|
|
24
|
+
return `message #${action.newMessage instanceof Api.Message ? action.newMessage.id : "?"}`;
|
|
25
|
+
}
|
|
26
|
+
if (action instanceof Api.ChannelAdminLogEventActionDeleteMessage) {
|
|
27
|
+
return `message #${action.message instanceof Api.Message ? action.message.id : "?"}`;
|
|
28
|
+
}
|
|
29
|
+
if (action instanceof Api.ChannelAdminLogEventActionParticipantInvite) {
|
|
30
|
+
const p = action.participant;
|
|
31
|
+
return `invited user ${"userId" in p ? describeUser(p.userId) : "?"}`;
|
|
32
|
+
}
|
|
33
|
+
if (action instanceof Api.ChannelAdminLogEventActionParticipantToggleBan) {
|
|
34
|
+
const p = action.newParticipant;
|
|
35
|
+
if (p instanceof Api.ChannelParticipantBanned) {
|
|
36
|
+
const uid = p.peer instanceof Api.PeerUser ? p.peer.userId : undefined;
|
|
37
|
+
return `banned user ${uid ? describeUser(uid) : "?"}`;
|
|
38
|
+
}
|
|
39
|
+
return `unbanned user ${"userId" in p ? describeUser(p.userId) : "?"}`;
|
|
40
|
+
}
|
|
41
|
+
if (action instanceof Api.ChannelAdminLogEventActionParticipantToggleAdmin) {
|
|
42
|
+
const p = action.newParticipant;
|
|
43
|
+
return `admin rights changed for ${"userId" in p ? describeUser(p.userId) : "?"}`;
|
|
44
|
+
}
|
|
45
|
+
if (action instanceof Api.ChannelAdminLogEventActionToggleSlowMode) {
|
|
46
|
+
return `${action.prevValue}s → ${action.newValue}s`;
|
|
47
|
+
}
|
|
48
|
+
if (action instanceof Api.ChannelAdminLogEventActionToggleInvites) {
|
|
49
|
+
return `invites ${action.newValue ? "enabled" : "disabled"}`;
|
|
50
|
+
}
|
|
51
|
+
if (action instanceof Api.ChannelAdminLogEventActionToggleSignatures) {
|
|
52
|
+
return `signatures ${action.newValue ? "enabled" : "disabled"}`;
|
|
53
|
+
}
|
|
54
|
+
if (action instanceof Api.ChannelAdminLogEventActionTogglePreHistoryHidden) {
|
|
55
|
+
return `pre-history hidden: ${action.newValue}`;
|
|
56
|
+
}
|
|
57
|
+
if (action instanceof Api.ChannelAdminLogEventActionChangeHistoryTTL) {
|
|
58
|
+
return `${action.prevValue}s → ${action.newValue}s`;
|
|
59
|
+
}
|
|
60
|
+
if (action instanceof Api.ChannelAdminLogEventActionChangeStickerSet) {
|
|
61
|
+
return `sticker set changed`;
|
|
62
|
+
}
|
|
63
|
+
if (action instanceof Api.ChannelAdminLogEventActionChangeLinkedChat) {
|
|
64
|
+
return `${action.prevValue.toString()} → ${action.newValue.toString()}`;
|
|
65
|
+
}
|
|
66
|
+
if (action instanceof Api.ChannelAdminLogEventActionStopPoll) {
|
|
67
|
+
return `poll in message #${action.message instanceof Api.Message ? action.message.id : "?"}`;
|
|
68
|
+
}
|
|
69
|
+
if (action instanceof Api.ChannelAdminLogEventActionSendMessage) {
|
|
70
|
+
return `message #${action.message instanceof Api.Message ? action.message.id : "?"}`;
|
|
71
|
+
}
|
|
72
|
+
if (action instanceof Api.ChannelAdminLogEventActionCreateTopic) {
|
|
73
|
+
return `topic "${action.topic instanceof Api.ForumTopic ? action.topic.title : "?"}"`;
|
|
74
|
+
}
|
|
75
|
+
if (action instanceof Api.ChannelAdminLogEventActionDeleteTopic) {
|
|
76
|
+
return `topic "${action.topic instanceof Api.ForumTopic ? action.topic.title : "?"}"`;
|
|
77
|
+
}
|
|
78
|
+
if (action instanceof Api.ChannelAdminLogEventActionEditTopic) {
|
|
79
|
+
return `topic "${action.newTopic instanceof Api.ForumTopic ? action.newTopic.title : "?"}"`;
|
|
80
|
+
}
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
export function reactionToEmoji(reaction) {
|
|
84
|
+
if (reaction instanceof Api.ReactionEmoji)
|
|
85
|
+
return reaction.emoticon;
|
|
86
|
+
if (reaction instanceof Api.ReactionCustomEmoji)
|
|
87
|
+
return `custom:${reaction.documentId.toString()}`;
|
|
88
|
+
if (reaction instanceof Api.ReactionPaid)
|
|
89
|
+
return "⭐";
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
function absValue(v) {
|
|
93
|
+
return { current: v?.current ?? 0, previous: v?.previous ?? 0 };
|
|
94
|
+
}
|
|
95
|
+
function compactGraph(g) {
|
|
96
|
+
if (g instanceof Api.StatsGraphAsync)
|
|
97
|
+
return { type: "async", token: g.token };
|
|
98
|
+
if (g instanceof Api.StatsGraphError)
|
|
99
|
+
return { type: "error", error: g.error };
|
|
100
|
+
if (g instanceof Api.StatsGraph) {
|
|
101
|
+
let parsed = g.json?.data;
|
|
102
|
+
if (typeof parsed === "string") {
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(parsed);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// leave raw string
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { type: "data", data: parsed, zoomToken: g.zoomToken };
|
|
111
|
+
}
|
|
112
|
+
const any = g;
|
|
113
|
+
if (typeof any.token === "string")
|
|
114
|
+
return { type: "async", token: any.token };
|
|
115
|
+
if (typeof any.error === "string")
|
|
116
|
+
return { type: "error", error: any.error };
|
|
117
|
+
return { type: "data", data: any.json?.data, zoomToken: any.zoomToken };
|
|
118
|
+
}
|
|
119
|
+
export function summarizeMegagroupStats(stats, includeGraphs) {
|
|
120
|
+
const summary = {
|
|
121
|
+
period: {
|
|
122
|
+
minDate: stats.period?.minDate ?? 0,
|
|
123
|
+
maxDate: stats.period?.maxDate ?? 0,
|
|
124
|
+
},
|
|
125
|
+
members: absValue(stats.members),
|
|
126
|
+
messages: absValue(stats.messages),
|
|
127
|
+
viewers: absValue(stats.viewers),
|
|
128
|
+
posters: absValue(stats.posters),
|
|
129
|
+
topPosters: (stats.topPosters ?? []).map((p) => ({
|
|
130
|
+
userId: p.userId?.toString() ?? "",
|
|
131
|
+
messages: p.messages,
|
|
132
|
+
avgChars: p.avgChars,
|
|
133
|
+
})),
|
|
134
|
+
topAdmins: (stats.topAdmins ?? []).map((a) => ({
|
|
135
|
+
userId: a.userId?.toString() ?? "",
|
|
136
|
+
deleted: a.deleted,
|
|
137
|
+
kicked: a.kicked,
|
|
138
|
+
banned: a.banned,
|
|
139
|
+
})),
|
|
140
|
+
topInviters: (stats.topInviters ?? []).map((i) => ({
|
|
141
|
+
userId: i.userId?.toString() ?? "",
|
|
142
|
+
invitations: i.invitations,
|
|
143
|
+
})),
|
|
144
|
+
};
|
|
145
|
+
if (includeGraphs) {
|
|
146
|
+
summary.graphs = {
|
|
147
|
+
growth: compactGraph(stats.growthGraph),
|
|
148
|
+
members: compactGraph(stats.membersGraph),
|
|
149
|
+
newMembersBySource: compactGraph(stats.newMembersBySourceGraph),
|
|
150
|
+
languages: compactGraph(stats.languagesGraph),
|
|
151
|
+
messages: compactGraph(stats.messagesGraph),
|
|
152
|
+
actions: compactGraph(stats.actionsGraph),
|
|
153
|
+
topHours: compactGraph(stats.topHoursGraph),
|
|
154
|
+
weekdays: compactGraph(stats.weekdaysGraph),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
return summary;
|
|
158
|
+
}
|
|
159
|
+
export function summarizeBroadcastStats(stats, includeGraphs) {
|
|
160
|
+
const enabled = stats.enabledNotifications;
|
|
161
|
+
const part = enabled?.part ?? 0;
|
|
162
|
+
const total = enabled?.total ?? 0;
|
|
163
|
+
const percent = total > 0 ? (part / total) * 100 : 0;
|
|
164
|
+
const summary = {
|
|
165
|
+
period: {
|
|
166
|
+
minDate: stats.period?.minDate ?? 0,
|
|
167
|
+
maxDate: stats.period?.maxDate ?? 0,
|
|
168
|
+
},
|
|
169
|
+
followers: absValue(stats.followers),
|
|
170
|
+
viewsPerPost: absValue(stats.viewsPerPost),
|
|
171
|
+
sharesPerPost: absValue(stats.sharesPerPost),
|
|
172
|
+
reactionsPerPost: absValue(stats.reactionsPerPost),
|
|
173
|
+
viewsPerStory: absValue(stats.viewsPerStory),
|
|
174
|
+
sharesPerStory: absValue(stats.sharesPerStory),
|
|
175
|
+
reactionsPerStory: absValue(stats.reactionsPerStory),
|
|
176
|
+
enabledNotifications: { part, total, percent },
|
|
177
|
+
recentPostsInteractions: (stats.recentPostsInteractions ?? []).map((p) => {
|
|
178
|
+
if (p instanceof Api.PostInteractionCountersStory) {
|
|
179
|
+
return {
|
|
180
|
+
kind: "story",
|
|
181
|
+
storyId: p.storyId,
|
|
182
|
+
views: p.views,
|
|
183
|
+
forwards: p.forwards,
|
|
184
|
+
reactions: p.reactions,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
const m = p;
|
|
188
|
+
return {
|
|
189
|
+
kind: "message",
|
|
190
|
+
msgId: m.msgId,
|
|
191
|
+
views: m.views,
|
|
192
|
+
forwards: m.forwards,
|
|
193
|
+
reactions: m.reactions,
|
|
194
|
+
};
|
|
195
|
+
}),
|
|
196
|
+
};
|
|
197
|
+
if (includeGraphs) {
|
|
198
|
+
summary.graphs = {
|
|
199
|
+
growth: compactGraph(stats.growthGraph),
|
|
200
|
+
followers: compactGraph(stats.followersGraph),
|
|
201
|
+
mute: compactGraph(stats.muteGraph),
|
|
202
|
+
topHours: compactGraph(stats.topHoursGraph),
|
|
203
|
+
interactions: compactGraph(stats.interactionsGraph),
|
|
204
|
+
ivInteractions: compactGraph(stats.ivInteractionsGraph),
|
|
205
|
+
viewsBySource: compactGraph(stats.viewsBySourceGraph),
|
|
206
|
+
newFollowersBySource: compactGraph(stats.newFollowersBySourceGraph),
|
|
207
|
+
languages: compactGraph(stats.languagesGraph),
|
|
208
|
+
reactionsByEmotion: compactGraph(stats.reactionsByEmotionGraph),
|
|
209
|
+
storyInteractions: compactGraph(stats.storyInteractionsGraph),
|
|
210
|
+
storyReactionsByEmotion: compactGraph(stats.storyReactionsByEmotionGraph),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return summary;
|
|
214
|
+
}
|
|
215
|
+
const BANNED_RIGHT_FLAGS = [
|
|
216
|
+
"sendMessages",
|
|
217
|
+
"sendMedia",
|
|
218
|
+
"sendStickers",
|
|
219
|
+
"sendGifs",
|
|
220
|
+
"sendPolls",
|
|
221
|
+
"sendInline",
|
|
222
|
+
"embedLinks",
|
|
223
|
+
"changeInfo",
|
|
224
|
+
"inviteUsers",
|
|
225
|
+
"pinMessages",
|
|
226
|
+
];
|
|
227
|
+
// Newer granular flags not exposed in ChatPermissions input but must be preserved from currentRights
|
|
228
|
+
const EXTRA_BANNED_RIGHT_FLAGS = [
|
|
229
|
+
"sendGames",
|
|
230
|
+
"manageTopics",
|
|
231
|
+
"sendPhotos",
|
|
232
|
+
"sendVideos",
|
|
233
|
+
"sendRoundvideos",
|
|
234
|
+
"sendAudios",
|
|
235
|
+
"sendVoices",
|
|
236
|
+
"sendDocs",
|
|
237
|
+
"sendPlain",
|
|
238
|
+
];
|
|
239
|
+
export function mergeBannedRights(current, permissions) {
|
|
240
|
+
const result = {};
|
|
241
|
+
for (const flag of BANNED_RIGHT_FLAGS) {
|
|
242
|
+
const userValue = permissions[flag];
|
|
243
|
+
if (userValue !== undefined) {
|
|
244
|
+
result[flag] = !userValue;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
result[flag] = Boolean(current?.[flag]);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// Preserve newer granular flags from existing rights so they are not silently cleared
|
|
251
|
+
for (const flag of EXTRA_BANNED_RIGHT_FLAGS) {
|
|
252
|
+
result[flag] = Boolean(current?.[flag]);
|
|
253
|
+
}
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
export function describeKeyboardButton(button, row, col) {
|
|
257
|
+
const base = {
|
|
258
|
+
row,
|
|
259
|
+
col,
|
|
260
|
+
type: button.className,
|
|
261
|
+
label: "text" in button && typeof button.text === "string" ? button.text : "",
|
|
262
|
+
};
|
|
263
|
+
if (button instanceof Api.KeyboardButtonCallback) {
|
|
264
|
+
base.data = Buffer.from(button.data).toString("base64");
|
|
265
|
+
if (button.requiresPassword)
|
|
266
|
+
base.requiresPassword = true;
|
|
267
|
+
return base;
|
|
268
|
+
}
|
|
269
|
+
if (button instanceof Api.KeyboardButtonUrl) {
|
|
270
|
+
base.url = button.url;
|
|
271
|
+
return base;
|
|
272
|
+
}
|
|
273
|
+
if (button instanceof Api.KeyboardButtonUrlAuth) {
|
|
274
|
+
base.url = button.url;
|
|
275
|
+
base.buttonId = button.buttonId;
|
|
276
|
+
return base;
|
|
277
|
+
}
|
|
278
|
+
if (button instanceof Api.KeyboardButtonSwitchInline) {
|
|
279
|
+
base.switchQuery = button.query;
|
|
280
|
+
base.samePeer = Boolean(button.samePeer);
|
|
281
|
+
return base;
|
|
282
|
+
}
|
|
283
|
+
if (button instanceof Api.KeyboardButtonWebView || button instanceof Api.KeyboardButtonSimpleWebView) {
|
|
284
|
+
base.url = button.url;
|
|
285
|
+
return base;
|
|
286
|
+
}
|
|
287
|
+
if (button instanceof Api.KeyboardButtonUserProfile) {
|
|
288
|
+
base.userId = button.userId?.toString();
|
|
289
|
+
return base;
|
|
290
|
+
}
|
|
291
|
+
if (button instanceof Api.KeyboardButtonRequestPoll) {
|
|
292
|
+
if (button.quiz)
|
|
293
|
+
base.quiz = true;
|
|
294
|
+
return base;
|
|
295
|
+
}
|
|
296
|
+
if (button instanceof Api.KeyboardButtonRequestPeer) {
|
|
297
|
+
base.buttonId = button.buttonId;
|
|
298
|
+
return base;
|
|
299
|
+
}
|
|
300
|
+
if (button instanceof Api.KeyboardButtonCopy) {
|
|
301
|
+
base.copyText = button.copyText;
|
|
302
|
+
return base;
|
|
303
|
+
}
|
|
304
|
+
return base;
|
|
305
|
+
}
|
|
306
|
+
export function peerToCompact(peer) {
|
|
307
|
+
if (!peer)
|
|
308
|
+
return undefined;
|
|
309
|
+
if (peer instanceof Api.PeerUser)
|
|
310
|
+
return { kind: "user", id: peer.userId.toString() };
|
|
311
|
+
if (peer instanceof Api.PeerChat)
|
|
312
|
+
return { kind: "chat", id: peer.chatId.toString() };
|
|
313
|
+
if (peer instanceof Api.PeerChannel)
|
|
314
|
+
return { kind: "channel", id: peer.channelId.toString() };
|
|
315
|
+
return undefined;
|
|
316
|
+
}
|
|
317
|
+
function summarizeMessageForUpdates(msg) {
|
|
318
|
+
if (msg instanceof Api.MessageEmpty)
|
|
319
|
+
return null;
|
|
320
|
+
const peer = peerToCompact(msg.peerId);
|
|
321
|
+
if (!peer)
|
|
322
|
+
return null;
|
|
323
|
+
const fromId = peerToCompact(msg.fromId);
|
|
324
|
+
const date = msg.date ?? 0;
|
|
325
|
+
if (msg instanceof Api.Message) {
|
|
326
|
+
return { id: msg.id, peer, fromId, date, text: msg.message ?? "", isService: false };
|
|
327
|
+
}
|
|
328
|
+
if (msg instanceof Api.MessageService) {
|
|
329
|
+
return {
|
|
330
|
+
id: msg.id,
|
|
331
|
+
peer,
|
|
332
|
+
fromId,
|
|
333
|
+
date,
|
|
334
|
+
text: `[${msg.action?.className ?? "service"}]`,
|
|
335
|
+
isService: true,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
function collectDeletedMessageIds(updates) {
|
|
341
|
+
const out = [];
|
|
342
|
+
for (const u of updates) {
|
|
343
|
+
if (u instanceof Api.UpdateDeleteMessages) {
|
|
344
|
+
out.push({ messageIds: u.messages });
|
|
345
|
+
}
|
|
346
|
+
else if (u instanceof Api.UpdateDeleteChannelMessages) {
|
|
347
|
+
out.push({
|
|
348
|
+
peer: { kind: "channel", id: u.channelId.toString() },
|
|
349
|
+
messageIds: u.messages,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
export function summarizeUpdatesDifference(diff, cursor) {
|
|
356
|
+
if (diff instanceof Api.updates.DifferenceEmpty) {
|
|
357
|
+
return {
|
|
358
|
+
state: { pts: cursor.pts, qts: cursor.qts, date: diff.date, seq: diff.seq },
|
|
359
|
+
isFinal: true,
|
|
360
|
+
newMessages: [],
|
|
361
|
+
deletedMessageIds: [],
|
|
362
|
+
otherUpdates: [],
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (diff instanceof Api.updates.DifferenceTooLong) {
|
|
366
|
+
return {
|
|
367
|
+
state: { pts: diff.pts, qts: cursor.qts, date: cursor.date, seq: 0 },
|
|
368
|
+
isFinal: true,
|
|
369
|
+
newMessages: [],
|
|
370
|
+
deletedMessageIds: [],
|
|
371
|
+
otherUpdates: [],
|
|
372
|
+
fallback: {
|
|
373
|
+
kind: "tooLong",
|
|
374
|
+
suggestedAction: "gap too large — call telegram-read-messages per chat or telegram-get-state to resync",
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
const isFinal = diff instanceof Api.updates.Difference;
|
|
379
|
+
const state = isFinal
|
|
380
|
+
? diff.state
|
|
381
|
+
: diff.intermediateState;
|
|
382
|
+
const newMessages = (diff.newMessages ?? [])
|
|
383
|
+
.map(summarizeMessageForUpdates)
|
|
384
|
+
.filter((m) => m !== null);
|
|
385
|
+
const otherUpdates = diff.otherUpdates ?? [];
|
|
386
|
+
return {
|
|
387
|
+
state: {
|
|
388
|
+
pts: state.pts,
|
|
389
|
+
qts: state.qts,
|
|
390
|
+
date: state.date,
|
|
391
|
+
seq: state.seq,
|
|
392
|
+
unreadCount: state.unreadCount,
|
|
393
|
+
},
|
|
394
|
+
isFinal,
|
|
395
|
+
newMessages,
|
|
396
|
+
deletedMessageIds: collectDeletedMessageIds(otherUpdates),
|
|
397
|
+
otherUpdates: otherUpdates.map((u) => ({ type: u.className })),
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
export function summarizeChannelDifference(diff, channelId, fallbackPts) {
|
|
401
|
+
if (diff instanceof Api.updates.ChannelDifferenceEmpty) {
|
|
402
|
+
return {
|
|
403
|
+
channelId,
|
|
404
|
+
pts: diff.pts,
|
|
405
|
+
isFinal: Boolean(diff.final),
|
|
406
|
+
timeout: diff.timeout,
|
|
407
|
+
newMessages: [],
|
|
408
|
+
otherUpdates: [],
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (diff instanceof Api.updates.ChannelDifferenceTooLong) {
|
|
412
|
+
const freshPts = diff.dialog instanceof Api.Dialog ? (diff.dialog.pts ?? fallbackPts) : fallbackPts;
|
|
413
|
+
return {
|
|
414
|
+
channelId,
|
|
415
|
+
pts: freshPts,
|
|
416
|
+
isFinal: Boolean(diff.final),
|
|
417
|
+
timeout: diff.timeout,
|
|
418
|
+
newMessages: (diff.messages ?? [])
|
|
419
|
+
.map(summarizeMessageForUpdates)
|
|
420
|
+
.filter((m) => m !== null),
|
|
421
|
+
otherUpdates: [],
|
|
422
|
+
fallback: {
|
|
423
|
+
kind: "tooLong",
|
|
424
|
+
suggestedAction: "channel gap too large — dialog snapshot returned; call telegram-read-messages for full history",
|
|
425
|
+
},
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
if (diff instanceof Api.updates.ChannelDifference) {
|
|
429
|
+
return {
|
|
430
|
+
channelId,
|
|
431
|
+
pts: diff.pts,
|
|
432
|
+
isFinal: Boolean(diff.final),
|
|
433
|
+
timeout: diff.timeout,
|
|
434
|
+
newMessages: (diff.newMessages ?? [])
|
|
435
|
+
.map(summarizeMessageForUpdates)
|
|
436
|
+
.filter((m) => m !== null),
|
|
437
|
+
otherUpdates: (diff.otherUpdates ?? []).map((u) => ({ type: u.className })),
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
return {
|
|
441
|
+
channelId,
|
|
442
|
+
pts: fallbackPts,
|
|
443
|
+
isFinal: false,
|
|
444
|
+
newMessages: [],
|
|
445
|
+
otherUpdates: [],
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
export function summarizeMyBoost(boost) {
|
|
449
|
+
const b = boost;
|
|
450
|
+
return {
|
|
451
|
+
slot: b.slot,
|
|
452
|
+
peer: peerToCompact(b.peer),
|
|
453
|
+
date: b.date,
|
|
454
|
+
expires: b.expires,
|
|
455
|
+
cooldownUntilDate: b.cooldownUntilDate,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
export function summarizeMyBoosts(result) {
|
|
459
|
+
const boosts = result.myBoosts ?? [];
|
|
460
|
+
return {
|
|
461
|
+
count: boosts.length,
|
|
462
|
+
myBoosts: boosts.map(summarizeMyBoost),
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
export function summarizePrepaidGiveaway(g) {
|
|
466
|
+
if (g instanceof Api.PrepaidStarsGiveaway) {
|
|
467
|
+
return {
|
|
468
|
+
kind: "stars",
|
|
469
|
+
id: g.id.toString(),
|
|
470
|
+
quantity: g.quantity,
|
|
471
|
+
date: g.date,
|
|
472
|
+
stars: g.stars.toString(),
|
|
473
|
+
boosts: g.boosts,
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
const p = g;
|
|
477
|
+
return {
|
|
478
|
+
kind: "premium",
|
|
479
|
+
id: p.id.toString(),
|
|
480
|
+
quantity: p.quantity,
|
|
481
|
+
date: p.date,
|
|
482
|
+
months: p.months,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
export function summarizeBoostsStatus(result) {
|
|
486
|
+
const r = result;
|
|
487
|
+
const out = {
|
|
488
|
+
level: r.level,
|
|
489
|
+
boosts: r.boosts,
|
|
490
|
+
currentLevelBoosts: r.currentLevelBoosts,
|
|
491
|
+
nextLevelBoosts: r.nextLevelBoosts,
|
|
492
|
+
giftBoosts: r.giftBoosts,
|
|
493
|
+
boostUrl: r.boostUrl,
|
|
494
|
+
myBoost: r.myBoost,
|
|
495
|
+
myBoostSlots: r.myBoostSlots,
|
|
496
|
+
};
|
|
497
|
+
if (r.premiumAudience) {
|
|
498
|
+
out.premiumAudience = { part: r.premiumAudience.part, total: r.premiumAudience.total };
|
|
499
|
+
}
|
|
500
|
+
if (r.prepaidGiveaways && r.prepaidGiveaways.length > 0) {
|
|
501
|
+
out.prepaidGiveaways = r.prepaidGiveaways.map(summarizePrepaidGiveaway);
|
|
502
|
+
}
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
export function summarizeBoost(boost) {
|
|
506
|
+
const b = boost;
|
|
507
|
+
return {
|
|
508
|
+
id: b.id,
|
|
509
|
+
userId: b.userId?.toString(),
|
|
510
|
+
date: b.date,
|
|
511
|
+
expires: b.expires,
|
|
512
|
+
gift: b.gift,
|
|
513
|
+
giveaway: b.giveaway,
|
|
514
|
+
unclaimed: b.unclaimed,
|
|
515
|
+
giveawayMsgId: b.giveawayMsgId,
|
|
516
|
+
usedGiftSlug: b.usedGiftSlug,
|
|
517
|
+
multiplier: b.multiplier,
|
|
518
|
+
stars: b.stars?.toString(),
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
export function summarizeBoostsList(result) {
|
|
522
|
+
const r = result;
|
|
523
|
+
return {
|
|
524
|
+
count: r.count,
|
|
525
|
+
boosts: (r.boosts ?? []).map(summarizeBoost),
|
|
526
|
+
nextOffset: r.nextOffset,
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
export function summarizeBusinessChatLink(link) {
|
|
530
|
+
const l = link;
|
|
531
|
+
return {
|
|
532
|
+
link: l.link,
|
|
533
|
+
message: l.message,
|
|
534
|
+
title: l.title,
|
|
535
|
+
views: l.views,
|
|
536
|
+
entityCount: l.entities?.length ?? 0,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
export function summarizeBusinessChatLinks(result) {
|
|
540
|
+
const r = result;
|
|
541
|
+
const links = r.links ?? [];
|
|
542
|
+
return {
|
|
543
|
+
count: links.length,
|
|
544
|
+
links: links.map(summarizeBusinessChatLink),
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
export function summarizeGroupCallInfo(call) {
|
|
548
|
+
if (call instanceof Api.GroupCallDiscarded) {
|
|
549
|
+
return {
|
|
550
|
+
kind: "discarded",
|
|
551
|
+
id: call.id.toString(),
|
|
552
|
+
accessHash: call.accessHash.toString(),
|
|
553
|
+
duration: call.duration,
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
const c = call;
|
|
557
|
+
return {
|
|
558
|
+
kind: "active",
|
|
559
|
+
id: c.id.toString(),
|
|
560
|
+
accessHash: c.accessHash.toString(),
|
|
561
|
+
participantsCount: c.participantsCount,
|
|
562
|
+
title: c.title,
|
|
563
|
+
scheduleDate: c.scheduleDate,
|
|
564
|
+
recordStartDate: c.recordStartDate,
|
|
565
|
+
streamDcId: c.streamDcId,
|
|
566
|
+
unmutedVideoCount: c.unmutedVideoCount,
|
|
567
|
+
unmutedVideoLimit: c.unmutedVideoLimit,
|
|
568
|
+
version: c.version,
|
|
569
|
+
joinMuted: c.joinMuted,
|
|
570
|
+
canChangeJoinMuted: c.canChangeJoinMuted,
|
|
571
|
+
joinDateAsc: c.joinDateAsc,
|
|
572
|
+
scheduleStartSubscribed: c.scheduleStartSubscribed,
|
|
573
|
+
canStartVideo: c.canStartVideo,
|
|
574
|
+
recordVideoActive: c.recordVideoActive,
|
|
575
|
+
rtmpStream: c.rtmpStream,
|
|
576
|
+
listenersHidden: c.listenersHidden,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
export function summarizeGroupCallParticipant(p) {
|
|
580
|
+
const gp = p;
|
|
581
|
+
return {
|
|
582
|
+
peer: peerToCompact(gp.peer),
|
|
583
|
+
date: gp.date,
|
|
584
|
+
activeDate: gp.activeDate,
|
|
585
|
+
source: gp.source,
|
|
586
|
+
volume: gp.volume,
|
|
587
|
+
muted: gp.muted,
|
|
588
|
+
left: gp.left,
|
|
589
|
+
canSelfUnmute: gp.canSelfUnmute,
|
|
590
|
+
justJoined: gp.justJoined,
|
|
591
|
+
self: gp.self,
|
|
592
|
+
mutedByYou: gp.mutedByYou,
|
|
593
|
+
volumeByAdmin: gp.volumeByAdmin,
|
|
594
|
+
videoJoined: gp.videoJoined,
|
|
595
|
+
about: gp.about,
|
|
596
|
+
raiseHandRating: gp.raiseHandRating?.toString(),
|
|
597
|
+
hasVideo: gp.video ? true : undefined,
|
|
598
|
+
hasPresentation: gp.presentation ? true : undefined,
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
export function summarizeGroupCall(result) {
|
|
602
|
+
const r = result;
|
|
603
|
+
return {
|
|
604
|
+
call: summarizeGroupCallInfo(r.call),
|
|
605
|
+
participants: (r.participants ?? []).map(summarizeGroupCallParticipant),
|
|
606
|
+
participantsNextOffset: r.participantsNextOffset || undefined,
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
export function summarizeGroupCallParticipants(result) {
|
|
610
|
+
const r = result;
|
|
611
|
+
return {
|
|
612
|
+
count: r.count,
|
|
613
|
+
participants: (r.participants ?? []).map(summarizeGroupCallParticipant),
|
|
614
|
+
nextOffset: r.nextOffset || undefined,
|
|
615
|
+
version: r.version,
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
export function summarizeStarsAmount(amount) {
|
|
619
|
+
const a = amount;
|
|
620
|
+
return { amount: a.amount.toString(), nanos: a.nanos };
|
|
621
|
+
}
|
|
622
|
+
export function summarizeStarsTransactionPeer(peer) {
|
|
623
|
+
if (peer instanceof Api.StarsTransactionPeerAppStore)
|
|
624
|
+
return { kind: "appStore" };
|
|
625
|
+
if (peer instanceof Api.StarsTransactionPeerPlayMarket)
|
|
626
|
+
return { kind: "playMarket" };
|
|
627
|
+
if (peer instanceof Api.StarsTransactionPeerPremiumBot)
|
|
628
|
+
return { kind: "premiumBot" };
|
|
629
|
+
if (peer instanceof Api.StarsTransactionPeerFragment)
|
|
630
|
+
return { kind: "fragment" };
|
|
631
|
+
if (peer instanceof Api.StarsTransactionPeerAds)
|
|
632
|
+
return { kind: "ads" };
|
|
633
|
+
if (peer instanceof Api.StarsTransactionPeerAPI)
|
|
634
|
+
return { kind: "api" };
|
|
635
|
+
if (peer instanceof Api.StarsTransactionPeer)
|
|
636
|
+
return { kind: "peer", peer: peerToCompact(peer.peer) };
|
|
637
|
+
return { kind: "unsupported" };
|
|
638
|
+
}
|
|
639
|
+
export function summarizeStarsTransaction(tx) {
|
|
640
|
+
const t = tx;
|
|
641
|
+
return {
|
|
642
|
+
id: t.id,
|
|
643
|
+
stars: summarizeStarsAmount(t.stars),
|
|
644
|
+
date: t.date,
|
|
645
|
+
peer: summarizeStarsTransactionPeer(t.peer),
|
|
646
|
+
refund: t.refund,
|
|
647
|
+
pending: t.pending,
|
|
648
|
+
failed: t.failed,
|
|
649
|
+
gift: t.gift,
|
|
650
|
+
reaction: t.reaction,
|
|
651
|
+
title: t.title,
|
|
652
|
+
description: t.description,
|
|
653
|
+
msgId: t.msgId,
|
|
654
|
+
subscriptionPeriod: t.subscriptionPeriod,
|
|
655
|
+
giveawayPostId: t.giveawayPostId,
|
|
656
|
+
transactionDate: t.transactionDate,
|
|
657
|
+
transactionUrl: t.transactionUrl,
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
export function summarizeStarsSubscription(sub) {
|
|
661
|
+
const s = sub;
|
|
662
|
+
const pricing = s.pricing;
|
|
663
|
+
return {
|
|
664
|
+
id: s.id,
|
|
665
|
+
peer: peerToCompact(s.peer),
|
|
666
|
+
untilDate: s.untilDate,
|
|
667
|
+
pricing: { period: pricing.period, amount: pricing.amount.toString() },
|
|
668
|
+
canceled: s.canceled,
|
|
669
|
+
canRefulfill: s.canRefulfill,
|
|
670
|
+
missingBalance: s.missingBalance,
|
|
671
|
+
botCanceled: s.botCanceled,
|
|
672
|
+
chatInviteHash: s.chatInviteHash,
|
|
673
|
+
title: s.title,
|
|
674
|
+
invoiceSlug: s.invoiceSlug,
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
export function summarizeQuickReply(reply) {
|
|
678
|
+
const r = reply;
|
|
679
|
+
return {
|
|
680
|
+
shortcutId: r.shortcutId,
|
|
681
|
+
shortcut: r.shortcut,
|
|
682
|
+
topMessage: r.topMessage,
|
|
683
|
+
count: r.count,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
export function summarizeQuickReplies(result) {
|
|
687
|
+
if (result instanceof Api.messages.QuickRepliesNotModified) {
|
|
688
|
+
return { notModified: true };
|
|
689
|
+
}
|
|
690
|
+
const r = result;
|
|
691
|
+
return { quickReplies: r.quickReplies.map(summarizeQuickReply) };
|
|
692
|
+
}
|
|
693
|
+
export function summarizeQuickReplyMessage(msg) {
|
|
694
|
+
if (msg instanceof Api.MessageEmpty)
|
|
695
|
+
return null;
|
|
696
|
+
const base = msg;
|
|
697
|
+
const fromId = peerToCompact(base.fromId);
|
|
698
|
+
const replyHeader = base.replyTo;
|
|
699
|
+
const replyToMsgId = replyHeader instanceof Api.MessageReplyHeader ? replyHeader.replyToMsgId : undefined;
|
|
700
|
+
if (msg instanceof Api.Message) {
|
|
701
|
+
return {
|
|
702
|
+
id: msg.id,
|
|
703
|
+
date: msg.date,
|
|
704
|
+
text: msg.message ?? "",
|
|
705
|
+
isService: false,
|
|
706
|
+
fromId,
|
|
707
|
+
replyToMsgId,
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
if (msg instanceof Api.MessageService) {
|
|
711
|
+
return {
|
|
712
|
+
id: msg.id,
|
|
713
|
+
date: msg.date,
|
|
714
|
+
text: `[${msg.action?.className ?? "service"}]`,
|
|
715
|
+
isService: true,
|
|
716
|
+
fromId,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
export function summarizeQuickReplyMessages(result) {
|
|
722
|
+
if (result instanceof Api.messages.MessagesNotModified) {
|
|
723
|
+
return { notModified: true, count: result.count };
|
|
724
|
+
}
|
|
725
|
+
const rawMessages = result
|
|
726
|
+
.messages;
|
|
727
|
+
const messages = rawMessages.map(summarizeQuickReplyMessage).filter((m) => m !== null);
|
|
728
|
+
const count = result instanceof Api.messages.Messages
|
|
729
|
+
? messages.length
|
|
730
|
+
: result.count;
|
|
731
|
+
return { count, messages };
|
|
732
|
+
}
|
|
733
|
+
export function summarizeStarsStatus(result) {
|
|
734
|
+
const r = result;
|
|
735
|
+
const out = {
|
|
736
|
+
balance: summarizeStarsAmount(r.balance),
|
|
737
|
+
subscriptionsNextOffset: r.subscriptionsNextOffset || undefined,
|
|
738
|
+
subscriptionsMissingBalance: r.subscriptionsMissingBalance?.toString(),
|
|
739
|
+
nextOffset: r.nextOffset || undefined,
|
|
740
|
+
};
|
|
741
|
+
if (r.subscriptions && r.subscriptions.length > 0) {
|
|
742
|
+
out.subscriptions = r.subscriptions.map(summarizeStarsSubscription);
|
|
743
|
+
}
|
|
744
|
+
if (r.history && r.history.length > 0) {
|
|
745
|
+
out.history = r.history.map(summarizeStarsTransaction);
|
|
746
|
+
}
|
|
747
|
+
return out;
|
|
748
|
+
}
|
|
749
|
+
export function summarizeStoryItem(item) {
|
|
750
|
+
if (item instanceof Api.StoryItemDeleted) {
|
|
751
|
+
return { id: item.id, kind: "deleted" };
|
|
752
|
+
}
|
|
753
|
+
if (item instanceof Api.StoryItemSkipped) {
|
|
754
|
+
return {
|
|
755
|
+
id: item.id,
|
|
756
|
+
kind: "skipped",
|
|
757
|
+
date: item.date,
|
|
758
|
+
expireDate: item.expireDate,
|
|
759
|
+
closeFriends: item.closeFriends,
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
const story = item;
|
|
763
|
+
return {
|
|
764
|
+
id: story.id,
|
|
765
|
+
kind: "active",
|
|
766
|
+
date: story.date,
|
|
767
|
+
expireDate: story.expireDate,
|
|
768
|
+
caption: story.caption,
|
|
769
|
+
mediaType: story.media?.className,
|
|
770
|
+
pinned: story.pinned,
|
|
771
|
+
public: story.public,
|
|
772
|
+
closeFriends: story.closeFriends,
|
|
773
|
+
edited: story.edited,
|
|
774
|
+
noforwards: story.noforwards,
|
|
775
|
+
fromId: peerToCompact(story.fromId),
|
|
776
|
+
viewsCount: story.views?.viewsCount,
|
|
777
|
+
reactionsCount: story.views?.reactionsCount,
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
export function summarizePeerStories(ps) {
|
|
781
|
+
const peer = peerToCompact(ps.peer);
|
|
782
|
+
if (!peer)
|
|
783
|
+
return null;
|
|
784
|
+
return {
|
|
785
|
+
peer,
|
|
786
|
+
maxReadId: ps.maxReadId,
|
|
787
|
+
stories: (ps.stories ?? []).map(summarizeStoryItem),
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
export function summarizeStoriesById(result) {
|
|
791
|
+
return {
|
|
792
|
+
count: result.count,
|
|
793
|
+
stories: (result.stories ?? []).map(summarizeStoryItem),
|
|
794
|
+
pinnedToTop: result.pinnedToTop,
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
export function summarizeStoryView(view) {
|
|
798
|
+
if (view instanceof Api.StoryViewPublicForward) {
|
|
799
|
+
const msg = view.message;
|
|
800
|
+
const messageId = msg instanceof Api.MessageEmpty ? undefined : msg?.id;
|
|
801
|
+
const peer = msg instanceof Api.MessageEmpty
|
|
802
|
+
? undefined
|
|
803
|
+
: peerToCompact(msg?.peerId);
|
|
804
|
+
return {
|
|
805
|
+
kind: "publicForward",
|
|
806
|
+
messageId,
|
|
807
|
+
peer,
|
|
808
|
+
blocked: view.blocked,
|
|
809
|
+
blockedMyStoriesFrom: view.blockedMyStoriesFrom,
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
if (view instanceof Api.StoryViewPublicRepost) {
|
|
813
|
+
const story = view.story;
|
|
814
|
+
return {
|
|
815
|
+
kind: "publicRepost",
|
|
816
|
+
peer: peerToCompact(view.peerId),
|
|
817
|
+
storyId: story?.id,
|
|
818
|
+
blocked: view.blocked,
|
|
819
|
+
blockedMyStoriesFrom: view.blockedMyStoriesFrom,
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
const v = view;
|
|
823
|
+
return {
|
|
824
|
+
kind: "user",
|
|
825
|
+
userId: v.userId.toString(),
|
|
826
|
+
date: v.date,
|
|
827
|
+
reaction: v.reaction ? reactionToEmoji(v.reaction) : undefined,
|
|
828
|
+
blocked: v.blocked,
|
|
829
|
+
blockedMyStoriesFrom: v.blockedMyStoriesFrom,
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
export function summarizeStoryViewsList(result) {
|
|
833
|
+
const list = result;
|
|
834
|
+
return {
|
|
835
|
+
count: list.count,
|
|
836
|
+
viewsCount: list.viewsCount,
|
|
837
|
+
forwardsCount: list.forwardsCount,
|
|
838
|
+
reactionsCount: list.reactionsCount,
|
|
839
|
+
views: (list.views ?? []).map(summarizeStoryView),
|
|
840
|
+
nextOffset: list.nextOffset,
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
export function summarizeAllStories(result) {
|
|
844
|
+
const stealthMode = result.stealthMode
|
|
845
|
+
? {
|
|
846
|
+
activeUntilDate: result.stealthMode.activeUntilDate,
|
|
847
|
+
cooldownUntilDate: result.stealthMode.cooldownUntilDate,
|
|
848
|
+
}
|
|
849
|
+
: undefined;
|
|
850
|
+
if (result instanceof Api.stories.AllStoriesNotModified) {
|
|
851
|
+
return {
|
|
852
|
+
modified: false,
|
|
853
|
+
state: result.state,
|
|
854
|
+
peerStories: [],
|
|
855
|
+
stealthMode,
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
const all = result;
|
|
859
|
+
const peerStories = (all.peerStories ?? [])
|
|
860
|
+
.map(summarizePeerStories)
|
|
861
|
+
.filter((p) => p !== null);
|
|
862
|
+
return {
|
|
863
|
+
modified: true,
|
|
864
|
+
state: all.state,
|
|
865
|
+
hasMore: all.hasMore,
|
|
866
|
+
count: all.count,
|
|
867
|
+
peerStories,
|
|
868
|
+
stealthMode,
|
|
869
|
+
};
|
|
870
|
+
}
|