@mtcute/core 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/highlevel/client.d.ts +29 -2
- package/cjs/highlevel/client.js.map +1 -1
- package/cjs/highlevel/methods/chats/delete-user-history.d.ts +5 -0
- package/cjs/highlevel/methods/chats/delete-user-history.js +4 -2
- package/cjs/highlevel/methods/chats/delete-user-history.js.map +1 -1
- package/cjs/highlevel/methods/forums/delete-forum-topic-history.d.ts +7 -1
- package/cjs/highlevel/methods/forums/delete-forum-topic-history.js +5 -2
- package/cjs/highlevel/methods/forums/delete-forum-topic-history.js.map +1 -1
- package/cjs/highlevel/methods/messages/delete-messages.d.ts +5 -0
- package/cjs/highlevel/methods/messages/delete-messages.js +4 -2
- package/cjs/highlevel/methods/messages/delete-messages.js.map +1 -1
- package/cjs/highlevel/methods/messages/read-history.d.ts +5 -0
- package/cjs/highlevel/methods/messages/read-history.js +11 -7
- package/cjs/highlevel/methods/messages/read-history.js.map +1 -1
- package/cjs/highlevel/methods/messages/read-reactions.d.ts +7 -1
- package/cjs/highlevel/methods/messages/read-reactions.js +5 -2
- package/cjs/highlevel/methods/messages/read-reactions.js.map +1 -1
- package/cjs/highlevel/methods/messages/send-common.d.ts +2 -2
- package/cjs/highlevel/methods/messages/send-common.js.map +1 -1
- package/cjs/highlevel/methods/messages/send-text.js +3 -3
- package/cjs/highlevel/methods/messages/send-text.js.map +1 -1
- package/cjs/highlevel/methods/messages/unpin-all-messages.d.ts +5 -0
- package/cjs/highlevel/methods/messages/unpin-all-messages.js +8 -6
- package/cjs/highlevel/methods/messages/unpin-all-messages.js.map +1 -1
- package/cjs/highlevel/updates/types.d.ts +2 -0
- package/cjs/highlevel/updates/types.js.map +1 -1
- package/cjs/highlevel/worker/invoker.js +1 -1
- package/cjs/highlevel/worker/invoker.js.map +1 -1
- package/cjs/highlevel/worker/protocol.d.ts +1 -1
- package/cjs/highlevel/worker/protocol.js +9 -6
- package/cjs/highlevel/worker/protocol.js.map +1 -1
- package/cjs/highlevel/worker/worker.js +6 -3
- package/cjs/highlevel/worker/worker.js.map +1 -1
- package/cjs/network/network-manager.js +1 -1
- package/esm/highlevel/client.d.ts +29 -2
- package/esm/highlevel/client.js.map +1 -1
- package/esm/highlevel/methods/chats/delete-user-history.d.ts +5 -0
- package/esm/highlevel/methods/chats/delete-user-history.js +4 -2
- package/esm/highlevel/methods/chats/delete-user-history.js.map +1 -1
- package/esm/highlevel/methods/forums/delete-forum-topic-history.d.ts +7 -1
- package/esm/highlevel/methods/forums/delete-forum-topic-history.js +5 -2
- package/esm/highlevel/methods/forums/delete-forum-topic-history.js.map +1 -1
- package/esm/highlevel/methods/messages/delete-messages.d.ts +5 -0
- package/esm/highlevel/methods/messages/delete-messages.js +4 -2
- package/esm/highlevel/methods/messages/delete-messages.js.map +1 -1
- package/esm/highlevel/methods/messages/read-history.d.ts +5 -0
- package/esm/highlevel/methods/messages/read-history.js +11 -7
- package/esm/highlevel/methods/messages/read-history.js.map +1 -1
- package/esm/highlevel/methods/messages/read-reactions.d.ts +7 -1
- package/esm/highlevel/methods/messages/read-reactions.js +5 -2
- package/esm/highlevel/methods/messages/read-reactions.js.map +1 -1
- package/esm/highlevel/methods/messages/send-common.d.ts +2 -2
- package/esm/highlevel/methods/messages/send-common.js.map +1 -1
- package/esm/highlevel/methods/messages/send-text.js +3 -3
- package/esm/highlevel/methods/messages/send-text.js.map +1 -1
- package/esm/highlevel/methods/messages/unpin-all-messages.d.ts +5 -0
- package/esm/highlevel/methods/messages/unpin-all-messages.js +8 -6
- package/esm/highlevel/methods/messages/unpin-all-messages.js.map +1 -1
- package/esm/highlevel/updates/types.d.ts +2 -0
- package/esm/highlevel/updates/types.js.map +1 -1
- package/esm/highlevel/worker/invoker.js +2 -2
- package/esm/highlevel/worker/invoker.js.map +1 -1
- package/esm/highlevel/worker/protocol.d.ts +1 -1
- package/esm/highlevel/worker/protocol.js +9 -6
- package/esm/highlevel/worker/protocol.js.map +1 -1
- package/esm/highlevel/worker/worker.js +7 -4
- package/esm/highlevel/worker/worker.js.map +1 -1
- package/esm/network/network-manager.js +1 -1
- package/package.json +1 -1
|
@@ -8,4 +8,9 @@ export declare function deleteUserHistory(client: ITelegramClient, params: {
|
|
|
8
8
|
chatId: InputPeerLike;
|
|
9
9
|
/** User/channel ID whose messages to delete */
|
|
10
10
|
participantId: InputPeerLike;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to dispatch the updates that will be generated by this call.
|
|
13
|
+
* Doesn't follow `disableNoDispatch`
|
|
14
|
+
*/
|
|
15
|
+
shouldDispatch?: true;
|
|
11
16
|
}): Promise<void>;
|
|
@@ -4,7 +4,7 @@ import { resolveChannel, resolvePeer } from '../users/resolve-peer.js';
|
|
|
4
4
|
* Delete all messages of a user (or channel) in a supergroup
|
|
5
5
|
*/
|
|
6
6
|
export async function deleteUserHistory(client, params) {
|
|
7
|
-
const { chatId, participantId } = params;
|
|
7
|
+
const { chatId, participantId, shouldDispatch } = params;
|
|
8
8
|
const channel = await resolveChannel(client, chatId);
|
|
9
9
|
const peer = await resolvePeer(client, participantId);
|
|
10
10
|
const res = await client.call({
|
|
@@ -12,6 +12,8 @@ export async function deleteUserHistory(client, params) {
|
|
|
12
12
|
channel,
|
|
13
13
|
participant: peer,
|
|
14
14
|
});
|
|
15
|
-
|
|
15
|
+
if (!shouldDispatch) {
|
|
16
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, channel.channelId));
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
//# sourceMappingURL=delete-user-history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-user-history.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/chats/delete-user-history.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,MAAuB,EACvB,
|
|
1
|
+
{"version":3,"file":"delete-user-history.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/chats/delete-user-history.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACnC,MAAuB,EACvB,MAWC;IAED,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,MAAM,CAAA;IAExD,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAEpD,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;IAErD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;QAC1B,CAAC,EAAE,mCAAmC;QACtC,OAAO;QACP,WAAW,EAAE,IAAI;KACpB,CAAC,CAAA;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAG,OAA8B,CAAC,SAAS,CAAC,CAAC,CAAA;IAClH,CAAC;AACL,CAAC","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { ITelegramClient } from '../../client.types.js'\nimport { InputPeerLike } from '../../types/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { resolveChannel, resolvePeer } from '../users/resolve-peer.js'\n\n/**\n * Delete all messages of a user (or channel) in a supergroup\n */\nexport async function deleteUserHistory(\n client: ITelegramClient,\n params: {\n /** Chat ID */\n chatId: InputPeerLike\n /** User/channel ID whose messages to delete */\n participantId: InputPeerLike\n\n /**\n * Whether to dispatch the updates that will be generated by this call.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n },\n): Promise<void> {\n const { chatId, participantId, shouldDispatch } = params\n\n const channel = await resolveChannel(client, chatId)\n\n const peer = await resolvePeer(client, participantId)\n\n const res = await client.call({\n _: 'channels.deleteParticipantHistory',\n channel,\n participant: peer,\n })\n\n if (!shouldDispatch) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, (channel as tl.RawInputChannel).channelId))\n }\n}\n"]}
|
|
@@ -6,4 +6,10 @@ import type { ForumTopic, InputPeerLike } from '../../types/index.js';
|
|
|
6
6
|
* @param chat Chat or user ID, username, phone number, `"me"` or `"self"`
|
|
7
7
|
* @param topicId ID of the topic (i.e. its top message ID)
|
|
8
8
|
*/
|
|
9
|
-
export declare function deleteForumTopicHistory(client: ITelegramClient, chat: InputPeerLike, topicId: number | ForumTopic
|
|
9
|
+
export declare function deleteForumTopicHistory(client: ITelegramClient, chat: InputPeerLike, topicId: number | ForumTopic, params?: {
|
|
10
|
+
/**
|
|
11
|
+
* Whether to dispatch updates that will be generated by this call.
|
|
12
|
+
* Doesn't follow `disableNoDispatch`
|
|
13
|
+
*/
|
|
14
|
+
shouldDispatch?: true;
|
|
15
|
+
}): Promise<void>;
|
|
@@ -7,7 +7,8 @@ import { resolveChannel } from '../users/resolve-peer.js';
|
|
|
7
7
|
* @param chat Chat or user ID, username, phone number, `"me"` or `"self"`
|
|
8
8
|
* @param topicId ID of the topic (i.e. its top message ID)
|
|
9
9
|
*/
|
|
10
|
-
export async function deleteForumTopicHistory(client, chat, topicId) {
|
|
10
|
+
export async function deleteForumTopicHistory(client, chat, topicId, params) {
|
|
11
|
+
const { shouldDispatch } = params ?? {};
|
|
11
12
|
const channel = await resolveChannel(client, chat);
|
|
12
13
|
assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty');
|
|
13
14
|
const res = await client.call({
|
|
@@ -15,6 +16,8 @@ export async function deleteForumTopicHistory(client, chat, topicId) {
|
|
|
15
16
|
channel,
|
|
16
17
|
topMsgId: typeof topicId === 'number' ? topicId : topicId.id,
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
+
if (!shouldDispatch) {
|
|
20
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, channel.channelId));
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
23
|
//# sourceMappingURL=delete-forum-topic-history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-forum-topic-history.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/forums/delete-forum-topic-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAGnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEzD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CACzC,MAAuB,EACvB,IAAmB,EACnB,OAA4B;
|
|
1
|
+
{"version":3,"file":"delete-forum-topic-history.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/forums/delete-forum-topic-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AAGnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEzD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CACzC,MAAuB,EACvB,IAAmB,EACnB,OAA4B,EAC5B,MAMC;IAED,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IAEvC,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAClD,eAAe,CAAC,yBAAyB,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAA;IAExE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;QAC1B,CAAC,EAAE,6BAA6B;QAChC,OAAO;QACP,QAAQ,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE;KAC/D,CAAC,CAAA;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IAC1F,CAAC;AACL,CAAC","sourcesContent":["import { assertTypeIsNot } from '../../../utils/type-assertions.js'\nimport { ITelegramClient } from '../../client.types.js'\nimport type { ForumTopic, InputPeerLike } from '../../types/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { resolveChannel } from '../users/resolve-peer.js'\n\n/**\n * Delete a forum topic and all its history\n *\n * @param chat Chat or user ID, username, phone number, `\"me\"` or `\"self\"`\n * @param topicId ID of the topic (i.e. its top message ID)\n */\nexport async function deleteForumTopicHistory(\n client: ITelegramClient,\n chat: InputPeerLike,\n topicId: number | ForumTopic,\n params?: {\n /**\n * Whether to dispatch updates that will be generated by this call.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n },\n): Promise<void> {\n const { shouldDispatch } = params ?? {}\n\n const channel = await resolveChannel(client, chat)\n assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty')\n\n const res = await client.call({\n _: 'channels.deleteTopicHistory',\n channel,\n topMsgId: typeof topicId === 'number' ? topicId : topicId.id,\n })\n\n if (!shouldDispatch) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, channel.channelId))\n }\n}\n"]}
|
|
@@ -8,6 +8,11 @@ export interface DeleteMessagesParams {
|
|
|
8
8
|
* @default true
|
|
9
9
|
*/
|
|
10
10
|
revoke?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to dispatch updates that will be generated by this call.
|
|
13
|
+
* Doesn't follow `disableNoDispatch`
|
|
14
|
+
*/
|
|
15
|
+
shouldDispatch?: true;
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
18
|
* Delete messages by their IDs
|
|
@@ -9,7 +9,7 @@ import { deleteScheduledMessages } from './delete-scheduled-messages.js';
|
|
|
9
9
|
* @param ids Message(s) ID(s) to delete.
|
|
10
10
|
*/
|
|
11
11
|
export async function deleteMessagesById(client, chatId, ids, params) {
|
|
12
|
-
const { revoke = true } = params ?? {};
|
|
12
|
+
const { revoke = true, shouldDispatch } = params ?? {};
|
|
13
13
|
const peer = await resolvePeer(client, chatId);
|
|
14
14
|
let upd;
|
|
15
15
|
if (isInputPeerChannel(peer)) {
|
|
@@ -29,7 +29,9 @@ export async function deleteMessagesById(client, chatId, ids, params) {
|
|
|
29
29
|
});
|
|
30
30
|
upd = createDummyUpdate(res.pts, res.ptsCount);
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
if (!shouldDispatch) {
|
|
33
|
+
client.handleClientUpdate(upd);
|
|
34
|
+
}
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* Delete one or more {@link Message}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-messages.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/delete-messages.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAA;
|
|
1
|
+
{"version":3,"file":"delete-messages.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/delete-messages.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAA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,CAAA;IACpD,CAAC;AACL,CAAC","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { ITelegramClient } from '../../client.types.js'\nimport { InputPeerLike, Message } from '../../types/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\nimport { deleteScheduledMessages } from './delete-scheduled-messages.js'\n\n// @exported\nexport interface DeleteMessagesParams {\n /**\n * Whether to \"revoke\" (i.e. delete for both sides).\n * Only used for chats and private chats.\n *\n * @default true\n */\n revoke?: boolean\n\n /**\n * Whether to dispatch updates that will be generated by this call.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n}\n\n/**\n * Delete messages by their IDs\n *\n * @param chatId Chat's marked ID, its username, phone or `\"me\"` or `\"self\"`.\n * @param ids Message(s) ID(s) to delete.\n */\nexport async function deleteMessagesById(\n client: ITelegramClient,\n chatId: InputPeerLike,\n ids: number[],\n params?: DeleteMessagesParams,\n): Promise<void> {\n const { revoke = true, shouldDispatch } = params ?? {}\n\n const peer = await resolvePeer(client, chatId)\n\n let upd\n\n if (isInputPeerChannel(peer)) {\n const channel = toInputChannel(peer)\n const res = await client.call({\n _: 'channels.deleteMessages',\n channel,\n id: ids,\n })\n upd = createDummyUpdate(res.pts, res.ptsCount, peer.channelId)\n } else {\n const res = await client.call({\n _: 'messages.deleteMessages',\n id: ids,\n revoke,\n })\n upd = createDummyUpdate(res.pts, res.ptsCount)\n }\n\n if (!shouldDispatch) {\n client.handleClientUpdate(upd)\n }\n}\n\n/**\n * Delete one or more {@link Message}\n *\n * @param messages Message(s) to delete\n */\nexport async function deleteMessages(\n client: ITelegramClient,\n messages: Message[],\n params?: DeleteMessagesParams,\n): Promise<void> {\n if (messages.length === 1) {\n return deleteMessagesById(client, messages[0].chat.inputPeer, [messages[0].id], params)\n }\n\n const byChat = new Map<number, [tl.TypeInputPeer, number[]]>()\n const byChatScheduled = new Map<number, [tl.TypeInputPeer, number[]]>()\n\n for (const msg of messages) {\n const map = msg.isScheduled ? byChatScheduled : byChat\n\n if (!map.has(msg.chat.id)) {\n map.set(msg.chat.id, [msg.chat.inputPeer, []])\n }\n map.get(msg.chat.id)![1].push(msg.id)\n }\n\n for (const [peer, ids] of byChat.values()) {\n await deleteMessagesById(client, peer, ids, params)\n }\n\n for (const [peer, ids] of byChatScheduled.values()) {\n await deleteScheduledMessages(client, peer, ids)\n }\n}\n"]}
|
|
@@ -16,4 +16,9 @@ export declare function readHistory(client: ITelegramClient, chatId: InputPeerLi
|
|
|
16
16
|
* Whether to also clear all mentions in the chat
|
|
17
17
|
*/
|
|
18
18
|
clearMentions?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether to dispatch updates that will be generated by this call.
|
|
21
|
+
* Doesn't follow `disableNoDispatch`
|
|
22
|
+
*/
|
|
23
|
+
shouldDispatch?: true;
|
|
19
24
|
}): Promise<void>;
|
|
@@ -8,18 +8,20 @@ import { resolvePeer } from '../users/resolve-peer.js';
|
|
|
8
8
|
* @param chatId Chat ID
|
|
9
9
|
*/
|
|
10
10
|
export async function readHistory(client, chatId, params) {
|
|
11
|
-
const { maxId = 0, clearMentions } = params ?? {};
|
|
11
|
+
const { maxId = 0, clearMentions, shouldDispatch } = params ?? {};
|
|
12
12
|
const peer = await resolvePeer(client, chatId);
|
|
13
13
|
if (clearMentions) {
|
|
14
14
|
const res = await client.call({
|
|
15
15
|
_: 'messages.readMentions',
|
|
16
16
|
peer,
|
|
17
17
|
});
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
if (!shouldDispatch) {
|
|
19
|
+
if (isInputPeerChannel(peer)) {
|
|
20
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount));
|
|
24
|
+
}
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
if (isInputPeerChannel(peer)) {
|
|
@@ -36,7 +38,9 @@ export async function readHistory(client, chatId, params) {
|
|
|
36
38
|
peer,
|
|
37
39
|
maxId,
|
|
38
40
|
});
|
|
39
|
-
|
|
41
|
+
if (!shouldDispatch) {
|
|
42
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount));
|
|
43
|
+
}
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
//# sourceMappingURL=read-history.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-history.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/read-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC7B,MAAuB,EACvB,MAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"read-history.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/read-history.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AAG9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC7B,MAAuB,EACvB,MAAqB,EACrB,MAkBC;IAED,MAAM,EAAE,KAAK,GAAG,CAAC,EAAE,aAAa,EAAE,cAAc,EAAE,GA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from '../../../utils/type-assertions.js'\nimport { ITelegramClient } from '../../client.types.js'\nimport { InputPeerLike } from '../../types/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { isInputPeerChannel, toInputChannel } from '../../utils/peer-utils.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\n\n/**\n * Mark chat history as read.\n *\n * @param chatId Chat ID\n */\nexport async function readHistory(\n client: ITelegramClient,\n chatId: InputPeerLike,\n params?: {\n /**\n * Message up until which to read history\n *\n * @default 0, i.e. read everything\n */\n maxId?: number\n\n /**\n * Whether to also clear all mentions in the chat\n */\n clearMentions?: boolean\n\n /**\n * Whether to dispatch updates that will be generated by this call.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n },\n): Promise<void> {\n const { maxId = 0, clearMentions, shouldDispatch } = params ?? {}\n\n const peer = await resolvePeer(client, chatId)\n\n if (clearMentions) {\n const res = await client.call({\n _: 'messages.readMentions',\n peer,\n })\n\n if (!shouldDispatch) {\n if (isInputPeerChannel(peer)) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))\n } else {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))\n }\n }\n }\n\n if (isInputPeerChannel(peer)) {\n const r = await client.call({\n _: 'channels.readHistory',\n channel: toInputChannel(peer),\n maxId,\n })\n\n assertTrue('channels.readHistory', r)\n } else {\n const res = await client.call({\n _: 'messages.readHistory',\n peer,\n maxId,\n })\n\n if (!shouldDispatch) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))\n }\n }\n}\n"]}
|
|
@@ -5,4 +5,10 @@ import { InputPeerLike } from '../../types/index.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @param chatId Chat ID
|
|
7
7
|
*/
|
|
8
|
-
export declare function readReactions(client: ITelegramClient, chatId: InputPeerLike
|
|
8
|
+
export declare function readReactions(client: ITelegramClient, chatId: InputPeerLike, params?: {
|
|
9
|
+
/**
|
|
10
|
+
* Whether to dispatch updates that will be generated by this call.
|
|
11
|
+
* Doesn't follow `disableNoDispatch`
|
|
12
|
+
*/
|
|
13
|
+
shouldDispatch?: true;
|
|
14
|
+
}): Promise<void>;
|
|
@@ -5,11 +5,14 @@ import { resolvePeer } from '../users/resolve-peer.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @param chatId Chat ID
|
|
7
7
|
*/
|
|
8
|
-
export async function readReactions(client, chatId) {
|
|
8
|
+
export async function readReactions(client, chatId, params) {
|
|
9
|
+
const { shouldDispatch } = params ?? {};
|
|
9
10
|
const res = await client.call({
|
|
10
11
|
_: 'messages.readReactions',
|
|
11
12
|
peer: await resolvePeer(client, chatId),
|
|
12
13
|
});
|
|
13
|
-
|
|
14
|
+
if (!shouldDispatch) {
|
|
15
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount));
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
//# sourceMappingURL=read-reactions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-reactions.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/read-reactions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,
|
|
1
|
+
{"version":3,"file":"read-reactions.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/read-reactions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAC/B,MAAuB,EACvB,MAAqB,EACrB,MAMC;IAED,MAAM,EAAE,cAAc,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IACvC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;QAC1B,CAAC,EAAE,wBAAwB;QAC3B,IAAI,EAAE,MAAM,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;KAC1C,CAAC,CAAA;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACvE,CAAC;AACL,CAAC","sourcesContent":["import { ITelegramClient } from '../../client.types.js'\nimport { InputPeerLike } from '../../types/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\n\n/**\n * Mark all reactions in chat as read.\n *\n * @param chatId Chat ID\n */\nexport async function readReactions(\n client: ITelegramClient,\n chatId: InputPeerLike,\n params?: {\n /**\n * Whether to dispatch updates that will be generated by this call.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n },\n): Promise<void> {\n const { shouldDispatch } = params ?? {}\n const res = await client.call({\n _: 'messages.readReactions',\n peer: await resolvePeer(client, chatId),\n })\n\n if (!shouldDispatch) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))\n }\n}\n"]}
|
|
@@ -83,8 +83,8 @@ export interface CommonSendParams {
|
|
|
83
83
|
*/
|
|
84
84
|
quickReply?: number | string;
|
|
85
85
|
/**
|
|
86
|
-
* Whether to dispatch the returned message
|
|
87
|
-
*
|
|
86
|
+
* Whether to dispatch the returned message to the client's update handler.
|
|
87
|
+
* Doesn't follow `disableNoDispatch`
|
|
88
88
|
*/
|
|
89
89
|
shouldDispatch?: true;
|
|
90
90
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-common.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/send-common.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,eAA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AAC;IAED,OAAO;QACH,IAAI;QACJ,OAAO,EAAE,SAAS;QAClB,YAAY;QACZ,kBAAkB,EAAE,4BAA4B,CAAC,MAAM,CAAC,UAAU,CAAC;QACnE,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC;KACjD,CAAA;AACL,CAAC","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtArgumentError } from '../../../types/errors.js'\nimport { getMarkedPeerId } from '../../../utils/peer-utils.js'\nimport { ITelegramClient } from '../../client.types.js'\nimport { MtMessageNotFoundError } from '../../types/errors.js'\nimport { Message } from '../../types/messages/message.js'\nimport { TextWithEntities } from '../../types/misc/entities.js'\nimport { InputPeerLike } from '../../types/peers/index.js'\nimport { normalizeDate, normalizeMessageId } from '../../utils/index.js'\nimport { _getPeerChainId } from '../misc/chain-id.js'\nimport { _normalizeInputText } from '../misc/normalize-text.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\nimport { _getDiscussionMessage } from './get-discussion-message.js'\nimport { getMessages } from './get-messages.js'\n\n// @exported\nexport interface CommonSendParams {\n /**\n * Message to reply to. Either a message object or message ID.\n *\n * For forums - can also be an ID of the topic (i.e. its top message ID)\n *\n * Can also be a message from another chat, in which case a quote will be sent.\n */\n replyTo?: number | Message\n\n /**\n * Whether to throw an error if {@link replyTo}\n * message does not exist.\n *\n * If that message was not found, `NotFoundError` is thrown,\n * with `text` set to `MESSAGE_NOT_FOUND`.\n *\n * Incurs an additional request, so only use when really needed.\n *\n * @default `false`\n */\n mustReply?: boolean\n\n /**\n * Message to comment to. Either a message object or message ID.\n *\n * This overwrites `replyTo` if it was passed\n */\n commentTo?: number | Message\n\n /**\n * Story to reply to.\n *\n * Must be the story sent by the peer you are sending the message to.\n *\n * Can't be used together with {@link replyTo} or {@link commentTo}.\n */\n replyToStory?: number\n\n /**\n * Quoted text. Must be exactly contained in the message\n * being quoted to be accepted by the server (as well as entities)\n */\n quote?: TextWithEntities\n\n /**\n * Offset of the start of the quote in the message.\n */\n quoteOffset?: number\n\n /**\n * Whether to send this message silently.\n */\n silent?: boolean\n\n /**\n * If set, the message will be scheduled to this date.\n * When passing a number, a UNIX time in ms is expected.\n *\n * You can also pass `online` - this will send the message\n * once the peer is online. Note that this requires that\n * peer's online status to be visible to you.\n */\n schedule?: Date | number | 'online'\n\n /**\n * Whether to clear draft after sending this message.\n *\n * @default `false`\n */\n clearDraft?: boolean\n\n /**\n * Whether to disallow further forwards of this message.\n *\n * Only for bots, works even if the target chat does not\n * have content protection.\n */\n forbidForwards?: boolean\n\n /**\n * Peer to use when sending the message.\n */\n sendAs?: InputPeerLike\n\n /**\n * If passed, instead of sending the message, it will be saved into the\n * given quick reply shortcut (either its ID or its shortcut string).\n */\n quickReply?: number | string\n\n /**\n * Whether to dispatch the returned message
|
|
1
|
+
{"version":3,"file":"send-common.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/send-common.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAI9D,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAkH/C;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CACxC,QAAqC;IAErC,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAA;IAE/B,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO;YACH,CAAC,EAAE,2BAA2B;YAC9B,UAAU,EAAE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,CAAC;QACV,SAAS,GAAG;YACR,CAAC,EAAE,qBAAqB;YACxB,YAAY,EAAE,OAAO;YACrB,aAAa,EAAE,WAAW;YAC1B,SAAS,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI;YAC7B,aAAa,EAAE,MAAM,CAAC,KAAK,EAAE,QAAkC;YAC/D,WAAW,EAAE,MAAM,CAAC,WAAW;SAClC,CAAA;IACL,CAAC;SAAM,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QAC7B,SAAS,GAAG;YACR,CAAC,EAAE,mBAAmB;YACtB,OAAO,EAAE,MAAM,CAAC,YAAY;YAC5B,IAAI;SACP,CAAA;IACL,CAAC;IAED,IAAI,YAAY,GAAuB,SAAS,CAAA;IAEhD,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC/B,YAAY,GAAG,UAAU,CAAA;IAC7B,CAAC;SAAM,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACzB,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACjD,CAAC;IAED,OAAO;QACH,IAAI;QACJ,OAAO,EAAE,SAAS;QAClB,YAAY;QACZ,kBAAkB,EAAE,4BAA4B,CAAC,MAAM,CAAC,UAAU,CAAC;QACnE,OAAO,EAAE,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC;KACjD,CAAA;AACL,CAAC","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtArgumentError } from '../../../types/errors.js'\nimport { getMarkedPeerId } from '../../../utils/peer-utils.js'\nimport { ITelegramClient } from '../../client.types.js'\nimport { MtMessageNotFoundError } from '../../types/errors.js'\nimport { Message } from '../../types/messages/message.js'\nimport { TextWithEntities } from '../../types/misc/entities.js'\nimport { InputPeerLike } from '../../types/peers/index.js'\nimport { normalizeDate, normalizeMessageId } from '../../utils/index.js'\nimport { _getPeerChainId } from '../misc/chain-id.js'\nimport { _normalizeInputText } from '../misc/normalize-text.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\nimport { _getDiscussionMessage } from './get-discussion-message.js'\nimport { getMessages } from './get-messages.js'\n\n// @exported\nexport interface CommonSendParams {\n /**\n * Message to reply to. Either a message object or message ID.\n *\n * For forums - can also be an ID of the topic (i.e. its top message ID)\n *\n * Can also be a message from another chat, in which case a quote will be sent.\n */\n replyTo?: number | Message\n\n /**\n * Whether to throw an error if {@link replyTo}\n * message does not exist.\n *\n * If that message was not found, `NotFoundError` is thrown,\n * with `text` set to `MESSAGE_NOT_FOUND`.\n *\n * Incurs an additional request, so only use when really needed.\n *\n * @default `false`\n */\n mustReply?: boolean\n\n /**\n * Message to comment to. Either a message object or message ID.\n *\n * This overwrites `replyTo` if it was passed\n */\n commentTo?: number | Message\n\n /**\n * Story to reply to.\n *\n * Must be the story sent by the peer you are sending the message to.\n *\n * Can't be used together with {@link replyTo} or {@link commentTo}.\n */\n replyToStory?: number\n\n /**\n * Quoted text. Must be exactly contained in the message\n * being quoted to be accepted by the server (as well as entities)\n */\n quote?: TextWithEntities\n\n /**\n * Offset of the start of the quote in the message.\n */\n quoteOffset?: number\n\n /**\n * Whether to send this message silently.\n */\n silent?: boolean\n\n /**\n * If set, the message will be scheduled to this date.\n * When passing a number, a UNIX time in ms is expected.\n *\n * You can also pass `online` - this will send the message\n * once the peer is online. Note that this requires that\n * peer's online status to be visible to you.\n */\n schedule?: Date | number | 'online'\n\n /**\n * Whether to clear draft after sending this message.\n *\n * @default `false`\n */\n clearDraft?: boolean\n\n /**\n * Whether to disallow further forwards of this message.\n *\n * Only for bots, works even if the target chat does not\n * have content protection.\n */\n forbidForwards?: boolean\n\n /**\n * Peer to use when sending the message.\n */\n sendAs?: InputPeerLike\n\n /**\n * If passed, instead of sending the message, it will be saved into the\n * given quick reply shortcut (either its ID or its shortcut string).\n */\n quickReply?: number | string\n\n /**\n * Whether to dispatch the returned message to the client's update handler.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n\n /**\n * Unique identifier of the business connection on behalf of which\n * the message will be sent\n */\n businessConnectionId?: string\n\n /**\n * ID of a message effect to use when sending the message\n * (see {@link TelegramClient.getAvailableMessageEffects})\n */\n effect?: tl.Long\n // todo: once we have a caching layer, we can accept an emoji here\n}\n\n/**\n * @internal\n * @noemit\n */\nexport function _normalizeQuickReplyShortcut(\n shortcut: number | string | undefined,\n): tl.TypeInputQuickReplyShortcut | undefined {\n if (!shortcut) return undefined\n\n if (typeof shortcut === 'number') {\n return {\n _: 'inputQuickReplyShortcutId',\n shortcutId: shortcut,\n }\n }\n\n return {\n _: 'inputQuickReplyShortcut',\n shortcut,\n }\n}\n\n/**\n * @internal\n * @noemit\n */\nexport async function _processCommonSendParameters(\n client: ITelegramClient,\n chatId: InputPeerLike,\n params: CommonSendParams,\n) {\n let peer = await resolvePeer(client, chatId)\n\n let replyTo = normalizeMessageId(params.replyTo)\n const replyToPeer = typeof params.replyTo === 'number' ? undefined : params.replyTo?.chat.inputPeer\n\n if (params.commentTo) {\n [peer, replyTo] = await _getDiscussionMessage(client, peer, normalizeMessageId(params.commentTo)!)\n }\n\n if (params.mustReply) {\n if (!replyTo) {\n throw new MtArgumentError('mustReply used, but replyTo was not passed')\n }\n\n const msg = await getMessages(client, peer, replyTo)\n\n if (!msg) {\n throw new MtMessageNotFoundError(getMarkedPeerId(peer), replyTo, 'to reply to')\n }\n }\n\n if (params.replyToStory && replyTo) {\n throw new MtArgumentError('replyTo/commentTo and replyToStory cannot be used together')\n }\n\n let tlReplyTo: tl.TypeInputReplyTo | undefined = undefined\n\n if (replyTo) {\n tlReplyTo = {\n _: 'inputReplyToMessage',\n replyToMsgId: replyTo,\n replyToPeerId: replyToPeer,\n quoteText: params.quote?.text,\n quoteEntities: params.quote?.entities as tl.TypeMessageEntity[],\n quoteOffset: params.quoteOffset,\n }\n } else if (params.replyToStory) {\n tlReplyTo = {\n _: 'inputReplyToStory',\n storyId: params.replyToStory,\n peer,\n }\n }\n\n let scheduleDate: number | undefined = undefined\n\n if (params.schedule === 'online') {\n scheduleDate = 0x7ffffffe\n } else if (params.schedule) {\n scheduleDate = normalizeDate(params.schedule)\n }\n\n return {\n peer,\n replyTo: tlReplyTo,\n scheduleDate,\n quickReplyShortcut: _normalizeQuickReplyShortcut(params.quickReply),\n chainId: _getPeerChainId(client, peer, 'send'),\n }\n}\n"]}
|
|
@@ -57,9 +57,9 @@ export async function sendText(client, chatId, text, params) {
|
|
|
57
57
|
replyMarkup,
|
|
58
58
|
entities: res.entities,
|
|
59
59
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
if (!params.shouldDispatch) {
|
|
61
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount));
|
|
62
|
+
}
|
|
63
63
|
const peers = new PeersIndex();
|
|
64
64
|
const fetchPeer = async (peer) => {
|
|
65
65
|
const id = getMarkedPeerId(peer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"send-text.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/send-text.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAA;AAE9D,OAAO,EAAE,WAAW,EAAe,MAAM,qCAAqC,CAAA;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAA;AAEzD,OAAO,EAAiB,UAAU,EAAE,MAAM,4BAA4B,CAAA;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAA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CAAC;gBACf,KAAK,MAAM;oBACP,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;oBAClC,MAAK;gBACT,KAAK,MAAM,CAAC;gBACZ,KAAK,eAAe,CAAC;gBACrB,KAAK,SAAS,CAAC;gBACf,KAAK,kBAAkB;oBACnB,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;oBAClC,MAAK;gBACT;oBACI,MAAM,IAAI,oBAAoB,CAC1B,6BAA6B,EAC7B,uBAAuB,EAAE,qCAAqC;oBAC9D,MAAM,CAAC,CAAC,CACX,CAAA;YACT,CAAC;QACL,CAAC,CAAA;QAED,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,MAAO,CAAC,CAAC,CAAC,CAAA;QAE5D,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAEnC,OAAO,GAAG,CAAA;IACd,CAAC;IAED,MAAM,GAAG,GAAG,oBAAoB,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,MAAM,CAAC,cAAc,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAA;IAE7F,OAAO,GAAG,CAAA;AACd,CAAC","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { MtTypeAssertionError } from '../../../types/errors.js'\nimport { randomLong } from '../../../utils/long-utils.js'\nimport { getMarkedPeerId } from '../../../utils/peer-utils.js'\nimport { ITelegramClient } from '../../client.types.js'\nimport { BotKeyboard, ReplyMarkup } from '../../types/bots/keyboards/index.js'\nimport { Message } from '../../types/messages/message.js'\nimport { InputText } from '../../types/misc/entities.js'\nimport { InputPeerLike, PeersIndex } from '../../types/peers/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { inputPeerToPeer } from '../../utils/peer-utils.js'\nimport { _getRawPeerBatched } from '../chats/batched-queries.js'\nimport { _normalizeInputText } from '../misc/normalize-text.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\nimport { _maybeInvokeWithBusinessConnection } from './_business-connection.js'\nimport { _findMessageInUpdate } from './find-in-update.js'\nimport { _getDiscussionMessage } from './get-discussion-message.js'\nimport { _processCommonSendParameters, CommonSendParams } from './send-common.js'\n\n/**\n * Send a text message\n *\n * @param chatId ID of the chat, its username, phone or `\"me\"` or `\"self\"`\n * @param text Text of the message\n * @param params Additional sending parameters\n */\nexport async function sendText(\n client: ITelegramClient,\n chatId: InputPeerLike,\n text: InputText,\n params?: CommonSendParams & {\n /**\n * For bots: inline or reply markup or an instruction\n * to hide a reply keyboard or to force a reply.\n */\n replyMarkup?: ReplyMarkup\n\n /**\n * Whether to disable links preview in this message\n */\n disableWebPreview?: boolean\n\n /**\n * Whether to invert media position.\n *\n * Currently only supported for web previews and makes the\n * client render the preview above the caption and not below.\n */\n invertMedia?: boolean\n },\n): Promise<Message> {\n if (!params) params = {}\n\n const [message, entities] = await _normalizeInputText(client, text)\n\n const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)\n const { peer, replyTo, scheduleDate, chainId, quickReplyShortcut } = await _processCommonSendParameters(\n client,\n chatId,\n params,\n )\n\n const randomId = randomLong()\n const res = await _maybeInvokeWithBusinessConnection(\n client,\n params.businessConnectionId,\n {\n _: 'messages.sendMessage',\n peer,\n noWebpage: params.disableWebPreview,\n silent: params.silent,\n replyTo,\n randomId,\n scheduleDate,\n replyMarkup,\n message,\n entities,\n clearDraft: params.clearDraft,\n noforwards: params.forbidForwards,\n sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,\n invertMedia: params.invertMedia,\n quickReplyShortcut,\n effect: params.effect,\n },\n { chainId },\n )\n\n if (res._ === 'updateShortSentMessage') {\n // todo extract this to updates manager?\n const msg: tl.RawMessage = {\n _: 'message',\n id: res.id,\n peerId: inputPeerToPeer(peer),\n fromId: { _: 'peerUser', userId: client.storage.self.getCached()!.userId },\n message,\n date: res.date,\n out: res.out,\n replyMarkup,\n entities: res.entities,\n }\n\n if (!params.shouldDispatch) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))\n }\n\n const peers = new PeersIndex()\n\n const fetchPeer = async (peer: tl.TypePeer | tl.TypeInputPeer): Promise<void> => {\n const id = getMarkedPeerId(peer)\n\n let cached = await client.storage.peers.getCompleteById(id)\n\n if (!cached) {\n cached = await _getRawPeerBatched(client, await resolvePeer(client, peer))\n }\n\n if (!cached) {\n throw new MtTypeAssertionError('sendText (@ getFullPeerById)', 'user | chat', 'null')\n }\n\n switch (cached._) {\n case 'user':\n peers.users.set(cached.id, cached)\n break\n case 'chat':\n case 'chatForbidden':\n case 'channel':\n case 'channelForbidden':\n peers.chats.set(cached.id, cached)\n break\n default:\n throw new MtTypeAssertionError(\n 'sendText (@ users.getUsers)',\n 'user | chat | channel', // not very accurate, but good enough\n cached._,\n )\n }\n }\n\n await Promise.all([fetchPeer(peer), fetchPeer(msg.fromId!)])\n\n const ret = new Message(msg, peers)\n\n return ret\n }\n\n const msg = _findMessageInUpdate(client, res, false, !params.shouldDispatch, false, randomId)\n\n return msg\n}\n"]}
|
|
@@ -10,4 +10,9 @@ export declare function unpinAllMessages(client: ITelegramClient, chatId: InputP
|
|
|
10
10
|
* For forums - unpin only messages from the given topic
|
|
11
11
|
*/
|
|
12
12
|
topicId?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Whether to dispatch updates that will be generated by this call.
|
|
15
|
+
* Doesn't follow `disableNoDispatch`
|
|
16
|
+
*/
|
|
17
|
+
shouldDispatch?: true;
|
|
13
18
|
}): Promise<void>;
|
|
@@ -7,18 +7,20 @@ import { resolvePeer } from '../users/resolve-peer.js';
|
|
|
7
7
|
* @param chatId Chat or user ID
|
|
8
8
|
*/
|
|
9
9
|
export async function unpinAllMessages(client, chatId, params) {
|
|
10
|
-
const { topicId } = params ?? {};
|
|
10
|
+
const { topicId, shouldDispatch } = params ?? {};
|
|
11
11
|
const peer = await resolvePeer(client, chatId);
|
|
12
12
|
const res = await client.call({
|
|
13
13
|
_: 'messages.unpinAllMessages',
|
|
14
14
|
peer,
|
|
15
15
|
topMsgId: topicId,
|
|
16
16
|
});
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
if (!shouldDispatch) {
|
|
18
|
+
if (isInputPeerChannel(peer)) {
|
|
19
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount));
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
//# sourceMappingURL=unpin-all-messages.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unpin-all-messages.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/unpin-all-messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAClC,MAAuB,EACvB,MAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"unpin-all-messages.js","sourceRoot":"","sources":["../../../../../src/highlevel/methods/messages/unpin-all-messages.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAA;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAEtD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAClC,MAAuB,EACvB,MAAqB,EACrB,MAWC;IAED,MAAM,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,MAAM,IAAI,EAAE,CAAA;IAEhD,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE9C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC;QAC1B,CAAC,EAAE,2BAA2B;QAC9B,IAAI;QACJ,QAAQ,EAAE,OAAO;KACpB,CAAC,CAAA;IAEF,IAAI,CAAC,cAAc,EAAE,CAAC;QAClB,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3B,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAA;QACvF,CAAC;aAAM,CAAC;YACJ,MAAM,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;QACvE,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import { ITelegramClient } from '../../client.types.js'\nimport { InputPeerLike } from '../../types/index.js'\nimport { createDummyUpdate } from '../../updates/utils.js'\nimport { isInputPeerChannel } from '../../utils/peer-utils.js'\nimport { resolvePeer } from '../users/resolve-peer.js'\n\n/**\n * Unpin all pinned messages in a chat.\n *\n * @param chatId Chat or user ID\n */\nexport async function unpinAllMessages(\n client: ITelegramClient,\n chatId: InputPeerLike,\n params?: {\n /**\n * For forums - unpin only messages from the given topic\n */\n topicId?: number\n\n /**\n * Whether to dispatch updates that will be generated by this call.\n * Doesn't follow `disableNoDispatch`\n */\n shouldDispatch?: true\n },\n): Promise<void> {\n const { topicId, shouldDispatch } = params ?? {}\n\n const peer = await resolvePeer(client, chatId)\n\n const res = await client.call({\n _: 'messages.unpinAllMessages',\n peer,\n topMsgId: topicId,\n })\n\n if (!shouldDispatch) {\n if (isInputPeerChannel(peer)) {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount, peer.channelId))\n } else {\n client.handleClientUpdate(createDummyUpdate(res.pts, res.ptsCount))\n }\n }\n}\n"]}
|
|
@@ -36,6 +36,8 @@ export interface UpdatesManagerParams {
|
|
|
36
36
|
*
|
|
37
37
|
* > **Note**: you can disable this on per-request basis by passing
|
|
38
38
|
* > `shouldDispatch: true` to the method call that accepts it.
|
|
39
|
+
* > For some methods you need to always pass `shouldDispatch: true` explicitly.
|
|
40
|
+
* > This is noted in the corresponding method's documentation by "Doesn't follow `disableNoDispatch`"
|
|
39
41
|
*
|
|
40
42
|
* @default false
|
|
41
43
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/highlevel/updates/types.ts"],"names":[],"mappings":"","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { AsyncLock, ConditionVariable, Deque, EarlyTimer, Logger, SortedLinkedList } from '../../utils/index.js'\nimport { CurrentUserInfo } from '../storage/service/current-user.js'\nimport { PeersIndex } from '../types/peers/peers-index.js'\n\n/**\n * Function to be called for each update.\n *\n * @param upd The update\n * @param peers Peers that are present in the update\n */\nexport type RawUpdateHandler = (upd: tl.TypeUpdate, peers: PeersIndex) => void\n\n/**\n * Parameters for the updates manager\n */\nexport interface UpdatesManagerParams {\n /**\n * **ADVANCED**\n *\n * Whether to globally disable no-dispatch mechanism.\n *\n * No-dispatch is a mechanism that allows you to call methods\n * that return updates and correctly handle them, without\n * actually dispatching them to the event handlers.\n *\n * In other words, the following code will work differently:\n * ```ts\n * dp.onNewMessage(console.log)\n * console.log(await tg.sendText('me', 'hello'))\n * ```\n * - if `disableNoDispatch` is `true`, the sent message will be\n * dispatched to the event handler, thus it will be printed twice\n * - if `disableNoDispatch` is `false`, the sent message will not be\n * dispatched to the event handler, thus it will onlt be printed once\n *\n * Disabling it may also improve performance, but it's not guaranteed.\n *\n * > **Note**: you can disable this on per-request basis by passing\n * > `shouldDispatch: true` to the method call that accepts it.\n *\n * @default false\n */\n disableNoDispatch?: boolean\n\n /**\n * **ADVANCED**\n *\n * PTS limit for `getChannelDifference` requests (max. 100000).\n * When there are more updates than this limit, the library will\n * skip some of them.\n * According to the [official docs](https://core.telegram.org/method/updates.getChannelDifference),\n * \"Ordinary (non-bot) users are supposed to pass `10-100`\", so passing >100\n * for users may lead to issues.\n *\n * @default 100 for users, 100000 for bots\n */\n channelPtsLimit?: number | ((channelId: number) => number)\n\n /**\n * **ADVANCED**\n *\n * Whenever an `updates.channelDifferenceTooLong` is received,\n * the library isn't able to efficiently handle it on its own,\n * and will call this function for you to handle it instead.\n *\n * [See docs](https://core.telegram.org/constructor/updates.channelDifferenceTooLong)\n */\n onChannelTooLong?: (channelId: number, update: tl.updates.RawChannelDifferenceTooLong) => void\n\n /**\n * **ADVANCED**\n *\n * When `openChat` method is used on a client, the library will\n * set up a timer to periodically fetch the new updates.\n * By default, it will respect the value provided by the server,\n * but it some cases you may want to override it (e.g. decrease it to\n * poll more often and potentially get updates faster).\n *\n * The returned value is treated as seconds.\n */\n overrideOpenChatTimeout?: (upd: tl.updates.TypeChannelDifference) => number\n\n /**\n * Whether to catch up with missed updates when starting updates loop.\n *\n * > **Note**: In case the storage was not properly closed the last time,\n * > \"catching up\" might result in duplicate updates.\n */\n catchUp?: boolean\n}\n\n/** @internal */\nexport interface PendingUpdateContainer {\n upd: tl.TypeUpdates\n seqStart: number\n seqEnd: number\n}\n\n/** @internal */\nexport interface PendingUpdate {\n update: tl.TypeUpdate\n channelId?: number\n pts?: number\n ptsBefore?: number\n qts?: number\n qtsBefore?: number\n timeout?: number\n peers: PeersIndex\n fromDifference: boolean\n}\n\n/** @internal */\nexport interface UpdatesState {\n updatesLoopActive: boolean\n updatesLoopCv: ConditionVariable\n\n postponedTimer: EarlyTimer\n hasTimedoutPostponed: boolean\n\n pendingUpdateContainers: SortedLinkedList<PendingUpdateContainer>\n pendingPtsUpdates: SortedLinkedList<PendingUpdate>\n pendingPtsUpdatesPostponed: SortedLinkedList<PendingUpdate>\n pendingQtsUpdates: SortedLinkedList<PendingUpdate>\n pendingQtsUpdatesPostponed: SortedLinkedList<PendingUpdate>\n pendingUnorderedUpdates: Deque<PendingUpdate>\n\n noDispatchEnabled: boolean\n // channel id or 0 => msg id\n noDispatchMsg: Map<number, Set<number>>\n // channel id or 0 => pts\n noDispatchPts: Map<number, Set<number>>\n noDispatchQts: Set<number>\n\n lock: AsyncLock\n // rpsIncoming?: RpsMeter\n // rpsProcessing?: RpsMeter\n\n // accessing storage every time might be expensive,\n // so store everything here, and load & save\n // every time session is loaded & saved.\n pts?: number\n qts?: number\n date?: number\n seq?: number\n\n // old values of the updates state (i.e. as in DB)\n // used to avoid redundant storage calls\n oldPts?: number\n oldQts?: number\n oldDate?: number\n oldSeq?: number\n selfChanged: boolean\n\n // whether to catch up channels from the locally stored pts\n catchUpChannels: boolean\n catchUpOnStart: boolean\n\n cpts: Map<number, number>\n cptsMod: Map<number, number>\n channelDiffTimeouts: Map<number, NodeJS.Timeout>\n channelsOpened: Map<number, number>\n\n log: Logger\n stop: () => void\n handler: RawUpdateHandler\n auth: CurrentUserInfo | null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/highlevel/updates/types.ts"],"names":[],"mappings":"","sourcesContent":["import { tl } from '@mtcute/tl'\n\nimport { AsyncLock, ConditionVariable, Deque, EarlyTimer, Logger, SortedLinkedList } from '../../utils/index.js'\nimport { CurrentUserInfo } from '../storage/service/current-user.js'\nimport { PeersIndex } from '../types/peers/peers-index.js'\n\n/**\n * Function to be called for each update.\n *\n * @param upd The update\n * @param peers Peers that are present in the update\n */\nexport type RawUpdateHandler = (upd: tl.TypeUpdate, peers: PeersIndex) => void\n\n/**\n * Parameters for the updates manager\n */\nexport interface UpdatesManagerParams {\n /**\n * **ADVANCED**\n *\n * Whether to globally disable no-dispatch mechanism.\n *\n * No-dispatch is a mechanism that allows you to call methods\n * that return updates and correctly handle them, without\n * actually dispatching them to the event handlers.\n *\n * In other words, the following code will work differently:\n * ```ts\n * dp.onNewMessage(console.log)\n * console.log(await tg.sendText('me', 'hello'))\n * ```\n * - if `disableNoDispatch` is `true`, the sent message will be\n * dispatched to the event handler, thus it will be printed twice\n * - if `disableNoDispatch` is `false`, the sent message will not be\n * dispatched to the event handler, thus it will onlt be printed once\n *\n * Disabling it may also improve performance, but it's not guaranteed.\n *\n * > **Note**: you can disable this on per-request basis by passing\n * > `shouldDispatch: true` to the method call that accepts it.\n * > For some methods you need to always pass `shouldDispatch: true` explicitly.\n * > This is noted in the corresponding method's documentation by \"Doesn't follow `disableNoDispatch`\"\n *\n * @default false\n */\n disableNoDispatch?: boolean\n\n /**\n * **ADVANCED**\n *\n * PTS limit for `getChannelDifference` requests (max. 100000).\n * When there are more updates than this limit, the library will\n * skip some of them.\n * According to the [official docs](https://core.telegram.org/method/updates.getChannelDifference),\n * \"Ordinary (non-bot) users are supposed to pass `10-100`\", so passing >100\n * for users may lead to issues.\n *\n * @default 100 for users, 100000 for bots\n */\n channelPtsLimit?: number | ((channelId: number) => number)\n\n /**\n * **ADVANCED**\n *\n * Whenever an `updates.channelDifferenceTooLong` is received,\n * the library isn't able to efficiently handle it on its own,\n * and will call this function for you to handle it instead.\n *\n * [See docs](https://core.telegram.org/constructor/updates.channelDifferenceTooLong)\n */\n onChannelTooLong?: (channelId: number, update: tl.updates.RawChannelDifferenceTooLong) => void\n\n /**\n * **ADVANCED**\n *\n * When `openChat` method is used on a client, the library will\n * set up a timer to periodically fetch the new updates.\n * By default, it will respect the value provided by the server,\n * but it some cases you may want to override it (e.g. decrease it to\n * poll more often and potentially get updates faster).\n *\n * The returned value is treated as seconds.\n */\n overrideOpenChatTimeout?: (upd: tl.updates.TypeChannelDifference) => number\n\n /**\n * Whether to catch up with missed updates when starting updates loop.\n *\n * > **Note**: In case the storage was not properly closed the last time,\n * > \"catching up\" might result in duplicate updates.\n */\n catchUp?: boolean\n}\n\n/** @internal */\nexport interface PendingUpdateContainer {\n upd: tl.TypeUpdates\n seqStart: number\n seqEnd: number\n}\n\n/** @internal */\nexport interface PendingUpdate {\n update: tl.TypeUpdate\n channelId?: number\n pts?: number\n ptsBefore?: number\n qts?: number\n qtsBefore?: number\n timeout?: number\n peers: PeersIndex\n fromDifference: boolean\n}\n\n/** @internal */\nexport interface UpdatesState {\n updatesLoopActive: boolean\n updatesLoopCv: ConditionVariable\n\n postponedTimer: EarlyTimer\n hasTimedoutPostponed: boolean\n\n pendingUpdateContainers: SortedLinkedList<PendingUpdateContainer>\n pendingPtsUpdates: SortedLinkedList<PendingUpdate>\n pendingPtsUpdatesPostponed: SortedLinkedList<PendingUpdate>\n pendingQtsUpdates: SortedLinkedList<PendingUpdate>\n pendingQtsUpdatesPostponed: SortedLinkedList<PendingUpdate>\n pendingUnorderedUpdates: Deque<PendingUpdate>\n\n noDispatchEnabled: boolean\n // channel id or 0 => msg id\n noDispatchMsg: Map<number, Set<number>>\n // channel id or 0 => pts\n noDispatchPts: Map<number, Set<number>>\n noDispatchQts: Set<number>\n\n lock: AsyncLock\n // rpsIncoming?: RpsMeter\n // rpsProcessing?: RpsMeter\n\n // accessing storage every time might be expensive,\n // so store everything here, and load & save\n // every time session is loaded & saved.\n pts?: number\n qts?: number\n date?: number\n seq?: number\n\n // old values of the updates state (i.e. as in DB)\n // used to avoid redundant storage calls\n oldPts?: number\n oldQts?: number\n oldDate?: number\n oldSeq?: number\n selfChanged: boolean\n\n // whether to catch up channels from the locally stored pts\n catchUpChannels: boolean\n catchUpOnStart: boolean\n\n cpts: Map<number, number>\n cptsMod: Map<number, number>\n channelDiffTimeouts: Map<number, NodeJS.Timeout>\n channelsOpened: Map<number, number>\n\n log: Logger\n stop: () => void\n handler: RawUpdateHandler\n auth: CurrentUserInfo | null\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createControllablePromise } from '../../utils/controllable-promise.js';
|
|
2
2
|
import { deserializeError } from './errors.js';
|
|
3
|
-
import { deserializeResult } from './protocol.js';
|
|
3
|
+
import { deserializeResult, serializeResult } from './protocol.js';
|
|
4
4
|
export class WorkerInvoker {
|
|
5
5
|
send;
|
|
6
6
|
constructor(send) {
|
|
@@ -15,7 +15,7 @@ export class WorkerInvoker {
|
|
|
15
15
|
id,
|
|
16
16
|
target,
|
|
17
17
|
method,
|
|
18
|
-
args,
|
|
18
|
+
args: serializeResult(args),
|
|
19
19
|
void: isVoid,
|
|
20
20
|
withAbort: Boolean(abortSignal),
|
|
21
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invoker.js","sourceRoot":"","sources":["../../../../src/highlevel/worker/invoker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"invoker.js","sourceRoot":"","sources":["../../../../src/highlevel/worker/invoker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,iBAAiB,EAAU,eAAe,EAA+C,MAAM,eAAe,CAAA;AAIvH,MAAM,OAAO,aAAa;IACF;IAApB,YAAoB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAE5B,OAAO,GAAG,CAAC,CAAA;IACX,QAAQ,GAAG,IAAI,GAAG,EAA+B,CAAA;IAEjD,OAAO,CAAC,MAAoB,EAAE,MAAc,EAAE,IAAe,EAAE,MAAe,EAAE,WAAyB;QAC7G,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAA;QAEzB,IAAI,CAAC,IAAI,CAAC;YACN,IAAI,EAAE,QAAQ;YACd,EAAE;YACF,MAAM;YACN,MA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;QAEpB,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;YACZ,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAA;QAC/C,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,OAAO,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAO,CAAC,CAAC,CAAA;QACnD,CAAC;IACL,CAAC;IAED,UAAU,CAAI,MAAoB;QAC9B,OAAO,CAAoB,MAAS,EAAE,MAAM,GAAG,KAAK,EAAE,EAAE;YACpD,IAAI,EAAE,CAAA;YAEN,IAAI,MAAM,EAAE,CAAC;gBACT,EAAE,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,MAAgB,EAAE,IAAI,CAAC,CAAA;YAChF,CAAC;iBAAM,CAAC;gBACJ,EAAE,GAAG,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,MAAgB,EAAE,IAAI,CAAC,CAAA;YAC5E,CAAC;YAED,OAAO,EAAU,CAAA;QACrB,CAAC,CAAA;IACL,CAAC;CACJ","sourcesContent":["import { ControllablePromise, createControllablePromise } from '../../utils/controllable-promise.js'\nimport { deserializeError } from './errors.js'\nimport { deserializeResult, SendFn, serializeResult, WorkerInboundMessage, WorkerOutboundMessage } from './protocol.js'\n\nexport type InvokeTarget = Extract<WorkerInboundMessage, { type: 'invoke' }>['target']\n\nexport class WorkerInvoker {\n constructor(private send: SendFn) {}\n\n private _nextId = 0\n private _pending = new Map<number, ControllablePromise>()\n\n private _invoke(target: InvokeTarget, method: string, args: unknown[], isVoid: boolean, abortSignal?: AbortSignal) {\n const id = this._nextId++\n\n this.send({\n type: 'invoke',\n id,\n target,\n method,\n args: serializeResult(args),\n void: isVoid,\n withAbort: Boolean(abortSignal),\n })\n\n abortSignal?.addEventListener('abort', () => {\n this.send({\n type: 'abort',\n id,\n })\n })\n\n if (!isVoid) {\n const promise = createControllablePromise()\n\n this._pending.set(id, promise)\n\n return promise\n }\n }\n\n invoke(target: InvokeTarget, method: string, args: unknown[]): Promise<unknown> {\n return this._invoke(target, method, args, false) as Promise<unknown>\n }\n\n invokeVoid(target: InvokeTarget, method: string, args: unknown[]): void {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n this._invoke(target, method, args, true)\n }\n\n invokeWithAbort(target: InvokeTarget, method: string, args: unknown[], abortSignal: AbortSignal): Promise<unknown> {\n if (abortSignal.aborted) return Promise.reject(abortSignal.reason)\n\n return this._invoke(target, method, args, false, abortSignal) as Promise<unknown>\n }\n\n handleResult(msg: Extract<WorkerOutboundMessage, { type: 'result' }>) {\n const promise = this._pending.get(msg.id)\n if (!promise) return\n\n if (msg.error) {\n promise.reject(deserializeError(msg.error))\n } else {\n promise.resolve(deserializeResult(msg.result!))\n }\n }\n\n makeBinder<T>(target: InvokeTarget) {\n return <K extends keyof T>(method: K, isVoid = false) => {\n let fn\n\n if (isVoid) {\n fn = (...args: unknown[]) => this.invokeVoid(target, method as string, args)\n } else {\n fn = (...args: unknown[]) => this.invoke(target, method as string, args)\n }\n\n return fn as T[K]\n }\n }\n}\n"]}
|
|
@@ -7,7 +7,7 @@ export type WorkerInboundMessage = {
|
|
|
7
7
|
id: number;
|
|
8
8
|
target: 'custom' | 'client' | 'storage' | 'storage-self' | 'storage-peers' | 'app-config';
|
|
9
9
|
method: string;
|
|
10
|
-
args: unknown[]
|
|
10
|
+
args: SerializedResult<unknown[]>;
|
|
11
11
|
void: boolean;
|
|
12
12
|
withAbort: boolean;
|
|
13
13
|
} | {
|
|
@@ -11,23 +11,26 @@ export function serializeResult(result) {
|
|
|
11
11
|
}
|
|
12
12
|
if (result && typeof result === 'object') {
|
|
13
13
|
// replace Long instances with a special object
|
|
14
|
+
const newResult = {};
|
|
14
15
|
for (const [key, value] of Object.entries(result)) {
|
|
15
16
|
if (Long.isLong(value)) {
|
|
16
17
|
// eslint-disable-next-line
|
|
17
|
-
|
|
18
|
-
result[key] = {
|
|
18
|
+
newResult[key] = {
|
|
19
19
|
__type: 'long',
|
|
20
20
|
low: value.low,
|
|
21
21
|
high: value.high,
|
|
22
22
|
unsigned: value.unsigned,
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
else {
|
|
25
|
+
else if (typeof value === 'object') {
|
|
26
26
|
// eslint-disable-next-line
|
|
27
|
-
;
|
|
28
|
-
|
|
27
|
+
newResult[key] = serializeResult(value);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
newResult[key] = value;
|
|
29
31
|
}
|
|
30
32
|
}
|
|
33
|
+
return newResult;
|
|
31
34
|
}
|
|
32
35
|
return result;
|
|
33
36
|
}
|
|
@@ -49,7 +52,7 @@ export function deserializeResult(result) {
|
|
|
49
52
|
;
|
|
50
53
|
result[key] = Long.fromValue(value);
|
|
51
54
|
}
|
|
52
|
-
else {
|
|
55
|
+
else if (typeof value === 'object') {
|
|
53
56
|
// eslint-disable-next-line
|
|
54
57
|
;
|
|
55
58
|
result[key] = deserializeResult(value);
|