@mtcute/core 0.21.1 → 0.22.2
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/client.cjs +13 -8
- package/client.js +13 -8
- package/highlevel/client.d.cts +27 -49
- package/highlevel/client.d.ts +27 -49
- package/highlevel/methods/auth/sign-in-qr.cjs +4 -4
- package/highlevel/methods/files/download-iterable.cjs +25 -0
- package/highlevel/methods/files/download-iterable.js +25 -0
- package/highlevel/methods/files/upload-file.js +1 -1
- package/highlevel/methods/messages/forward-messages.cjs +2 -1
- package/highlevel/methods/messages/forward-messages.d.cts +6 -0
- package/highlevel/methods/messages/forward-messages.d.ts +6 -0
- package/highlevel/methods/messages/forward-messages.js +2 -1
- package/highlevel/methods/messages/get-web-page-preview.cjs +22 -0
- package/highlevel/methods/messages/get-web-page-preview.d.cts +9 -0
- package/highlevel/methods/messages/get-web-page-preview.d.ts +9 -0
- package/highlevel/methods/messages/get-web-page-preview.js +17 -0
- package/highlevel/methods/messages/send-common.d.cts +5 -0
- package/highlevel/methods/messages/send-common.d.ts +5 -0
- package/highlevel/methods/messages/send-media-group.cjs +2 -1
- package/highlevel/methods/messages/send-media-group.js +2 -1
- package/highlevel/methods/messages/send-media.cjs +2 -1
- package/highlevel/methods/messages/send-media.js +2 -1
- package/highlevel/methods/messages/send-text.cjs +2 -1
- package/highlevel/methods/messages/send-text.js +2 -1
- package/highlevel/methods/premium/pin-star-gift.cjs +24 -0
- package/highlevel/methods/premium/pin-star-gift.d.cts +13 -0
- package/highlevel/methods/premium/pin-star-gift.d.ts +13 -0
- package/highlevel/methods/premium/pin-star-gift.js +19 -0
- package/highlevel/methods/{premium/get-star-gifts.cjs → users/get-peer-settings.cjs} +10 -6
- package/highlevel/methods/users/get-peer-settings.d.cts +4 -0
- package/highlevel/methods/users/get-peer-settings.d.ts +4 -0
- package/highlevel/methods/users/get-peer-settings.js +14 -0
- package/highlevel/methods/users/resolve-peer.cjs +16 -31
- package/highlevel/methods/users/resolve-peer.js +7 -22
- package/highlevel/methods.d.cts +3 -2
- package/highlevel/methods.d.ts +3 -2
- package/highlevel/storage/repository/peers.d.cts +2 -3
- package/highlevel/storage/repository/peers.d.ts +2 -3
- package/highlevel/storage/service/peers.cjs +10 -4
- package/highlevel/storage/service/peers.d.cts +1 -0
- package/highlevel/storage/service/peers.d.ts +1 -0
- package/highlevel/storage/service/peers.js +10 -4
- package/highlevel/types/bots/keyboards/factories.cjs +4 -4
- package/highlevel/types/media/document.cjs +1 -1
- package/highlevel/types/media/document.js +1 -1
- package/highlevel/types/media/web-page.cjs +40 -3
- package/highlevel/types/media/web-page.d.cts +23 -1
- package/highlevel/types/media/web-page.d.ts +23 -1
- package/highlevel/types/media/web-page.js +41 -4
- package/highlevel/types/messages/message-media.cjs +1 -1
- package/highlevel/types/messages/message-media.d.cts +2 -2
- package/highlevel/types/messages/message-media.d.ts +2 -2
- package/highlevel/types/messages/message-media.js +2 -2
- package/highlevel/types/messages/message.cjs +4 -0
- package/highlevel/types/messages/message.d.cts +2 -0
- package/highlevel/types/messages/message.d.ts +2 -0
- package/highlevel/types/messages/message.js +4 -0
- package/highlevel/types/peers/chat-event/actions.cjs +5 -0
- package/highlevel/types/peers/chat-event/actions.js +5 -0
- package/highlevel/types/peers/chat.cjs +4 -2
- package/highlevel/types/peers/chat.d.cts +2 -2
- package/highlevel/types/peers/chat.d.ts +2 -2
- package/highlevel/types/peers/chat.js +4 -2
- package/highlevel/types/peers/full-chat.cjs +4 -0
- package/highlevel/types/peers/full-chat.d.cts +2 -0
- package/highlevel/types/peers/full-chat.d.ts +2 -0
- package/highlevel/types/peers/full-chat.js +4 -0
- package/highlevel/types/peers/index.d.cts +1 -0
- package/highlevel/types/peers/index.d.ts +1 -0
- package/highlevel/types/peers/peer-settings.cjs +101 -0
- package/highlevel/types/peers/peer-settings.d.cts +84 -0
- package/highlevel/types/peers/peer-settings.d.ts +84 -0
- package/highlevel/types/peers/peer-settings.js +96 -0
- package/highlevel/types/peers/user.cjs +4 -0
- package/highlevel/types/peers/user.d.cts +2 -0
- package/highlevel/types/peers/user.d.ts +2 -0
- package/highlevel/types/peers/user.js +4 -0
- package/highlevel/types/premium/saved-star-gift.cjs +4 -1
- package/highlevel/types/premium/saved-star-gift.d.cts +2 -3
- package/highlevel/types/premium/saved-star-gift.d.ts +2 -3
- package/highlevel/types/premium/saved-star-gift.js +5 -2
- package/highlevel/types/premium/stars-transaction.cjs +14 -0
- package/highlevel/types/premium/stars-transaction.d.cts +14 -0
- package/highlevel/types/premium/stars-transaction.d.ts +14 -0
- package/highlevel/types/premium/stars-transaction.js +14 -0
- package/highlevel/types/stories/story-viewer.cjs +1 -1
- package/highlevel/types/stories/story-viewer.js +1 -1
- package/highlevel/types/updates/history-read-update.cjs +1 -0
- package/highlevel/types/updates/history-read-update.js +1 -0
- package/highlevel/updates/manager.js +2 -2
- package/highlevel/utils/file-utils.js +1 -1
- package/highlevel/utils/inline-utils.cjs +5 -5
- package/highlevel/utils/inline-utils.js +1 -1
- package/highlevel/worker/storage.cjs +2 -0
- package/highlevel/worker/storage.d.cts +1 -0
- package/highlevel/worker/storage.d.ts +1 -0
- package/highlevel/worker/storage.js +2 -0
- package/index.cjs +3 -1
- package/index.js +5 -3
- package/methods.cjs +6 -4
- package/methods.js +6 -4
- package/network/authorization.js +2 -2
- package/network/network-manager.cjs +1 -1
- package/network/network-manager.js +1 -1
- package/network/persistent-connection.cjs +6 -4
- package/network/persistent-connection.js +6 -4
- package/network/session-connection.cjs +14 -7
- package/network/session-connection.d.cts +1 -1
- package/network/session-connection.d.ts +1 -1
- package/network/session-connection.js +15 -8
- package/package.json +4 -4
- package/storage/memory/repository/peers.cjs +2 -2
- package/storage/memory/repository/peers.d.cts +1 -1
- package/storage/memory/repository/peers.d.ts +1 -1
- package/storage/memory/repository/peers.js +2 -2
- package/storage/sqlite/repository/peers.cjs +3 -5
- package/storage/sqlite/repository/peers.d.cts +1 -2
- package/storage/sqlite/repository/peers.d.ts +1 -2
- package/storage/sqlite/repository/peers.js +3 -5
- package/utils/binary/asn1-parser.js +1 -1
- package/utils/binary/compat.cjs +150 -0
- package/utils/binary/compat.d.cts +13 -0
- package/utils/binary/compat.d.ts +13 -0
- package/utils/binary/compat.js +145 -0
- package/utils/binary/compat.test.d.cts +1 -0
- package/utils/binary/compat.test.d.ts +1 -0
- package/utils/binary/serialization.cjs +59 -0
- package/utils/binary/serialization.d.cts +10 -0
- package/utils/binary/serialization.d.ts +10 -0
- package/utils/binary/serialization.js +54 -0
- package/utils/index.d.cts +2 -0
- package/utils/index.d.ts +2 -0
- package/utils/long-utils.js +1 -1
- package/utils/peer-utils.js +1 -1
- package/utils.cjs +8 -0
- package/utils.js +8 -0
- package/highlevel/methods/premium/get-star-gifts.d.cts +0 -23
- package/highlevel/methods/premium/get-star-gifts.d.ts +0 -23
- package/highlevel/methods/premium/get-star-gifts.js +0 -10
- package/highlevel/methods/premium/iter-star-gifts.cjs +0 -29
- package/highlevel/methods/premium/iter-star-gifts.d.cts +0 -26
- package/highlevel/methods/premium/iter-star-gifts.d.ts +0 -26
- package/highlevel/methods/premium/iter-star-gifts.js +0 -24
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputText } from '../../types/misc/entities.js';
|
|
3
|
+
import { WebPageMedia } from '../../types/media/web-page.js';
|
|
4
|
+
/**
|
|
5
|
+
* Get a preview of a web page contained in the message
|
|
6
|
+
*
|
|
7
|
+
* @param text Text of the message, or simply the link for which the preview should be retrieved
|
|
8
|
+
*/
|
|
9
|
+
export declare function getWebPagePreview(client: ITelegramClient, text: InputText): Promise<WebPageMedia | null>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { assert } from "@fuman/utils";
|
|
2
|
+
import { WebPageMedia as WebPageMedia$2 } from "../../types/media/web-page.js";
|
|
3
|
+
import { _normalizeInputText } from "../misc/normalize-text.js";
|
|
4
|
+
async function getWebPagePreview(client, text) {
|
|
5
|
+
const [message, entities] = await _normalizeInputText(client, text);
|
|
6
|
+
const res = await client.call({
|
|
7
|
+
_: "messages.getWebPagePreview",
|
|
8
|
+
message,
|
|
9
|
+
entities
|
|
10
|
+
});
|
|
11
|
+
if (res.media._ === "messageMediaEmpty") return null;
|
|
12
|
+
assert(res.media._ === "messageMediaWebPage");
|
|
13
|
+
return new WebPageMedia$2(res.media);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
getWebPagePreview
|
|
17
|
+
};
|
|
@@ -98,6 +98,11 @@ export interface CommonSendParams {
|
|
|
98
98
|
* The Stars will be withdrawn from the bot's balance.
|
|
99
99
|
*/
|
|
100
100
|
allowPaidFloodskip?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether to allow payment for messages.
|
|
103
|
+
* If set, the value represents the maximum number of stars to be paid
|
|
104
|
+
*/
|
|
105
|
+
allowPaidMessages?: tl.Long;
|
|
101
106
|
/**
|
|
102
107
|
* ID of a message effect to use when sending the message
|
|
103
108
|
* (see {@link TelegramClient.getAvailableMessageEffects})
|
|
@@ -98,6 +98,11 @@ export interface CommonSendParams {
|
|
|
98
98
|
* The Stars will be withdrawn from the bot's balance.
|
|
99
99
|
*/
|
|
100
100
|
allowPaidFloodskip?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Whether to allow payment for messages.
|
|
103
|
+
* If set, the value represents the maximum number of stars to be paid
|
|
104
|
+
*/
|
|
105
|
+
allowPaidMessages?: tl.Long;
|
|
101
106
|
/**
|
|
102
107
|
* ID of a message effect to use when sending the message
|
|
103
108
|
* (see {@link TelegramClient.getAvailableMessageEffects})
|
|
@@ -73,7 +73,8 @@ async function sendMediaGroup(client, chatId, medias, params) {
|
|
|
73
73
|
invertMedia: params.invertMedia,
|
|
74
74
|
quickReplyShortcut,
|
|
75
75
|
effect: params.effect,
|
|
76
|
-
allowPaidFloodskip: params.allowPaidFloodskip
|
|
76
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
77
|
+
allowPaidStars: params.allowPaidMessages
|
|
77
78
|
},
|
|
78
79
|
{ chainId }
|
|
79
80
|
);
|
|
@@ -66,7 +66,8 @@ async function sendMediaGroup(client, chatId, medias, params) {
|
|
|
66
66
|
invertMedia: params.invertMedia,
|
|
67
67
|
quickReplyShortcut,
|
|
68
68
|
effect: params.effect,
|
|
69
|
-
allowPaidFloodskip: params.allowPaidFloodskip
|
|
69
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
70
|
+
allowPaidStars: params.allowPaidMessages
|
|
70
71
|
},
|
|
71
72
|
{ chainId }
|
|
72
73
|
);
|
|
@@ -58,7 +58,8 @@ async function sendMedia(client, chatId, media, params) {
|
|
|
58
58
|
invertMedia: params.invert,
|
|
59
59
|
quickReplyShortcut,
|
|
60
60
|
effect: params.effect,
|
|
61
|
-
allowPaidFloodskip: params.allowPaidFloodskip
|
|
61
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
62
|
+
allowPaidStars: params.allowPaidMessages
|
|
62
63
|
},
|
|
63
64
|
{ chainId }
|
|
64
65
|
);
|
|
@@ -51,7 +51,8 @@ async function sendMedia(client, chatId, media, params) {
|
|
|
51
51
|
invertMedia: params.invert,
|
|
52
52
|
quickReplyShortcut,
|
|
53
53
|
effect: params.effect,
|
|
54
|
-
allowPaidFloodskip: params.allowPaidFloodskip
|
|
54
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
55
|
+
allowPaidStars: params.allowPaidMessages
|
|
55
56
|
},
|
|
56
57
|
{ chainId }
|
|
57
58
|
);
|
|
@@ -49,7 +49,8 @@ async function sendText(client, chatId, text, params) {
|
|
|
49
49
|
invertMedia: params.invertMedia,
|
|
50
50
|
quickReplyShortcut,
|
|
51
51
|
effect: params.effect,
|
|
52
|
-
allowPaidFloodskip: params.allowPaidFloodskip
|
|
52
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
53
|
+
allowPaidStars: params.allowPaidMessages
|
|
53
54
|
},
|
|
54
55
|
{ chainId }
|
|
55
56
|
);
|
|
@@ -42,7 +42,8 @@ async function sendText(client, chatId, text, params) {
|
|
|
42
42
|
invertMedia: params.invertMedia,
|
|
43
43
|
quickReplyShortcut,
|
|
44
44
|
effect: params.effect,
|
|
45
|
-
allowPaidFloodskip: params.allowPaidFloodskip
|
|
45
|
+
allowPaidFloodskip: params.allowPaidFloodskip,
|
|
46
|
+
allowPaidStars: params.allowPaidMessages
|
|
46
47
|
},
|
|
47
48
|
{ chainId }
|
|
48
49
|
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS support is deprecated and will be removed in 0.25.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const utils = require("@fuman/utils");
|
|
9
|
+
const typeAssertions = require("../../../utils/type-assertions.cjs");
|
|
10
|
+
const resolvePeer = require("../users/resolve-peer.cjs");
|
|
11
|
+
const _normalizeInputStarGift = require("./_normalize-input-star-gift.cjs");
|
|
12
|
+
async function togglePinnedStarGifts(client, params) {
|
|
13
|
+
const gifts = await utils.parallelMap(
|
|
14
|
+
Array.isArray(params.gifts) ? params.gifts : [params.gifts],
|
|
15
|
+
(it) => _normalizeInputStarGift._normalizeInputStarGift(client, it)
|
|
16
|
+
);
|
|
17
|
+
const res = await client.call({
|
|
18
|
+
_: "payments.toggleStarGiftsPinnedToTop",
|
|
19
|
+
stargift: gifts,
|
|
20
|
+
peer: await resolvePeer.resolvePeer(client, params.peer)
|
|
21
|
+
});
|
|
22
|
+
typeAssertions.assertTrue("payments.toggleStarGiftsPinnedToTop", res);
|
|
23
|
+
}
|
|
24
|
+
exports.togglePinnedStarGifts = togglePinnedStarGifts;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputPeerLike } from '../../types/peers/peer.js';
|
|
3
|
+
import { InputStarGift } from '../../types/premium/stars-gift.js';
|
|
4
|
+
import { MaybeArray } from '@fuman/utils';
|
|
5
|
+
/**
|
|
6
|
+
* Toggles whether one or more star gift is pinned to the top of the list
|
|
7
|
+
*/
|
|
8
|
+
export declare function togglePinnedStarGifts(client: ITelegramClient, params: {
|
|
9
|
+
/** One or more gifts to pin */
|
|
10
|
+
gifts: MaybeArray<InputStarGift>;
|
|
11
|
+
/** Peer where the gift is sent */
|
|
12
|
+
peer: InputPeerLike;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputPeerLike } from '../../types/peers/peer.js';
|
|
3
|
+
import { InputStarGift } from '../../types/premium/stars-gift.js';
|
|
4
|
+
import { MaybeArray } from '@fuman/utils';
|
|
5
|
+
/**
|
|
6
|
+
* Toggles whether one or more star gift is pinned to the top of the list
|
|
7
|
+
*/
|
|
8
|
+
export declare function togglePinnedStarGifts(client: ITelegramClient, params: {
|
|
9
|
+
/** One or more gifts to pin */
|
|
10
|
+
gifts: MaybeArray<InputStarGift>;
|
|
11
|
+
/** Peer where the gift is sent */
|
|
12
|
+
peer: InputPeerLike;
|
|
13
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parallelMap } from "@fuman/utils";
|
|
2
|
+
import { assertTrue } from "../../../utils/type-assertions.js";
|
|
3
|
+
import { resolvePeer } from "../users/resolve-peer.js";
|
|
4
|
+
import { _normalizeInputStarGift } from "./_normalize-input-star-gift.js";
|
|
5
|
+
async function togglePinnedStarGifts(client, params) {
|
|
6
|
+
const gifts = await parallelMap(
|
|
7
|
+
Array.isArray(params.gifts) ? params.gifts : [params.gifts],
|
|
8
|
+
(it) => _normalizeInputStarGift(client, it)
|
|
9
|
+
);
|
|
10
|
+
const res = await client.call({
|
|
11
|
+
_: "payments.toggleStarGiftsPinnedToTop",
|
|
12
|
+
stargift: gifts,
|
|
13
|
+
peer: await resolvePeer(client, params.peer)
|
|
14
|
+
});
|
|
15
|
+
assertTrue("payments.toggleStarGiftsPinnedToTop", res);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
togglePinnedStarGifts
|
|
19
|
+
};
|
|
@@ -5,11 +5,15 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
|
|
|
5
5
|
}
|
|
6
6
|
"use strict";
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const resolvePeer = require("./resolve-peer.cjs");
|
|
9
|
+
const peerSettings = require("../../types/peers/peer-settings.cjs");
|
|
10
|
+
const peersIndex = require("../../types/peers/peers-index.cjs");
|
|
11
|
+
async function getPeerSettings(client, peerId) {
|
|
12
|
+
const res = await client.call({
|
|
13
|
+
_: "messages.getPeerSettings",
|
|
14
|
+
peer: await resolvePeer.resolvePeer(client, peerId)
|
|
13
15
|
});
|
|
16
|
+
const peers = peersIndex.PeersIndex.from(res);
|
|
17
|
+
return new peerSettings.PeerSettings(res.settings, peers);
|
|
14
18
|
}
|
|
15
|
-
exports.
|
|
19
|
+
exports.getPeerSettings = getPeerSettings;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputPeerLike, PeerSettings } from '../../types/index.js';
|
|
3
|
+
/** Get {@link PeerSettings} for a peer */
|
|
4
|
+
export declare function getPeerSettings(client: ITelegramClient, peerId: InputPeerLike): Promise<PeerSettings>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ITelegramClient } from '../../client.types.js';
|
|
2
|
+
import { InputPeerLike, PeerSettings } from '../../types/index.js';
|
|
3
|
+
/** Get {@link PeerSettings} for a peer */
|
|
4
|
+
export declare function getPeerSettings(client: ITelegramClient, peerId: InputPeerLike): Promise<PeerSettings>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { resolvePeer } from "./resolve-peer.js";
|
|
2
|
+
import { PeerSettings as PeerSettings$2 } from "../../types/peers/peer-settings.js";
|
|
3
|
+
import { PeersIndex } from "../../types/peers/peers-index.js";
|
|
4
|
+
async function getPeerSettings(client, peerId) {
|
|
5
|
+
const res = await client.call({
|
|
6
|
+
_: "messages.getPeerSettings",
|
|
7
|
+
peer: await resolvePeer(client, peerId)
|
|
8
|
+
});
|
|
9
|
+
const peers = PeersIndex.from(res);
|
|
10
|
+
return new PeerSettings$2(res.settings, peers);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
getPeerSettings
|
|
14
|
+
};
|
|
@@ -8,18 +8,18 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
8
|
const tl = require("@mtcute/tl");
|
|
9
9
|
const Long = require("long");
|
|
10
10
|
const errors$1 = require("../../../types/errors.cjs");
|
|
11
|
-
const peerUtils
|
|
11
|
+
const peerUtils = require("../../../utils/peer-utils.cjs");
|
|
12
12
|
const errors = require("../../types/errors.cjs");
|
|
13
|
-
const peerUtils = require("../../utils/peer-utils.cjs");
|
|
13
|
+
const peerUtils$1 = require("../../utils/peer-utils.cjs");
|
|
14
14
|
const batchedQueries = require("../chats/batched-queries.cjs");
|
|
15
15
|
function _normalizePeerId(peerId) {
|
|
16
16
|
if (typeof peerId === "object") {
|
|
17
17
|
if (tl.tl.isAnyPeer(peerId)) {
|
|
18
|
-
peerId = peerUtils
|
|
18
|
+
peerId = peerUtils.getMarkedPeerId(peerId);
|
|
19
19
|
} else if ("inputPeer" in peerId) {
|
|
20
20
|
peerId = peerId.inputPeer;
|
|
21
21
|
} else {
|
|
22
|
-
peerId = peerUtils.toInputPeer(peerId);
|
|
22
|
+
peerId = peerUtils$1.toInputPeer(peerId);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
if (typeof peerId === "object") {
|
|
@@ -27,7 +27,7 @@ function _normalizePeerId(peerId) {
|
|
|
27
27
|
case "mtcute.dummyInputPeerMinUser":
|
|
28
28
|
return peerId.userId;
|
|
29
29
|
case "mtcute.dummyInputPeerMinChannel":
|
|
30
|
-
return peerUtils
|
|
30
|
+
return peerUtils.toggleChannelIdMark(peerId.channelId);
|
|
31
31
|
default:
|
|
32
32
|
return peerId;
|
|
33
33
|
}
|
|
@@ -116,40 +116,25 @@ async function resolvePeer(client, peerId, force = false) {
|
|
|
116
116
|
}
|
|
117
117
|
throw new errors.MtPeerNotFoundError(`Could not find a peer by ${peerId}`);
|
|
118
118
|
}
|
|
119
|
-
const [peerType, bareId] = peerUtils
|
|
120
|
-
if (peerType === "chat"
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
userId: bareId,
|
|
126
|
-
accessHash: Long.ZERO
|
|
127
|
-
};
|
|
128
|
-
case "chat":
|
|
129
|
-
return {
|
|
130
|
-
_: "inputPeerChat",
|
|
131
|
-
chatId: bareId
|
|
132
|
-
};
|
|
133
|
-
case "channel":
|
|
134
|
-
return {
|
|
135
|
-
_: "inputPeerChannel",
|
|
136
|
-
channelId: bareId,
|
|
137
|
-
accessHash: Long.ZERO
|
|
138
|
-
};
|
|
139
|
-
}
|
|
119
|
+
const [peerType, bareId] = peerUtils.parseMarkedPeerId(peerId);
|
|
120
|
+
if (peerType === "chat") {
|
|
121
|
+
return {
|
|
122
|
+
_: "inputPeerChat",
|
|
123
|
+
chatId: bareId
|
|
124
|
+
};
|
|
140
125
|
}
|
|
141
126
|
const cached = await client.storage.peers.getCompleteById(peerId, true);
|
|
142
127
|
if (cached && (cached._ === "channel" || cached._ === "user")) {
|
|
143
|
-
const [username] = peerUtils.extractUsernames(cached);
|
|
128
|
+
const [username] = peerUtils$1.extractUsernames(cached);
|
|
144
129
|
if (username) {
|
|
145
130
|
const resolved = await resolvePeer(client, username, true);
|
|
146
|
-
if (peerUtils
|
|
131
|
+
if (peerUtils.getMarkedPeerId(resolved) === peerId) {
|
|
147
132
|
return resolved;
|
|
148
133
|
}
|
|
149
134
|
}
|
|
150
135
|
if (cached._ === "user" && cached.phone) {
|
|
151
136
|
const resolved = await resolvePeer(client, cached.phone, true);
|
|
152
|
-
if (peerUtils
|
|
137
|
+
if (peerUtils.getMarkedPeerId(resolved) === peerId) {
|
|
153
138
|
return resolved;
|
|
154
139
|
}
|
|
155
140
|
}
|
|
@@ -189,10 +174,10 @@ async function resolvePeer(client, peerId, force = false) {
|
|
|
189
174
|
throw new errors.MtPeerNotFoundError(`Peer ${peerId} is not found in local cache`);
|
|
190
175
|
}
|
|
191
176
|
async function resolveUser(client, peerId, force = false) {
|
|
192
|
-
return peerUtils.toInputUser(await resolvePeer(client, peerId, force), peerId);
|
|
177
|
+
return peerUtils$1.toInputUser(await resolvePeer(client, peerId, force), peerId);
|
|
193
178
|
}
|
|
194
179
|
async function resolveChannel(client, peerId, force = false) {
|
|
195
|
-
return peerUtils.toInputChannel(await resolvePeer(client, peerId, force), peerId);
|
|
180
|
+
return peerUtils$1.toInputChannel(await resolvePeer(client, peerId, force), peerId);
|
|
196
181
|
}
|
|
197
182
|
exports._normalizePeerId = _normalizePeerId;
|
|
198
183
|
exports.resolveChannel = resolveChannel;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { tl } from "@mtcute/tl";
|
|
2
2
|
import Long from "long";
|
|
3
3
|
import { MtTypeAssertionError } from "../../../types/errors.js";
|
|
4
|
-
import { getMarkedPeerId, toggleChannelIdMark
|
|
4
|
+
import { parseMarkedPeerId, getMarkedPeerId, toggleChannelIdMark } from "../../../utils/peer-utils.js";
|
|
5
5
|
import { MtPeerNotFoundError } from "../../types/errors.js";
|
|
6
|
-
import {
|
|
6
|
+
import { extractUsernames, toInputUser, toInputChannel, toInputPeer } from "../../utils/peer-utils.js";
|
|
7
7
|
import { _getChannelsBatched, _getUsersBatched } from "../chats/batched-queries.js";
|
|
8
8
|
function _normalizePeerId(peerId) {
|
|
9
9
|
if (typeof peerId === "object") {
|
|
@@ -110,26 +110,11 @@ async function resolvePeer(client, peerId, force = false) {
|
|
|
110
110
|
throw new MtPeerNotFoundError(`Could not find a peer by ${peerId}`);
|
|
111
111
|
}
|
|
112
112
|
const [peerType, bareId] = parseMarkedPeerId(peerId);
|
|
113
|
-
if (peerType === "chat"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
userId: bareId,
|
|
119
|
-
accessHash: Long.ZERO
|
|
120
|
-
};
|
|
121
|
-
case "chat":
|
|
122
|
-
return {
|
|
123
|
-
_: "inputPeerChat",
|
|
124
|
-
chatId: bareId
|
|
125
|
-
};
|
|
126
|
-
case "channel":
|
|
127
|
-
return {
|
|
128
|
-
_: "inputPeerChannel",
|
|
129
|
-
channelId: bareId,
|
|
130
|
-
accessHash: Long.ZERO
|
|
131
|
-
};
|
|
132
|
-
}
|
|
113
|
+
if (peerType === "chat") {
|
|
114
|
+
return {
|
|
115
|
+
_: "inputPeerChat",
|
|
116
|
+
chatId: bareId
|
|
117
|
+
};
|
|
133
118
|
}
|
|
134
119
|
const cached = await client.storage.peers.getCompleteById(peerId, true);
|
|
135
120
|
if (cached && (cached._ === "channel" || cached._ === "user")) {
|
package/highlevel/methods.d.cts
CHANGED
|
@@ -156,6 +156,7 @@ export { getReactionUsers } from './methods/messages/get-reaction-users.js';
|
|
|
156
156
|
export type { GetReactionUsersOffset } from './methods/messages/get-reaction-users.js';
|
|
157
157
|
export { getReplyTo } from './methods/messages/get-reply-to.js';
|
|
158
158
|
export { getScheduledMessages } from './methods/messages/get-scheduled-messages.js';
|
|
159
|
+
export { getWebPagePreview } from './methods/messages/get-web-page-preview.js';
|
|
159
160
|
export { iterHistory } from './methods/messages/iter-history.js';
|
|
160
161
|
export { iterReactionUsers } from './methods/messages/iter-reaction-users.js';
|
|
161
162
|
export { iterSearchGlobal } from './methods/messages/iter-search-global.js';
|
|
@@ -226,13 +227,12 @@ export { getSavedStarGiftsById } from './methods/premium/get-saved-star-gifts-by
|
|
|
226
227
|
export { getSavedStarGifts } from './methods/premium/get-saved-star-gifts.js';
|
|
227
228
|
export { getStarGiftOptions } from './methods/premium/get-star-gift-options.js';
|
|
228
229
|
export { getStarGiftWithdrawalUrl } from './methods/premium/get-star-gift-withdrawal-url.js';
|
|
229
|
-
export { getStarGifts } from './methods/premium/get-star-gifts.js';
|
|
230
230
|
export { getStarsTransactions } from './methods/premium/get-stars-transactions.js';
|
|
231
231
|
export { getUniqueStarGift } from './methods/premium/get-unique-star-gift.js';
|
|
232
232
|
export { iterBoosters } from './methods/premium/iter-boosters.js';
|
|
233
233
|
export { iterSavedStarGifts } from './methods/premium/iter-saved-star-gifts.js';
|
|
234
|
-
export { iterStarGifts } from './methods/premium/iter-star-gifts.js';
|
|
235
234
|
export { iterStarsTransactions } from './methods/premium/iter-stars-transactions.js';
|
|
235
|
+
export { togglePinnedStarGifts } from './methods/premium/pin-star-gift.js';
|
|
236
236
|
export { sendStarGift } from './methods/premium/send-star-gift.js';
|
|
237
237
|
export { setBusinessIntro } from './methods/premium/set-business-intro.js';
|
|
238
238
|
export { setBusinessWorkHours } from './methods/premium/set-business-work-hours.js';
|
|
@@ -279,6 +279,7 @@ export { getCommonChats } from './methods/users/get-common-chats.js';
|
|
|
279
279
|
export { getGlobalTtl } from './methods/users/get-global-ttl.js';
|
|
280
280
|
export { getMe } from './methods/users/get-me.js';
|
|
281
281
|
export { getMyUsername } from './methods/users/get-my-username.js';
|
|
282
|
+
export { getPeerSettings } from './methods/users/get-peer-settings.js';
|
|
282
283
|
export { getProfilePhoto } from './methods/users/get-profile-photo.js';
|
|
283
284
|
export { getProfilePhotos } from './methods/users/get-profile-photos.js';
|
|
284
285
|
export { getUsers } from './methods/users/get-users.js';
|
package/highlevel/methods.d.ts
CHANGED
|
@@ -156,6 +156,7 @@ export { getReactionUsers } from './methods/messages/get-reaction-users.js';
|
|
|
156
156
|
export type { GetReactionUsersOffset } from './methods/messages/get-reaction-users.js';
|
|
157
157
|
export { getReplyTo } from './methods/messages/get-reply-to.js';
|
|
158
158
|
export { getScheduledMessages } from './methods/messages/get-scheduled-messages.js';
|
|
159
|
+
export { getWebPagePreview } from './methods/messages/get-web-page-preview.js';
|
|
159
160
|
export { iterHistory } from './methods/messages/iter-history.js';
|
|
160
161
|
export { iterReactionUsers } from './methods/messages/iter-reaction-users.js';
|
|
161
162
|
export { iterSearchGlobal } from './methods/messages/iter-search-global.js';
|
|
@@ -226,13 +227,12 @@ export { getSavedStarGiftsById } from './methods/premium/get-saved-star-gifts-by
|
|
|
226
227
|
export { getSavedStarGifts } from './methods/premium/get-saved-star-gifts.js';
|
|
227
228
|
export { getStarGiftOptions } from './methods/premium/get-star-gift-options.js';
|
|
228
229
|
export { getStarGiftWithdrawalUrl } from './methods/premium/get-star-gift-withdrawal-url.js';
|
|
229
|
-
export { getStarGifts } from './methods/premium/get-star-gifts.js';
|
|
230
230
|
export { getStarsTransactions } from './methods/premium/get-stars-transactions.js';
|
|
231
231
|
export { getUniqueStarGift } from './methods/premium/get-unique-star-gift.js';
|
|
232
232
|
export { iterBoosters } from './methods/premium/iter-boosters.js';
|
|
233
233
|
export { iterSavedStarGifts } from './methods/premium/iter-saved-star-gifts.js';
|
|
234
|
-
export { iterStarGifts } from './methods/premium/iter-star-gifts.js';
|
|
235
234
|
export { iterStarsTransactions } from './methods/premium/iter-stars-transactions.js';
|
|
235
|
+
export { togglePinnedStarGifts } from './methods/premium/pin-star-gift.js';
|
|
236
236
|
export { sendStarGift } from './methods/premium/send-star-gift.js';
|
|
237
237
|
export { setBusinessIntro } from './methods/premium/set-business-intro.js';
|
|
238
238
|
export { setBusinessWorkHours } from './methods/premium/set-business-work-hours.js';
|
|
@@ -279,6 +279,7 @@ export { getCommonChats } from './methods/users/get-common-chats.js';
|
|
|
279
279
|
export { getGlobalTtl } from './methods/users/get-global-ttl.js';
|
|
280
280
|
export { getMe } from './methods/users/get-me.js';
|
|
281
281
|
export { getMyUsername } from './methods/users/get-my-username.js';
|
|
282
|
+
export { getPeerSettings } from './methods/users/get-peer-settings.js';
|
|
282
283
|
export { getProfilePhoto } from './methods/users/get-profile-photo.js';
|
|
283
284
|
export { getProfilePhotos } from './methods/users/get-profile-photos.js';
|
|
284
285
|
export { getUsers } from './methods/users/get-users.js';
|
|
@@ -26,10 +26,9 @@ export interface IPeersRepository {
|
|
|
26
26
|
store: (peer: IPeersRepository.PeerInfo) => MaybePromise<void>;
|
|
27
27
|
/**
|
|
28
28
|
* Find a peer by their `id`.
|
|
29
|
-
*
|
|
30
|
-
* @param allowMin Whether to allow "min" peers to be returned
|
|
29
|
+
* Should return a "min" peer if one is available.
|
|
31
30
|
*/
|
|
32
|
-
getById: (id: number
|
|
31
|
+
getById: (id: number) => MaybePromise<IPeersRepository.PeerInfo | null>;
|
|
33
32
|
/**
|
|
34
33
|
* Find a peer by their username (where `usernames` includes `username`).
|
|
35
34
|
* Should never return "min" peers
|
|
@@ -26,10 +26,9 @@ export interface IPeersRepository {
|
|
|
26
26
|
store: (peer: IPeersRepository.PeerInfo) => MaybePromise<void>;
|
|
27
27
|
/**
|
|
28
28
|
* Find a peer by their `id`.
|
|
29
|
-
*
|
|
30
|
-
* @param allowMin Whether to allow "min" peers to be returned
|
|
29
|
+
* Should return a "min" peer if one is available.
|
|
31
30
|
*/
|
|
32
|
-
getById: (id: number
|
|
31
|
+
getById: (id: number) => MaybePromise<IPeersRepository.PeerInfo | null>;
|
|
33
32
|
/**
|
|
34
33
|
* Find a peer by their username (where `usernames` includes `username`).
|
|
35
34
|
* Should never return "min" peers
|
|
@@ -207,11 +207,11 @@ class PeersService extends base.BaseService {
|
|
|
207
207
|
async getById(id, allowRefs = true) {
|
|
208
208
|
const cached = this._cache.get(id);
|
|
209
209
|
if (cached) return cached.peer;
|
|
210
|
-
const dto = await this._peers.getById(id
|
|
211
|
-
if (dto) {
|
|
210
|
+
const dto = await this._peers.getById(id);
|
|
211
|
+
if (dto && !dto.isMin) {
|
|
212
212
|
return this._returnCaching(id, dto);
|
|
213
213
|
}
|
|
214
|
-
if (allowRefs) {
|
|
214
|
+
if ((!dto || dto.isMin) && allowRefs) {
|
|
215
215
|
const ref = await this._refs.getForPeer(id);
|
|
216
216
|
if (!ref) return null;
|
|
217
217
|
const [chatId, msgId] = ref;
|
|
@@ -234,6 +234,11 @@ class PeersService extends base.BaseService {
|
|
|
234
234
|
}
|
|
235
235
|
return null;
|
|
236
236
|
}
|
|
237
|
+
async getMinAccessHash(id) {
|
|
238
|
+
const dto = await this._peers.getById(id);
|
|
239
|
+
if (!dto) return null;
|
|
240
|
+
return longUtils.longFromFastString(dto.accessHash);
|
|
241
|
+
}
|
|
237
242
|
async getByPhone(phone) {
|
|
238
243
|
const dto = await this._peers.getByPhone(phone);
|
|
239
244
|
if (!dto) return null;
|
|
@@ -250,8 +255,9 @@ class PeersService extends base.BaseService {
|
|
|
250
255
|
async getCompleteById(id, allowMin = false) {
|
|
251
256
|
const cached = this._cache.get(id);
|
|
252
257
|
if (cached) return cached.complete;
|
|
253
|
-
const dto = await this._peers.getById(id
|
|
258
|
+
const dto = await this._peers.getById(id);
|
|
254
259
|
if (!dto) return null;
|
|
260
|
+
if (!allowMin && dto.isMin) return null;
|
|
255
261
|
const cacheItem = {
|
|
256
262
|
peer: getInputPeer(dto),
|
|
257
263
|
complete: this._deserializeTl(dto.complete)
|
|
@@ -17,6 +17,7 @@ export declare class PeersService extends BaseService {
|
|
|
17
17
|
store(peer: tl.TypeUser | tl.TypeChat): Promise<void>;
|
|
18
18
|
private _returnCaching;
|
|
19
19
|
getById(id: number, allowRefs?: boolean): Promise<tl.TypeInputPeer | null>;
|
|
20
|
+
getMinAccessHash(id: number): Promise<tl.Long | null>;
|
|
20
21
|
getByPhone(phone: string): Promise<tl.TypeInputPeer | null>;
|
|
21
22
|
getByUsername(username: string): Promise<tl.TypeInputPeer | null>;
|
|
22
23
|
getCompleteById(id: number, allowMin?: boolean): Promise<tl.TypeUser | tl.TypeChat | null>;
|
|
@@ -17,6 +17,7 @@ export declare class PeersService extends BaseService {
|
|
|
17
17
|
store(peer: tl.TypeUser | tl.TypeChat): Promise<void>;
|
|
18
18
|
private _returnCaching;
|
|
19
19
|
getById(id: number, allowRefs?: boolean): Promise<tl.TypeInputPeer | null>;
|
|
20
|
+
getMinAccessHash(id: number): Promise<tl.Long | null>;
|
|
20
21
|
getByPhone(phone: string): Promise<tl.TypeInputPeer | null>;
|
|
21
22
|
getByUsername(username: string): Promise<tl.TypeInputPeer | null>;
|
|
22
23
|
getCompleteById(id: number, allowMin?: boolean): Promise<tl.TypeUser | tl.TypeChat | null>;
|
|
@@ -200,11 +200,11 @@ class PeersService extends BaseService {
|
|
|
200
200
|
async getById(id, allowRefs = true) {
|
|
201
201
|
const cached = this._cache.get(id);
|
|
202
202
|
if (cached) return cached.peer;
|
|
203
|
-
const dto = await this._peers.getById(id
|
|
204
|
-
if (dto) {
|
|
203
|
+
const dto = await this._peers.getById(id);
|
|
204
|
+
if (dto && !dto.isMin) {
|
|
205
205
|
return this._returnCaching(id, dto);
|
|
206
206
|
}
|
|
207
|
-
if (allowRefs) {
|
|
207
|
+
if ((!dto || dto.isMin) && allowRefs) {
|
|
208
208
|
const ref = await this._refs.getForPeer(id);
|
|
209
209
|
if (!ref) return null;
|
|
210
210
|
const [chatId, msgId] = ref;
|
|
@@ -227,6 +227,11 @@ class PeersService extends BaseService {
|
|
|
227
227
|
}
|
|
228
228
|
return null;
|
|
229
229
|
}
|
|
230
|
+
async getMinAccessHash(id) {
|
|
231
|
+
const dto = await this._peers.getById(id);
|
|
232
|
+
if (!dto) return null;
|
|
233
|
+
return longFromFastString(dto.accessHash);
|
|
234
|
+
}
|
|
230
235
|
async getByPhone(phone) {
|
|
231
236
|
const dto = await this._peers.getByPhone(phone);
|
|
232
237
|
if (!dto) return null;
|
|
@@ -243,8 +248,9 @@ class PeersService extends BaseService {
|
|
|
243
248
|
async getCompleteById(id, allowMin = false) {
|
|
244
249
|
const cached = this._cache.get(id);
|
|
245
250
|
if (cached) return cached.complete;
|
|
246
|
-
const dto = await this._peers.getById(id
|
|
251
|
+
const dto = await this._peers.getById(id);
|
|
247
252
|
if (!dto) return null;
|
|
253
|
+
if (!allowMin && dto.isMin) return null;
|
|
248
254
|
const cacheItem = {
|
|
249
255
|
peer: getInputPeer(dto),
|
|
250
256
|
complete: this._deserializeTl(dto.complete)
|
|
@@ -5,9 +5,9 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
|
|
|
5
5
|
}
|
|
6
6
|
"use strict";
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
-
const utils
|
|
8
|
+
const utils = require("@fuman/utils");
|
|
9
9
|
const tl = require("@mtcute/tl");
|
|
10
|
-
const utils = require("../../../../types/utils.cjs");
|
|
10
|
+
const utils$1 = require("../../../../types/utils.cjs");
|
|
11
11
|
const peerUtils = require("../../../utils/peer-utils.cjs");
|
|
12
12
|
const builder$1 = require("./builder.cjs");
|
|
13
13
|
function builder(maxRowWidth) {
|
|
@@ -73,7 +73,7 @@ function callback(text2, data, requiresPassword) {
|
|
|
73
73
|
_: "keyboardButtonCallback",
|
|
74
74
|
text: text2,
|
|
75
75
|
requiresPassword,
|
|
76
|
-
data: typeof data === "string" ? utils
|
|
76
|
+
data: typeof data === "string" ? utils.utf8.encoder.encode(data) : data
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
function switchInline(text2, query = "", currentChat) {
|
|
@@ -199,7 +199,7 @@ function _convertToTl(obj) {
|
|
|
199
199
|
rows: _2dToRows(obj.buttons, true)
|
|
200
200
|
};
|
|
201
201
|
default:
|
|
202
|
-
utils.assertNever();
|
|
202
|
+
utils$1.assertNever();
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
exports._2dToRows = _2dToRows;
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
8
8
|
const fileId = require("@mtcute/file-id");
|
|
9
9
|
const memoize = require("../../utils/memoize.cjs");
|
|
10
10
|
const thumbnail = require("./thumbnail.cjs");
|
|
11
|
-
const fileLocation = require("../files/file-location.cjs");
|
|
12
11
|
const inspectable = require("../../utils/inspectable.cjs");
|
|
12
|
+
const fileLocation = require("../files/file-location.cjs");
|
|
13
13
|
class RawDocument extends fileLocation.FileLocation {
|
|
14
14
|
constructor(raw) {
|
|
15
15
|
super(
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { tdFileId, toFileId, toUniqueFileId } from "@mtcute/file-id";
|
|
2
2
|
import { memoizeGetters } from "../../utils/memoize.js";
|
|
3
3
|
import { Thumbnail as Thumbnail$2 } from "./thumbnail.js";
|
|
4
|
-
import { FileLocation as FileLocation$1 } from "../files/file-location.js";
|
|
5
4
|
import { makeInspectable } from "../../utils/inspectable.js";
|
|
5
|
+
import { FileLocation as FileLocation$1 } from "../files/file-location.js";
|
|
6
6
|
class RawDocument extends FileLocation$1 {
|
|
7
7
|
constructor(raw) {
|
|
8
8
|
super(
|