@mtkruto/node 0.1.132 → 0.1.134
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/esm/3_errors.d.ts +519 -510
- package/esm/3_errors.js +521 -509
- package/esm/3_types.d.ts +19 -7
- package/esm/3_types.js +19 -7
- package/esm/4_constants.d.ts +2 -2
- package/esm/4_constants.js +2 -2
- package/esm/4_errors.d.ts +7 -12
- package/esm/4_errors.js +6 -7
- package/esm/5_client.d.ts +3 -3
- package/esm/5_client.js +3 -3
- package/esm/client/0_utilities.d.ts +30 -2
- package/esm/client/0_utilities.js +13 -5
- package/esm/client/1_composer.d.ts +30 -0
- package/esm/client/{4_composer.js → 1_composer.js} +15 -2
- package/esm/client/2_client_plain.d.ts +1 -1
- package/esm/client/2_client_plain.js +1 -1
- package/esm/client/{3_types.d.ts → 3_params.d.ts} +68 -172
- package/esm/client/3_params.js +1 -0
- package/esm/client/{5_client.d.ts → 4_client.d.ts} +89 -57
- package/esm/client/{5_client.js → 4_client.js} +499 -308
- package/esm/client/5_composer.d.ts +4 -0
- package/esm/client/5_composer.js +3 -0
- package/esm/storage/0_storage.d.ts +4 -1
- package/esm/storage/0_storage.js +36 -7
- package/esm/storage/1_storage_indexed_db.d.ts +6 -2
- package/esm/storage/1_storage_indexed_db.js +7 -5
- package/esm/storage/1_storage_local_storage.d.ts +1 -1
- package/esm/storage/1_storage_local_storage.js +1 -1
- package/esm/storage/1_storage_memory.d.ts +1 -1
- package/esm/storage/1_storage_memory.js +1 -1
- package/esm/storage/1_storage_session_storage.d.ts +1 -1
- package/esm/storage/1_storage_session_storage.js +1 -1
- package/esm/tl/2_types.d.ts +313 -24
- package/esm/tl/2_types.js +982 -46
- package/esm/tl/3_functions.d.ts +95 -32
- package/esm/tl/3_functions.js +227 -66
- package/esm/tl/3_utilities.d.ts +1 -0
- package/esm/tl/3_utilities.js +14 -0
- package/esm/tl/6_message.js +1 -1
- package/esm/types/0_authorization_state.d.ts +5 -0
- package/esm/types/0_authorization_state.js +1 -0
- package/esm/types/0_chat_photo.d.ts +22 -21
- package/esm/types/0_connection_state.d.ts +17 -0
- package/esm/types/0_connection_state.js +1 -0
- package/esm/types/0_giveaway_parameters.d.ts +9 -0
- package/esm/types/0_giveaway_parameters.js +9 -0
- package/esm/types/0_login_url.d.ts +0 -4
- package/esm/types/0_mask_position.d.ts +0 -4
- package/esm/types/0_message_entity.d.ts +91 -74
- package/esm/types/0_message_identifier.d.ts +4 -0
- package/esm/types/0_message_identifier.js +1 -0
- package/esm/types/0_network_statistics_entry.d.ts +4 -0
- package/esm/types/0_network_statistics_entry.js +1 -0
- package/esm/types/0_reaction.d.ts +14 -10
- package/esm/types/0_reaction.js +29 -1
- package/esm/types/1__getters.d.ts +3 -0
- package/esm/types/1_bot_command_scope.d.ts +32 -27
- package/esm/types/1_chat_p.d.ts +77 -68
- package/esm/types/1_giveaway.d.ts +8 -0
- package/esm/types/1_giveaway.js +7 -0
- package/esm/types/1_keyboard_button.d.ts +41 -57
- package/esm/types/1_keyboard_button.js +3 -0
- package/esm/types/1_message_reaction.d.ts +14 -0
- package/esm/types/1_message_reaction.js +22 -0
- package/esm/types/1_network_statistics.d.ts +5 -0
- package/esm/types/1_network_statistics.js +1 -0
- package/esm/types/1_poll.d.ts +0 -13
- package/esm/types/1_reaction_count.d.ts +7 -0
- package/esm/types/1_reaction_count.js +6 -0
- package/esm/types/1_user.d.ts +2 -2
- package/esm/types/2_game.d.ts +0 -7
- package/esm/types/2_inline_keyboard_button.d.ts +36 -37
- package/esm/types/2_inline_query.d.ts +0 -6
- package/esm/types/2_message_interactions.d.ts +8 -0
- package/esm/types/2_message_interactions.js +1 -0
- package/esm/types/2_message_reaction_count.d.ts +8 -0
- package/esm/types/2_message_reaction_count.js +1 -0
- package/esm/types/2_reply_keyboard_markup.d.ts +0 -7
- package/esm/types/3_inline_keyboard_markup.d.ts +0 -2
- package/esm/types/4_message.d.ts +457 -0
- package/esm/types/{3_message.js → 4_message.js} +216 -129
- package/{script/types/4_callback_query.d.ts → esm/types/5_callback_query.d.ts} +1 -1
- package/esm/types/5_chat.d.ts +37 -0
- package/esm/types/{4_chat.js → 5_chat.js} +2 -2
- package/esm/types/6_update.d.ts +134 -0
- package/esm/types/6_update.js +1 -0
- package/package.json +1 -1
- package/script/3_errors.d.ts +519 -510
- package/script/3_errors.js +533 -520
- package/script/3_types.d.ts +19 -7
- package/script/3_types.js +19 -7
- package/script/4_constants.d.ts +2 -2
- package/script/4_constants.js +2 -2
- package/script/4_errors.d.ts +7 -12
- package/script/4_errors.js +5 -6
- package/script/5_client.d.ts +3 -3
- package/script/5_client.js +3 -3
- package/script/client/0_utilities.d.ts +30 -2
- package/script/client/0_utilities.js +15 -6
- package/script/client/1_composer.d.ts +30 -0
- package/script/client/{4_composer.js → 1_composer.js} +17 -4
- package/script/client/2_client_plain.d.ts +1 -1
- package/script/client/2_client_plain.js +2 -2
- package/script/client/{3_types.d.ts → 3_params.d.ts} +68 -172
- package/script/client/3_params.js +2 -0
- package/script/client/{5_client.d.ts → 4_client.d.ts} +89 -57
- package/script/client/{5_client.js → 4_client.js} +505 -314
- package/script/client/5_composer.d.ts +4 -0
- package/script/client/{6_composer.js → 5_composer.js} +2 -2
- package/script/storage/0_storage.d.ts +4 -1
- package/script/storage/0_storage.js +36 -7
- package/script/storage/1_storage_indexed_db.d.ts +6 -2
- package/script/storage/1_storage_indexed_db.js +7 -5
- package/script/storage/1_storage_local_storage.d.ts +1 -1
- package/script/storage/1_storage_local_storage.js +1 -1
- package/script/storage/1_storage_memory.d.ts +1 -1
- package/script/storage/1_storage_memory.js +1 -1
- package/script/storage/1_storage_session_storage.d.ts +1 -1
- package/script/storage/1_storage_session_storage.js +1 -1
- package/script/tl/2_types.d.ts +313 -24
- package/script/tl/2_types.js +1169 -217
- package/script/tl/3_functions.d.ts +95 -32
- package/script/tl/3_functions.js +241 -77
- package/script/tl/3_utilities.d.ts +1 -0
- package/script/tl/3_utilities.js +16 -1
- package/script/tl/6_message.js +1 -1
- package/script/types/0_authorization_state.d.ts +5 -0
- package/script/types/0_authorization_state.js +2 -0
- package/script/types/0_chat_photo.d.ts +22 -21
- package/script/types/0_connection_state.d.ts +17 -0
- package/script/types/0_connection_state.js +2 -0
- package/script/types/0_giveaway_parameters.d.ts +9 -0
- package/script/types/0_giveaway_parameters.js +13 -0
- package/script/types/0_login_url.d.ts +0 -4
- package/script/types/0_mask_position.d.ts +0 -4
- package/script/types/0_message_entity.d.ts +91 -74
- package/script/types/0_message_identifier.d.ts +4 -0
- package/script/types/0_message_identifier.js +2 -0
- package/script/types/0_network_statistics_entry.d.ts +4 -0
- package/script/types/0_network_statistics_entry.js +2 -0
- package/script/types/0_reaction.d.ts +14 -10
- package/script/types/0_reaction.js +33 -0
- package/script/types/1__getters.d.ts +3 -0
- package/script/types/1_bot_command_scope.d.ts +32 -27
- package/script/types/1_chat_p.d.ts +77 -68
- package/script/types/1_giveaway.d.ts +8 -0
- package/script/types/1_giveaway.js +11 -0
- package/script/types/1_keyboard_button.d.ts +41 -57
- package/script/types/1_keyboard_button.js +3 -0
- package/script/types/1_message_reaction.d.ts +14 -0
- package/script/types/1_message_reaction.js +26 -0
- package/script/types/1_network_statistics.d.ts +5 -0
- package/script/types/1_network_statistics.js +2 -0
- package/script/types/1_poll.d.ts +0 -13
- package/script/types/1_reaction_count.d.ts +7 -0
- package/script/types/1_reaction_count.js +10 -0
- package/script/types/1_user.d.ts +2 -2
- package/script/types/2_game.d.ts +0 -7
- package/script/types/2_inline_keyboard_button.d.ts +36 -37
- package/script/types/2_inline_query.d.ts +0 -6
- package/script/types/2_message_interactions.d.ts +8 -0
- package/script/types/2_message_interactions.js +2 -0
- package/script/types/2_message_reaction_count.d.ts +8 -0
- package/script/types/2_message_reaction_count.js +2 -0
- package/script/types/2_reply_keyboard_markup.d.ts +0 -7
- package/script/types/3_inline_keyboard_markup.d.ts +0 -2
- package/script/types/4_message.d.ts +457 -0
- package/script/types/{3_message.js → 4_message.js} +218 -130
- package/{esm/types/4_callback_query.d.ts → script/types/5_callback_query.d.ts} +1 -1
- package/script/types/5_chat.d.ts +37 -0
- package/script/types/{4_chat.js → 5_chat.js} +3 -3
- package/script/types/6_update.d.ts +134 -0
- package/script/types/6_update.js +2 -0
- package/esm/client/3_types.js +0 -11
- package/esm/client/4_composer.d.ts +0 -31
- package/esm/client/6_composer.d.ts +0 -4
- package/esm/client/6_composer.js +0 -3
- package/esm/types/3_message.d.ts +0 -182
- package/esm/types/4_chat.d.ts +0 -34
- package/script/client/3_types.js +0 -15
- package/script/client/4_composer.d.ts +0 -31
- package/script/client/6_composer.d.ts +0 -4
- package/script/types/3_message.d.ts +0 -182
- package/script/types/4_chat.d.ts +0 -34
- /package/esm/client/{1_client_abstract.d.ts → 0_client_abstract.d.ts} +0 -0
- /package/esm/client/{1_client_abstract.js → 0_client_abstract.js} +0 -0
- /package/esm/types/{0_audio.d.ts → 1_audio.d.ts} +0 -0
- /package/esm/types/{0_audio.js → 1_audio.js} +0 -0
- /package/esm/types/{4_callback_query.js → 5_callback_query.js} +0 -0
- /package/script/client/{1_client_abstract.d.ts → 0_client_abstract.d.ts} +0 -0
- /package/script/client/{1_client_abstract.js → 0_client_abstract.js} +0 -0
- /package/script/types/{0_audio.d.ts → 1_audio.d.ts} +0 -0
- /package/script/types/{0_audio.js → 1_audio.js} +0 -0
- /package/script/types/{4_callback_query.js → 5_callback_query.js} +0 -0
|
@@ -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 _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers,
|
|
13
|
+
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_guaranteeUpdateDelivery, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueues, _Client_getHandleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_channelUpdateQueues, _Client_processChannelPtsUpdateInner, _Client_queueUpdate, _Client_processChannelPtsUpdate, _Client_mainBoxId, _Client_processPtsUpdateInner, _Client_ptsUpdateQueue, _Client_processPtsUpdate, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_constructReplyTo, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdatesSet, _Client_handleStoredUpdates, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendDocumentInner, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_tryGetChatId, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats, _Client_sendReaction;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Client = exports.ConnectionError = exports.restartAuth = exports.skipInvoke = exports.handleMigrationError = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -20,14 +20,13 @@ const _3_storage_js_1 = require("../3_storage.js");
|
|
|
20
20
|
const _3_types_js_1 = require("../3_types.js");
|
|
21
21
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
22
22
|
const _4_errors_js_1 = require("../4_errors.js");
|
|
23
|
+
const _0_client_abstract_js_1 = require("./0_client_abstract.js");
|
|
23
24
|
const _0_html_js_1 = require("./0_html.js");
|
|
24
25
|
const _0_message_js_1 = require("./0_message.js");
|
|
25
26
|
const _0_password_js_1 = require("./0_password.js");
|
|
26
27
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
27
|
-
const
|
|
28
|
+
const _1_composer_js_1 = require("./1_composer.js");
|
|
28
29
|
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
29
|
-
const _3_types_js_2 = require("./3_types.js");
|
|
30
|
-
const _4_composer_js_1 = require("./4_composer.js");
|
|
31
30
|
const d = (0, _0_deps_js_1.debug)("Client");
|
|
32
31
|
const dGap = (0, _0_deps_js_1.debug)("Client/recoverUpdateGap");
|
|
33
32
|
const dGapC = (0, _0_deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
@@ -47,7 +46,7 @@ exports.restartAuth = Symbol();
|
|
|
47
46
|
class ConnectionError extends Error {
|
|
48
47
|
}
|
|
49
48
|
exports.ConnectionError = ConnectionError;
|
|
50
|
-
class Client extends
|
|
49
|
+
class Client extends _0_client_abstract_js_1.ClientAbstract {
|
|
51
50
|
/**
|
|
52
51
|
* Constructs the client.
|
|
53
52
|
*
|
|
@@ -76,6 +75,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
76
75
|
_Client_promises.set(this, new Map());
|
|
77
76
|
_Client_toAcknowledge.set(this, new Set());
|
|
78
77
|
_Client_updateState.set(this, void 0);
|
|
78
|
+
_Client_guaranteeUpdateDelivery.set(this, void 0);
|
|
79
79
|
Object.defineProperty(this, "storage", {
|
|
80
80
|
enumerable: true,
|
|
81
81
|
configurable: true,
|
|
@@ -185,163 +185,179 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
185
185
|
})
|
|
186
186
|
});
|
|
187
187
|
_Client_constructContext.set(this, async (update) => {
|
|
188
|
-
const msg = update.message
|
|
188
|
+
const msg = "message" in update ? update.message : "editedMessage" in update ? update.editedMessage : "callbackQuery" in update ? update.callbackQuery.message : undefined;
|
|
189
|
+
const reactions = "messageInteractions" in update ? update.messageInteractions : undefined;
|
|
189
190
|
const mustGetMsg = () => {
|
|
190
191
|
if (msg !== undefined) {
|
|
191
|
-
return msg;
|
|
192
|
+
return { chatId: msg.chat.id, messageId: msg.id };
|
|
193
|
+
}
|
|
194
|
+
else if (reactions !== undefined) {
|
|
195
|
+
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
192
196
|
}
|
|
193
197
|
else {
|
|
194
198
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
195
199
|
}
|
|
196
200
|
};
|
|
197
201
|
const chat = msg?.chat;
|
|
198
|
-
const from = update.callbackQuery
|
|
202
|
+
const from = "callbackQuery" in update ? update.callbackQuery.from : "inlineQuery" in update ? update.inlineQuery.from : "message" in update ? update.message.from : "editedMessage" in update ? update.editedMessage?.from : undefined;
|
|
199
203
|
const senderChat = msg?.senderChat;
|
|
200
|
-
const getReplyToMessageId = (quote,
|
|
201
|
-
const
|
|
202
|
-
const
|
|
204
|
+
const getReplyToMessageId = (quote, chatId, messageId) => {
|
|
205
|
+
const isPrivate = chatId > 0;
|
|
206
|
+
const shouldQuote = quote === undefined ? !isPrivate : quote;
|
|
207
|
+
const replyToMessageId = shouldQuote ? messageId : undefined;
|
|
203
208
|
return replyToMessageId;
|
|
204
209
|
};
|
|
205
|
-
const me =
|
|
206
|
-
|
|
210
|
+
const me = "connectionState" in update ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : ("authorizationState" in update && !update.authorizationState.authorized) ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMe).call(this);
|
|
211
|
+
const context = {
|
|
207
212
|
...update,
|
|
208
213
|
client: this,
|
|
209
|
-
me: me == null ? undefined : me,
|
|
210
|
-
msg,
|
|
211
|
-
chat,
|
|
212
|
-
from,
|
|
213
|
-
senderChat,
|
|
214
|
+
me: (me == null ? undefined : me),
|
|
215
|
+
msg: msg,
|
|
216
|
+
chat: chat,
|
|
217
|
+
from: from,
|
|
218
|
+
senderChat: senderChat,
|
|
219
|
+
get toJSON() {
|
|
220
|
+
return () => update;
|
|
221
|
+
},
|
|
214
222
|
reply: (text, params) => {
|
|
215
|
-
const
|
|
216
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
217
|
-
return this.sendMessage(
|
|
223
|
+
const { chatId, messageId } = mustGetMsg();
|
|
224
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
225
|
+
return this.sendMessage(chatId, text, { ...params, replyToMessageId });
|
|
218
226
|
},
|
|
219
227
|
replyPoll: (question, options, params) => {
|
|
220
|
-
const
|
|
221
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
222
|
-
return this.sendPoll(
|
|
228
|
+
const { chatId, messageId } = mustGetMsg();
|
|
229
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
230
|
+
return this.sendPoll(chatId, question, options, { ...params, replyToMessageId });
|
|
223
231
|
},
|
|
224
232
|
replyPhoto: (photo, params) => {
|
|
225
|
-
const
|
|
226
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
227
|
-
return this.sendPhoto(
|
|
233
|
+
const { chatId, messageId } = mustGetMsg();
|
|
234
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
235
|
+
return this.sendPhoto(chatId, photo, { ...params, replyToMessageId });
|
|
228
236
|
},
|
|
229
237
|
replyDocument: (document, params) => {
|
|
230
|
-
const
|
|
231
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
232
|
-
return this.sendDocument(
|
|
238
|
+
const { chatId, messageId } = mustGetMsg();
|
|
239
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
240
|
+
return this.sendDocument(chatId, document, { ...params, replyToMessageId });
|
|
233
241
|
},
|
|
234
242
|
replyContact: (firstName, number, params) => {
|
|
235
|
-
const
|
|
236
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
237
|
-
return this.sendContact(
|
|
243
|
+
const { chatId, messageId } = mustGetMsg();
|
|
244
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
245
|
+
return this.sendContact(chatId, firstName, number, { ...params, replyToMessageId });
|
|
238
246
|
},
|
|
239
247
|
replyLocation: (latitude, longitude, params) => {
|
|
240
|
-
const
|
|
241
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
242
|
-
return this.sendLocation(
|
|
248
|
+
const { chatId, messageId } = mustGetMsg();
|
|
249
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
250
|
+
return this.sendLocation(chatId, latitude, longitude, { ...params, replyToMessageId });
|
|
243
251
|
},
|
|
244
252
|
replyDice: (params) => {
|
|
245
|
-
const
|
|
246
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
247
|
-
return this.sendDice(
|
|
253
|
+
const { chatId, messageId } = mustGetMsg();
|
|
254
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
255
|
+
return this.sendDice(chatId, { ...params, replyToMessageId });
|
|
248
256
|
},
|
|
249
257
|
replyVenue: (latitude, longitude, title, address, params) => {
|
|
250
|
-
const
|
|
251
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
252
|
-
return this.sendVenue(
|
|
258
|
+
const { chatId, messageId } = mustGetMsg();
|
|
259
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
260
|
+
return this.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyToMessageId });
|
|
253
261
|
},
|
|
254
|
-
replyVideo: (
|
|
255
|
-
const
|
|
256
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
257
|
-
return this.
|
|
262
|
+
replyVideo: (video, params) => {
|
|
263
|
+
const { chatId, messageId } = mustGetMsg();
|
|
264
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
265
|
+
return this.sendVideo(chatId, video, { ...params, replyToMessageId });
|
|
258
266
|
},
|
|
259
267
|
replyAnimation: (document, params) => {
|
|
260
|
-
const
|
|
261
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
262
|
-
return this.sendAnimation(
|
|
268
|
+
const { chatId, messageId } = mustGetMsg();
|
|
269
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
270
|
+
return this.sendAnimation(chatId, document, { ...params, replyToMessageId });
|
|
263
271
|
},
|
|
264
272
|
replyVoice: (document, params) => {
|
|
265
|
-
const
|
|
266
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
267
|
-
return this.sendVoice(
|
|
273
|
+
const { chatId, messageId } = mustGetMsg();
|
|
274
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
275
|
+
return this.sendVoice(chatId, document, { ...params, replyToMessageId });
|
|
268
276
|
},
|
|
269
277
|
replyAudio: (document, params) => {
|
|
270
|
-
const
|
|
271
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
272
|
-
return this.sendAudio(
|
|
278
|
+
const { chatId, messageId } = mustGetMsg();
|
|
279
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
280
|
+
return this.sendAudio(chatId, document, { ...params, replyToMessageId });
|
|
273
281
|
},
|
|
274
282
|
replyVideoNote: (videoNote, params) => {
|
|
275
|
-
const
|
|
276
|
-
const replyToMessageId = getReplyToMessageId(params?.quote,
|
|
277
|
-
return this.sendVideoNote(
|
|
283
|
+
const { chatId, messageId } = mustGetMsg();
|
|
284
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, chatId, messageId);
|
|
285
|
+
return this.sendVideoNote(chatId, videoNote, { ...params, replyToMessageId });
|
|
278
286
|
},
|
|
279
287
|
delete: () => {
|
|
280
|
-
const
|
|
281
|
-
return this.deleteMessage(
|
|
288
|
+
const { chatId, messageId } = mustGetMsg();
|
|
289
|
+
return this.deleteMessage(chatId, messageId);
|
|
282
290
|
},
|
|
283
291
|
forward: (to, params) => {
|
|
284
|
-
const
|
|
285
|
-
return this.forwardMessage(
|
|
292
|
+
const { chatId, messageId } = mustGetMsg();
|
|
293
|
+
return this.forwardMessage(chatId, to, messageId, params);
|
|
294
|
+
},
|
|
295
|
+
react: (reactions, params) => {
|
|
296
|
+
const { chatId, messageId } = mustGetMsg();
|
|
297
|
+
return this.setReactions(chatId, messageId, reactions, params);
|
|
286
298
|
},
|
|
287
299
|
answerCallbackQuery: (params) => {
|
|
288
|
-
|
|
289
|
-
if (callbackQuery === undefined) {
|
|
300
|
+
if (!("callbackQuery" in update)) {
|
|
290
301
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
291
302
|
}
|
|
292
|
-
return this.answerCallbackQuery(callbackQuery.id, params);
|
|
303
|
+
return this.answerCallbackQuery(update.callbackQuery.id, params);
|
|
293
304
|
},
|
|
294
305
|
answerInlineQuery: (results, params) => {
|
|
295
|
-
|
|
296
|
-
if (inlineQuery == undefined) {
|
|
306
|
+
if (!("inlineQuery" in update)) {
|
|
297
307
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
298
308
|
}
|
|
299
|
-
return this.answerInlineQuery(inlineQuery.id, results, params);
|
|
309
|
+
return this.answerInlineQuery(update.inlineQuery.id, results, params);
|
|
300
310
|
},
|
|
301
311
|
sendChatAction: (chatAction, params) => {
|
|
302
|
-
const
|
|
303
|
-
return this.sendChatAction(
|
|
312
|
+
const { chatId } = mustGetMsg();
|
|
313
|
+
return this.sendChatAction(chatId, chatAction, params);
|
|
304
314
|
},
|
|
305
315
|
editMessageText: (messageId, text, params) => {
|
|
306
|
-
const
|
|
307
|
-
return this.editMessageText(
|
|
316
|
+
const { chatId } = mustGetMsg();
|
|
317
|
+
return this.editMessageText(chatId, messageId, text, params);
|
|
308
318
|
},
|
|
309
319
|
getMessage: (messageId) => {
|
|
310
|
-
const
|
|
311
|
-
return this.getMessage(
|
|
320
|
+
const { chatId } = mustGetMsg();
|
|
321
|
+
return this.getMessage(chatId, messageId);
|
|
312
322
|
},
|
|
313
323
|
getMessages: (messageIds) => {
|
|
314
|
-
const
|
|
315
|
-
return this.getMessages(
|
|
324
|
+
const { chatId } = mustGetMsg();
|
|
325
|
+
return this.getMessages(chatId, messageIds);
|
|
316
326
|
},
|
|
317
327
|
forwardMessage: (to, messageId, params) => {
|
|
318
|
-
const
|
|
319
|
-
return this.forwardMessage(
|
|
328
|
+
const { chatId } = mustGetMsg();
|
|
329
|
+
return this.forwardMessage(chatId, to, messageId, params);
|
|
320
330
|
},
|
|
321
331
|
forwardMessages: (to, messageIds, params) => {
|
|
322
|
-
const
|
|
323
|
-
return this.forwardMessages(
|
|
332
|
+
const { chatId } = mustGetMsg();
|
|
333
|
+
return this.forwardMessages(chatId, to, messageIds, params);
|
|
324
334
|
},
|
|
325
335
|
deleteMessage: (messageId, params) => {
|
|
326
|
-
const
|
|
327
|
-
return this.deleteMessage(
|
|
336
|
+
const { chatId } = mustGetMsg();
|
|
337
|
+
return this.deleteMessage(chatId, messageId, params);
|
|
328
338
|
},
|
|
329
339
|
deleteMessages: (messageIds, params) => {
|
|
330
|
-
const
|
|
331
|
-
return this.deleteMessages(
|
|
340
|
+
const { chatId } = mustGetMsg();
|
|
341
|
+
return this.deleteMessages(chatId, messageIds, params);
|
|
332
342
|
},
|
|
333
343
|
setAvailableReactions: (availableReactions) => {
|
|
334
|
-
const
|
|
335
|
-
return this.setAvailableReactions(
|
|
344
|
+
const { chatId } = mustGetMsg();
|
|
345
|
+
return this.setAvailableReactions(chatId, availableReactions);
|
|
336
346
|
},
|
|
337
347
|
addReaction: (messageId, reaction, params) => {
|
|
338
|
-
const
|
|
339
|
-
return this.addReaction(
|
|
348
|
+
const { chatId } = mustGetMsg();
|
|
349
|
+
return this.addReaction(chatId, messageId, reaction, params);
|
|
340
350
|
},
|
|
341
|
-
|
|
342
|
-
|
|
351
|
+
removeReaction: (messageId, reaction) => {
|
|
352
|
+
const { chatId } = mustGetMsg();
|
|
353
|
+
return this.removeReaction(chatId, messageId, reaction);
|
|
354
|
+
},
|
|
355
|
+
setReactions: (messageId, reactions, params) => {
|
|
356
|
+
const { chatId } = mustGetMsg();
|
|
357
|
+
return this.setReactions(chatId, messageId, reactions, params);
|
|
343
358
|
},
|
|
344
|
-
}
|
|
359
|
+
};
|
|
360
|
+
return (0, _1_utilities_js_1.cleanObject)(context, false);
|
|
345
361
|
});
|
|
346
362
|
_Client_lastPropagatedConnectionState.set(this, null);
|
|
347
363
|
Object.defineProperty(this, "stateChangeHandler", {
|
|
@@ -399,16 +415,20 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
399
415
|
},
|
|
400
416
|
})
|
|
401
417
|
});
|
|
402
|
-
|
|
418
|
+
_Client_handleUpdateQueues.set(this, new Map());
|
|
403
419
|
_Client_processUpdatesQueue.set(this, new _1_utilities_js_1.Queue("processUpdates"));
|
|
420
|
+
_Client_channelUpdateQueues.set(this, new Map());
|
|
421
|
+
_Client_mainBoxId.set(this, 0n);
|
|
422
|
+
_Client_ptsUpdateQueue.set(this, new _1_utilities_js_1.Queue("ptsUpdate"));
|
|
404
423
|
_Client_lastUpdates.set(this, new Date());
|
|
405
424
|
_Client_lastGetMe.set(this, null);
|
|
425
|
+
_Client_handleUpdatesSet.set(this, new Set());
|
|
406
426
|
_Client_usernameResolver.set(this, async (v) => {
|
|
407
427
|
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
408
428
|
return new _2_tl_js_1.types.InputUser(inputPeer);
|
|
409
429
|
});
|
|
410
430
|
//#region Composer
|
|
411
|
-
_Client_handle.set(this,
|
|
431
|
+
_Client_handle.set(this, _1_composer_js_1.skip);
|
|
412
432
|
_Client_chats.set(this, new Map());
|
|
413
433
|
_Client_archivedChats.set(this, new Map());
|
|
414
434
|
_Client_chatsLoadedFromStorage.set(this, false);
|
|
@@ -428,6 +448,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
428
448
|
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
429
449
|
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
430
450
|
__classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
|
|
451
|
+
__classPrivateFieldSet(this, _Client_guaranteeUpdateDelivery, params?.guaranteeUpdateDelivery ?? false, "f");
|
|
431
452
|
const transportProvider = this.transportProvider;
|
|
432
453
|
this.transportProvider = (params) => {
|
|
433
454
|
const transport = transportProvider(params);
|
|
@@ -492,7 +513,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
492
513
|
*/
|
|
493
514
|
async setDc(dc) {
|
|
494
515
|
if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
|
|
495
|
-
await this.storage.
|
|
516
|
+
await this.storage.initialize();
|
|
496
517
|
__classPrivateFieldSet(this, _Client_storageInited, true, "f");
|
|
497
518
|
}
|
|
498
519
|
if (await this.storage.getDc() != dc) {
|
|
@@ -514,7 +535,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
514
535
|
const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
|
|
515
536
|
try {
|
|
516
537
|
if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
|
|
517
|
-
await this.storage.
|
|
538
|
+
await this.storage.initialize();
|
|
539
|
+
if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
|
|
540
|
+
await this.storage.deleteUpdates();
|
|
541
|
+
}
|
|
518
542
|
__classPrivateFieldSet(this, _Client_storageInited, true, "f");
|
|
519
543
|
}
|
|
520
544
|
const authKey = await this.storage.getAuthKey();
|
|
@@ -557,8 +581,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
557
581
|
release();
|
|
558
582
|
}
|
|
559
583
|
}
|
|
560
|
-
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(),
|
|
561
|
-
__classPrivateFieldGet(this,
|
|
584
|
+
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_namespaceProxies = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueues = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_channelUpdateQueues = new WeakMap(), _Client_mainBoxId = new WeakMap(), _Client_ptsUpdateQueue = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_handleUpdatesSet = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_chats = new WeakMap(), _Client_archivedChats = new WeakMap(), _Client_chatsLoadedFromStorage = new WeakMap(), _Client_pinnedChats = new WeakMap(), _Client_pinnedArchiveChats = new WeakMap(), _Client_storageHadPinnedChats = new WeakMap(), _Client_pinnedChatsLoaded = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
585
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
|
|
562
586
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), _0_utilities_js_1.resolve);
|
|
563
587
|
});
|
|
564
588
|
__classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
|
|
@@ -889,11 +913,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
889
913
|
dRecv("RPCResult: %s", (typeof result === "object" && _2_tl_js_1.name in result) ? result[_2_tl_js_1.name] : result.constructor.name);
|
|
890
914
|
}
|
|
891
915
|
const messageId = message.body.messageId;
|
|
916
|
+
const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
|
|
892
917
|
const resolvePromise = () => {
|
|
893
|
-
const promise = __classPrivateFieldGet(this, _Client_promises, "f").get(messageId);
|
|
894
918
|
if (promise) {
|
|
895
919
|
if (result instanceof _2_tl_js_1.types.Rpc_error) {
|
|
896
|
-
promise.reject((0, _4_errors_js_1.upgradeInstance)(result));
|
|
920
|
+
promise.reject((0, _4_errors_js_1.upgradeInstance)(result, promise.call));
|
|
897
921
|
}
|
|
898
922
|
else {
|
|
899
923
|
promise.resolve(result);
|
|
@@ -903,7 +927,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
903
927
|
};
|
|
904
928
|
if (result instanceof _2_tl_js_1.types._Updates || result instanceof _2_tl_js_1.types._Update) {
|
|
905
929
|
__classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(async () => {
|
|
906
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true);
|
|
930
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true, promise?.call);
|
|
907
931
|
resolvePromise();
|
|
908
932
|
});
|
|
909
933
|
}
|
|
@@ -1004,13 +1028,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1004
1028
|
}
|
|
1005
1029
|
},
|
|
1006
1030
|
reject: () => { },
|
|
1031
|
+
call: function_,
|
|
1007
1032
|
});
|
|
1008
1033
|
return;
|
|
1009
1034
|
}
|
|
1010
1035
|
let result;
|
|
1011
1036
|
try {
|
|
1012
1037
|
result = await new Promise((resolve, reject) => {
|
|
1013
|
-
__classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject });
|
|
1038
|
+
__classPrivateFieldGet(this, _Client_promises, "f").set(message.id, { resolve, reject, call: function_ });
|
|
1014
1039
|
});
|
|
1015
1040
|
}
|
|
1016
1041
|
catch (err) {
|
|
@@ -1071,6 +1096,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1071
1096
|
}
|
|
1072
1097
|
}
|
|
1073
1098
|
}
|
|
1099
|
+
}, _Client_getHandleUpdateQueue = function _Client_getHandleUpdateQueue(boxId) {
|
|
1100
|
+
let queue = __classPrivateFieldGet(this, _Client_handleUpdateQueues, "f").get(boxId);
|
|
1101
|
+
if (queue !== undefined) {
|
|
1102
|
+
return queue;
|
|
1103
|
+
}
|
|
1104
|
+
else {
|
|
1105
|
+
queue = new _1_utilities_js_1.Queue(`handleUpdate-${boxId}`);
|
|
1106
|
+
return queue;
|
|
1107
|
+
}
|
|
1074
1108
|
}, _Client_checkGap = async function _Client_checkGap(pts, ptsCount) {
|
|
1075
1109
|
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1076
1110
|
if (localState.pts + ptsCount < pts) {
|
|
@@ -1084,9 +1118,77 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1084
1118
|
if (localPts + ptsCount < pts) {
|
|
1085
1119
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
1086
1120
|
}
|
|
1087
|
-
},
|
|
1121
|
+
}, _Client_processChannelPtsUpdateInner = async function _Client_processChannelPtsUpdateInner(update, checkGap) {
|
|
1122
|
+
const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peer_id[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channel_id : update.channel_id;
|
|
1123
|
+
if (update instanceof _2_tl_js_1.types.UpdateChannelTooLong) {
|
|
1124
|
+
if (update.pts != undefined) {
|
|
1125
|
+
await this.storage.setChannelPts(channelId, update.pts);
|
|
1126
|
+
}
|
|
1127
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "updateChannelTooLong");
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
if (update.pts != 0) {
|
|
1131
|
+
const ptsCount = update.pts_count;
|
|
1132
|
+
if (checkGap) {
|
|
1133
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkChannelGap).call(this, channelId, update.pts, ptsCount);
|
|
1134
|
+
}
|
|
1135
|
+
let currentPts = await this.storage.getChannelPts(channelId);
|
|
1136
|
+
currentPts ??= update.pts - ptsCount;
|
|
1137
|
+
if (currentPts + ptsCount > update.pts) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
|
|
1142
|
+
await this.storage.setUpdate(channelId, update);
|
|
1143
|
+
}
|
|
1144
|
+
if (update.pts != 0) {
|
|
1145
|
+
await this.storage.setChannelPts(channelId, update.pts);
|
|
1146
|
+
}
|
|
1147
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, channelId, true);
|
|
1148
|
+
}, _Client_queueUpdate = function _Client_queueUpdate(update, boxId, pts) {
|
|
1149
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, boxId).add(async () => {
|
|
1150
|
+
if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f") && pts) {
|
|
1151
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleStoredUpdates).call(this, boxId);
|
|
1152
|
+
}
|
|
1153
|
+
else {
|
|
1154
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
}, _Client_processChannelPtsUpdate = function _Client_processChannelPtsUpdate(update, checkGap) {
|
|
1158
|
+
const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peer_id[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channel_id : update.channel_id;
|
|
1159
|
+
let queue = __classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").get(channelId);
|
|
1160
|
+
if (queue == undefined) {
|
|
1161
|
+
queue = new _1_utilities_js_1.Queue(`channelUpdates-${channelId}`);
|
|
1162
|
+
__classPrivateFieldGet(this, _Client_channelUpdateQueues, "f").set(channelId, queue);
|
|
1163
|
+
}
|
|
1164
|
+
queue.add(async () => {
|
|
1165
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdateInner).call(this, update, checkGap);
|
|
1166
|
+
});
|
|
1167
|
+
}, _Client_processPtsUpdateInner = async function _Client_processPtsUpdateInner(update, checkGap) {
|
|
1168
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1169
|
+
if (update.pts != 0) {
|
|
1170
|
+
if (checkGap) {
|
|
1171
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkGap).call(this, update.pts, update.pts_count);
|
|
1172
|
+
}
|
|
1173
|
+
if (localState.pts + update.pts_count > update.pts) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
if (__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
|
|
1178
|
+
await this.storage.setUpdate(__classPrivateFieldGet(this, _Client_mainBoxId, "f"), update);
|
|
1179
|
+
}
|
|
1180
|
+
console.log("set pts to", update.pts, "from", update);
|
|
1181
|
+
if (update.pts != 0) {
|
|
1182
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
|
|
1183
|
+
}
|
|
1184
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, true);
|
|
1185
|
+
}, _Client_processPtsUpdate = function _Client_processPtsUpdate(update, checkGap) {
|
|
1186
|
+
__classPrivateFieldGet(this, _Client_ptsUpdateQueue, "f").add(async () => {
|
|
1187
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdateInner).call(this, update, checkGap);
|
|
1188
|
+
});
|
|
1189
|
+
}, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap, call = null) {
|
|
1088
1190
|
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
1089
|
-
/// First, individual updates (Update[1])
|
|
1191
|
+
/// First, individual updates (Update[1]) are extracted from Updates.[2]
|
|
1090
1192
|
///
|
|
1091
1193
|
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
1092
1194
|
///
|
|
@@ -1107,14 +1209,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1107
1209
|
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1108
1210
|
const localSeq = localState.seq;
|
|
1109
1211
|
if (localSeq + 1 == seqStart) {
|
|
1110
|
-
// The
|
|
1212
|
+
// The update sequence can be applied.
|
|
1111
1213
|
localState.seq = seq;
|
|
1112
1214
|
localState.date = updates_.date;
|
|
1113
1215
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
1114
1216
|
await this.storage.setState(localState);
|
|
1115
1217
|
}
|
|
1116
1218
|
else if (localSeq + 1 > seqStart) {
|
|
1117
|
-
// The
|
|
1219
|
+
// The update sequence was already applied, and must be ignored.
|
|
1118
1220
|
d("localSeq + 1 > seqStart");
|
|
1119
1221
|
return;
|
|
1120
1222
|
}
|
|
@@ -1128,10 +1230,77 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1128
1230
|
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort) {
|
|
1129
1231
|
updates = [updates_.update];
|
|
1130
1232
|
}
|
|
1131
|
-
else if (updates_ instanceof _2_tl_js_1.types.UpdateShortMessage
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1233
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShortMessage) {
|
|
1234
|
+
updates = [
|
|
1235
|
+
new _2_tl_js_1.types.UpdateNewMessage({
|
|
1236
|
+
message: new _2_tl_js_1.types.Message({
|
|
1237
|
+
out: updates_.out,
|
|
1238
|
+
mentioned: updates_.mentioned,
|
|
1239
|
+
media_unread: updates_.media_unread,
|
|
1240
|
+
silent: updates_.silent,
|
|
1241
|
+
id: updates_.id,
|
|
1242
|
+
from_id: updates_.out ? new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ user_id: updates_.user_id }),
|
|
1243
|
+
peer_id: new _2_tl_js_1.types.PeerUser({ user_id: updates_.user_id }),
|
|
1244
|
+
message: updates_.message,
|
|
1245
|
+
date: updates_.date,
|
|
1246
|
+
fwd_from: updates_.fwd_from,
|
|
1247
|
+
via_bot_id: updates_.via_bot_id,
|
|
1248
|
+
reply_to: updates_.reply_to,
|
|
1249
|
+
entities: updates_.entities,
|
|
1250
|
+
ttl_period: updates_.ttl_period,
|
|
1251
|
+
}),
|
|
1252
|
+
pts: updates_.pts,
|
|
1253
|
+
pts_count: updates_.pts_count,
|
|
1254
|
+
}),
|
|
1255
|
+
];
|
|
1256
|
+
}
|
|
1257
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShortChatMessage) {
|
|
1258
|
+
updates = [
|
|
1259
|
+
new _2_tl_js_1.types.UpdateNewMessage({
|
|
1260
|
+
message: new _2_tl_js_1.types.Message({
|
|
1261
|
+
out: updates_.out,
|
|
1262
|
+
mentioned: updates_.mentioned,
|
|
1263
|
+
media_unread: updates_.media_unread,
|
|
1264
|
+
silent: updates_.silent,
|
|
1265
|
+
id: updates_.id,
|
|
1266
|
+
from_id: new _2_tl_js_1.types.PeerUser({ user_id: updates_.from_id }),
|
|
1267
|
+
peer_id: new _2_tl_js_1.types.PeerChat({ chat_id: updates_.chat_id }),
|
|
1268
|
+
fwd_from: updates_.fwd_from,
|
|
1269
|
+
via_bot_id: updates_.via_bot_id,
|
|
1270
|
+
reply_to: updates_.reply_to,
|
|
1271
|
+
date: updates_.date,
|
|
1272
|
+
message: updates_.message,
|
|
1273
|
+
entities: updates_.entities,
|
|
1274
|
+
ttl_period: updates_.ttl_period,
|
|
1275
|
+
}),
|
|
1276
|
+
pts: updates_.pts,
|
|
1277
|
+
pts_count: updates_.pts_count,
|
|
1278
|
+
}),
|
|
1279
|
+
];
|
|
1280
|
+
}
|
|
1281
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1282
|
+
if (!(call instanceof _2_tl_js_1.functions.messages.sendMessage)) {
|
|
1283
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1284
|
+
}
|
|
1285
|
+
updates = [
|
|
1286
|
+
new _2_tl_js_1.types.UpdateNewMessage({
|
|
1287
|
+
message: new _2_tl_js_1.types.Message({
|
|
1288
|
+
out: updates_.out,
|
|
1289
|
+
silent: call.silent,
|
|
1290
|
+
id: updates_.id,
|
|
1291
|
+
from_id: new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }),
|
|
1292
|
+
peer_id: (0, _2_tl_js_1.inputPeerToPeer)(call.peer),
|
|
1293
|
+
message: call.message,
|
|
1294
|
+
media: updates_.media,
|
|
1295
|
+
date: updates_.date,
|
|
1296
|
+
// reply_to: call.reply_to, // TODO?
|
|
1297
|
+
entities: updates_.entities,
|
|
1298
|
+
ttl_period: updates_.ttl_period,
|
|
1299
|
+
}),
|
|
1300
|
+
pts: updates_.pts,
|
|
1301
|
+
pts_count: updates_.pts_count,
|
|
1302
|
+
}),
|
|
1303
|
+
];
|
|
1135
1304
|
}
|
|
1136
1305
|
else if (updates_ instanceof _2_tl_js_1.types.UpdatesTooLong) {
|
|
1137
1306
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "updatesTooLong");
|
|
@@ -1143,86 +1312,20 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1143
1312
|
else {
|
|
1144
1313
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1145
1314
|
}
|
|
1146
|
-
/// Then, we go through each Update and updateShort*, and see if they are order-sensitive.
|
|
1147
|
-
/// If they were, we check the local state to see if it is OK to process them right away.
|
|
1148
|
-
///
|
|
1149
|
-
/// If we there was a gap, a recovery process will be initiated and the processing will be postponed.
|
|
1150
|
-
let localState = null;
|
|
1151
|
-
let originalPts = null;
|
|
1152
|
-
const channelPtsMap = new Map();
|
|
1153
|
-
for (const update of updates) {
|
|
1154
|
-
if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
|
|
1155
|
-
if (update.pts == 0) {
|
|
1156
|
-
continue;
|
|
1157
|
-
}
|
|
1158
|
-
if (checkGap) {
|
|
1159
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkGap).call(this, update.pts, update.pts_count);
|
|
1160
|
-
}
|
|
1161
|
-
localState ??= await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1162
|
-
originalPts ??= localState.pts;
|
|
1163
|
-
if (localState.pts + update.pts_count > update.pts) {
|
|
1164
|
-
updates = updates.filter((v) => v != update);
|
|
1165
|
-
}
|
|
1166
|
-
else {
|
|
1167
|
-
localState.pts = update.pts;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
else if ((0, _0_utilities_js_1.isChannelPtsUpdate)(update)) {
|
|
1171
|
-
if (update.pts == 0) {
|
|
1172
|
-
continue;
|
|
1173
|
-
}
|
|
1174
|
-
const ptsCount = update.pts_count;
|
|
1175
|
-
const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peer_id[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channel_id : update.channel_id;
|
|
1176
|
-
if (checkGap) {
|
|
1177
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkChannelGap).call(this, channelId, update.pts, ptsCount);
|
|
1178
|
-
}
|
|
1179
|
-
let currentPts = channelPtsMap.get(channelId);
|
|
1180
|
-
if (currentPts === undefined) {
|
|
1181
|
-
currentPts = await this.storage.getChannelPts(channelId);
|
|
1182
|
-
}
|
|
1183
|
-
currentPts ??= update.pts - ptsCount;
|
|
1184
|
-
if (currentPts + ptsCount > update.pts) {
|
|
1185
|
-
updates = updates.filter((v) => v != update);
|
|
1186
|
-
}
|
|
1187
|
-
else {
|
|
1188
|
-
channelPtsMap.set(channelId, update.pts);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
1315
|
/// We process the updates when we are sure there is no gap.
|
|
1193
1316
|
if (updates_ instanceof _2_tl_js_1.types.Updates || updates_ instanceof _2_tl_js_1.types.UpdatesCombined) {
|
|
1194
1317
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, updates_.chats);
|
|
1195
1318
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, updates_.users);
|
|
1196
1319
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
1197
1320
|
}
|
|
1198
|
-
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort
|
|
1321
|
+
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort ||
|
|
1322
|
+
updates_ instanceof _2_tl_js_1.types.UpdateShortMessage ||
|
|
1323
|
+
updates_ instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
|
|
1324
|
+
updates_ instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1199
1325
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
1200
1326
|
}
|
|
1201
|
-
const updatesToHandle = new Array();
|
|
1202
1327
|
for (const update of updates) {
|
|
1203
|
-
if (update instanceof _2_tl_js_1.types.
|
|
1204
|
-
update instanceof _2_tl_js_1.types.UpdateShortChatMessage ||
|
|
1205
|
-
update instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1206
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, update.date);
|
|
1207
|
-
}
|
|
1208
|
-
else if (update instanceof _2_tl_js_1.types.UpdateChannelTooLong) {
|
|
1209
|
-
if (update.pts != undefined) {
|
|
1210
|
-
await this.storage.setChannelPts(update.channel_id, update.pts);
|
|
1211
|
-
}
|
|
1212
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, update.channel_id, "updateChannelTooLong");
|
|
1213
|
-
}
|
|
1214
|
-
else if (update instanceof _2_tl_js_1.types.UpdateUserName) {
|
|
1215
|
-
await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
|
|
1216
|
-
const peer = new _2_tl_js_1.types.PeerUser(update);
|
|
1217
|
-
const entity = await this[getEntity](peer);
|
|
1218
|
-
if (entity != null) {
|
|
1219
|
-
entity.usernames = update.usernames;
|
|
1220
|
-
entity.first_name = update.first_name;
|
|
1221
|
-
entity.last_name = update.last_name;
|
|
1222
|
-
await this.storage.setEntity(entity);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
else if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
|
|
1328
|
+
if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
|
|
1226
1329
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
|
|
1227
1330
|
if (__classPrivateFieldGet(this, _Client_updateState, "f")) {
|
|
1228
1331
|
await this.storage.setState(__classPrivateFieldGet(this, _Client_updateState, "f"));
|
|
@@ -1231,31 +1334,16 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1231
1334
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1232
1335
|
}
|
|
1233
1336
|
}
|
|
1234
|
-
if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
|
|
1235
|
-
|
|
1337
|
+
else if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
|
|
1338
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_processPtsUpdate).call(this, update, checkGap);
|
|
1236
1339
|
}
|
|
1237
1340
|
else if ((0, _0_utilities_js_1.isChannelPtsUpdate)(update)) {
|
|
1238
|
-
|
|
1239
|
-
if ("channel_id" in update) {
|
|
1240
|
-
channelId = update.channel_id;
|
|
1241
|
-
}
|
|
1242
|
-
else if ("peer_id" in update.message && update.message.peer_id !== undefined && "channel_id" in update.message.peer_id) {
|
|
1243
|
-
channelId = update.message.peer_id.channel_id;
|
|
1244
|
-
}
|
|
1245
|
-
if (channelId != null) {
|
|
1246
|
-
await this.storage.setChannelPts(channelId, update.pts);
|
|
1247
|
-
}
|
|
1341
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_processChannelPtsUpdate).call(this, update, checkGap);
|
|
1248
1342
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
updatesToHandle.push(update);
|
|
1343
|
+
else {
|
|
1344
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_queueUpdate).call(this, update, 0n, false);
|
|
1252
1345
|
}
|
|
1253
1346
|
}
|
|
1254
|
-
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
1255
|
-
for (const update of updatesToHandle) {
|
|
1256
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
|
|
1257
|
-
}
|
|
1258
|
-
});
|
|
1259
1347
|
}, _Client_setUpdateStateDate = async function _Client_setUpdateStateDate(date) {
|
|
1260
1348
|
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1261
1349
|
localState.date = date;
|
|
@@ -1531,7 +1619,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1531
1619
|
reply_markup: replyMarkup,
|
|
1532
1620
|
});
|
|
1533
1621
|
const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1534
|
-
return
|
|
1622
|
+
return (0, _3_types_js_1.assertMessageType)(message_, "text");
|
|
1535
1623
|
}
|
|
1536
1624
|
/**
|
|
1537
1625
|
* Edit a message's text.
|
|
@@ -1553,7 +1641,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1553
1641
|
reply_markup: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params),
|
|
1554
1642
|
});
|
|
1555
1643
|
const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1556
|
-
return
|
|
1644
|
+
return (0, _3_types_js_1.assertMessageType)(message_, "text");
|
|
1557
1645
|
}
|
|
1558
1646
|
/**
|
|
1559
1647
|
* Retrieve multiple messages.
|
|
@@ -1584,7 +1672,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1584
1672
|
}
|
|
1585
1673
|
}
|
|
1586
1674
|
}
|
|
1587
|
-
else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage
|
|
1675
|
+
else if (updates instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
|
|
1588
1676
|
const message = await this.getMessage(chatId, updates.id);
|
|
1589
1677
|
if (message != null) {
|
|
1590
1678
|
messages.push(message);
|
|
@@ -1941,7 +2029,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1941
2029
|
message: "",
|
|
1942
2030
|
});
|
|
1943
2031
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1944
|
-
return
|
|
2032
|
+
return (0, _3_types_js_1.assertMessageType)(message, "poll");
|
|
1945
2033
|
}
|
|
1946
2034
|
/**
|
|
1947
2035
|
* Send a chat action.
|
|
@@ -2126,13 +2214,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2126
2214
|
});
|
|
2127
2215
|
}
|
|
2128
2216
|
use(...middleware) {
|
|
2129
|
-
const composer = new
|
|
2130
|
-
__classPrivateFieldSet(this, _Client_handle, (0,
|
|
2217
|
+
const composer = new _1_composer_js_1.Composer(...middleware);
|
|
2218
|
+
__classPrivateFieldSet(this, _Client_handle, (0, _1_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _1_composer_js_1.flatten)(composer)), "f");
|
|
2131
2219
|
return composer;
|
|
2132
2220
|
}
|
|
2133
2221
|
branch(predicate, trueHandler_, falseHandler_) {
|
|
2134
|
-
const trueHandler = (0,
|
|
2135
|
-
const falseHandler = (0,
|
|
2222
|
+
const trueHandler = (0, _1_composer_js_1.flatten)(trueHandler_);
|
|
2223
|
+
const falseHandler = (0, _1_composer_js_1.flatten)(falseHandler_);
|
|
2136
2224
|
return this.use(async (upd, next) => {
|
|
2137
2225
|
if (await predicate(upd)) {
|
|
2138
2226
|
await trueHandler(upd, next);
|
|
@@ -2143,15 +2231,25 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2143
2231
|
});
|
|
2144
2232
|
}
|
|
2145
2233
|
filter(predicate, ...middleware) {
|
|
2146
|
-
const composer = new
|
|
2147
|
-
this.branch(predicate, composer,
|
|
2234
|
+
const composer = new _1_composer_js_1.Composer(...middleware);
|
|
2235
|
+
this.branch(predicate, composer, _1_composer_js_1.skip);
|
|
2148
2236
|
return composer;
|
|
2149
2237
|
}
|
|
2150
2238
|
on(filter, ...middleawre) {
|
|
2151
2239
|
const type = typeof filter === "string" ? filter : filter[0];
|
|
2152
|
-
|
|
2240
|
+
let keys = Array.isArray(filter) ? filter.slice(1) : [];
|
|
2241
|
+
let messageType = null;
|
|
2242
|
+
if (type == "message") {
|
|
2243
|
+
messageType = keys[0];
|
|
2244
|
+
keys = keys.slice(1);
|
|
2245
|
+
}
|
|
2153
2246
|
return this.filter((ctx) => {
|
|
2154
2247
|
if (type in ctx) {
|
|
2248
|
+
if (messageType != null) {
|
|
2249
|
+
// deno-lint-ignore ban-ts-comment
|
|
2250
|
+
// @ts-ignore
|
|
2251
|
+
(0, _3_types_js_1.assertMessageType)(ctx[type], messageType);
|
|
2252
|
+
}
|
|
2155
2253
|
if (keys.length > 0) {
|
|
2156
2254
|
for (const key of keys) {
|
|
2157
2255
|
// deno-lint-ignore ban-ts-comment
|
|
@@ -2216,27 +2314,27 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2216
2314
|
*
|
|
2217
2315
|
* @method
|
|
2218
2316
|
*/
|
|
2219
|
-
async setMyDescription(
|
|
2317
|
+
async setMyDescription(params) {
|
|
2220
2318
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyDescription");
|
|
2221
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description, lang_code: languageCode ?? "" });
|
|
2319
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
|
|
2222
2320
|
}
|
|
2223
2321
|
/**
|
|
2224
2322
|
* Set the bot's name in the given language. Bot-only.
|
|
2225
2323
|
*
|
|
2226
2324
|
* @method
|
|
2227
2325
|
*/
|
|
2228
|
-
async setMyName(
|
|
2326
|
+
async setMyName(params) {
|
|
2229
2327
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyName");
|
|
2230
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name, lang_code: languageCode ?? "" });
|
|
2328
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
|
|
2231
2329
|
}
|
|
2232
2330
|
/**
|
|
2233
2331
|
* Set the bot's short description in the given language. Bot-only.
|
|
2234
2332
|
*
|
|
2235
2333
|
* @method
|
|
2236
2334
|
*/
|
|
2237
|
-
async setMyShortDescription(
|
|
2335
|
+
async setMyShortDescription(params) {
|
|
2238
2336
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "setMyShortDescription");
|
|
2239
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about, lang_code: languageCode ?? "" });
|
|
2337
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
|
|
2240
2338
|
}
|
|
2241
2339
|
/**
|
|
2242
2340
|
* Get the bot's description in the given language. Bot-only.
|
|
@@ -2321,7 +2419,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2321
2419
|
}
|
|
2322
2420
|
}
|
|
2323
2421
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
2324
|
-
return
|
|
2422
|
+
return (0, _3_types_js_1.assertMessageType)(message, "photo");
|
|
2325
2423
|
}
|
|
2326
2424
|
/**
|
|
2327
2425
|
* Send a document.
|
|
@@ -2332,7 +2430,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2332
2430
|
*/
|
|
2333
2431
|
async sendDocument(chatId, document, params) {
|
|
2334
2432
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendDocumentInner).call(this, chatId, document, params, _3_types_js_1.FileType.Document, []);
|
|
2335
|
-
return
|
|
2433
|
+
return (0, _3_types_js_1.assertMessageType)(message, "document");
|
|
2336
2434
|
}
|
|
2337
2435
|
/**
|
|
2338
2436
|
* Send a video.
|
|
@@ -2350,7 +2448,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2350
2448
|
duration: params?.duration ?? 0,
|
|
2351
2449
|
}),
|
|
2352
2450
|
]);
|
|
2353
|
-
return
|
|
2451
|
+
return (0, _3_types_js_1.assertMessageType)(message, "video");
|
|
2354
2452
|
}
|
|
2355
2453
|
/**
|
|
2356
2454
|
* Send an animation.
|
|
@@ -2369,7 +2467,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2369
2467
|
duration: params?.duration ?? 0,
|
|
2370
2468
|
}),
|
|
2371
2469
|
]);
|
|
2372
|
-
return
|
|
2470
|
+
return (0, _3_types_js_1.assertMessageType)(message, "animation");
|
|
2373
2471
|
}
|
|
2374
2472
|
/**
|
|
2375
2473
|
* Send a voice message.
|
|
@@ -2385,7 +2483,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2385
2483
|
duration: params?.duration ?? 0,
|
|
2386
2484
|
}),
|
|
2387
2485
|
]);
|
|
2388
|
-
return
|
|
2486
|
+
return (0, _3_types_js_1.assertMessageType)(message, "voice");
|
|
2389
2487
|
}
|
|
2390
2488
|
/**
|
|
2391
2489
|
* Send an audio file.
|
|
@@ -2402,7 +2500,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2402
2500
|
title: params?.title,
|
|
2403
2501
|
}),
|
|
2404
2502
|
]);
|
|
2405
|
-
return
|
|
2503
|
+
return (0, _3_types_js_1.assertMessageType)(message, "audio");
|
|
2406
2504
|
}
|
|
2407
2505
|
/**
|
|
2408
2506
|
* Send a video note.
|
|
@@ -2420,7 +2518,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2420
2518
|
duration: params?.duration ?? 0,
|
|
2421
2519
|
}),
|
|
2422
2520
|
], false);
|
|
2423
|
-
return
|
|
2521
|
+
return (0, _3_types_js_1.assertMessageType)(message, "videoNote");
|
|
2424
2522
|
}
|
|
2425
2523
|
/**
|
|
2426
2524
|
* Send a location.
|
|
@@ -2466,7 +2564,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2466
2564
|
message: "",
|
|
2467
2565
|
});
|
|
2468
2566
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2469
|
-
return
|
|
2567
|
+
return (0, _3_types_js_1.assertMessageType)(message, "location");
|
|
2470
2568
|
}
|
|
2471
2569
|
/**
|
|
2472
2570
|
* Send a contact.
|
|
@@ -2500,7 +2598,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2500
2598
|
message: "",
|
|
2501
2599
|
});
|
|
2502
2600
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2503
|
-
return
|
|
2601
|
+
return (0, _3_types_js_1.assertMessageType)(message, "contact");
|
|
2504
2602
|
}
|
|
2505
2603
|
/**
|
|
2506
2604
|
* Send a dice.
|
|
@@ -2529,7 +2627,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2529
2627
|
message: "",
|
|
2530
2628
|
});
|
|
2531
2629
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2532
|
-
return
|
|
2630
|
+
return (0, _3_types_js_1.assertMessageType)(message, "dice");
|
|
2533
2631
|
}
|
|
2534
2632
|
/**
|
|
2535
2633
|
* Send a venue.
|
|
@@ -2570,7 +2668,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2570
2668
|
message: "",
|
|
2571
2669
|
});
|
|
2572
2670
|
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2573
|
-
return
|
|
2671
|
+
return (0, _3_types_js_1.assertMessageType)(message, "venue");
|
|
2574
2672
|
}
|
|
2575
2673
|
/**
|
|
2576
2674
|
* Get network statistics. This might not always be available.
|
|
@@ -2611,7 +2709,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2611
2709
|
if (limit <= 0 || limit > 100) {
|
|
2612
2710
|
limit = 100;
|
|
2613
2711
|
}
|
|
2614
|
-
const listId = (0,
|
|
2712
|
+
const listId = (0, _0_utilities_js_1.getChatListId)(params?.from ?? "main");
|
|
2615
2713
|
let chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLoadedChats).call(this, listId);
|
|
2616
2714
|
if (params?.after) {
|
|
2617
2715
|
chats = chats
|
|
@@ -2808,21 +2906,48 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2808
2906
|
});
|
|
2809
2907
|
}
|
|
2810
2908
|
/**
|
|
2811
|
-
*
|
|
2909
|
+
* Change reactions made to a message.
|
|
2910
|
+
*
|
|
2911
|
+
* @param chatId The identifier of the chat which the message belongs to.
|
|
2912
|
+
* @param messageId The identifier of the message to add the reaction to.
|
|
2913
|
+
* @param reactions The new reactions.
|
|
2914
|
+
*/
|
|
2915
|
+
async setReactions(chatId, messageId, reactions, params) {
|
|
2916
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendReaction).call(this, chatId, messageId, reactions, params);
|
|
2917
|
+
}
|
|
2918
|
+
/**
|
|
2919
|
+
* Make a reaction to a message.
|
|
2812
2920
|
*
|
|
2813
2921
|
* @param chatId The identifier of the chat which the message belongs to.
|
|
2814
2922
|
* @param messageId The identifier of the message to add the reaction to.
|
|
2815
2923
|
* @param reaction The reaction to add.
|
|
2816
2924
|
*/
|
|
2817
2925
|
async addReaction(chatId, messageId, reaction, params) {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2926
|
+
const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
|
|
2927
|
+
for (const r of chosenReactions) {
|
|
2928
|
+
if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
|
|
2929
|
+
return;
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
|
|
2933
|
+
await this.setReactions(chatId, messageId, reactions, params);
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* Undo a reaction made to a message.
|
|
2937
|
+
*
|
|
2938
|
+
* @param chatId The identifier of the chat which the message belongs to.
|
|
2939
|
+
* @param messageId The identifier of the message which the reaction was made to.
|
|
2940
|
+
* @param reaction The reaction to remove.
|
|
2941
|
+
*/
|
|
2942
|
+
async removeReaction(chatId, messageId, reaction) {
|
|
2943
|
+
const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
|
|
2944
|
+
for (const r of chosenReactions) {
|
|
2945
|
+
if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
|
|
2946
|
+
const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction);
|
|
2947
|
+
await this.setReactions(chatId, messageId, reactions);
|
|
2948
|
+
break;
|
|
2949
|
+
}
|
|
2950
|
+
}
|
|
2826
2951
|
}
|
|
2827
2952
|
}
|
|
2828
2953
|
exports.Client = Client;
|
|
@@ -2835,65 +2960,92 @@ _a = Client, _Client_getMe = async function _Client_getMe() {
|
|
|
2835
2960
|
__classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
|
|
2836
2961
|
return user;
|
|
2837
2962
|
}
|
|
2838
|
-
},
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
if (update instanceof _2_tl_js_1.types.UpdateShortMessage) {
|
|
2842
|
-
update = new _2_tl_js_1.types.UpdateNewMessage({
|
|
2843
|
-
message: new _2_tl_js_1.types.Message({
|
|
2844
|
-
out: update.out,
|
|
2845
|
-
mentioned: update.mentioned,
|
|
2846
|
-
media_unread: update.media_unread,
|
|
2847
|
-
silent: update.silent,
|
|
2848
|
-
id: update.id,
|
|
2849
|
-
from_id: update.out ? new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
|
|
2850
|
-
peer_id: new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
|
|
2851
|
-
message: update.message,
|
|
2852
|
-
date: update.date,
|
|
2853
|
-
fwd_from: update.fwd_from,
|
|
2854
|
-
via_bot_id: update.via_bot_id,
|
|
2855
|
-
reply_to: update.reply_to,
|
|
2856
|
-
entities: update.entities,
|
|
2857
|
-
ttl_period: update.ttl_period,
|
|
2858
|
-
}),
|
|
2859
|
-
pts: update.pts,
|
|
2860
|
-
pts_count: update.pts_count,
|
|
2861
|
-
});
|
|
2963
|
+
}, _Client_handleStoredUpdates = async function _Client_handleStoredUpdates(boxId) {
|
|
2964
|
+
if (__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").has(boxId)) {
|
|
2965
|
+
return;
|
|
2862
2966
|
}
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2967
|
+
__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").add(boxId);
|
|
2968
|
+
do {
|
|
2969
|
+
const maybeUpdate = await this.storage.getFirstUpdate(boxId);
|
|
2970
|
+
if (maybeUpdate == null) {
|
|
2971
|
+
break;
|
|
2972
|
+
}
|
|
2973
|
+
const [key, update] = maybeUpdate;
|
|
2974
|
+
for (let i = 0; i < 100; ++i) {
|
|
2975
|
+
try {
|
|
2976
|
+
const handle = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).call(this, update);
|
|
2977
|
+
handle: for (let i = 0; i < 2; ++i) {
|
|
2978
|
+
try {
|
|
2979
|
+
await handle();
|
|
2980
|
+
break handle;
|
|
2981
|
+
}
|
|
2982
|
+
catch {
|
|
2983
|
+
continue handle;
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
break;
|
|
2987
|
+
}
|
|
2988
|
+
catch (err) {
|
|
2989
|
+
d("#handleUpdate error: %o", err);
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
await this.storage.set(key, null);
|
|
2993
|
+
} while (true);
|
|
2994
|
+
__classPrivateFieldGet(this, _Client_handleUpdatesSet, "f").delete(boxId);
|
|
2995
|
+
}, _Client_handleUpdate = async function _Client_handleUpdate(update) {
|
|
2996
|
+
const promises = new Array();
|
|
2997
|
+
if (update instanceof _2_tl_js_1.types.UpdateUserName) {
|
|
2998
|
+
await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
|
|
2999
|
+
const peer = new _2_tl_js_1.types.PeerUser(update);
|
|
3000
|
+
const entity = await this[getEntity](peer);
|
|
3001
|
+
if (entity != null) {
|
|
3002
|
+
entity.usernames = update.usernames;
|
|
3003
|
+
entity.first_name = update.first_name;
|
|
3004
|
+
entity.last_name = update.last_name;
|
|
3005
|
+
await this.storage.setEntity(entity);
|
|
3006
|
+
}
|
|
2884
3007
|
}
|
|
2885
3008
|
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) {
|
|
2886
3009
|
if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
|
|
2887
3010
|
const chatId = (0, _2_tl_js_1.peerToChatId)(update.message.peer_id);
|
|
2888
3011
|
await this.storage.setMessage(chatId, update.message.id, update.message);
|
|
2889
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
|
|
3012
|
+
promises.push((await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId))());
|
|
3013
|
+
}
|
|
3014
|
+
}
|
|
3015
|
+
if (update instanceof _2_tl_js_1.types.UpdateMessageReactions) {
|
|
3016
|
+
const chatId = (0, _2_tl_js_1.peerToChatId)(update.peer);
|
|
3017
|
+
const message = await this.storage.getMessage(chatId, update.msg_id);
|
|
3018
|
+
if (message instanceof _2_tl_js_1.types.Message) {
|
|
3019
|
+
message.reactions = update.reactions;
|
|
3020
|
+
await this.storage.setMessage(chatId, update.msg_id, message);
|
|
3021
|
+
const views = message.views ?? 0;
|
|
3022
|
+
const forwards = message.forwards ?? 0;
|
|
3023
|
+
const recentReactions = update.reactions.recent_reactions ?? [];
|
|
3024
|
+
const reactions = update.reactions.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions));
|
|
3025
|
+
promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } }), _0_utilities_js_1.resolve))());
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
else if (update instanceof _2_tl_js_1.types.UpdateChannelMessageViews || update instanceof _2_tl_js_1.types.UpdateChannelMessageForwards) {
|
|
3029
|
+
const chatId = (0, _2_tl_js_1.peerToChatId)(new _2_tl_js_1.types.PeerChannel(update));
|
|
3030
|
+
const message = await this.storage.getMessage(chatId, update.id);
|
|
3031
|
+
if (message instanceof _2_tl_js_1.types.Message) {
|
|
3032
|
+
if ("views" in update) {
|
|
3033
|
+
message.views = update.views;
|
|
3034
|
+
}
|
|
3035
|
+
if ("forwards" in update) {
|
|
3036
|
+
message.forwards = update.forwards;
|
|
3037
|
+
}
|
|
3038
|
+
const views = message.views ?? 0;
|
|
3039
|
+
const forwards = message.forwards ?? 0;
|
|
3040
|
+
const recentReactions = message.reactions?.recent_reactions ?? [];
|
|
3041
|
+
const reactions = message.reactions?.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions)) ?? [];
|
|
3042
|
+
promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } }), _0_utilities_js_1.resolve))());
|
|
2890
3043
|
}
|
|
2891
3044
|
}
|
|
2892
3045
|
if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
|
|
2893
3046
|
update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
|
|
2894
3047
|
update instanceof _2_tl_js_1.types.UpdateEditMessage ||
|
|
2895
3048
|
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
2896
|
-
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
2897
3049
|
if (!(update.message instanceof _2_tl_js_1.types.MessageEmpty)) {
|
|
2898
3050
|
const isOutgoing = update.message.out;
|
|
2899
3051
|
let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
|
|
@@ -2902,7 +3054,16 @@ async function _Client_handleUpdate(update) {
|
|
|
2902
3054
|
}
|
|
2903
3055
|
if (!shouldIgnore) {
|
|
2904
3056
|
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
2905
|
-
|
|
3057
|
+
promises.push((async () => {
|
|
3058
|
+
let context;
|
|
3059
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
|
|
3060
|
+
context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { message });
|
|
3061
|
+
}
|
|
3062
|
+
else {
|
|
3063
|
+
context = await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { editedMessage: message });
|
|
3064
|
+
}
|
|
3065
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, context, _0_utilities_js_1.resolve);
|
|
3066
|
+
})());
|
|
2906
3067
|
}
|
|
2907
3068
|
}
|
|
2908
3069
|
}
|
|
@@ -2911,16 +3072,21 @@ async function _Client_handleUpdate(update) {
|
|
|
2911
3072
|
for (const messageId of update.messages) {
|
|
2912
3073
|
const chatId = await this.storage.getMessageChat(messageId);
|
|
2913
3074
|
if (chatId) {
|
|
2914
|
-
|
|
2915
|
-
if (message != null && !(message instanceof _2_tl_js_1.types.MessageEmpty)) {
|
|
2916
|
-
deletedMessages.push(await (0, _3_types_js_1.constructMessage)(message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this)));
|
|
2917
|
-
}
|
|
2918
|
-
await this.storage.setMessage(chatId, messageId, null);
|
|
2919
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
|
|
3075
|
+
deletedMessages.push({ chatId, messageId });
|
|
2920
3076
|
}
|
|
2921
3077
|
}
|
|
2922
3078
|
if (deletedMessages.length > 0) {
|
|
2923
|
-
|
|
3079
|
+
promises.push((async () => {
|
|
3080
|
+
try {
|
|
3081
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages }), _0_utilities_js_1.resolve);
|
|
3082
|
+
}
|
|
3083
|
+
finally {
|
|
3084
|
+
for (const { chatId, messageId } of deletedMessages) {
|
|
3085
|
+
await this.storage.setMessage(chatId, messageId, null);
|
|
3086
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
|
|
3087
|
+
}
|
|
3088
|
+
}
|
|
3089
|
+
})());
|
|
2924
3090
|
}
|
|
2925
3091
|
}
|
|
2926
3092
|
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
@@ -2928,24 +3094,43 @@ async function _Client_handleUpdate(update) {
|
|
|
2928
3094
|
const deletedMessages = new Array();
|
|
2929
3095
|
for (const messageId of update.messages) {
|
|
2930
3096
|
const message = await this.storage.getMessage(chatId, messageId);
|
|
2931
|
-
if (message != null
|
|
2932
|
-
deletedMessages.push(
|
|
3097
|
+
if (message != null) {
|
|
3098
|
+
deletedMessages.push({ chatId, messageId });
|
|
2933
3099
|
}
|
|
2934
|
-
await this.storage.setMessage(chatId, messageId, null);
|
|
2935
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
|
|
2936
3100
|
}
|
|
2937
3101
|
if (deletedMessages.length > 0) {
|
|
2938
|
-
|
|
3102
|
+
promises.push((async () => {
|
|
3103
|
+
try {
|
|
3104
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages }), _0_utilities_js_1.resolve);
|
|
3105
|
+
}
|
|
3106
|
+
finally {
|
|
3107
|
+
for (const { chatId, messageId } of deletedMessages) {
|
|
3108
|
+
await this.storage.setMessage(chatId, messageId, null);
|
|
3109
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId);
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
})());
|
|
2939
3113
|
}
|
|
2940
3114
|
}
|
|
2941
3115
|
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
2942
|
-
|
|
3116
|
+
promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), _0_utilities_js_1.resolve))());
|
|
2943
3117
|
}
|
|
2944
3118
|
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
2945
|
-
|
|
3119
|
+
promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve))());
|
|
2946
3120
|
}
|
|
2947
3121
|
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineSend) {
|
|
2948
|
-
|
|
3122
|
+
promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { chosenInlineResult: await (0, _3_types_js_1.constructChosenInlineResult)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve))());
|
|
3123
|
+
}
|
|
3124
|
+
else if (update instanceof _2_tl_js_1.types.UpdateBotMessageReactions) {
|
|
3125
|
+
const date = new Date(update.date * 1000);
|
|
3126
|
+
const reactions = update.reactions.map((v) => (0, _3_types_js_1.constructReactionCount)(v));
|
|
3127
|
+
const entity = await this[getEntity](update.peer);
|
|
3128
|
+
if (entity) {
|
|
3129
|
+
const chat = (0, _3_types_js_1.constructChatP)(entity);
|
|
3130
|
+
const messageId = update.msg_id;
|
|
3131
|
+
const messageReactionCount = { chat, messageId, date, reactions };
|
|
3132
|
+
promises.push((async () => __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { messageReactionCount }), _0_utilities_js_1.resolve))());
|
|
3133
|
+
}
|
|
2949
3134
|
}
|
|
2950
3135
|
if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
|
|
2951
3136
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
|
|
@@ -2983,16 +3168,12 @@ async function _Client_handleUpdate(update) {
|
|
|
2983
3168
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
|
|
2984
3169
|
}
|
|
2985
3170
|
}
|
|
3171
|
+
return () => Promise.all(promises);
|
|
2986
3172
|
}, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
|
|
2987
3173
|
if (params?.replyMarkup) {
|
|
2988
3174
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
|
|
2989
3175
|
return (0, _3_types_js_1.replyMarkupToTlObject)(params.replyMarkup, __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this));
|
|
2990
3176
|
}
|
|
2991
|
-
}, _Client_assertMsgHas = function _Client_assertMsgHas(message, key) {
|
|
2992
|
-
if (!(key in message) || message[key] === undefined) {
|
|
2993
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
2994
|
-
}
|
|
2995
|
-
return message;
|
|
2996
3177
|
}, _Client_setMyInfo =
|
|
2997
3178
|
//#endregion
|
|
2998
3179
|
async function _Client_setMyInfo(info) {
|
|
@@ -3094,7 +3275,7 @@ async function _Client_setMyInfo(info) {
|
|
|
3094
3275
|
}
|
|
3095
3276
|
const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
3096
3277
|
const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
|
|
3097
|
-
__classPrivateFieldGet(this,
|
|
3278
|
+
__classPrivateFieldGet(this, _Client_instances, "m", _Client_getHandleUpdateQueue).call(this, __classPrivateFieldGet(this, _Client_mainBoxId, "f")).add(async () => {
|
|
3098
3279
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
|
|
3099
3280
|
});
|
|
3100
3281
|
}, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
|
|
@@ -3102,11 +3283,11 @@ async function _Client_setMyInfo(info) {
|
|
|
3102
3283
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
|
|
3103
3284
|
}
|
|
3104
3285
|
catch {
|
|
3105
|
-
return;
|
|
3286
|
+
return () => Promise.resolve();
|
|
3106
3287
|
}
|
|
3107
3288
|
const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
|
|
3108
3289
|
if (!chat && !add) {
|
|
3109
|
-
return;
|
|
3290
|
+
return () => Promise.resolve();
|
|
3110
3291
|
}
|
|
3111
3292
|
const message_ = await this.storage.getLastMessage(chatId);
|
|
3112
3293
|
if (message_ != null) {
|
|
@@ -3126,9 +3307,9 @@ async function _Client_setMyInfo(info) {
|
|
|
3126
3307
|
await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
|
|
3127
3308
|
}
|
|
3128
3309
|
if (sendUpdate) {
|
|
3129
|
-
|
|
3310
|
+
return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
3130
3311
|
}
|
|
3131
|
-
return;
|
|
3312
|
+
return () => Promise.resolve();
|
|
3132
3313
|
}
|
|
3133
3314
|
const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
|
|
3134
3315
|
if (message !== undefined) {
|
|
@@ -3146,17 +3327,18 @@ async function _Client_setMyInfo(info) {
|
|
|
3146
3327
|
__classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
|
|
3147
3328
|
}
|
|
3148
3329
|
if (sendUpdate) {
|
|
3149
|
-
|
|
3330
|
+
return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
|
|
3150
3331
|
}
|
|
3151
|
-
return;
|
|
3332
|
+
return () => Promise.resolve();
|
|
3152
3333
|
}
|
|
3153
3334
|
if (chat) {
|
|
3154
3335
|
chat.order = (0, _3_types_js_1.getChatOrder)(undefined, chat.pinned);
|
|
3155
3336
|
chat.lastMessage = undefined;
|
|
3156
3337
|
if (sendUpdate) {
|
|
3157
|
-
|
|
3338
|
+
return () => __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
|
|
3158
3339
|
}
|
|
3159
3340
|
}
|
|
3341
|
+
return () => Promise.resolve();
|
|
3160
3342
|
}, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
|
|
3161
3343
|
username = username.toLowerCase();
|
|
3162
3344
|
for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
|
|
@@ -3308,6 +3490,7 @@ async function _Client_setMyInfo(info) {
|
|
|
3308
3490
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chat.id, false);
|
|
3309
3491
|
}
|
|
3310
3492
|
}
|
|
3493
|
+
await this.storage.setPinnedChats(listId, await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId));
|
|
3311
3494
|
}, _Client_fetchChats = async function _Client_fetchChats(listId, limit, after) {
|
|
3312
3495
|
const dialogs = await this.api.messages.getDialogs({
|
|
3313
3496
|
limit,
|
|
@@ -3330,4 +3513,12 @@ async function _Client_setMyInfo(info) {
|
|
|
3330
3513
|
chats.set(chat.id, chat);
|
|
3331
3514
|
await this.storage.setChat(listId, chat.id, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
|
|
3332
3515
|
}
|
|
3516
|
+
}, _Client_sendReaction = async function _Client_sendReaction(chatId, messageId, reactions, params) {
|
|
3517
|
+
await this.api.messages.sendReaction({
|
|
3518
|
+
peer: await this.getInputPeer(chatId),
|
|
3519
|
+
msg_id: messageId,
|
|
3520
|
+
reaction: reactions.map((v) => (0, _3_types_js_1.reactionToTlObject)(v)),
|
|
3521
|
+
big: params?.big ? true : undefined,
|
|
3522
|
+
add_to_recent: params?.addToRecents ? true : undefined,
|
|
3523
|
+
});
|
|
3333
3524
|
};
|