@mtkruto/node 0.1.140 → 0.1.142

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