@mtkruto/node 0.1.141 → 0.1.143

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.
Files changed (53) hide show
  1. package/esm/4_constants.d.ts +1 -1
  2. package/esm/4_constants.js +1 -1
  3. package/esm/5_client.d.ts +1 -0
  4. package/esm/5_client.js +1 -0
  5. package/esm/client/0_types.d.ts +2 -0
  6. package/esm/client/1_bot_info_manager.d.ts +30 -0
  7. package/esm/client/1_bot_info_manager.js +66 -0
  8. package/esm/client/1_network_statistics_manager.d.ts +19 -0
  9. package/esm/client/1_network_statistics_manager.js +48 -0
  10. package/esm/client/1_reaction_manager.d.ts +9 -0
  11. package/esm/client/1_reaction_manager.js +84 -0
  12. package/esm/client/2_message_manager.d.ts +22 -2
  13. package/esm/client/2_message_manager.js +282 -28
  14. package/esm/client/3_callback_query_manager.d.ts +16 -0
  15. package/esm/client/3_callback_query_manager.js +36 -0
  16. package/esm/client/3_chat_list_manager.d.ts +5 -9
  17. package/esm/client/3_chat_list_manager.js +190 -103
  18. package/esm/client/3_inline_query_manager.d.ts +16 -0
  19. package/esm/client/3_inline_query_manager.js +49 -0
  20. package/esm/client/4_client.d.ts +12 -12
  21. package/esm/client/4_client.js +162 -538
  22. package/esm/client/5_session_string.d.ts +3 -0
  23. package/esm/client/5_session_string.js +22 -0
  24. package/esm/connection/1_connection_web_socket.js +1 -1
  25. package/package.json +1 -1
  26. package/script/4_constants.d.ts +1 -1
  27. package/script/4_constants.js +1 -1
  28. package/script/5_client.d.ts +1 -0
  29. package/script/5_client.js +1 -0
  30. package/script/client/0_types.d.ts +2 -0
  31. package/script/client/1_bot_info_manager.d.ts +30 -0
  32. package/script/client/1_bot_info_manager.js +70 -0
  33. package/script/client/1_network_statistics_manager.d.ts +19 -0
  34. package/script/client/1_network_statistics_manager.js +52 -0
  35. package/script/client/1_reaction_manager.d.ts +9 -0
  36. package/script/client/1_reaction_manager.js +88 -0
  37. package/script/client/2_message_manager.d.ts +22 -2
  38. package/script/client/2_message_manager.js +281 -27
  39. package/script/client/3_callback_query_manager.d.ts +16 -0
  40. package/script/client/3_callback_query_manager.js +40 -0
  41. package/script/client/3_chat_list_manager.d.ts +5 -9
  42. package/script/client/3_chat_list_manager.js +187 -100
  43. package/script/client/3_inline_query_manager.d.ts +16 -0
  44. package/script/client/3_inline_query_manager.js +53 -0
  45. package/script/client/4_client.d.ts +12 -12
  46. package/script/client/4_client.js +158 -534
  47. package/script/client/5_session_string.d.ts +3 -0
  48. package/script/client/5_session_string.js +27 -0
  49. package/script/connection/1_connection_web_socket.js +1 -1
  50. package/esm/client/3_reaction_manager.d.ts +0 -16
  51. package/esm/client/3_reaction_manager.js +0 -61
  52. package/script/client/3_reaction_manager.d.ts +0 -16
  53. package/script/client/3_reaction_manager.js +0 -65
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _ChatListManager_instances, _ChatListManager_c, _ChatListManager_sendChatUpdate, _ChatListManager_chats, _ChatListManager_archivedChats, _ChatListManager_chatsLoadedFromStorage, _ChatListManager_getChatList, _ChatListManager_loadChatsFromStorage, _ChatListManager_getLoadedChats, _ChatListManager_pinnedChats, _ChatListManager_pinnedArchiveChats, _ChatListManager_storageHadPinnedChats, _ChatListManager_pinnedChatsLoaded, _ChatListManager_loadPinnedChats, _ChatListManager_fetchPinnedChats, _ChatListManager_getPinnedChats, _ChatListManager_updateOrAddChat, _ChatListManager_removeChat, _ChatListManager_fetchChats;
13
+ var _ChatListManager_instances, _ChatListManager_c, _ChatListManager_sendChatUpdate, _ChatListManager_chats, _ChatListManager_archivedChats, _ChatListManager_chatsLoadedFromStorage, _ChatListManager_tryGetChatId, _ChatListManager_getChatAnywhere, _ChatListManager_getChatList, _ChatListManager_loadChatsFromStorage, _ChatListManager_getLoadedChats, _ChatListManager_pinnedChats, _ChatListManager_pinnedArchiveChats, _ChatListManager_storageHadPinnedChats, _ChatListManager_pinnedChatsLoaded, _ChatListManager_loadPinnedChats, _ChatListManager_fetchPinnedChats, _ChatListManager_getPinnedChats, _ChatListManager_updateOrAddChat, _ChatListManager_removeChat, _ChatListManager_handleUpdateFolderPeers, _ChatListManager_handleUpdatePinnedDialogs, _ChatListManager_handleUpdateChannel, _ChatListManager_handleUpdateChat, _ChatListManager_handleUpdateUser, _ChatListManager_fetchChats;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ChatListManager = void 0;
16
16
  const _0_deps_js_1 = require("../0_deps.js");
@@ -39,7 +39,7 @@ class ChatListManager {
39
39
  catch {
40
40
  return () => Promise.resolve();
41
41
  }
42
- const [chat, listId] = this.getChatAnywhere(chatId);
42
+ const [chat, listId] = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatAnywhere).call(this, chatId);
43
43
  if (!chat && !add) {
44
44
  return () => Promise.resolve();
45
45
  }
@@ -94,101 +94,6 @@ class ChatListManager {
94
94
  }
95
95
  return () => Promise.resolve();
96
96
  }
97
- tryGetChatId(username) {
98
- username = username.toLowerCase();
99
- for (const chat of __classPrivateFieldGet(this, _ChatListManager_chats, "f").values()) {
100
- if ("username" in chat) {
101
- if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
102
- return chat.id;
103
- }
104
- }
105
- }
106
- for (const chat of __classPrivateFieldGet(this, _ChatListManager_archivedChats, "f").values()) {
107
- if ("username" in chat) {
108
- if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
109
- return chat.id;
110
- }
111
- }
112
- }
113
- return null;
114
- }
115
- getChatAnywhere(chatId) {
116
- let chat = __classPrivateFieldGet(this, _ChatListManager_chats, "f").get(chatId);
117
- if (chat) {
118
- return [chat, 0];
119
- }
120
- chat = __classPrivateFieldGet(this, _ChatListManager_archivedChats, "f").get(chatId);
121
- if (chat) {
122
- return [chat, 1];
123
- }
124
- return [undefined, -1];
125
- }
126
- async handelUpdateFolderPeers(update) {
127
- for (const { peer, folder_id: listId } of update.folder_peers) {
128
- const chatId = (0, _2_tl_js_1.peerToChatId)(peer);
129
- const [chat, currentListId] = this.getChatAnywhere(chatId);
130
- if (chat !== undefined && listId != currentListId) {
131
- __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, currentListId).delete(chatId);
132
- __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, listId).set(chatId, chat);
133
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chatId, true);
134
- }
135
- }
136
- }
137
- async handleUpdatePinnedDialogs(update) {
138
- const listId = update.folder_id ?? 0;
139
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_fetchPinnedChats).call(this, update.folder_id);
140
- const chats = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, listId);
141
- const pinnedChats = await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getPinnedChats).call(this, listId);
142
- for (const [i, chatId] of pinnedChats.entries()) {
143
- const chat = chats.get(chatId);
144
- if (chat !== undefined) {
145
- chat.order = (0, _3_types_js_1.getChatOrder)(chat.lastMessage, i);
146
- chat.pinned = i;
147
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chatId, false);
148
- }
149
- }
150
- for (const chat of chats.values()) {
151
- if (chat.pinned != -1 && pinnedChats.indexOf(chat.id) == -1) {
152
- chat.order = (0, _3_types_js_1.getChatOrder)(chat.lastMessage, -1);
153
- chat.pinned = -1;
154
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chat.id, false);
155
- }
156
- }
157
- await __classPrivateFieldGet(this, _ChatListManager_c, "f").storage.setPinnedChats(listId, await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getPinnedChats).call(this, listId));
158
- }
159
- async handleUpdateChannel(update) {
160
- const peer = new _2_tl_js_1.types.PeerChannel(update);
161
- const channel = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity(peer);
162
- if (channel != null && "left" in channel && channel.left) {
163
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
164
- }
165
- else if (channel instanceof _2_tl_js_1.types.ChannelForbidden) {
166
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
167
- }
168
- else if (channel instanceof _2_tl_js_1.types.Channel) {
169
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
170
- }
171
- }
172
- async handleUpdateChat(update) {
173
- const peer = new _2_tl_js_1.types.PeerChat(update);
174
- const chat = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity(peer);
175
- if (chat != null && "left" in chat && chat.left) {
176
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
177
- }
178
- else if (chat instanceof _2_tl_js_1.types.ChatForbidden) {
179
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
180
- }
181
- else if (chat instanceof _2_tl_js_1.types.Chat) {
182
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
183
- }
184
- }
185
- async handleUpdateUser(update) {
186
- const peer = new _2_tl_js_1.types.PeerUser(update);
187
- const chat = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity(peer);
188
- if (chat != null) {
189
- await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
190
- }
191
- }
192
97
  async getChats(from = "main", after, limit = 100) {
193
98
  await __classPrivateFieldGet(this, _ChatListManager_c, "f").storage.assertUser("getChats");
194
99
  if (!__classPrivateFieldGet(this, _ChatListManager_chatsLoadedFromStorage, "f")) {
@@ -216,6 +121,100 @@ class ChatListManager {
216
121
  chats = chats.slice(0, limit);
217
122
  return chats;
218
123
  }
124
+ static canHandleUpdate(update) {
125
+ return update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdatePinnedDialogs || update instanceof _2_tl_js_1.types.UpdateFolderPeers || update instanceof _2_tl_js_1.types.UpdateChannel || update instanceof _2_tl_js_1.types.UpdateChat || update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName;
126
+ }
127
+ async handleUpdate(update) {
128
+ if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
129
+ if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
130
+ const chatId = (0, _2_tl_js_1.peerToChatId)(update.message.peer_id);
131
+ await this.reassignChatLastMessage(chatId);
132
+ }
133
+ }
134
+ else if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
135
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_handleUpdatePinnedDialogs).call(this, update);
136
+ }
137
+ else if (update instanceof _2_tl_js_1.types.UpdateFolderPeers) {
138
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_handleUpdateFolderPeers).call(this, update);
139
+ }
140
+ else if (update instanceof _2_tl_js_1.types.UpdateChannel) {
141
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_handleUpdateChannel).call(this, update);
142
+ }
143
+ else if (update instanceof _2_tl_js_1.types.UpdateChat) {
144
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_handleUpdateChat).call(this, update);
145
+ }
146
+ else if (update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName) {
147
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_handleUpdateUser).call(this, update);
148
+ }
149
+ else {
150
+ (0, _1_utilities_js_1.UNREACHABLE)();
151
+ }
152
+ }
153
+ async getChat(chatId) {
154
+ if (await __classPrivateFieldGet(this, _ChatListManager_c, "f").storage.getAccountType() == "user") {
155
+ let maybeChatId = null;
156
+ if (typeof chatId === "number") {
157
+ maybeChatId = chatId;
158
+ }
159
+ else if (typeof chatId === "string") {
160
+ maybeChatId = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_tryGetChatId).call(this, (0, _0_utilities_js_1.getUsername)(chatId));
161
+ }
162
+ else {
163
+ (0, _1_utilities_js_1.UNREACHABLE)();
164
+ }
165
+ if (maybeChatId != null) {
166
+ const [chat] = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatAnywhere).call(this, maybeChatId);
167
+ if (chat !== undefined) {
168
+ return chat;
169
+ }
170
+ }
171
+ }
172
+ let inputPeer = null;
173
+ if (typeof chatId === "number") {
174
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId, -1, undefined, __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity);
175
+ if (chat != null) {
176
+ return chat;
177
+ }
178
+ }
179
+ else {
180
+ inputPeer = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getInputPeer(chatId);
181
+ const chatId_ = (0, _2_tl_js_1.peerToChatId)(inputPeer);
182
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId_, -1, undefined, __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity);
183
+ if (chat != null) {
184
+ return chat;
185
+ }
186
+ }
187
+ if (inputPeer == null) {
188
+ inputPeer = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getInputPeer(chatId);
189
+ }
190
+ if (inputPeer instanceof _2_tl_js_1.types.InputPeerChat) {
191
+ const chats = await __classPrivateFieldGet(this, _ChatListManager_c, "f").api.messages.getChats({ id: [inputPeer.chat_id] }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.Chats));
192
+ const chat = chats.chats[0];
193
+ if (chat instanceof _2_tl_js_1.types.ChatEmpty) {
194
+ (0, _1_utilities_js_1.UNREACHABLE)();
195
+ }
196
+ return (0, _3_types_js_1.constructChat2)(chat, -1, undefined);
197
+ }
198
+ else if (inputPeer instanceof _2_tl_js_1.types.InputPeerChannel) {
199
+ const channels = await __classPrivateFieldGet(this, _ChatListManager_c, "f").api.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel(inputPeer)] });
200
+ const channel = channels.chats[0];
201
+ if (channel instanceof _2_tl_js_1.types.ChatEmpty) {
202
+ (0, _1_utilities_js_1.UNREACHABLE)();
203
+ }
204
+ return (0, _3_types_js_1.constructChat2)(channel, -1, undefined);
205
+ }
206
+ else if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser) {
207
+ const users = await __classPrivateFieldGet(this, _ChatListManager_c, "f").api.users.getUsers({ id: [new _2_tl_js_1.types.InputUser(inputPeer)] });
208
+ const user = users[0];
209
+ if (user instanceof _2_tl_js_1.types.UserEmpty) {
210
+ (0, _1_utilities_js_1.UNREACHABLE)();
211
+ }
212
+ return (0, _3_types_js_1.constructChat2)(user, -1, undefined);
213
+ }
214
+ else {
215
+ (0, _1_utilities_js_1.UNREACHABLE)();
216
+ }
217
+ }
219
218
  }
220
219
  exports.ChatListManager = ChatListManager;
221
220
  _ChatListManager_c = new WeakMap(), _ChatListManager_chats = new WeakMap(), _ChatListManager_archivedChats = new WeakMap(), _ChatListManager_chatsLoadedFromStorage = new WeakMap(), _ChatListManager_pinnedChats = new WeakMap(), _ChatListManager_pinnedArchiveChats = new WeakMap(), _ChatListManager_storageHadPinnedChats = new WeakMap(), _ChatListManager_pinnedChatsLoaded = new WeakMap(), _ChatListManager_instances = new WeakSet(), _ChatListManager_sendChatUpdate = async function _ChatListManager_sendChatUpdate(chatId, added) {
@@ -225,9 +224,36 @@ _ChatListManager_c = new WeakMap(), _ChatListManager_chats = new WeakMap(), _Cha
225
224
  catch {
226
225
  return;
227
226
  }
228
- const [chat] = this.getChatAnywhere(chatId);
227
+ const [chat] = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatAnywhere).call(this, chatId);
229
228
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
230
229
  __classPrivateFieldGet(this, _ChatListManager_c, "f").handleUpdate(update);
230
+ }, _ChatListManager_tryGetChatId = function _ChatListManager_tryGetChatId(username) {
231
+ username = username.toLowerCase();
232
+ for (const chat of __classPrivateFieldGet(this, _ChatListManager_chats, "f").values()) {
233
+ if ("username" in chat) {
234
+ if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
235
+ return chat.id;
236
+ }
237
+ }
238
+ }
239
+ for (const chat of __classPrivateFieldGet(this, _ChatListManager_archivedChats, "f").values()) {
240
+ if ("username" in chat) {
241
+ if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
242
+ return chat.id;
243
+ }
244
+ }
245
+ }
246
+ return null;
247
+ }, _ChatListManager_getChatAnywhere = function _ChatListManager_getChatAnywhere(chatId) {
248
+ let chat = __classPrivateFieldGet(this, _ChatListManager_chats, "f").get(chatId);
249
+ if (chat) {
250
+ return [chat, 0];
251
+ }
252
+ chat = __classPrivateFieldGet(this, _ChatListManager_archivedChats, "f").get(chatId);
253
+ if (chat) {
254
+ return [chat, 1];
255
+ }
256
+ return [undefined, -1];
231
257
  }, _ChatListManager_getChatList = function _ChatListManager_getChatList(listId) {
232
258
  switch (listId) {
233
259
  case 0:
@@ -310,7 +336,7 @@ _ChatListManager_c = new WeakMap(), _ChatListManager_chats = new WeakMap(), _Cha
310
336
  (0, _1_utilities_js_1.UNREACHABLE)();
311
337
  }
312
338
  }, _ChatListManager_updateOrAddChat = async function _ChatListManager_updateOrAddChat(chatId) {
313
- const [chat, listId] = this.getChatAnywhere(chatId);
339
+ const [chat, listId] = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatAnywhere).call(this, chatId);
314
340
  if (chat !== undefined) {
315
341
  const newChat = await (0, _3_types_js_1.constructChat3)(chatId, chat.pinned, chat.lastMessage, __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity);
316
342
  if (newChat != null) {
@@ -327,11 +353,72 @@ _ChatListManager_c = new WeakMap(), _ChatListManager_chats = new WeakMap(), _Cha
327
353
  }
328
354
  }
329
355
  }, _ChatListManager_removeChat = async function _ChatListManager_removeChat(chatId) {
330
- const [chat, listId] = this.getChatAnywhere(chatId);
356
+ const [chat, listId] = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatAnywhere).call(this, chatId);
331
357
  if (chat !== undefined) {
332
358
  __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, listId).delete(chatId);
333
359
  await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chatId, false);
334
360
  }
361
+ }, _ChatListManager_handleUpdateFolderPeers = async function _ChatListManager_handleUpdateFolderPeers(update) {
362
+ for (const { peer, folder_id: listId } of update.folder_peers) {
363
+ const chatId = (0, _2_tl_js_1.peerToChatId)(peer);
364
+ const [chat, currentListId] = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatAnywhere).call(this, chatId);
365
+ if (chat !== undefined && listId != currentListId) {
366
+ __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, currentListId).delete(chatId);
367
+ __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, listId).set(chatId, chat);
368
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chatId, true);
369
+ }
370
+ }
371
+ }, _ChatListManager_handleUpdatePinnedDialogs = async function _ChatListManager_handleUpdatePinnedDialogs(update) {
372
+ const listId = update.folder_id ?? 0;
373
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_fetchPinnedChats).call(this, update.folder_id);
374
+ const chats = __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getChatList).call(this, listId);
375
+ const pinnedChats = await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getPinnedChats).call(this, listId);
376
+ for (const [i, chatId] of pinnedChats.entries()) {
377
+ const chat = chats.get(chatId);
378
+ if (chat !== undefined) {
379
+ chat.order = (0, _3_types_js_1.getChatOrder)(chat.lastMessage, i);
380
+ chat.pinned = i;
381
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chatId, false);
382
+ }
383
+ }
384
+ for (const chat of chats.values()) {
385
+ if (chat.pinned != -1 && pinnedChats.indexOf(chat.id) == -1) {
386
+ chat.order = (0, _3_types_js_1.getChatOrder)(chat.lastMessage, -1);
387
+ chat.pinned = -1;
388
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_sendChatUpdate).call(this, chat.id, false);
389
+ }
390
+ }
391
+ await __classPrivateFieldGet(this, _ChatListManager_c, "f").storage.setPinnedChats(listId, await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_getPinnedChats).call(this, listId));
392
+ }, _ChatListManager_handleUpdateChannel = async function _ChatListManager_handleUpdateChannel(update) {
393
+ const peer = new _2_tl_js_1.types.PeerChannel(update);
394
+ const channel = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity(peer);
395
+ if (channel != null && "left" in channel && channel.left) {
396
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
397
+ }
398
+ else if (channel instanceof _2_tl_js_1.types.ChannelForbidden) {
399
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
400
+ }
401
+ else if (channel instanceof _2_tl_js_1.types.Channel) {
402
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
403
+ }
404
+ }, _ChatListManager_handleUpdateChat = async function _ChatListManager_handleUpdateChat(update) {
405
+ const peer = new _2_tl_js_1.types.PeerChat(update);
406
+ const chat = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity(peer);
407
+ if (chat != null && "left" in chat && chat.left) {
408
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
409
+ }
410
+ else if (chat instanceof _2_tl_js_1.types.ChatForbidden) {
411
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
412
+ }
413
+ else if (chat instanceof _2_tl_js_1.types.Chat) {
414
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
415
+ }
416
+ }, _ChatListManager_handleUpdateUser = async function _ChatListManager_handleUpdateUser(update) {
417
+ const peer = new _2_tl_js_1.types.PeerUser(update);
418
+ const chat = await __classPrivateFieldGet(this, _ChatListManager_c, "f").getEntity(peer);
419
+ if (chat != null) {
420
+ await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
421
+ }
335
422
  }, _ChatListManager_fetchChats = async function _ChatListManager_fetchChats(listId, limit, after) {
336
423
  const dialogs = await __classPrivateFieldGet(this, _ChatListManager_c, "f").api.messages.getDialogs({
337
424
  limit,
@@ -0,0 +1,16 @@
1
+ import { enums, types } from "../2_tl.js";
2
+ import { InlineQueryResult, Update } from "../3_types.js";
3
+ import { AnswerInlineQueryParams } from "./0_params.js";
4
+ import { C as C_ } from "./0_types.js";
5
+ import { MessageManager } from "./2_message_manager.js";
6
+ type C = C_ & {
7
+ messageManager: MessageManager;
8
+ };
9
+ export declare class InlineQueryManager {
10
+ #private;
11
+ constructor(c: C);
12
+ answerInlineQuery(id: string, results: InlineQueryResult[], params?: AnswerInlineQueryParams): Promise<void>;
13
+ static canHandleUpdate(update: enums.Update): update is types.UpdateBotInlineQuery | types.UpdateBotInlineSend;
14
+ handleUpdate(update: types.UpdateBotInlineQuery | types.UpdateBotInlineSend): Promise<Update>;
15
+ }
16
+ export {};
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _InlineQueryManager_c;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.InlineQueryManager = void 0;
16
+ const _1_utilities_js_1 = require("../1_utilities.js");
17
+ const _2_tl_js_1 = require("../2_tl.js");
18
+ const _3_types_js_1 = require("../3_types.js");
19
+ class InlineQueryManager {
20
+ constructor(c) {
21
+ _InlineQueryManager_c.set(this, void 0);
22
+ __classPrivateFieldSet(this, _InlineQueryManager_c, c, "f");
23
+ }
24
+ async answerInlineQuery(id, results, params) {
25
+ await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").storage.assertBot("answerInlineQuery");
26
+ await __classPrivateFieldGet(this, _InlineQueryManager_c, "f").api.messages.setInlineBotResults({
27
+ query_id: BigInt(id),
28
+ results: await Promise.all(results.map((v) => (0, _3_types_js_1.inlineQueryResultToTlObject)(v, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.parseText.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager), __classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager.usernameResolver.bind(__classPrivateFieldGet(this, _InlineQueryManager_c, "f").messageManager)))),
29
+ cache_time: params?.cacheTime ?? 300,
30
+ private: params?.isPersonal ? true : undefined,
31
+ switch_webview: params?.button && params.button.webApp ? new _2_tl_js_1.types.InlineBotWebView({ text: params.button.text, url: params.button.webApp.url }) : undefined,
32
+ switch_pm: params?.button && params.button.startParameter ? new _2_tl_js_1.types.InlineBotSwitchPM({ text: params.button.text, start_param: params.button.startParameter }) : undefined,
33
+ gallery: params?.isGallery ? true : undefined,
34
+ next_offset: params?.nextOffset,
35
+ });
36
+ }
37
+ static canHandleUpdate(update) {
38
+ return update instanceof _2_tl_js_1.types.UpdateBotInlineQuery || update instanceof _2_tl_js_1.types.UpdateBotInlineSend;
39
+ }
40
+ async handleUpdate(update) {
41
+ if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
42
+ return { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getEntity) };
43
+ }
44
+ else if (update instanceof _2_tl_js_1.types.UpdateBotInlineSend) {
45
+ return { chosenInlineResult: await (0, _3_types_js_1.constructChosenInlineResult)(update, __classPrivateFieldGet(this, _InlineQueryManager_c, "f").getEntity) };
46
+ }
47
+ else {
48
+ (0, _1_utilities_js_1.UNREACHABLE)();
49
+ }
50
+ }
51
+ }
52
+ exports.InlineQueryManager = InlineQueryManager;
53
+ _InlineQueryManager_c = new WeakMap();
@@ -84,9 +84,9 @@ export interface Context {
84
84
  editMessageText: (messageId: number, text: string, params?: EditMessageParams) => Promise<MessageText>;
85
85
  /** Edit the reply markup of a message in the chat which the message was received from. */
86
86
  editMessageReplyMarkup: (messageId: number, params?: EditMessageReplyMarkupParams) => Promise<Message>;
87
- /** Answer the received callback query. */
87
+ /** Answer the received callback query. Bot-only. */
88
88
  answerCallbackQuery: (params?: AnswerCallbackQueryParams) => Promise<void>;
89
- /** Answer the received inline query. */
89
+ /** Answer the received inline query. Bot-only */
90
90
  answerInlineQuery: (results: InlineQueryResult[], params?: AnswerInlineQueryParams) => Promise<void>;
91
91
  /** Retrieve a single message of the chat which the message was received from. */
92
92
  getMessage: (messageId: number) => Promise<Message | null>;
@@ -212,7 +212,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
212
212
  */
213
213
  authorize(params?: string | types.auth.ExportedAuthorization | AuthorizeUserParams): Promise<void>;
214
214
  /**
215
- * Same as calling `.connect()` followed by `.authorize(params)` if the session didn't have an auth key.
215
+ * Same as calling `.connect()` followed by `.authorize(params)`.
216
216
  */
217
217
  start(params?: string | types.auth.ExportedAuthorization | AuthorizeUserParams): Promise<void>;
218
218
  /**
@@ -236,6 +236,15 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
236
236
  private [getEntity];
237
237
  private [getEntity];
238
238
  private [getEntity];
239
+ use(...middleware: Middleware<UpdateIntersection<C>>[]): Composer<UpdateIntersection<C>>;
240
+ branch(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, trueHandler_: Middleware<UpdateIntersection<C>>, falseHandler_: Middleware<UpdateIntersection<C>>): Composer<UpdateIntersection<C>>;
241
+ filter<D extends C>(predicate: (ctx: UpdateIntersection<C>) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
242
+ filter(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, ...middleware: Middleware<UpdateIntersection<C>>[]): Composer<C>;
243
+ on<Q extends FilterQuery>(filter: Q, ...middleawre: Middleware<WithFilter<C, Q>>[]): Composer<UpdateIntersection<WithFilter<C, Q>>>;
244
+ command(commands: string | RegExp | (string | RegExp)[] | {
245
+ names: string | RegExp | (string | RegExp)[];
246
+ prefixes: string | string[];
247
+ }, ...middleawre: Middleware<WithFilter<C, "message:text">>[]): Composer<UpdateIntersection<WithFilter<C, "message:text">>>;
239
248
  /**
240
249
  * Send a text message.
241
250
  *
@@ -381,15 +390,6 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
381
390
  * @param results The results to answer with.
382
391
  */
383
392
  answerInlineQuery(id: string, results: InlineQueryResult[], params?: AnswerInlineQueryParams): Promise<void>;
384
- use(...middleware: Middleware<UpdateIntersection<C>>[]): Composer<UpdateIntersection<C>>;
385
- branch(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, trueHandler_: Middleware<UpdateIntersection<C>>, falseHandler_: Middleware<UpdateIntersection<C>>): Composer<UpdateIntersection<C>>;
386
- filter<D extends C>(predicate: (ctx: UpdateIntersection<C>) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
387
- filter(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, ...middleware: Middleware<UpdateIntersection<C>>[]): Composer<C>;
388
- on<Q extends FilterQuery>(filter: Q, ...middleawre: Middleware<WithFilter<C, Q>>[]): Composer<UpdateIntersection<WithFilter<C, Q>>>;
389
- command(commands: string | RegExp | (string | RegExp)[] | {
390
- names: string | RegExp | (string | RegExp)[];
391
- prefixes: string | string[];
392
- }, ...middleawre: Middleware<WithFilter<C, "message:text">>[]): Composer<UpdateIntersection<WithFilter<C, "message:text">>>;
393
393
  /**
394
394
  * Set the bot's description in the given language. Bot-only.
395
395
  *