@mtkruto/node 0.1.126 → 0.1.128

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.
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
6
  export declare const LAYER = 167;
7
- export declare const APP_VERSION = "MTKruto 0.1.126";
7
+ export declare const APP_VERSION = "MTKruto 0.1.128";
8
8
  export declare const DEVICE_MODEL: string;
9
9
  export declare const LANG_CODE: string;
10
10
  export declare const LANG_PACK = "";
@@ -53,7 +53,7 @@ export const PUBLIC_KEYS = Object.freeze([
53
53
  ]);
54
54
  export const INITIAL_DC = "2";
55
55
  export const LAYER = 167;
56
- export const APP_VERSION = "MTKruto 0.1.126";
56
+ export const APP_VERSION = "MTKruto 0.1.128";
57
57
  // @ts-ignore: lib
58
58
  export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
59
59
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1645,12 +1645,21 @@ export class Client extends ClientAbstract {
1645
1645
  }
1646
1646
  }
1647
1647
  async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
1648
+ const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
1649
+ if (id != null) {
1650
+ const partCount = await this.storage.getFile(id);
1651
+ if (partCount != null && partCount > 0) {
1652
+ for await (const part of this.storage.iterFileParts(id, partCount)) {
1653
+ yield part;
1654
+ }
1655
+ return;
1656
+ }
1657
+ }
1648
1658
  const chunkSize = params?.chunkSize ?? 1024 * 1024;
1649
1659
  if (mod(chunkSize, 1024) != 0) {
1650
1660
  throw new Error("chunkSize must be divisible by 1024");
1651
1661
  }
1652
- const exportedAuth = await this.invoke(new functions.auth.exportAuthorization({ dc_id: dcId }));
1653
- const client = new _a(new StorageMemory(), this.apiId, this.apiHash, {
1662
+ const client = new _a(dcId == this.dcId ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
1654
1663
  transportProvider: this.transportProvider,
1655
1664
  appVersion: this.appVersion,
1656
1665
  deviceModel: this.deviceModel,
@@ -1666,14 +1675,37 @@ export class Client extends ClientAbstract {
1666
1675
  }
1667
1676
  await client.setDc(dc);
1668
1677
  await client.connect();
1669
- await client.authorize(exportedAuth);
1678
+ await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
1679
+ client.invoke.use(async (ctx, next) => {
1680
+ if (ctx.error instanceof AuthKeyUnregistered) {
1681
+ try {
1682
+ const exportedAuth = await this.invoke(new functions.auth.exportAuthorization({ dc_id: dcId }));
1683
+ await client.authorize(exportedAuth);
1684
+ return true;
1685
+ }
1686
+ catch (err) {
1687
+ throw err;
1688
+ }
1689
+ }
1690
+ else {
1691
+ return await next();
1692
+ }
1693
+ });
1670
1694
  const limit = chunkSize;
1671
1695
  let offset = 0n;
1696
+ let part = 0;
1672
1697
  while (true) {
1673
1698
  const file = await (client ?? this).invoke(new functions.upload.getFile({ location, offset, limit }));
1674
1699
  if (file instanceof types.upload.File) {
1675
1700
  yield file.bytes;
1701
+ if (id != null) {
1702
+ await this.storage.saveFilePart(id, part, file.bytes);
1703
+ }
1704
+ ++part;
1676
1705
  if (file.bytes.length < limit) {
1706
+ if (id != null) {
1707
+ await this.storage.setFilePartCount(id, part + 1);
1708
+ }
1677
1709
  break;
1678
1710
  }
1679
1711
  else {
@@ -2277,7 +2309,7 @@ export class Client extends ClientAbstract {
2277
2309
  let chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLoadedChats).call(this, listId);
2278
2310
  if (params?.after) {
2279
2311
  chats = chats
2280
- .filter((v) => v.id < params.after.id);
2312
+ .filter((v) => v.order < params.after.order);
2281
2313
  }
2282
2314
  if (chats.length < limit) {
2283
2315
  d("have only %d chats but %d more is needed", chats.length, limit - chats.length);
@@ -2715,7 +2747,7 @@ async function _Client_setMyInfo(info) {
2715
2747
  if (!(dialogs instanceof types.messages.Dialogs) && !(dialogs instanceof types.messages.DialogsSlice)) {
2716
2748
  UNREACHABLE();
2717
2749
  }
2718
- if (dialogs.dialogs.length == 0) {
2750
+ if (dialogs.dialogs.length < limit) {
2719
2751
  await this.storage.setHasAllChats(listId, true);
2720
2752
  }
2721
2753
  const chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
@@ -18,6 +18,8 @@ export declare abstract class Storage {
18
18
  limit?: number;
19
19
  reverse?: boolean;
20
20
  }): MaybePromise<Generator<[readonly StorageKeyPart[], T]> | AsyncGenerator<[readonly StorageKeyPart[], T]>>;
21
+ abstract get supportsFiles(): boolean;
22
+ abstract branch(id: string): Storage;
21
23
  setDc(dc: DC | null): MaybePromise<void>;
22
24
  getDc(): MaybePromise<DC | null>;
23
25
  getAuthKey(): Promise<Uint8Array | null>;
@@ -66,4 +68,8 @@ export declare abstract class Storage {
66
68
  setPinnedChats(listId: number, chatIds: number[] | null): Promise<void>;
67
69
  getPinnedChats(listId: number): Promise<number[] | null>;
68
70
  getHistory(chatId: number, offsetId: number, limit: number): Promise<enums.Message[]>;
71
+ getFile(id: bigint): Promise<number | null>;
72
+ iterFileParts(id: bigint, partCount: number): AsyncGenerator<Uint8Array, void, unknown>;
73
+ saveFilePart(id: bigint, index: number, bytes: Uint8Array): Promise<void>;
74
+ setFilePartCount(id: bigint, partCount: number): Promise<void>;
69
75
  }
@@ -30,6 +30,8 @@ const KPARTS_CHATS = (listId) => ["chats", listId];
30
30
  const KPARTS_CHAT = (listId, chatId) => ["chats", listId, chatId];
31
31
  const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
32
32
  const KPARTS_SERVER_SALT = ["serverSalt"];
33
+ const KPARTS_FILE = (fileId) => ["files", fileId];
34
+ const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
33
35
  export class Storage {
34
36
  constructor() {
35
37
  _Storage_instances.add(this);
@@ -208,12 +210,47 @@ export class Storage {
208
210
  if (offsetId == 0) {
209
211
  offsetId = Infinity;
210
212
  }
213
+ ++limit;
211
214
  const messages = new Array();
212
215
  for await (const [_, buffer] of await this.getMany({ start: KPARTS_MESSAGE(chatId, 0), end: KPARTS_MESSAGE(chatId, offsetId) }, { limit, reverse: true })) {
213
- messages.push(await this.getTLObject(buffer));
216
+ const message = await this.getTLObject(buffer);
217
+ if ("id" in message && message.id == offsetId) {
218
+ continue;
219
+ }
220
+ messages.push(message);
214
221
  }
215
222
  return messages;
216
223
  }
224
+ async getFile(id) {
225
+ if (!this.supportsFiles) {
226
+ return null;
227
+ }
228
+ return await this.get(KPARTS_FILE(id));
229
+ }
230
+ async *iterFileParts(id, partCount) {
231
+ if (!this.supportsFiles) {
232
+ return;
233
+ }
234
+ for (let i = 0; i < partCount; i++) {
235
+ const part = await this.get(KPARTS_FILE_PART(id, i));
236
+ if (part == null) {
237
+ continue;
238
+ }
239
+ yield part;
240
+ }
241
+ }
242
+ async saveFilePart(id, index, bytes) {
243
+ if (!this.supportsFiles) {
244
+ return;
245
+ }
246
+ await this.set(KPARTS_FILE_PART(id, index), bytes);
247
+ }
248
+ async setFilePartCount(id, partCount) {
249
+ if (!this.supportsFiles) {
250
+ return;
251
+ }
252
+ await this.set(KPARTS_FILE(id), partCount);
253
+ }
217
254
  }
218
255
  _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
219
256
  if (authKey != null) {
@@ -1,11 +1,14 @@
1
1
  import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
2
2
  export declare class StorageIndexedDB extends Storage {
3
- readonly name: string;
3
+ #private;
4
4
  database: IDBDatabase | null;
5
5
  constructor(name: string);
6
+ get name(): string;
7
+ branch(id: string): StorageIndexedDB;
6
8
  init(): Promise<void>;
9
+ get supportsFiles(): boolean;
7
10
  set(k: readonly StorageKeyPart[], v: unknown, tx_?: IDBTransaction): Promise<void>;
8
- get<T>(k: readonly StorageKeyPart[], tx_?: IDBTransaction): Promise<T | null>;
11
+ get<T>(k: readonly StorageKeyPart[], tx_?: IDBTransaction | null, fix?: boolean): Promise<T | null>;
9
12
  getMany<T>(filter: GetManyFilter, params?: {
10
13
  limit?: number;
11
14
  reverse?: boolean;
@@ -1,3 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _StorageIndexedDB_instances, _StorageIndexedDB_name, _StorageIndexedDB_id, _StorageIndexedDB_fixKey;
1
13
  import { Storage } from "./0_storage.js";
2
14
  import { fixKey, getPrefixKeyRange, restoreKey } from "./0_utilities.js";
3
15
  const VERSION = 1;
@@ -8,18 +20,24 @@ export class StorageIndexedDB extends Storage {
8
20
  throw new Error("Unavailable in current environment");
9
21
  }
10
22
  super();
11
- Object.defineProperty(this, "name", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: name
16
- });
23
+ _StorageIndexedDB_instances.add(this);
17
24
  Object.defineProperty(this, "database", {
18
25
  enumerable: true,
19
26
  configurable: true,
20
27
  writable: true,
21
28
  value: null
22
29
  });
30
+ _StorageIndexedDB_name.set(this, void 0);
31
+ _StorageIndexedDB_id.set(this, null);
32
+ __classPrivateFieldSet(this, _StorageIndexedDB_name, name, "f");
33
+ }
34
+ get name() {
35
+ return __classPrivateFieldGet(this, _StorageIndexedDB_name, "f");
36
+ }
37
+ branch(id) {
38
+ const storage = new StorageIndexedDB(this.name);
39
+ __classPrivateFieldSet(storage, _StorageIndexedDB_id, id, "f");
40
+ return storage;
23
41
  }
24
42
  init() {
25
43
  const db = indexedDB.open(this.name, VERSION);
@@ -35,7 +53,11 @@ export class StorageIndexedDB extends Storage {
35
53
  };
36
54
  });
37
55
  }
56
+ get supportsFiles() {
57
+ return true;
58
+ }
38
59
  set(k, v, tx_) {
60
+ k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
39
61
  if (!this.database) {
40
62
  throw new Error("Not initialized");
41
63
  }
@@ -57,7 +79,10 @@ export class StorageIndexedDB extends Storage {
57
79
  };
58
80
  });
59
81
  }
60
- get(k, tx_) {
82
+ get(k, tx_, fix = true) {
83
+ if (fix) {
84
+ k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
85
+ }
61
86
  if (!this.database) {
62
87
  throw new Error("Not initialized");
63
88
  }
@@ -73,6 +98,15 @@ export class StorageIndexedDB extends Storage {
73
98
  });
74
99
  }
75
100
  async *getMany(filter, params, tx_) {
101
+ if ("prefix" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
102
+ filter.prefix = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.prefix);
103
+ }
104
+ if ("start" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
105
+ filter.start = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.start);
106
+ }
107
+ if ("end" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
108
+ filter.end = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.end);
109
+ }
76
110
  if (!this.database) {
77
111
  throw new Error("Not initialized");
78
112
  }
@@ -108,7 +142,7 @@ export class StorageIndexedDB extends Storage {
108
142
  };
109
143
  });
110
144
  for (const key of keys) {
111
- yield [key, await this.get(key)];
145
+ yield [key, await this.get(key, null, false)];
112
146
  }
113
147
  }
114
148
  async incr(key, by) {
@@ -121,3 +155,11 @@ export class StorageIndexedDB extends Storage {
121
155
  await this.set(key, (currentValue || 0) + by, tx);
122
156
  }
123
157
  }
158
+ _StorageIndexedDB_name = new WeakMap(), _StorageIndexedDB_id = new WeakMap(), _StorageIndexedDB_instances = new WeakSet(), _StorageIndexedDB_fixKey = function _StorageIndexedDB_fixKey(key) {
159
+ if (__classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
160
+ return ["__S" + __classPrivateFieldGet(this, _StorageIndexedDB_id, "f"), ...key];
161
+ }
162
+ else {
163
+ return key;
164
+ }
165
+ };
@@ -1,8 +1,11 @@
1
1
  import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
2
2
  export declare class StorageLocalStorage extends Storage implements Storage {
3
- private readonly prefix;
3
+ #private;
4
4
  constructor(prefix: string);
5
+ get prefix(): string;
6
+ branch(id: string): StorageLocalStorage;
5
7
  init(): void;
8
+ get supportsFiles(): boolean;
6
9
  get<T>(key_: readonly StorageKeyPart[]): T | null;
7
10
  getMany<T>(filter: GetManyFilter, params?: {
8
11
  limit?: number;
@@ -1,3 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _StorageLocalStorage_prefix;
1
13
  import { Storage } from "./0_storage.js";
2
14
  import { fromString, isInRange, toString } from "./0_utilities.js";
3
15
  export class StorageLocalStorage extends Storage {
@@ -12,15 +24,20 @@ export class StorageLocalStorage extends Storage {
12
24
  throw new Error("Unallowed prefix");
13
25
  }
14
26
  super();
15
- Object.defineProperty(this, "prefix", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: prefix
20
- });
27
+ _StorageLocalStorage_prefix.set(this, void 0);
28
+ __classPrivateFieldSet(this, _StorageLocalStorage_prefix, prefix, "f");
29
+ }
30
+ get prefix() {
31
+ return __classPrivateFieldGet(this, _StorageLocalStorage_prefix, "f");
32
+ }
33
+ branch(id) {
34
+ return new StorageLocalStorage(this.prefix + "S__" + id);
21
35
  }
22
36
  init() {
23
37
  }
38
+ get supportsFiles() {
39
+ return false;
40
+ }
24
41
  get(key_) {
25
42
  const key = this.prefix + toString(key_);
26
43
  const value = localStorage.getItem(key);
@@ -74,3 +91,4 @@ export class StorageLocalStorage extends Storage {
74
91
  this.set(key, (this.get(key) || 0) + by);
75
92
  }
76
93
  }
94
+ _StorageLocalStorage_prefix = new WeakMap();
@@ -4,6 +4,8 @@ export declare class StorageMemory extends Storage implements Storage {
4
4
  #private;
5
5
  protected map: Map<string, unknown>;
6
6
  init(): void;
7
+ branch(id: string): Storage;
8
+ get supportsFiles(): boolean;
7
9
  get<T>(key: readonly StorageKeyPart[]): NonNullable<T> | null;
8
10
  getMany<T>(filter: GetManyFilter, params?: {
9
11
  limit?: number;
@@ -3,7 +3,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _StorageMemory_instances, _StorageMemory_getEntries;
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _StorageMemory_instances, _StorageMemory_id, _StorageMemory_fixKey, _StorageMemory_getEntries;
7
13
  import { Storage } from "./0_storage.js";
8
14
  import { fromString, isInRange, toString } from "./0_utilities.js";
9
15
  export class StorageMemory extends Storage {
@@ -16,10 +22,20 @@ export class StorageMemory extends Storage {
16
22
  writable: true,
17
23
  value: new Map()
18
24
  });
25
+ _StorageMemory_id.set(this, null);
19
26
  }
20
27
  init() {
21
28
  }
29
+ branch(id) {
30
+ const storage = new StorageMemory();
31
+ __classPrivateFieldSet(storage, _StorageMemory_id, id, "f");
32
+ return storage;
33
+ }
34
+ get supportsFiles() {
35
+ return false;
36
+ }
22
37
  get(key) {
38
+ key = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, key);
23
39
  return this.map.get(toString(key)) ?? null;
24
40
  }
25
41
  *getMany(filter, params) {
@@ -50,6 +66,7 @@ export class StorageMemory extends Storage {
50
66
  }
51
67
  }
52
68
  set(key_, value) {
69
+ key_ = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, key_);
53
70
  const key = toString(key_);
54
71
  if (value != null) {
55
72
  this.map.set(key, value);
@@ -62,9 +79,19 @@ export class StorageMemory extends Storage {
62
79
  this.set(key, (this.get(key) || 0) + by);
63
80
  }
64
81
  }
65
- _StorageMemory_instances = new WeakSet(), _StorageMemory_getEntries = function _StorageMemory_getEntries() {
82
+ _StorageMemory_id = new WeakMap(), _StorageMemory_instances = new WeakSet(), _StorageMemory_fixKey = function _StorageMemory_fixKey(key) {
83
+ if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null) {
84
+ return ["__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"), ...key];
85
+ }
86
+ else {
87
+ return key;
88
+ }
89
+ }, _StorageMemory_getEntries = function _StorageMemory_getEntries() {
66
90
  const entries = new Array();
67
91
  for (const entry of this.map.entries()) {
92
+ if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null && !entry[0].startsWith("__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"))) {
93
+ continue;
94
+ }
68
95
  entries.push(entry);
69
96
  }
70
97
  return entries;
@@ -1,9 +1,12 @@
1
1
  import { MaybePromise } from "../1_utilities.js";
2
2
  import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageSessionStorage extends Storage implements Storage {
4
- private readonly prefix;
4
+ #private;
5
5
  constructor(prefix: string);
6
+ get prefix(): string;
7
+ branch(id: string): StorageSessionStorage;
6
8
  init(): void;
9
+ get supportsFiles(): boolean;
7
10
  get<T>(key_: readonly StorageKeyPart[]): T | null;
8
11
  getMany<T>(filter: GetManyFilter, params?: {
9
12
  limit?: number;
@@ -1,3 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _StorageSessionStorage_prefix;
1
13
  import { Storage } from "./0_storage.js";
2
14
  import { fromString, isInRange, toString } from "./0_utilities.js";
3
15
  export class StorageSessionStorage extends Storage {
@@ -12,15 +24,20 @@ export class StorageSessionStorage extends Storage {
12
24
  throw new Error("Unallowed prefix");
13
25
  }
14
26
  super();
15
- Object.defineProperty(this, "prefix", {
16
- enumerable: true,
17
- configurable: true,
18
- writable: true,
19
- value: prefix
20
- });
27
+ _StorageSessionStorage_prefix.set(this, void 0);
28
+ __classPrivateFieldSet(this, _StorageSessionStorage_prefix, prefix, "f");
29
+ }
30
+ get prefix() {
31
+ return __classPrivateFieldGet(this, _StorageSessionStorage_prefix, "f");
32
+ }
33
+ branch(id) {
34
+ return new StorageSessionStorage(this.prefix + "S__" + id);
21
35
  }
22
36
  init() {
23
37
  }
38
+ get supportsFiles() {
39
+ return false;
40
+ }
24
41
  get(key_) {
25
42
  const key = this.prefix + toString(key_);
26
43
  const value = sessionStorage.getItem(key);
@@ -74,3 +91,4 @@ export class StorageSessionStorage extends Storage {
74
91
  this.set(key, (this.get(key) || 0) + by);
75
92
  }
76
93
  }
94
+ _StorageSessionStorage_prefix = new WeakMap();
@@ -297,33 +297,24 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
297
297
  message.forwardSenderName = message_.fwd_from.from_name;
298
298
  message.forwardId = message_.fwd_from.channel_post;
299
299
  message.forwardSignature = message_.fwd_from.post_author;
300
- message.forwardDate = new Date(message_.date * 1000);
300
+ message.forwardDate = new Date(message_.fwd_from.date * 1000);
301
301
  if (message_.fwd_from.from_id instanceof types.PeerUser) {
302
302
  const entity = await getEntity(message_.fwd_from.from_id);
303
303
  if (entity) {
304
304
  message.forwardFrom = constructUser(entity);
305
305
  }
306
- else {
307
- UNREACHABLE();
308
- }
309
306
  }
310
307
  else if (message_.fwd_from.from_id instanceof types.PeerChat) {
311
308
  const entity = await getEntity(message_.fwd_from.from_id);
312
309
  if (entity) {
313
310
  message.forwardFromChat = constructChatP(entity);
314
311
  }
315
- else {
316
- UNREACHABLE();
317
- }
318
312
  }
319
313
  else if (message_.fwd_from.from_id instanceof types.PeerChannel) {
320
314
  const entity = await getEntity(message_.fwd_from.from_id);
321
315
  if (entity) {
322
316
  message.forwardFromChat = constructChatP(entity);
323
317
  }
324
- else {
325
- UNREACHABLE();
326
- }
327
318
  }
328
319
  }
329
320
  if (message_.media) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtkruto/node",
3
- "version": "0.1.126",
3
+ "version": "0.1.128",
4
4
  "description": "MTKruto for Node.js",
5
5
  "author": "Roj <rojvv@icloud.com>",
6
6
  "repository": {
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
6
  export declare const LAYER = 167;
7
- export declare const APP_VERSION = "MTKruto 0.1.126";
7
+ export declare const APP_VERSION = "MTKruto 0.1.128";
8
8
  export declare const DEVICE_MODEL: string;
9
9
  export declare const LANG_CODE: string;
10
10
  export declare const LANG_PACK = "";
@@ -79,7 +79,7 @@ exports.PUBLIC_KEYS = Object.freeze([
79
79
  ]);
80
80
  exports.INITIAL_DC = "2";
81
81
  exports.LAYER = 167;
82
- exports.APP_VERSION = "MTKruto 0.1.126";
82
+ exports.APP_VERSION = "MTKruto 0.1.128";
83
83
  // @ts-ignore: lib
84
84
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
85
85
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -1650,12 +1650,21 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1650
1650
  }
1651
1651
  }
1652
1652
  async [(_Client_downloadInner = async function* _Client_downloadInner(location, dcId, params) {
1653
+ const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
1654
+ if (id != null) {
1655
+ const partCount = await this.storage.getFile(id);
1656
+ if (partCount != null && partCount > 0) {
1657
+ for await (const part of this.storage.iterFileParts(id, partCount)) {
1658
+ yield part;
1659
+ }
1660
+ return;
1661
+ }
1662
+ }
1653
1663
  const chunkSize = params?.chunkSize ?? 1024 * 1024;
1654
1664
  if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
1655
1665
  throw new Error("chunkSize must be divisible by 1024");
1656
1666
  }
1657
- const exportedAuth = await this.invoke(new _2_tl_js_1.functions.auth.exportAuthorization({ dc_id: dcId }));
1658
- const client = new _a(new _3_storage_js_1.StorageMemory(), this.apiId, this.apiHash, {
1667
+ const client = new _a(dcId == this.dcId ? this.storage : this.storage.branch(`download_client_${dcId}`), this.apiId, this.apiHash, {
1659
1668
  transportProvider: this.transportProvider,
1660
1669
  appVersion: this.appVersion,
1661
1670
  deviceModel: this.deviceModel,
@@ -1671,14 +1680,37 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1671
1680
  }
1672
1681
  await client.setDc(dc);
1673
1682
  await client.connect();
1674
- await client.authorize(exportedAuth);
1683
+ await __classPrivateFieldGet(client, _Client_instances, "m", _Client_initConnection).call(client);
1684
+ client.invoke.use(async (ctx, next) => {
1685
+ if (ctx.error instanceof _4_errors_js_1.AuthKeyUnregistered) {
1686
+ try {
1687
+ const exportedAuth = await this.invoke(new _2_tl_js_1.functions.auth.exportAuthorization({ dc_id: dcId }));
1688
+ await client.authorize(exportedAuth);
1689
+ return true;
1690
+ }
1691
+ catch (err) {
1692
+ throw err;
1693
+ }
1694
+ }
1695
+ else {
1696
+ return await next();
1697
+ }
1698
+ });
1675
1699
  const limit = chunkSize;
1676
1700
  let offset = 0n;
1701
+ let part = 0;
1677
1702
  while (true) {
1678
1703
  const file = await (client ?? this).invoke(new _2_tl_js_1.functions.upload.getFile({ location, offset, limit }));
1679
1704
  if (file instanceof _2_tl_js_1.types.upload.File) {
1680
1705
  yield file.bytes;
1706
+ if (id != null) {
1707
+ await this.storage.saveFilePart(id, part, file.bytes);
1708
+ }
1709
+ ++part;
1681
1710
  if (file.bytes.length < limit) {
1711
+ if (id != null) {
1712
+ await this.storage.setFilePartCount(id, part + 1);
1713
+ }
1682
1714
  break;
1683
1715
  }
1684
1716
  else {
@@ -2282,7 +2314,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2282
2314
  let chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLoadedChats).call(this, listId);
2283
2315
  if (params?.after) {
2284
2316
  chats = chats
2285
- .filter((v) => v.id < params.after.id);
2317
+ .filter((v) => v.order < params.after.order);
2286
2318
  }
2287
2319
  if (chats.length < limit) {
2288
2320
  d("have only %d chats but %d more is needed", chats.length, limit - chats.length);
@@ -2721,7 +2753,7 @@ async function _Client_setMyInfo(info) {
2721
2753
  if (!(dialogs instanceof _2_tl_js_1.types.messages.Dialogs) && !(dialogs instanceof _2_tl_js_1.types.messages.DialogsSlice)) {
2722
2754
  (0, _1_utilities_js_1.UNREACHABLE)();
2723
2755
  }
2724
- if (dialogs.dialogs.length == 0) {
2756
+ if (dialogs.dialogs.length < limit) {
2725
2757
  await this.storage.setHasAllChats(listId, true);
2726
2758
  }
2727
2759
  const chats = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId);
@@ -18,6 +18,8 @@ export declare abstract class Storage {
18
18
  limit?: number;
19
19
  reverse?: boolean;
20
20
  }): MaybePromise<Generator<[readonly StorageKeyPart[], T]> | AsyncGenerator<[readonly StorageKeyPart[], T]>>;
21
+ abstract get supportsFiles(): boolean;
22
+ abstract branch(id: string): Storage;
21
23
  setDc(dc: DC | null): MaybePromise<void>;
22
24
  getDc(): MaybePromise<DC | null>;
23
25
  getAuthKey(): Promise<Uint8Array | null>;
@@ -66,4 +68,8 @@ export declare abstract class Storage {
66
68
  setPinnedChats(listId: number, chatIds: number[] | null): Promise<void>;
67
69
  getPinnedChats(listId: number): Promise<number[] | null>;
68
70
  getHistory(chatId: number, offsetId: number, limit: number): Promise<enums.Message[]>;
71
+ getFile(id: bigint): Promise<number | null>;
72
+ iterFileParts(id: bigint, partCount: number): AsyncGenerator<Uint8Array, void, unknown>;
73
+ saveFilePart(id: bigint, index: number, bytes: Uint8Array): Promise<void>;
74
+ setFilePartCount(id: bigint, partCount: number): Promise<void>;
69
75
  }
@@ -33,6 +33,8 @@ const KPARTS_CHATS = (listId) => ["chats", listId];
33
33
  const KPARTS_CHAT = (listId, chatId) => ["chats", listId, chatId];
34
34
  const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
35
35
  const KPARTS_SERVER_SALT = ["serverSalt"];
36
+ const KPARTS_FILE = (fileId) => ["files", fileId];
37
+ const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
36
38
  class Storage {
37
39
  constructor() {
38
40
  _Storage_instances.add(this);
@@ -211,12 +213,47 @@ class Storage {
211
213
  if (offsetId == 0) {
212
214
  offsetId = Infinity;
213
215
  }
216
+ ++limit;
214
217
  const messages = new Array();
215
218
  for await (const [_, buffer] of await this.getMany({ start: KPARTS_MESSAGE(chatId, 0), end: KPARTS_MESSAGE(chatId, offsetId) }, { limit, reverse: true })) {
216
- messages.push(await this.getTLObject(buffer));
219
+ const message = await this.getTLObject(buffer);
220
+ if ("id" in message && message.id == offsetId) {
221
+ continue;
222
+ }
223
+ messages.push(message);
217
224
  }
218
225
  return messages;
219
226
  }
227
+ async getFile(id) {
228
+ if (!this.supportsFiles) {
229
+ return null;
230
+ }
231
+ return await this.get(KPARTS_FILE(id));
232
+ }
233
+ async *iterFileParts(id, partCount) {
234
+ if (!this.supportsFiles) {
235
+ return;
236
+ }
237
+ for (let i = 0; i < partCount; i++) {
238
+ const part = await this.get(KPARTS_FILE_PART(id, i));
239
+ if (part == null) {
240
+ continue;
241
+ }
242
+ yield part;
243
+ }
244
+ }
245
+ async saveFilePart(id, index, bytes) {
246
+ if (!this.supportsFiles) {
247
+ return;
248
+ }
249
+ await this.set(KPARTS_FILE_PART(id, index), bytes);
250
+ }
251
+ async setFilePartCount(id, partCount) {
252
+ if (!this.supportsFiles) {
253
+ return;
254
+ }
255
+ await this.set(KPARTS_FILE(id), partCount);
256
+ }
220
257
  }
221
258
  exports.Storage = Storage;
222
259
  _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
@@ -1,11 +1,14 @@
1
1
  import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
2
2
  export declare class StorageIndexedDB extends Storage {
3
- readonly name: string;
3
+ #private;
4
4
  database: IDBDatabase | null;
5
5
  constructor(name: string);
6
+ get name(): string;
7
+ branch(id: string): StorageIndexedDB;
6
8
  init(): Promise<void>;
9
+ get supportsFiles(): boolean;
7
10
  set(k: readonly StorageKeyPart[], v: unknown, tx_?: IDBTransaction): Promise<void>;
8
- get<T>(k: readonly StorageKeyPart[], tx_?: IDBTransaction): Promise<T | null>;
11
+ get<T>(k: readonly StorageKeyPart[], tx_?: IDBTransaction | null, fix?: boolean): Promise<T | null>;
9
12
  getMany<T>(filter: GetManyFilter, params?: {
10
13
  limit?: number;
11
14
  reverse?: boolean;
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _StorageIndexedDB_instances, _StorageIndexedDB_name, _StorageIndexedDB_id, _StorageIndexedDB_fixKey;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.StorageIndexedDB = void 0;
4
16
  const _0_storage_js_1 = require("./0_storage.js");
@@ -11,18 +23,24 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
11
23
  throw new Error("Unavailable in current environment");
12
24
  }
13
25
  super();
14
- Object.defineProperty(this, "name", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: name
19
- });
26
+ _StorageIndexedDB_instances.add(this);
20
27
  Object.defineProperty(this, "database", {
21
28
  enumerable: true,
22
29
  configurable: true,
23
30
  writable: true,
24
31
  value: null
25
32
  });
33
+ _StorageIndexedDB_name.set(this, void 0);
34
+ _StorageIndexedDB_id.set(this, null);
35
+ __classPrivateFieldSet(this, _StorageIndexedDB_name, name, "f");
36
+ }
37
+ get name() {
38
+ return __classPrivateFieldGet(this, _StorageIndexedDB_name, "f");
39
+ }
40
+ branch(id) {
41
+ const storage = new StorageIndexedDB(this.name);
42
+ __classPrivateFieldSet(storage, _StorageIndexedDB_id, id, "f");
43
+ return storage;
26
44
  }
27
45
  init() {
28
46
  const db = indexedDB.open(this.name, VERSION);
@@ -38,7 +56,11 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
38
56
  };
39
57
  });
40
58
  }
59
+ get supportsFiles() {
60
+ return true;
61
+ }
41
62
  set(k, v, tx_) {
63
+ k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
42
64
  if (!this.database) {
43
65
  throw new Error("Not initialized");
44
66
  }
@@ -60,7 +82,10 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
60
82
  };
61
83
  });
62
84
  }
63
- get(k, tx_) {
85
+ get(k, tx_, fix = true) {
86
+ if (fix) {
87
+ k = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, k);
88
+ }
64
89
  if (!this.database) {
65
90
  throw new Error("Not initialized");
66
91
  }
@@ -76,6 +101,15 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
76
101
  });
77
102
  }
78
103
  async *getMany(filter, params, tx_) {
104
+ if ("prefix" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
105
+ filter.prefix = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.prefix);
106
+ }
107
+ if ("start" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
108
+ filter.start = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.start);
109
+ }
110
+ if ("end" in filter && __classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
111
+ filter.end = __classPrivateFieldGet(this, _StorageIndexedDB_instances, "m", _StorageIndexedDB_fixKey).call(this, filter.end);
112
+ }
79
113
  if (!this.database) {
80
114
  throw new Error("Not initialized");
81
115
  }
@@ -111,7 +145,7 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
111
145
  };
112
146
  });
113
147
  for (const key of keys) {
114
- yield [key, await this.get(key)];
148
+ yield [key, await this.get(key, null, false)];
115
149
  }
116
150
  }
117
151
  async incr(key, by) {
@@ -125,3 +159,11 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
125
159
  }
126
160
  }
127
161
  exports.StorageIndexedDB = StorageIndexedDB;
162
+ _StorageIndexedDB_name = new WeakMap(), _StorageIndexedDB_id = new WeakMap(), _StorageIndexedDB_instances = new WeakSet(), _StorageIndexedDB_fixKey = function _StorageIndexedDB_fixKey(key) {
163
+ if (__classPrivateFieldGet(this, _StorageIndexedDB_id, "f") !== null) {
164
+ return ["__S" + __classPrivateFieldGet(this, _StorageIndexedDB_id, "f"), ...key];
165
+ }
166
+ else {
167
+ return key;
168
+ }
169
+ };
@@ -1,8 +1,11 @@
1
1
  import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
2
2
  export declare class StorageLocalStorage extends Storage implements Storage {
3
- private readonly prefix;
3
+ #private;
4
4
  constructor(prefix: string);
5
+ get prefix(): string;
6
+ branch(id: string): StorageLocalStorage;
5
7
  init(): void;
8
+ get supportsFiles(): boolean;
6
9
  get<T>(key_: readonly StorageKeyPart[]): T | null;
7
10
  getMany<T>(filter: GetManyFilter, params?: {
8
11
  limit?: number;
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _StorageLocalStorage_prefix;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.StorageLocalStorage = void 0;
4
16
  const _0_storage_js_1 = require("./0_storage.js");
@@ -15,15 +27,20 @@ class StorageLocalStorage extends _0_storage_js_1.Storage {
15
27
  throw new Error("Unallowed prefix");
16
28
  }
17
29
  super();
18
- Object.defineProperty(this, "prefix", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: prefix
23
- });
30
+ _StorageLocalStorage_prefix.set(this, void 0);
31
+ __classPrivateFieldSet(this, _StorageLocalStorage_prefix, prefix, "f");
32
+ }
33
+ get prefix() {
34
+ return __classPrivateFieldGet(this, _StorageLocalStorage_prefix, "f");
35
+ }
36
+ branch(id) {
37
+ return new StorageLocalStorage(this.prefix + "S__" + id);
24
38
  }
25
39
  init() {
26
40
  }
41
+ get supportsFiles() {
42
+ return false;
43
+ }
27
44
  get(key_) {
28
45
  const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
29
46
  const value = localStorage.getItem(key);
@@ -78,3 +95,4 @@ class StorageLocalStorage extends _0_storage_js_1.Storage {
78
95
  }
79
96
  }
80
97
  exports.StorageLocalStorage = StorageLocalStorage;
98
+ _StorageLocalStorage_prefix = new WeakMap();
@@ -4,6 +4,8 @@ export declare class StorageMemory extends Storage implements Storage {
4
4
  #private;
5
5
  protected map: Map<string, unknown>;
6
6
  init(): void;
7
+ branch(id: string): Storage;
8
+ get supportsFiles(): boolean;
7
9
  get<T>(key: readonly StorageKeyPart[]): NonNullable<T> | null;
8
10
  getMany<T>(filter: GetManyFilter, params?: {
9
11
  limit?: number;
@@ -4,7 +4,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
5
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
6
  };
7
- var _StorageMemory_instances, _StorageMemory_getEntries;
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _StorageMemory_instances, _StorageMemory_id, _StorageMemory_fixKey, _StorageMemory_getEntries;
8
14
  Object.defineProperty(exports, "__esModule", { value: true });
9
15
  exports.StorageMemory = void 0;
10
16
  const _0_storage_js_1 = require("./0_storage.js");
@@ -19,10 +25,20 @@ class StorageMemory extends _0_storage_js_1.Storage {
19
25
  writable: true,
20
26
  value: new Map()
21
27
  });
28
+ _StorageMemory_id.set(this, null);
22
29
  }
23
30
  init() {
24
31
  }
32
+ branch(id) {
33
+ const storage = new StorageMemory();
34
+ __classPrivateFieldSet(storage, _StorageMemory_id, id, "f");
35
+ return storage;
36
+ }
37
+ get supportsFiles() {
38
+ return false;
39
+ }
25
40
  get(key) {
41
+ key = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, key);
26
42
  return this.map.get((0, _0_utilities_js_1.toString)(key)) ?? null;
27
43
  }
28
44
  *getMany(filter, params) {
@@ -53,6 +69,7 @@ class StorageMemory extends _0_storage_js_1.Storage {
53
69
  }
54
70
  }
55
71
  set(key_, value) {
72
+ key_ = __classPrivateFieldGet(this, _StorageMemory_instances, "m", _StorageMemory_fixKey).call(this, key_);
56
73
  const key = (0, _0_utilities_js_1.toString)(key_);
57
74
  if (value != null) {
58
75
  this.map.set(key, value);
@@ -66,9 +83,19 @@ class StorageMemory extends _0_storage_js_1.Storage {
66
83
  }
67
84
  }
68
85
  exports.StorageMemory = StorageMemory;
69
- _StorageMemory_instances = new WeakSet(), _StorageMemory_getEntries = function _StorageMemory_getEntries() {
86
+ _StorageMemory_id = new WeakMap(), _StorageMemory_instances = new WeakSet(), _StorageMemory_fixKey = function _StorageMemory_fixKey(key) {
87
+ if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null) {
88
+ return ["__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"), ...key];
89
+ }
90
+ else {
91
+ return key;
92
+ }
93
+ }, _StorageMemory_getEntries = function _StorageMemory_getEntries() {
70
94
  const entries = new Array();
71
95
  for (const entry of this.map.entries()) {
96
+ if (__classPrivateFieldGet(this, _StorageMemory_id, "f") !== null && !entry[0].startsWith("__S" + __classPrivateFieldGet(this, _StorageMemory_id, "f"))) {
97
+ continue;
98
+ }
72
99
  entries.push(entry);
73
100
  }
74
101
  return entries;
@@ -1,9 +1,12 @@
1
1
  import { MaybePromise } from "../1_utilities.js";
2
2
  import { GetManyFilter, Storage, StorageKeyPart } from "./0_storage.js";
3
3
  export declare class StorageSessionStorage extends Storage implements Storage {
4
- private readonly prefix;
4
+ #private;
5
5
  constructor(prefix: string);
6
+ get prefix(): string;
7
+ branch(id: string): StorageSessionStorage;
6
8
  init(): void;
9
+ get supportsFiles(): boolean;
7
10
  get<T>(key_: readonly StorageKeyPart[]): T | null;
8
11
  getMany<T>(filter: GetManyFilter, params?: {
9
12
  limit?: number;
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _StorageSessionStorage_prefix;
2
14
  Object.defineProperty(exports, "__esModule", { value: true });
3
15
  exports.StorageSessionStorage = void 0;
4
16
  const _0_storage_js_1 = require("./0_storage.js");
@@ -15,15 +27,20 @@ class StorageSessionStorage extends _0_storage_js_1.Storage {
15
27
  throw new Error("Unallowed prefix");
16
28
  }
17
29
  super();
18
- Object.defineProperty(this, "prefix", {
19
- enumerable: true,
20
- configurable: true,
21
- writable: true,
22
- value: prefix
23
- });
30
+ _StorageSessionStorage_prefix.set(this, void 0);
31
+ __classPrivateFieldSet(this, _StorageSessionStorage_prefix, prefix, "f");
32
+ }
33
+ get prefix() {
34
+ return __classPrivateFieldGet(this, _StorageSessionStorage_prefix, "f");
35
+ }
36
+ branch(id) {
37
+ return new StorageSessionStorage(this.prefix + "S__" + id);
24
38
  }
25
39
  init() {
26
40
  }
41
+ get supportsFiles() {
42
+ return false;
43
+ }
27
44
  get(key_) {
28
45
  const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
29
46
  const value = sessionStorage.getItem(key);
@@ -78,3 +95,4 @@ class StorageSessionStorage extends _0_storage_js_1.Storage {
78
95
  }
79
96
  }
80
97
  exports.StorageSessionStorage = StorageSessionStorage;
98
+ _StorageSessionStorage_prefix = new WeakMap();
@@ -300,33 +300,24 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
300
300
  message.forwardSenderName = message_.fwd_from.from_name;
301
301
  message.forwardId = message_.fwd_from.channel_post;
302
302
  message.forwardSignature = message_.fwd_from.post_author;
303
- message.forwardDate = new Date(message_.date * 1000);
303
+ message.forwardDate = new Date(message_.fwd_from.date * 1000);
304
304
  if (message_.fwd_from.from_id instanceof _2_tl_js_1.types.PeerUser) {
305
305
  const entity = await getEntity(message_.fwd_from.from_id);
306
306
  if (entity) {
307
307
  message.forwardFrom = (0, _1_user_js_1.constructUser)(entity);
308
308
  }
309
- else {
310
- (0, _1_utilities_js_1.UNREACHABLE)();
311
- }
312
309
  }
313
310
  else if (message_.fwd_from.from_id instanceof _2_tl_js_1.types.PeerChat) {
314
311
  const entity = await getEntity(message_.fwd_from.from_id);
315
312
  if (entity) {
316
313
  message.forwardFromChat = (0, _1_chat_p_js_1.constructChatP)(entity);
317
314
  }
318
- else {
319
- (0, _1_utilities_js_1.UNREACHABLE)();
320
- }
321
315
  }
322
316
  else if (message_.fwd_from.from_id instanceof _2_tl_js_1.types.PeerChannel) {
323
317
  const entity = await getEntity(message_.fwd_from.from_id);
324
318
  if (entity) {
325
319
  message.forwardFromChat = (0, _1_chat_p_js_1.constructChatP)(entity);
326
320
  }
327
- else {
328
- (0, _1_utilities_js_1.UNREACHABLE)();
329
- }
330
321
  }
331
322
  }
332
323
  if (message_.media) {