@mtcute/core 0.22.3 → 0.23.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/client.cjs +1 -1
- package/client.js +1 -1
- package/highlevel/base.cjs +1 -0
- package/highlevel/base.js +1 -0
- package/highlevel/client.d.cts +7 -3
- package/highlevel/client.d.ts +7 -3
- package/highlevel/methods/auth/send-code.cjs +8 -2
- package/highlevel/methods/auth/send-code.d.cts +4 -2
- package/highlevel/methods/auth/send-code.d.ts +4 -2
- package/highlevel/methods/auth/send-code.js +8 -2
- package/highlevel/methods/auth/start.cjs +6 -1
- package/highlevel/methods/auth/start.d.cts +1 -1
- package/highlevel/methods/auth/start.d.ts +1 -1
- package/highlevel/methods/auth/start.js +6 -1
- package/highlevel/methods/chats/open-chat.cjs +1 -1
- package/highlevel/methods/chats/open-chat.js +1 -1
- package/highlevel/methods/dialogs/find-dialogs.cjs +3 -1
- package/highlevel/methods/dialogs/find-dialogs.js +3 -1
- package/highlevel/methods/dialogs/get-peer-dialogs.cjs +49 -11
- package/highlevel/methods/dialogs/get-peer-dialogs.d.cts +1 -1
- package/highlevel/methods/dialogs/get-peer-dialogs.d.ts +1 -1
- package/highlevel/methods/dialogs/get-peer-dialogs.js +49 -11
- package/highlevel/methods/files/normalize-input-file.d.cts +1 -0
- package/highlevel/methods/files/normalize-input-file.d.ts +1 -0
- package/highlevel/methods/files/normalize-input-media.cjs +13 -6
- package/highlevel/methods/files/normalize-input-media.d.cts +1 -0
- package/highlevel/methods/files/normalize-input-media.d.ts +1 -0
- package/highlevel/methods/files/normalize-input-media.js +13 -6
- package/highlevel/methods/files/upload-file.cjs +6 -3
- package/highlevel/methods/files/upload-file.d.cts +1 -0
- package/highlevel/methods/files/upload-file.d.ts +1 -0
- package/highlevel/methods/files/upload-file.js +6 -3
- package/highlevel/methods/messages/send-common.d.cts +1 -0
- package/highlevel/methods/messages/send-common.d.ts +1 -0
- package/highlevel/methods/messages/send-media-group.cjs +3 -2
- package/highlevel/methods/messages/send-media-group.js +3 -2
- package/highlevel/methods/messages/send-media.cjs +3 -2
- package/highlevel/methods/messages/send-media.js +3 -2
- package/highlevel/methods/messages/send-text.cjs +1 -1
- package/highlevel/methods/messages/send-text.js +1 -1
- package/highlevel/methods/users/resolve-peer-many.cjs +8 -43
- package/highlevel/methods/users/resolve-peer-many.js +9 -44
- package/highlevel/storage/service/peers.cjs +37 -9
- package/highlevel/storage/service/peers.d.cts +4 -0
- package/highlevel/storage/service/peers.d.ts +4 -0
- package/highlevel/storage/service/peers.js +38 -10
- package/highlevel/storage/storage.cjs +3 -0
- package/highlevel/storage/storage.d.cts +1 -0
- package/highlevel/storage/storage.d.ts +1 -0
- package/highlevel/storage/storage.js +3 -0
- package/highlevel/types/conversation.cjs +3 -4
- package/highlevel/types/conversation.js +3 -4
- package/highlevel/types/messages/message-action.cjs +11 -0
- package/highlevel/types/messages/message-action.d.cts +15 -1
- package/highlevel/types/messages/message-action.d.ts +15 -1
- package/highlevel/types/messages/message-action.js +11 -0
- package/highlevel/types/peers/full-user.cjs +8 -0
- package/highlevel/types/peers/full-user.d.cts +4 -0
- package/highlevel/types/peers/full-user.d.ts +4 -0
- package/highlevel/types/peers/full-user.js +8 -0
- package/highlevel/types/peers/peers-index.cjs +10 -0
- package/highlevel/types/peers/peers-index.d.cts +1 -0
- package/highlevel/types/peers/peers-index.d.ts +1 -0
- package/highlevel/types/peers/peers-index.js +10 -0
- package/highlevel/types/premium/business-connection.cjs +3 -3
- package/highlevel/types/premium/business-connection.d.cts +2 -2
- package/highlevel/types/premium/business-connection.d.ts +2 -2
- package/highlevel/types/premium/business-connection.js +3 -3
- package/highlevel/types/premium/saved-star-gift.cjs +2 -2
- package/highlevel/types/premium/saved-star-gift.d.cts +2 -2
- package/highlevel/types/premium/saved-star-gift.d.ts +2 -2
- package/highlevel/types/premium/saved-star-gift.js +2 -2
- package/highlevel/types/premium/stars-gift-unique.cjs +35 -5
- package/highlevel/types/premium/stars-gift-unique.d.cts +23 -3
- package/highlevel/types/premium/stars-gift-unique.d.ts +23 -3
- package/highlevel/types/premium/stars-gift-unique.js +35 -5
- package/highlevel/types/premium/stars-transaction.cjs +4 -0
- package/highlevel/types/premium/stars-transaction.d.cts +2 -0
- package/highlevel/types/premium/stars-transaction.d.ts +2 -0
- package/highlevel/types/premium/stars-transaction.js +4 -0
- package/highlevel/updates/manager.cjs +4 -4
- package/highlevel/updates/manager.js +4 -4
- package/highlevel/worker/storage.cjs +4 -0
- package/highlevel/worker/storage.d.cts +2 -0
- package/highlevel/worker/storage.d.ts +2 -0
- package/highlevel/worker/storage.js +4 -0
- package/network/authorization.cjs +1 -1
- package/network/authorization.js +1 -1
- package/network/middlewares/flood-waiter.cjs +20 -4
- package/network/middlewares/flood-waiter.d.cts +9 -2
- package/network/middlewares/flood-waiter.d.ts +9 -2
- package/network/middlewares/flood-waiter.js +20 -4
- package/network/mtproto-session.cjs +3 -4
- package/network/mtproto-session.d.cts +1 -1
- package/network/mtproto-session.d.ts +1 -1
- package/network/mtproto-session.js +3 -4
- package/network/network-manager.cjs +3 -3
- package/network/network-manager.d.cts +1 -1
- package/network/network-manager.d.ts +1 -1
- package/network/network-manager.js +3 -3
- package/network/persistent-connection.cjs +1 -0
- package/network/persistent-connection.js +1 -0
- package/network/session-connection.cjs +7 -5
- package/network/session-connection.js +7 -5
- package/package.json +7 -7
- package/utils/binary/compat.cjs +2 -0
- package/utils/binary/compat.js +2 -0
- package/utils/early-timer.cjs +12 -7
- package/utils/early-timer.d.cts +3 -3
- package/utils/early-timer.d.ts +3 -3
- package/utils/early-timer.js +12 -7
package/client.cjs
CHANGED
|
@@ -320,7 +320,7 @@ class TelegramClient {
|
|
|
320
320
|
Object.defineProperty(this, "stopSignal", { value: this._client.stopSignal });
|
|
321
321
|
Object.defineProperty(this, "appConfig", { value: this._client.appConfig });
|
|
322
322
|
Object.defineProperty(this, "onServerUpdate", { value: this._client.onServerUpdate });
|
|
323
|
-
Object.defineProperty(this, "onRawUpdate", { value: this._client.
|
|
323
|
+
Object.defineProperty(this, "onRawUpdate", { value: this._client.onRawUpdate });
|
|
324
324
|
Object.defineProperty(this, "onConnectionState", { value: this._client.onConnectionState });
|
|
325
325
|
Object.defineProperty(this, "onError", { value: this._client.onError });
|
|
326
326
|
if (!opts.disableUpdates) {
|
package/client.js
CHANGED
|
@@ -313,7 +313,7 @@ class TelegramClient {
|
|
|
313
313
|
Object.defineProperty(this, "stopSignal", { value: this._client.stopSignal });
|
|
314
314
|
Object.defineProperty(this, "appConfig", { value: this._client.appConfig });
|
|
315
315
|
Object.defineProperty(this, "onServerUpdate", { value: this._client.onServerUpdate });
|
|
316
|
-
Object.defineProperty(this, "onRawUpdate", { value: this._client.
|
|
316
|
+
Object.defineProperty(this, "onRawUpdate", { value: this._client.onRawUpdate });
|
|
317
317
|
Object.defineProperty(this, "onConnectionState", { value: this._client.onConnectionState });
|
|
318
318
|
Object.defineProperty(this, "onError", { value: this._client.onError });
|
|
319
319
|
if (!opts.disableUpdates) {
|
package/highlevel/base.cjs
CHANGED
package/highlevel/base.js
CHANGED
package/highlevel/client.d.cts
CHANGED
|
@@ -221,7 +221,8 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
221
221
|
*
|
|
222
222
|
* **Available**: 👤 users only
|
|
223
223
|
*
|
|
224
|
-
* @returns An object containing information about the sent confirmation code
|
|
224
|
+
* @returns An object containing information about the sent confirmation code,
|
|
225
|
+
* or a user if the user was already logged in
|
|
225
226
|
*/
|
|
226
227
|
sendCode(params: {
|
|
227
228
|
/** Phone number in international format */
|
|
@@ -232,7 +233,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
232
233
|
codeSettings?: Omit<tl.RawCodeSettings, '_' | 'logoutTokens'>;
|
|
233
234
|
/** Abort signal */
|
|
234
235
|
abortSignal?: AbortSignal;
|
|
235
|
-
}): Promise<SentCode>;
|
|
236
|
+
}): Promise<SentCode | User>;
|
|
236
237
|
/**
|
|
237
238
|
* Send a code to email needed to recover your password
|
|
238
239
|
*
|
|
@@ -1848,7 +1849,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
1848
1849
|
*
|
|
1849
1850
|
* @param peers Peers for which to fetch dialogs.
|
|
1850
1851
|
*/
|
|
1851
|
-
getPeerDialogs(peers: MaybeArray<InputPeerLike>): Promise<Dialog[]>;
|
|
1852
|
+
getPeerDialogs(peers: MaybeArray<InputPeerLike>): Promise<(Dialog | null)[]>;
|
|
1852
1853
|
/**
|
|
1853
1854
|
* Iterate over dialogs.
|
|
1854
1855
|
*
|
|
@@ -2028,6 +2029,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
2028
2029
|
*/
|
|
2029
2030
|
_normalizeInputFile(input: InputFileLike, params: {
|
|
2030
2031
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
2032
|
+
abortSignal?: AbortSignal;
|
|
2031
2033
|
fileName?: string;
|
|
2032
2034
|
fileSize?: number;
|
|
2033
2035
|
fileMime?: string;
|
|
@@ -2041,6 +2043,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
2041
2043
|
_normalizeInputMedia(media: InputMediaLike, params?: {
|
|
2042
2044
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
2043
2045
|
uploadPeer?: tl.TypeInputPeer;
|
|
2046
|
+
abortSignal?: AbortSignal;
|
|
2044
2047
|
businessConnectionId?: string;
|
|
2045
2048
|
}, uploadMedia?: boolean): Promise<tl.TypeInputMedia>;
|
|
2046
2049
|
/**
|
|
@@ -2114,6 +2117,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
2114
2117
|
* or throw an error if it cannot be guessed.
|
|
2115
2118
|
*/
|
|
2116
2119
|
requireExtension?: boolean;
|
|
2120
|
+
abortSignal?: AbortSignal;
|
|
2117
2121
|
}): Promise<UploadedFile>;
|
|
2118
2122
|
/**
|
|
2119
2123
|
* Upload a media to Telegram servers, without actually
|
package/highlevel/client.d.ts
CHANGED
|
@@ -221,7 +221,8 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
221
221
|
*
|
|
222
222
|
* **Available**: 👤 users only
|
|
223
223
|
*
|
|
224
|
-
* @returns An object containing information about the sent confirmation code
|
|
224
|
+
* @returns An object containing information about the sent confirmation code,
|
|
225
|
+
* or a user if the user was already logged in
|
|
225
226
|
*/
|
|
226
227
|
sendCode(params: {
|
|
227
228
|
/** Phone number in international format */
|
|
@@ -232,7 +233,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
232
233
|
codeSettings?: Omit<tl.RawCodeSettings, '_' | 'logoutTokens'>;
|
|
233
234
|
/** Abort signal */
|
|
234
235
|
abortSignal?: AbortSignal;
|
|
235
|
-
}): Promise<SentCode>;
|
|
236
|
+
}): Promise<SentCode | User>;
|
|
236
237
|
/**
|
|
237
238
|
* Send a code to email needed to recover your password
|
|
238
239
|
*
|
|
@@ -1848,7 +1849,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
1848
1849
|
*
|
|
1849
1850
|
* @param peers Peers for which to fetch dialogs.
|
|
1850
1851
|
*/
|
|
1851
|
-
getPeerDialogs(peers: MaybeArray<InputPeerLike>): Promise<Dialog[]>;
|
|
1852
|
+
getPeerDialogs(peers: MaybeArray<InputPeerLike>): Promise<(Dialog | null)[]>;
|
|
1852
1853
|
/**
|
|
1853
1854
|
* Iterate over dialogs.
|
|
1854
1855
|
*
|
|
@@ -2028,6 +2029,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
2028
2029
|
*/
|
|
2029
2030
|
_normalizeInputFile(input: InputFileLike, params: {
|
|
2030
2031
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
2032
|
+
abortSignal?: AbortSignal;
|
|
2031
2033
|
fileName?: string;
|
|
2032
2034
|
fileSize?: number;
|
|
2033
2035
|
fileMime?: string;
|
|
@@ -2041,6 +2043,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
2041
2043
|
_normalizeInputMedia(media: InputMediaLike, params?: {
|
|
2042
2044
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
2043
2045
|
uploadPeer?: tl.TypeInputPeer;
|
|
2046
|
+
abortSignal?: AbortSignal;
|
|
2044
2047
|
businessConnectionId?: string;
|
|
2045
2048
|
}, uploadMedia?: boolean): Promise<tl.TypeInputMedia>;
|
|
2046
2049
|
/**
|
|
@@ -2114,6 +2117,7 @@ export interface TelegramClient extends ITelegramClient {
|
|
|
2114
2117
|
* or throw an error if it cannot be guessed.
|
|
2115
2118
|
*/
|
|
2116
2119
|
requireExtension?: boolean;
|
|
2120
|
+
abortSignal?: AbortSignal;
|
|
2117
2121
|
}): Promise<UploadedFile>;
|
|
2118
2122
|
/**
|
|
2119
2123
|
* Upload a media to Telegram servers, without actually
|
|
@@ -5,9 +5,10 @@ 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
|
|
8
|
+
const errors = require("../../../types/errors.cjs");
|
|
9
9
|
const sentCode = require("../../types/auth/sent-code.cjs");
|
|
10
10
|
const miscUtils = require("../../utils/misc-utils.cjs");
|
|
11
|
+
const user = require("../../types/peers/user.cjs");
|
|
11
12
|
async function sendCode(client, params) {
|
|
12
13
|
const phone = miscUtils.normalizePhoneNumber(params.phone);
|
|
13
14
|
const { id, hash } = await client.getApiCredentials();
|
|
@@ -25,7 +26,12 @@ async function sendCode(client, params) {
|
|
|
25
26
|
},
|
|
26
27
|
{ abortSignal: params.abortSignal }
|
|
27
28
|
);
|
|
28
|
-
|
|
29
|
+
if (res._ === "auth.sentCodeSuccess") {
|
|
30
|
+
return new user.User(await client.notifyLoggedIn(res.authorization));
|
|
31
|
+
}
|
|
32
|
+
if (res._ === "auth.sentCodePaymentRequired") {
|
|
33
|
+
throw new errors.MtArgumentError("Payment is required to sign in, please log in with a first-party client first");
|
|
34
|
+
}
|
|
29
35
|
return new sentCode.SentCode(res);
|
|
30
36
|
}
|
|
31
37
|
exports.sendCode = sendCode;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { tl } from '@mtcute/tl';
|
|
2
2
|
import { ITelegramClient } from '../../client.types.js';
|
|
3
3
|
import { SentCode } from '../../types/auth/sent-code.js';
|
|
4
|
+
import { User } from '../../types/index.js';
|
|
4
5
|
/**
|
|
5
6
|
* Send the confirmation code to the given phone number
|
|
6
7
|
*
|
|
7
|
-
* @returns An object containing information about the sent confirmation code
|
|
8
|
+
* @returns An object containing information about the sent confirmation code,
|
|
9
|
+
* or a user if the user was already logged in
|
|
8
10
|
*/
|
|
9
11
|
export declare function sendCode(client: ITelegramClient, params: {
|
|
10
12
|
/** Phone number in international format */
|
|
@@ -15,4 +17,4 @@ export declare function sendCode(client: ITelegramClient, params: {
|
|
|
15
17
|
codeSettings?: Omit<tl.RawCodeSettings, '_' | 'logoutTokens'>;
|
|
16
18
|
/** Abort signal */
|
|
17
19
|
abortSignal?: AbortSignal;
|
|
18
|
-
}): Promise<SentCode>;
|
|
20
|
+
}): Promise<SentCode | User>;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { tl } from '@mtcute/tl';
|
|
2
2
|
import { ITelegramClient } from '../../client.types.js';
|
|
3
3
|
import { SentCode } from '../../types/auth/sent-code.js';
|
|
4
|
+
import { User } from '../../types/index.js';
|
|
4
5
|
/**
|
|
5
6
|
* Send the confirmation code to the given phone number
|
|
6
7
|
*
|
|
7
|
-
* @returns An object containing information about the sent confirmation code
|
|
8
|
+
* @returns An object containing information about the sent confirmation code,
|
|
9
|
+
* or a user if the user was already logged in
|
|
8
10
|
*/
|
|
9
11
|
export declare function sendCode(client: ITelegramClient, params: {
|
|
10
12
|
/** Phone number in international format */
|
|
@@ -15,4 +17,4 @@ export declare function sendCode(client: ITelegramClient, params: {
|
|
|
15
17
|
codeSettings?: Omit<tl.RawCodeSettings, '_' | 'logoutTokens'>;
|
|
16
18
|
/** Abort signal */
|
|
17
19
|
abortSignal?: AbortSignal;
|
|
18
|
-
}): Promise<SentCode>;
|
|
20
|
+
}): Promise<SentCode | User>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MtArgumentError } from "../../../types/errors.js";
|
|
2
2
|
import { SentCode as SentCode$1 } from "../../types/auth/sent-code.js";
|
|
3
3
|
import { normalizePhoneNumber } from "../../utils/misc-utils.js";
|
|
4
|
+
import { User as User$2 } from "../../types/peers/user.js";
|
|
4
5
|
async function sendCode(client, params) {
|
|
5
6
|
const phone = normalizePhoneNumber(params.phone);
|
|
6
7
|
const { id, hash } = await client.getApiCredentials();
|
|
@@ -18,7 +19,12 @@ async function sendCode(client, params) {
|
|
|
18
19
|
},
|
|
19
20
|
{ abortSignal: params.abortSignal }
|
|
20
21
|
);
|
|
21
|
-
|
|
22
|
+
if (res._ === "auth.sentCodeSuccess") {
|
|
23
|
+
return new User$2(await client.notifyLoggedIn(res.authorization));
|
|
24
|
+
}
|
|
25
|
+
if (res._ === "auth.sentCodePaymentRequired") {
|
|
26
|
+
throw new MtArgumentError("Payment is required to sign in, please log in with a first-party client first");
|
|
27
|
+
}
|
|
22
28
|
return new SentCode$1(res);
|
|
23
29
|
}
|
|
24
30
|
export {
|
|
@@ -7,6 +7,7 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
|
|
|
7
7
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
8
|
const tl = require("@mtcute/tl");
|
|
9
9
|
const errors = require("../../../types/errors.cjs");
|
|
10
|
+
const user = require("../../types/peers/user.cjs");
|
|
10
11
|
const miscUtils = require("../../utils/misc-utils.cjs");
|
|
11
12
|
const getMe = require("../users/get-me.cjs");
|
|
12
13
|
const checkPassword = require("./check-password.cjs");
|
|
@@ -62,12 +63,16 @@ async function start(client, params) {
|
|
|
62
63
|
return signInBot.signInBot(client, botToken);
|
|
63
64
|
}
|
|
64
65
|
try {
|
|
65
|
-
|
|
66
|
+
const res = await sendCode.sendCode(client, {
|
|
66
67
|
phone,
|
|
67
68
|
futureAuthTokens: params.futureAuthTokens,
|
|
68
69
|
codeSettings: params.codeSettings,
|
|
69
70
|
abortSignal
|
|
70
71
|
});
|
|
72
|
+
if (res instanceof user.User) {
|
|
73
|
+
return res;
|
|
74
|
+
}
|
|
75
|
+
sentCode = res;
|
|
71
76
|
} catch (e) {
|
|
72
77
|
if (tl.tl.RpcError.is(e, "SESSION_PASSWORD_NEEDED")) {
|
|
73
78
|
has2fa = true;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MaybePromise } from '../../../types/utils.js';
|
|
2
2
|
import { ITelegramClient } from '../../client.types.js';
|
|
3
3
|
import { SentCode } from '../../types/auth/sent-code.js';
|
|
4
|
-
import { User } from '../../types/peers/user.js';
|
|
5
4
|
import { MaybeDynamic } from '../../types/utils.js';
|
|
6
5
|
import { InputStringSessionData } from '../../utils/string-session.js';
|
|
7
6
|
import { tl } from '@mtcute/tl';
|
|
7
|
+
import { User } from '../../types/peers/user.js';
|
|
8
8
|
/**
|
|
9
9
|
* Start the client in an interactive and declarative manner,
|
|
10
10
|
* by providing callbacks for authorization details.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MaybePromise } from '../../../types/utils.js';
|
|
2
2
|
import { ITelegramClient } from '../../client.types.js';
|
|
3
3
|
import { SentCode } from '../../types/auth/sent-code.js';
|
|
4
|
-
import { User } from '../../types/peers/user.js';
|
|
5
4
|
import { MaybeDynamic } from '../../types/utils.js';
|
|
6
5
|
import { InputStringSessionData } from '../../utils/string-session.js';
|
|
7
6
|
import { tl } from '@mtcute/tl';
|
|
7
|
+
import { User } from '../../types/peers/user.js';
|
|
8
8
|
/**
|
|
9
9
|
* Start the client in an interactive and declarative manner,
|
|
10
10
|
* by providing callbacks for authorization details.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { tl } from "@mtcute/tl";
|
|
2
2
|
import { MtArgumentError, MtcuteError } from "../../../types/errors.js";
|
|
3
|
+
import { User as User$2 } from "../../types/peers/user.js";
|
|
3
4
|
import { resolveMaybeDynamic, normalizePhoneNumber } from "../../utils/misc-utils.js";
|
|
4
5
|
import { getMe } from "../users/get-me.js";
|
|
5
6
|
import { checkPassword } from "./check-password.js";
|
|
@@ -55,12 +56,16 @@ async function start(client, params) {
|
|
|
55
56
|
return signInBot(client, botToken);
|
|
56
57
|
}
|
|
57
58
|
try {
|
|
58
|
-
|
|
59
|
+
const res = await sendCode(client, {
|
|
59
60
|
phone,
|
|
60
61
|
futureAuthTokens: params.futureAuthTokens,
|
|
61
62
|
codeSettings: params.codeSettings,
|
|
62
63
|
abortSignal
|
|
63
64
|
});
|
|
65
|
+
if (res instanceof User$2) {
|
|
66
|
+
return res;
|
|
67
|
+
}
|
|
68
|
+
sentCode = res;
|
|
64
69
|
} catch (e) {
|
|
65
70
|
if (tl.RpcError.is(e, "SESSION_PASSWORD_NEEDED")) {
|
|
66
71
|
has2fa = true;
|
|
@@ -14,7 +14,7 @@ async function openChat(client, chat) {
|
|
|
14
14
|
let pts;
|
|
15
15
|
if (!client.storage.self.getCached()?.isBot) {
|
|
16
16
|
const [dialog] = await getPeerDialogs.getPeerDialogs(client, peer);
|
|
17
|
-
pts = dialog
|
|
17
|
+
pts = dialog?.raw.pts;
|
|
18
18
|
} else {
|
|
19
19
|
pts = await client.storage.updates.getChannelPts(peer.channelId) ?? void 0;
|
|
20
20
|
}
|
|
@@ -7,7 +7,7 @@ async function openChat(client, chat) {
|
|
|
7
7
|
let pts;
|
|
8
8
|
if (!client.storage.self.getCached()?.isBot) {
|
|
9
9
|
const [dialog] = await getPeerDialogs(client, peer);
|
|
10
|
-
pts = dialog
|
|
10
|
+
pts = dialog?.raw.pts;
|
|
11
11
|
} else {
|
|
12
12
|
pts = await client.storage.updates.getChannelPts(peer.channelId) ?? void 0;
|
|
13
13
|
}
|
|
@@ -5,6 +5,7 @@ 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 typeAssertions = require("../../../utils/type-assertions.cjs");
|
|
8
9
|
const errors = require("../../types/errors.cjs");
|
|
9
10
|
const resolvePeerMany = require("../users/resolve-peer-many.cjs");
|
|
10
11
|
const getPeerDialogs = require("./get-peer-dialogs.cjs");
|
|
@@ -35,10 +36,11 @@ async function findDialogs(client, peers) {
|
|
|
35
36
|
const ret = Array.from({ length: peers.length });
|
|
36
37
|
if (foundInputPeers.length !== 0) {
|
|
37
38
|
const dialogs = await getPeerDialogs.getPeerDialogs(client, foundInputPeers);
|
|
38
|
-
if (foundInputPeers.length === peers.length) {
|
|
39
|
+
if (foundInputPeers.length === peers.length && dialogs.every(typeAssertions.isPresent)) {
|
|
39
40
|
return dialogs;
|
|
40
41
|
}
|
|
41
42
|
for (const [idx, origIdx] of foundIdxToOriginalIdx) {
|
|
43
|
+
if (!dialogs[idx]) continue;
|
|
42
44
|
ret[origIdx] = dialogs[idx];
|
|
43
45
|
}
|
|
44
46
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isPresent } from "../../../utils/type-assertions.js";
|
|
1
2
|
import { MtPeerNotFoundError } from "../../types/errors.js";
|
|
2
3
|
import { resolvePeerMany } from "../users/resolve-peer-many.js";
|
|
3
4
|
import { getPeerDialogs } from "./get-peer-dialogs.js";
|
|
@@ -28,10 +29,11 @@ async function findDialogs(client, peers) {
|
|
|
28
29
|
const ret = Array.from({ length: peers.length });
|
|
29
30
|
if (foundInputPeers.length !== 0) {
|
|
30
31
|
const dialogs = await getPeerDialogs(client, foundInputPeers);
|
|
31
|
-
if (foundInputPeers.length === peers.length) {
|
|
32
|
+
if (foundInputPeers.length === peers.length && dialogs.every(isPresent)) {
|
|
32
33
|
return dialogs;
|
|
33
34
|
}
|
|
34
35
|
for (const [idx, origIdx] of foundIdxToOriginalIdx) {
|
|
36
|
+
if (!dialogs[idx]) continue;
|
|
35
37
|
ret[origIdx] = dialogs[idx];
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -5,20 +5,58 @@ 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
|
|
8
|
+
const peerUtils = require("../../../utils/peer-utils.cjs");
|
|
9
|
+
const errors = require("../../types/errors.cjs");
|
|
9
10
|
const dialog = require("../../types/messages/dialog.cjs");
|
|
10
11
|
const resolvePeerMany = require("../users/resolve-peer-many.cjs");
|
|
12
|
+
const resolvePeer = require("../users/resolve-peer.cjs");
|
|
11
13
|
async function getPeerDialogs(client, peers) {
|
|
12
|
-
if (!Array.isArray(peers))
|
|
13
|
-
|
|
14
|
+
if (!Array.isArray(peers)) {
|
|
15
|
+
let peer;
|
|
16
|
+
try {
|
|
17
|
+
peer = await resolvePeer.resolvePeer(client, peers);
|
|
18
|
+
} catch (e) {
|
|
19
|
+
if (e instanceof errors.MtPeerNotFoundError) {
|
|
20
|
+
return [null];
|
|
21
|
+
}
|
|
22
|
+
throw e;
|
|
23
|
+
}
|
|
24
|
+
const res = await client.call({
|
|
25
|
+
_: "messages.getPeerDialogs",
|
|
26
|
+
peers: [
|
|
27
|
+
{
|
|
28
|
+
_: "inputDialogPeer",
|
|
29
|
+
peer
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
return dialog.Dialog.parseTlDialogs(res);
|
|
34
|
+
}
|
|
35
|
+
const resolved = await resolvePeerMany.resolvePeerMany(client, peers);
|
|
36
|
+
const dialogPeers = [];
|
|
37
|
+
const result = [];
|
|
38
|
+
const peerToIdx = /* @__PURE__ */ new Map();
|
|
39
|
+
for (let i = 0; i < resolved.length; i++) {
|
|
40
|
+
result[i] = null;
|
|
41
|
+
const peer = resolved[i];
|
|
42
|
+
if (!peer || peer._ === "inputPeerEmpty") {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
dialogPeers.push({
|
|
46
|
+
_: "inputDialogPeer",
|
|
47
|
+
peer
|
|
48
|
+
});
|
|
49
|
+
peerToIdx.set(peerUtils.getMarkedPeerId(peer), i);
|
|
50
|
+
}
|
|
51
|
+
const dialogs = dialog.Dialog.parseTlDialogs(await client.call({
|
|
14
52
|
_: "messages.getPeerDialogs",
|
|
15
|
-
peers:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
return
|
|
53
|
+
peers: dialogPeers
|
|
54
|
+
}));
|
|
55
|
+
for (const dialog2 of dialogs) {
|
|
56
|
+
const peerIdx = peerToIdx.get(dialog2.peer.id);
|
|
57
|
+
if (peerIdx === void 0) continue;
|
|
58
|
+
result[peerIdx] = dialog2;
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
23
61
|
}
|
|
24
62
|
exports.getPeerDialogs = getPeerDialogs;
|
|
@@ -7,4 +7,4 @@ import { Dialog } from '../../types/messages/dialog.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @param peers Peers for which to fetch dialogs.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getPeerDialogs(client: ITelegramClient, peers: MaybeArray<InputPeerLike>): Promise<Dialog[]>;
|
|
10
|
+
export declare function getPeerDialogs(client: ITelegramClient, peers: MaybeArray<InputPeerLike>): Promise<(Dialog | null)[]>;
|
|
@@ -7,4 +7,4 @@ import { Dialog } from '../../types/messages/dialog.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @param peers Peers for which to fetch dialogs.
|
|
9
9
|
*/
|
|
10
|
-
export declare function getPeerDialogs(client: ITelegramClient, peers: MaybeArray<InputPeerLike>): Promise<Dialog[]>;
|
|
10
|
+
export declare function getPeerDialogs(client: ITelegramClient, peers: MaybeArray<InputPeerLike>): Promise<(Dialog | null)[]>;
|
|
@@ -1,18 +1,56 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getMarkedPeerId } from "../../../utils/peer-utils.js";
|
|
2
|
+
import { MtPeerNotFoundError } from "../../types/errors.js";
|
|
2
3
|
import { Dialog as Dialog$2 } from "../../types/messages/dialog.js";
|
|
3
4
|
import { resolvePeerMany } from "../users/resolve-peer-many.js";
|
|
5
|
+
import { resolvePeer } from "../users/resolve-peer.js";
|
|
4
6
|
async function getPeerDialogs(client, peers) {
|
|
5
|
-
if (!Array.isArray(peers))
|
|
6
|
-
|
|
7
|
+
if (!Array.isArray(peers)) {
|
|
8
|
+
let peer;
|
|
9
|
+
try {
|
|
10
|
+
peer = await resolvePeer(client, peers);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
if (e instanceof MtPeerNotFoundError) {
|
|
13
|
+
return [null];
|
|
14
|
+
}
|
|
15
|
+
throw e;
|
|
16
|
+
}
|
|
17
|
+
const res = await client.call({
|
|
18
|
+
_: "messages.getPeerDialogs",
|
|
19
|
+
peers: [
|
|
20
|
+
{
|
|
21
|
+
_: "inputDialogPeer",
|
|
22
|
+
peer
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
return Dialog$2.parseTlDialogs(res);
|
|
27
|
+
}
|
|
28
|
+
const resolved = await resolvePeerMany(client, peers);
|
|
29
|
+
const dialogPeers = [];
|
|
30
|
+
const result = [];
|
|
31
|
+
const peerToIdx = /* @__PURE__ */ new Map();
|
|
32
|
+
for (let i = 0; i < resolved.length; i++) {
|
|
33
|
+
result[i] = null;
|
|
34
|
+
const peer = resolved[i];
|
|
35
|
+
if (!peer || peer._ === "inputPeerEmpty") {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
dialogPeers.push({
|
|
39
|
+
_: "inputDialogPeer",
|
|
40
|
+
peer
|
|
41
|
+
});
|
|
42
|
+
peerToIdx.set(getMarkedPeerId(peer), i);
|
|
43
|
+
}
|
|
44
|
+
const dialogs = Dialog$2.parseTlDialogs(await client.call({
|
|
7
45
|
_: "messages.getPeerDialogs",
|
|
8
|
-
peers:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return
|
|
46
|
+
peers: dialogPeers
|
|
47
|
+
}));
|
|
48
|
+
for (const dialog of dialogs) {
|
|
49
|
+
const peerIdx = peerToIdx.get(dialog.peer.id);
|
|
50
|
+
if (peerIdx === void 0) continue;
|
|
51
|
+
result[peerIdx] = dialog;
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
16
54
|
}
|
|
17
55
|
export {
|
|
18
56
|
getPeerDialogs
|
|
@@ -7,6 +7,7 @@ import { tl } from '@mtcute/tl';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function _normalizeInputFile(client: ITelegramClient, input: InputFileLike, params: {
|
|
9
9
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
10
|
+
abortSignal?: AbortSignal;
|
|
10
11
|
fileName?: string;
|
|
11
12
|
fileSize?: number;
|
|
12
13
|
fileMime?: string;
|
|
@@ -7,6 +7,7 @@ import { tl } from '@mtcute/tl';
|
|
|
7
7
|
*/
|
|
8
8
|
export declare function _normalizeInputFile(client: ITelegramClient, input: InputFileLike, params: {
|
|
9
9
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
10
|
+
abortSignal?: AbortSignal;
|
|
10
11
|
fileName?: string;
|
|
11
12
|
fileSize?: number;
|
|
12
13
|
fileMime?: string;
|
|
@@ -208,14 +208,15 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
|
|
|
208
208
|
fileMime: sendMime,
|
|
209
209
|
fileSize: media.fileSize,
|
|
210
210
|
requireFileSize: media.type === "photo",
|
|
211
|
-
requireExtension: media.type === "photo"
|
|
211
|
+
requireExtension: media.type === "photo",
|
|
212
|
+
abortSignal: params.abortSignal
|
|
212
213
|
});
|
|
213
214
|
inputFile = uploaded.inputFile;
|
|
214
215
|
mime = uploaded.mime;
|
|
215
216
|
};
|
|
216
217
|
let videoCover;
|
|
217
218
|
if (media.type === "video" && media.cover) {
|
|
218
|
-
const inputMedia = await _normalizeInputMedia(client, media.cover);
|
|
219
|
+
const inputMedia = await _normalizeInputMedia(client, media.cover, params);
|
|
219
220
|
typeAssertions.assertTypeIs("uploadMediaIfNeeded", inputMedia, "inputMediaPhoto");
|
|
220
221
|
videoCover = inputMedia.id;
|
|
221
222
|
}
|
|
@@ -227,7 +228,7 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
|
|
|
227
228
|
peer: uploadPeer,
|
|
228
229
|
media: inputMedia,
|
|
229
230
|
businessConnectionId: params.businessConnectionId
|
|
230
|
-
});
|
|
231
|
+
}, { abortSignal: params.abortSignal });
|
|
231
232
|
if (photo) {
|
|
232
233
|
typeAssertions.assertTypeIs("normalizeInputMedia (@ messages.uploadMedia)", res, "messageMediaPhoto");
|
|
233
234
|
typeAssertions.assertTypeIs("normalizeInputMedia (@ messages.uploadMedia)", res.photo, "photo");
|
|
@@ -315,7 +316,7 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
|
|
|
315
316
|
);
|
|
316
317
|
}
|
|
317
318
|
if ("thumb" in media && media.thumb) {
|
|
318
|
-
thumb = await normalizeInputFile._normalizeInputFile(client, media.thumb, {});
|
|
319
|
+
thumb = await normalizeInputFile._normalizeInputFile(client, media.thumb, { abortSignal: params.abortSignal });
|
|
319
320
|
}
|
|
320
321
|
const attributes = [];
|
|
321
322
|
if (media.type !== "voice") {
|
|
@@ -325,14 +326,20 @@ async function _normalizeInputMedia(client, media, params = {}, uploadMedia = fa
|
|
|
325
326
|
});
|
|
326
327
|
}
|
|
327
328
|
if (media.type === "video") {
|
|
328
|
-
|
|
329
|
+
const attr = {
|
|
329
330
|
_: "documentAttributeVideo",
|
|
330
331
|
duration: media.duration || 0,
|
|
331
332
|
w: media.width || 0,
|
|
332
333
|
h: media.height || 0,
|
|
333
334
|
supportsStreaming: media.supportsStreaming,
|
|
334
335
|
roundMessage: media.isRound
|
|
335
|
-
}
|
|
336
|
+
};
|
|
337
|
+
if (media.isRound) {
|
|
338
|
+
if (attr.w === 0) attr.w = 1;
|
|
339
|
+
if (attr.h === 0) attr.h = 1;
|
|
340
|
+
if (attr.duration === 0) attr.duration = 1;
|
|
341
|
+
}
|
|
342
|
+
attributes.push(attr);
|
|
336
343
|
if (media.isAnimated) {
|
|
337
344
|
attributes.push({ _: "documentAttributeAnimated" });
|
|
338
345
|
}
|
|
@@ -8,5 +8,6 @@ import { tl } from '@mtcute/tl';
|
|
|
8
8
|
export declare function _normalizeInputMedia(client: ITelegramClient, media: InputMediaLike, params?: {
|
|
9
9
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
10
10
|
uploadPeer?: tl.TypeInputPeer;
|
|
11
|
+
abortSignal?: AbortSignal;
|
|
11
12
|
businessConnectionId?: string;
|
|
12
13
|
}, uploadMedia?: boolean): Promise<tl.TypeInputMedia>;
|
|
@@ -8,5 +8,6 @@ import { tl } from '@mtcute/tl';
|
|
|
8
8
|
export declare function _normalizeInputMedia(client: ITelegramClient, media: InputMediaLike, params?: {
|
|
9
9
|
progressCallback?: (uploaded: number, total: number) => void;
|
|
10
10
|
uploadPeer?: tl.TypeInputPeer;
|
|
11
|
+
abortSignal?: AbortSignal;
|
|
11
12
|
businessConnectionId?: string;
|
|
12
13
|
}, uploadMedia?: boolean): Promise<tl.TypeInputMedia>;
|