@mtcute/core 0.27.8 → 0.27.9
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/highlevel/methods/dialogs/iter-dialogs.cjs +4 -0
- package/highlevel/methods/dialogs/iter-dialogs.js +4 -0
- package/highlevel/updates/manager.cjs +11 -0
- package/highlevel/updates/manager.d.cts +2 -1
- package/highlevel/updates/manager.d.ts +2 -1
- package/highlevel/updates/manager.js +12 -1
- package/index.cjs +2 -0
- package/index.js +2 -0
- package/network/network-manager.cjs +1 -1
- package/network/network-manager.js +1 -1
- package/network/server-salt.cjs +2 -7
- package/network/server-salt.js +2 -7
- package/network/transports/index.d.cts +1 -0
- package/network/transports/index.d.ts +1 -0
- package/network/transports/proxy.cjs +46 -0
- package/network/transports/proxy.d.cts +10 -0
- package/network/transports/proxy.d.ts +10 -0
- package/network/transports/proxy.js +41 -0
- package/network/transports/proxy.test.d.cts +1 -0
- package/network/transports/proxy.test.d.ts +1 -0
- package/package.json +1 -1
|
@@ -158,6 +158,10 @@ async function* iterDialogs(client, params) {
|
|
|
158
158
|
}
|
|
159
159
|
for (const d of dialogs) {
|
|
160
160
|
if (filterFolder && !filterFolder(d)) continue;
|
|
161
|
+
if (d.isPinned) {
|
|
162
|
+
if (archived === "exclude" && d.isArchived) continue;
|
|
163
|
+
if (archived === "only" && !d.isArchived) continue;
|
|
164
|
+
}
|
|
161
165
|
yield d;
|
|
162
166
|
if (++current >= limit) return;
|
|
163
167
|
}
|
|
@@ -151,6 +151,10 @@ async function* iterDialogs(client, params) {
|
|
|
151
151
|
}
|
|
152
152
|
for (const d of dialogs) {
|
|
153
153
|
if (filterFolder && !filterFolder(d)) continue;
|
|
154
|
+
if (d.isPinned) {
|
|
155
|
+
if (archived === "exclude" && d.isArchived) continue;
|
|
156
|
+
if (archived === "only" && !d.isArchived) continue;
|
|
157
|
+
}
|
|
154
158
|
yield d;
|
|
155
159
|
if (++current >= limit) return;
|
|
156
160
|
}
|
|
@@ -64,6 +64,10 @@ class UpdatesManager {
|
|
|
64
64
|
// channel id or 0 => pts
|
|
65
65
|
noDispatchPts = /* @__PURE__ */ new Map();
|
|
66
66
|
noDispatchQts = /* @__PURE__ */ new Set();
|
|
67
|
+
// message IDs from common message box that were dispatched recently,
|
|
68
|
+
// used to deduplicate messages from getDifference.newMessages that may have
|
|
69
|
+
// already been processed via regular pts-ordered updates
|
|
70
|
+
_recentlyDispatchedCommonMsgs = new utils.LruSet(100);
|
|
67
71
|
lock = new utils.AsyncLock();
|
|
68
72
|
// rpsIncoming?: RpsMeter
|
|
69
73
|
// rpsProcessing?: RpsMeter
|
|
@@ -777,6 +781,10 @@ class UpdatesManager {
|
|
|
777
781
|
diff.newMessages.forEach((message) => {
|
|
778
782
|
log.debug("processing message %d in %j (%s) from common diff", message.id, message.peerId, message._);
|
|
779
783
|
if (message._ === "messageEmpty") return;
|
|
784
|
+
if (this._recentlyDispatchedCommonMsgs.has(message.id)) {
|
|
785
|
+
log.debug("skipping message %d from common diff because it was already dispatched", message.id);
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
780
788
|
pendingUnorderedUpdates.pushBack(utils$2.toPendingUpdate(utils$2.messageToUpdate(message), peers, true));
|
|
781
789
|
});
|
|
782
790
|
diff.otherUpdates.forEach((upd) => {
|
|
@@ -984,6 +992,9 @@ class UpdatesManager {
|
|
|
984
992
|
}
|
|
985
993
|
}
|
|
986
994
|
log.debug("dispatching %s (postponed = %s)", upd._, postponed);
|
|
995
|
+
if (upd._ === "updateNewMessage" && upd.message._ !== "messageEmpty") {
|
|
996
|
+
this._recentlyDispatchedCommonMsgs.add(upd.message.id);
|
|
997
|
+
}
|
|
987
998
|
client.onRawUpdate.emit(new types.RawUpdateInfo(upd, pending.peers));
|
|
988
999
|
}
|
|
989
1000
|
async _loop() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger, EarlyTimer, SortedArray } from '../../utils/index.js';
|
|
2
2
|
import { BaseTelegramClient } from '../base.js';
|
|
3
3
|
import { PendingUpdate, PendingUpdateContainer, UpdatesManagerParams } from './types.js';
|
|
4
|
-
import { AsyncLock, ConditionVariable, Deque, timers } from '@fuman/utils';
|
|
4
|
+
import { AsyncLock, ConditionVariable, Deque, LruSet, timers } from '@fuman/utils';
|
|
5
5
|
import { tl } from '@mtcute/tl';
|
|
6
6
|
import { PeersIndex } from '../types/peers/peers-index.js';
|
|
7
7
|
export declare class UpdatesManager {
|
|
@@ -21,6 +21,7 @@ export declare class UpdatesManager {
|
|
|
21
21
|
noDispatchMsg: Map<number, Set<number>>;
|
|
22
22
|
noDispatchPts: Map<number, Set<number>>;
|
|
23
23
|
noDispatchQts: Set<number>;
|
|
24
|
+
_recentlyDispatchedCommonMsgs: LruSet<number>;
|
|
24
25
|
lock: AsyncLock;
|
|
25
26
|
pts?: number;
|
|
26
27
|
qts?: number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger, EarlyTimer, SortedArray } from '../../utils/index.js';
|
|
2
2
|
import { BaseTelegramClient } from '../base.js';
|
|
3
3
|
import { PendingUpdate, PendingUpdateContainer, UpdatesManagerParams } from './types.js';
|
|
4
|
-
import { AsyncLock, ConditionVariable, Deque, timers } from '@fuman/utils';
|
|
4
|
+
import { AsyncLock, ConditionVariable, Deque, LruSet, timers } from '@fuman/utils';
|
|
5
5
|
import { tl } from '@mtcute/tl';
|
|
6
6
|
import { PeersIndex } from '../types/peers/peers-index.js';
|
|
7
7
|
export declare class UpdatesManager {
|
|
@@ -21,6 +21,7 @@ export declare class UpdatesManager {
|
|
|
21
21
|
noDispatchMsg: Map<number, Set<number>>;
|
|
22
22
|
noDispatchPts: Map<number, Set<number>>;
|
|
23
23
|
noDispatchQts: Set<number>;
|
|
24
|
+
_recentlyDispatchedCommonMsgs: LruSet<number>;
|
|
24
25
|
lock: AsyncLock;
|
|
25
26
|
pts?: number;
|
|
26
27
|
qts?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConditionVariable, Deque, AsyncLock, unknownToError, timers } from "@fuman/utils";
|
|
1
|
+
import { ConditionVariable, Deque, LruSet, AsyncLock, unknownToError, timers } from "@fuman/utils";
|
|
2
2
|
import { tl } from "@mtcute/tl";
|
|
3
3
|
import Long from "long";
|
|
4
4
|
import { MtArgumentError } from "../../types/errors.js";
|
|
@@ -57,6 +57,10 @@ class UpdatesManager {
|
|
|
57
57
|
// channel id or 0 => pts
|
|
58
58
|
noDispatchPts = /* @__PURE__ */ new Map();
|
|
59
59
|
noDispatchQts = /* @__PURE__ */ new Set();
|
|
60
|
+
// message IDs from common message box that were dispatched recently,
|
|
61
|
+
// used to deduplicate messages from getDifference.newMessages that may have
|
|
62
|
+
// already been processed via regular pts-ordered updates
|
|
63
|
+
_recentlyDispatchedCommonMsgs = new LruSet(100);
|
|
60
64
|
lock = new AsyncLock();
|
|
61
65
|
// rpsIncoming?: RpsMeter
|
|
62
66
|
// rpsProcessing?: RpsMeter
|
|
@@ -770,6 +774,10 @@ class UpdatesManager {
|
|
|
770
774
|
diff.newMessages.forEach((message) => {
|
|
771
775
|
log.debug("processing message %d in %j (%s) from common diff", message.id, message.peerId, message._);
|
|
772
776
|
if (message._ === "messageEmpty") return;
|
|
777
|
+
if (this._recentlyDispatchedCommonMsgs.has(message.id)) {
|
|
778
|
+
log.debug("skipping message %d from common diff because it was already dispatched", message.id);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
773
781
|
pendingUnorderedUpdates.pushBack(toPendingUpdate(messageToUpdate(message), peers, true));
|
|
774
782
|
});
|
|
775
783
|
diff.otherUpdates.forEach((upd) => {
|
|
@@ -977,6 +985,9 @@ class UpdatesManager {
|
|
|
977
985
|
}
|
|
978
986
|
}
|
|
979
987
|
log.debug("dispatching %s (postponed = %s)", upd._, postponed);
|
|
988
|
+
if (upd._ === "updateNewMessage" && upd.message._ !== "messageEmpty") {
|
|
989
|
+
this._recentlyDispatchedCommonMsgs.add(upd.message.id);
|
|
990
|
+
}
|
|
980
991
|
client.onRawUpdate.emit(new RawUpdateInfo(upd, pending.peers));
|
|
981
992
|
}
|
|
982
993
|
async _loop() {
|
package/index.cjs
CHANGED
|
@@ -145,6 +145,7 @@ const sessionConnection = require("./network/session-connection.cjs");
|
|
|
145
145
|
const abstract = require("./network/transports/abstract.cjs");
|
|
146
146
|
const intermediate = require("./network/transports/intermediate.cjs");
|
|
147
147
|
const obfuscated = require("./network/transports/obfuscated.cjs");
|
|
148
|
+
const proxy = require("./network/transports/proxy.cjs");
|
|
148
149
|
const driver = require("./storage/driver.cjs");
|
|
149
150
|
const driver$1 = require("./storage/memory/driver.cjs");
|
|
150
151
|
const authKeys = require("./storage/memory/repository/auth-keys.cjs");
|
|
@@ -334,6 +335,7 @@ exports.TransportError = abstract.TransportError;
|
|
|
334
335
|
exports.IntermediatePacketCodec = intermediate.IntermediatePacketCodec;
|
|
335
336
|
exports.PaddedIntermediatePacketCodec = intermediate.PaddedIntermediatePacketCodec;
|
|
336
337
|
exports.ObfuscatedPacketCodec = obfuscated.ObfuscatedPacketCodec;
|
|
338
|
+
exports.createProxyTransportFactory = proxy.createProxyTransportFactory;
|
|
337
339
|
exports.BaseStorageDriver = driver.BaseStorageDriver;
|
|
338
340
|
exports.MemoryStorageDriver = driver$1.MemoryStorageDriver;
|
|
339
341
|
exports.MemoryAuthKeysRepository = authKeys.MemoryAuthKeysRepository;
|
package/index.js
CHANGED
|
@@ -138,6 +138,7 @@ import { SessionConnection } from "./network/session-connection.js";
|
|
|
138
138
|
import { TransportError } from "./network/transports/abstract.js";
|
|
139
139
|
import { IntermediatePacketCodec, PaddedIntermediatePacketCodec } from "./network/transports/intermediate.js";
|
|
140
140
|
import { ObfuscatedPacketCodec } from "./network/transports/obfuscated.js";
|
|
141
|
+
import { createProxyTransportFactory } from "./network/transports/proxy.js";
|
|
141
142
|
import { BaseStorageDriver } from "./storage/driver.js";
|
|
142
143
|
import { MemoryStorageDriver } from "./storage/memory/driver.js";
|
|
143
144
|
import { MemoryAuthKeysRepository } from "./storage/memory/repository/auth-keys.js";
|
|
@@ -323,6 +324,7 @@ export {
|
|
|
323
324
|
_storyInteractiveElementFromTl,
|
|
324
325
|
assertNever,
|
|
325
326
|
businessWorkHoursDaysToRaw,
|
|
327
|
+
createProxyTransportFactory,
|
|
326
328
|
getAllPeersFrom,
|
|
327
329
|
getBarePeerId,
|
|
328
330
|
getBasicPeerType,
|
package/network/server-salt.cjs
CHANGED
|
@@ -17,16 +17,11 @@ class ServerSaltManager {
|
|
|
17
17
|
setFutureSalts(salts) {
|
|
18
18
|
this._futureSalts = salts;
|
|
19
19
|
const now = Date.now() / 1e3;
|
|
20
|
-
while (salts.length > 0 &&
|
|
20
|
+
while (salts.length > 0 && salts[0].validSince <= now) {
|
|
21
21
|
this.currentSalt = salts[0].salt;
|
|
22
22
|
this._futureSalts.shift();
|
|
23
23
|
}
|
|
24
|
-
if (
|
|
25
|
-
this.currentSalt = salts[0].salt;
|
|
26
|
-
this._futureSalts.shift();
|
|
27
|
-
}
|
|
28
|
-
if (!this._futureSalts.length) ;
|
|
29
|
-
else {
|
|
24
|
+
if (this._futureSalts.length) {
|
|
30
25
|
this._scheduleReplace(this._futureSalts[0]);
|
|
31
26
|
}
|
|
32
27
|
}
|
package/network/server-salt.js
CHANGED
|
@@ -10,16 +10,11 @@ class ServerSaltManager {
|
|
|
10
10
|
setFutureSalts(salts) {
|
|
11
11
|
this._futureSalts = salts;
|
|
12
12
|
const now = Date.now() / 1e3;
|
|
13
|
-
while (salts.length > 0 &&
|
|
13
|
+
while (salts.length > 0 && salts[0].validSince <= now) {
|
|
14
14
|
this.currentSalt = salts[0].salt;
|
|
15
15
|
this._futureSalts.shift();
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
18
|
-
this.currentSalt = salts[0].salt;
|
|
19
|
-
this._futureSalts.shift();
|
|
20
|
-
}
|
|
21
|
-
if (!this._futureSalts.length) ;
|
|
22
|
-
else {
|
|
17
|
+
if (this._futureSalts.length) {
|
|
23
18
|
this._scheduleReplace(this._futureSalts[0]);
|
|
24
19
|
}
|
|
25
20
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. 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 errors = require("../../types/errors.cjs");
|
|
9
|
+
const proxy = require("../../utils/links/proxy.cjs");
|
|
10
|
+
function createProxyTransportFactory(options) {
|
|
11
|
+
const { SocksProxyTcpTransport, MtProxyTcpTransport, HttpProxyTcpTransport } = options;
|
|
12
|
+
return (url) => {
|
|
13
|
+
const obj = new URL(url);
|
|
14
|
+
if (SocksProxyTcpTransport != null && (obj.protocol === "socks4:" || obj.protocol === "socks5:")) {
|
|
15
|
+
return new SocksProxyTcpTransport({
|
|
16
|
+
version: obj.protocol === "socks4:" ? 4 : 5,
|
|
17
|
+
host: obj.hostname,
|
|
18
|
+
port: Number(obj.port) || 1080,
|
|
19
|
+
user: obj.username,
|
|
20
|
+
password: obj.password
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (MtProxyTcpTransport != null) {
|
|
24
|
+
const mtproxy = proxy.mtproxy.parse(url);
|
|
25
|
+
if (mtproxy) {
|
|
26
|
+
return new MtProxyTcpTransport({
|
|
27
|
+
host: mtproxy.server,
|
|
28
|
+
port: mtproxy.port,
|
|
29
|
+
secret: mtproxy.secret
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (HttpProxyTcpTransport && (obj.protocol === "http:" || obj.protocol === "https:")) {
|
|
34
|
+
return new HttpProxyTcpTransport({
|
|
35
|
+
tls: obj.protocol === "https:",
|
|
36
|
+
host: obj.hostname,
|
|
37
|
+
port: Number(obj.port) || (obj.protocol === "https:" ? 443 : 80),
|
|
38
|
+
user: obj.username,
|
|
39
|
+
password: obj.password
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
throw new errors.MtArgumentError(`Unsupported proxy protocol: ${obj.protocol}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
exports.createProxyTransportFactory = createProxyTransportFactory;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HttpProxySettings, SocksProxySettings } from '@fuman/net';
|
|
2
|
+
import { MtProxySettings } from '../mtproxy/index.js';
|
|
3
|
+
import { TelegramTransport } from './abstract.js';
|
|
4
|
+
export declare function createProxyTransportFactory(options: {
|
|
5
|
+
SocksProxyTcpTransport?: new (options: SocksProxySettings) => TelegramTransport;
|
|
6
|
+
MtProxyTcpTransport?: new (options: MtProxySettings) => TelegramTransport;
|
|
7
|
+
HttpProxyTcpTransport?: new (options: HttpProxySettings & {
|
|
8
|
+
tls?: boolean;
|
|
9
|
+
}) => TelegramTransport;
|
|
10
|
+
}): (url: string) => TelegramTransport;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { HttpProxySettings, SocksProxySettings } from '@fuman/net';
|
|
2
|
+
import { MtProxySettings } from '../mtproxy/index.js';
|
|
3
|
+
import { TelegramTransport } from './abstract.js';
|
|
4
|
+
export declare function createProxyTransportFactory(options: {
|
|
5
|
+
SocksProxyTcpTransport?: new (options: SocksProxySettings) => TelegramTransport;
|
|
6
|
+
MtProxyTcpTransport?: new (options: MtProxySettings) => TelegramTransport;
|
|
7
|
+
HttpProxyTcpTransport?: new (options: HttpProxySettings & {
|
|
8
|
+
tls?: boolean;
|
|
9
|
+
}) => TelegramTransport;
|
|
10
|
+
}): (url: string) => TelegramTransport;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MtArgumentError } from "../../types/errors.js";
|
|
2
|
+
import { mtproxy } from "../../utils/links/proxy.js";
|
|
3
|
+
function createProxyTransportFactory(options) {
|
|
4
|
+
const { SocksProxyTcpTransport, MtProxyTcpTransport, HttpProxyTcpTransport } = options;
|
|
5
|
+
return (url) => {
|
|
6
|
+
const obj = new URL(url);
|
|
7
|
+
if (SocksProxyTcpTransport != null && (obj.protocol === "socks4:" || obj.protocol === "socks5:")) {
|
|
8
|
+
return new SocksProxyTcpTransport({
|
|
9
|
+
version: obj.protocol === "socks4:" ? 4 : 5,
|
|
10
|
+
host: obj.hostname,
|
|
11
|
+
port: Number(obj.port) || 1080,
|
|
12
|
+
user: obj.username,
|
|
13
|
+
password: obj.password
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
if (MtProxyTcpTransport != null) {
|
|
17
|
+
const mtproxy$1 = mtproxy.parse(url);
|
|
18
|
+
if (mtproxy$1) {
|
|
19
|
+
return new MtProxyTcpTransport({
|
|
20
|
+
host: mtproxy$1.server,
|
|
21
|
+
port: mtproxy$1.port,
|
|
22
|
+
secret: mtproxy$1.secret
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (HttpProxyTcpTransport && (obj.protocol === "http:" || obj.protocol === "https:")) {
|
|
27
|
+
return new HttpProxyTcpTransport({
|
|
28
|
+
tls: obj.protocol === "https:",
|
|
29
|
+
host: obj.hostname,
|
|
30
|
+
port: Number(obj.port) || (obj.protocol === "https:" ? 443 : 80),
|
|
31
|
+
user: obj.username,
|
|
32
|
+
password: obj.password
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
throw new MtArgumentError(`Unsupported proxy protocol: ${obj.protocol}`);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
createProxyTransportFactory
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|