@mtkruto/node 0.0.988 → 0.0.990

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.
Files changed (55) hide show
  1. package/esm/client/1_client_abstract.d.ts +6 -0
  2. package/esm/client/2_client_plain.d.ts +1 -1
  3. package/esm/client/3_client.d.ts +17 -15
  4. package/esm/client/3_client.js +75 -38
  5. package/esm/constants.d.ts +1 -1
  6. package/esm/constants.js +1 -1
  7. package/esm/tl/2_types.d.ts +2055 -1617
  8. package/esm/tl/2_types.js +3447 -3447
  9. package/esm/tl/3_functions.d.ts +154 -154
  10. package/esm/tl/3_functions.js +988 -988
  11. package/esm/types/0_poll_option.d.ts +8 -0
  12. package/esm/types/0_poll_option.js +6 -0
  13. package/esm/types/1_chat.js +3 -4
  14. package/esm/types/1_keyboard_button.js +4 -5
  15. package/esm/types/1_photo.js +0 -2
  16. package/esm/types/1_poll.d.ts +32 -0
  17. package/esm/types/1_poll.js +23 -0
  18. package/esm/types/1_sticker.js +1 -1
  19. package/esm/types/1_user.js +1 -2
  20. package/esm/types/2_game.js +2 -2
  21. package/esm/types/2_inline_keyboard_markup.js +1 -2
  22. package/esm/types/2_reply_keyboard_markup.js +1 -2
  23. package/esm/types/3_message.d.ts +2 -0
  24. package/esm/types/3_message.js +4 -0
  25. package/esm/utilities/0_queue.d.ts +2 -0
  26. package/esm/utilities/0_queue.js +14 -2
  27. package/esm/utilities/1_misc.js +1 -1
  28. package/package.json +1 -1
  29. package/script/client/1_client_abstract.d.ts +6 -0
  30. package/script/client/2_client_plain.d.ts +1 -1
  31. package/script/client/3_client.d.ts +17 -15
  32. package/script/client/3_client.js +75 -38
  33. package/script/constants.d.ts +1 -1
  34. package/script/constants.js +1 -1
  35. package/script/tl/2_types.d.ts +2055 -1617
  36. package/script/tl/2_types.js +3894 -3894
  37. package/script/tl/3_functions.d.ts +154 -154
  38. package/script/tl/3_functions.js +988 -988
  39. package/script/types/0_poll_option.d.ts +8 -0
  40. package/script/types/0_poll_option.js +10 -0
  41. package/script/types/1_chat.js +3 -4
  42. package/script/types/1_keyboard_button.js +4 -5
  43. package/script/types/1_photo.js +0 -2
  44. package/script/types/1_poll.d.ts +32 -0
  45. package/script/types/1_poll.js +27 -0
  46. package/script/types/1_sticker.js +1 -1
  47. package/script/types/1_user.js +1 -2
  48. package/script/types/2_game.js +2 -2
  49. package/script/types/2_inline_keyboard_markup.js +1 -2
  50. package/script/types/2_reply_keyboard_markup.js +1 -2
  51. package/script/types/3_message.d.ts +2 -0
  52. package/script/types/3_message.js +4 -0
  53. package/script/utilities/0_queue.d.ts +2 -0
  54. package/script/utilities/0_queue.js +14 -2
  55. package/script/utilities/1_misc.js +1 -1
@@ -26,34 +26,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Client = exports.ParseMode = exports.restartAuth = exports.handleMigrationError = exports.getStickerSetName = exports.getEntity = void 0;
27
27
  const deps_js_1 = require("../deps.js");
28
28
  const constants_js_1 = require("../constants.js");
29
+ const _1_misc_js_1 = require("../utilities/1_misc.js");
29
30
  const _0_bigint_js_1 = require("../utilities/0_bigint.js");
31
+ const _0_utilities_js_1 = require("./0_utilities.js");
30
32
  const _0_control_js_1 = require("../utilities/0_control.js");
33
+ const _0_queue_js_1 = require("../utilities/0_queue.js");
31
34
  const _0_hash_js_1 = require("../utilities/0_hash.js");
35
+ const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
32
36
  const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
33
37
  const types = __importStar(require("../tl/2_types.js"));
34
- const functions = __importStar(require("../tl/3_functions.js"));
35
38
  const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
39
+ const functions = __importStar(require("../tl/3_functions.js"));
36
40
  const _5_rpc_result_js_1 = require("../tl/5_rpc_result.js");
37
41
  const _6_message_js_1 = require("../tl/6_message.js"); // MTProto API message
38
42
  const _7_message_container_js_1 = require("../tl/7_message_container.js");
39
- const _1_storage_memory_js_1 = require("../storage/1_storage_memory.js");
40
43
  const _0_file_id_js_1 = require("../types/!0_file_id.js");
41
- const _0_message_entity_js_1 = require("../types/0_message_entity.js");
42
44
  const _0_reply_keyboard_remove_js_1 = require("../types/0_reply_keyboard_remove.js");
45
+ const _0_message_entity_js_1 = require("../types/0_message_entity.js");
43
46
  const _0_force_reply_js_1 = require("../types/0_force_reply.js");
44
- const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
47
+ const _1_user_js_1 = require("../types/1_user.js");
45
48
  const _2_inline_keyboard_markup_js_1 = require("../types/2_inline_keyboard_markup.js");
49
+ const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
46
50
  const _3_message_js_1 = require("../types/3_message.js"); // high-level wrapper for Telegram API's message
51
+ const _1_storage_memory_js_1 = require("../storage/1_storage_memory.js");
47
52
  const _0_message_js_1 = require("./0_message.js");
48
- const _0_html_js_1 = require("./0_html.js");
49
53
  const _0_password_js_1 = require("./0_password.js");
50
- const _1_client_abstract_js_1 = require("./1_client_abstract.js");
54
+ const _0_html_js_1 = require("./0_html.js");
51
55
  const _2_client_plain_js_1 = require("./2_client_plain.js");
52
- const _1_misc_js_1 = require("../utilities/1_misc.js");
53
- const _0_utilities_js_1 = require("./0_utilities.js");
54
- const _1_user_js_1 = require("../types/1_user.js");
55
- const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
56
- const _0_queue_js_1 = require("../utilities/0_queue.js");
56
+ const _1_client_abstract_js_1 = require("./1_client_abstract.js");
57
57
  const d = (0, deps_js_1.debug)("Client");
58
58
  const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
59
59
  const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
@@ -187,12 +187,29 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
187
187
  writable: true,
188
188
  value: void 0
189
189
  });
190
+ Object.defineProperty(this, "lastPropagatedConnectionState", {
191
+ enumerable: true,
192
+ configurable: true,
193
+ writable: true,
194
+ value: null
195
+ });
190
196
  Object.defineProperty(this, "stateChangeHandler", {
191
197
  enumerable: true,
192
198
  configurable: true,
193
199
  writable: true,
194
200
  value: ((connected) => {
195
- this.propagateConnectionState(connected ? "ready" : "not-connected");
201
+ this.connectMutex.acquire().then(async (release) => {
202
+ try {
203
+ const connectionState = connected ? "ready" : "not-connected";
204
+ if (this.connected == connected && this.lastPropagatedConnectionState != connectionState) {
205
+ await this.propagateConnectionState(connectionState);
206
+ this.lastPropagatedConnectionState = connectionState;
207
+ }
208
+ }
209
+ finally {
210
+ release();
211
+ }
212
+ });
196
213
  }).bind(this)
197
214
  });
198
215
  Object.defineProperty(this, "storageInited", {
@@ -229,13 +246,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
229
246
  enumerable: true,
230
247
  configurable: true,
231
248
  writable: true,
232
- value: new _0_queue_js_1.Queue()
249
+ value: new _0_queue_js_1.Queue("handleUpdate")
233
250
  });
234
251
  Object.defineProperty(this, "processUpdatesQueue", {
235
252
  enumerable: true,
236
253
  configurable: true,
237
254
  writable: true,
238
- value: new _0_queue_js_1.Queue()
255
+ value: new _0_queue_js_1.Queue("processUpdates")
239
256
  });
240
257
  Object.defineProperty(this, "handler", {
241
258
  enumerable: true,
@@ -587,7 +604,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
587
604
  body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
588
605
  }
589
606
  dRecv("received %s", body.constructor.name);
590
- if (body instanceof types.TypeUpdates || body instanceof types.TypeUpdate) {
607
+ if (body instanceof types._TypeUpdates || body instanceof types._TypeUpdate) {
591
608
  this.processUpdatesQueue.add(() => this.processUpdates(body));
592
609
  }
593
610
  else if (message.body instanceof _5_rpc_result_js_1.RPCResult) {
@@ -614,7 +631,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
614
631
  this.promises.delete(messageId);
615
632
  }
616
633
  };
617
- if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
634
+ if (result instanceof types._TypeUpdates || result instanceof types._TypeUpdate) {
618
635
  this.processUpdatesQueue.add(async () => {
619
636
  await this.processUpdates(result);
620
637
  resolvePromise();
@@ -718,7 +735,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
718
735
  await this.storage.updateUsernames("channel", chat.id, [chat.username]);
719
736
  }
720
737
  if (chat.usernames) {
721
- await this.storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username));
738
+ await this.storage.updateUsernames("channel", chat.id, chat.usernames.map((v) => v.username));
722
739
  }
723
740
  }
724
741
  else if (chat instanceof types.Chat) {
@@ -735,7 +752,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
735
752
  await this.storage.updateUsernames("user", user.id, [user.username]);
736
753
  }
737
754
  if (user.usernames) {
738
- await this.storage.updateUsernames("user", user.id, user.usernames.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username));
755
+ await this.storage.updateUsernames("user", user.id, user.usernames.map((v) => v.username));
739
756
  }
740
757
  }
741
758
  }
@@ -789,7 +806,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
789
806
  await this.recoverUpdateGap("updatesTooLong");
790
807
  return;
791
808
  }
792
- else if (updates_ instanceof types.TypeUpdate) {
809
+ else if (updates_ instanceof types._TypeUpdate) {
793
810
  updates = [updates_];
794
811
  }
795
812
  else {
@@ -868,7 +885,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
868
885
  await this.recoverChannelUpdateGap(update.channelId, "updateChannelTooLong");
869
886
  }
870
887
  else if (update instanceof types.UpdateUserName) {
871
- await this.storage.updateUsernames("user", update.userId, update.usernames.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username));
888
+ await this.storage.updateUsernames("user", update.userId, update.usernames.map((v) => v.username));
872
889
  }
873
890
  else if (update instanceof types.UpdatePtsChanged) {
874
891
  await this.fetchState("updatePtsChanged");
@@ -880,7 +897,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
880
897
  }
881
898
  }
882
899
  /// If there were any Update, they will be passed to the update handling queue.
883
- if (update instanceof types.TypeUpdate) {
900
+ if (update instanceof types._TypeUpdate) {
884
901
  updatesToHandle.push(update);
885
902
  }
886
903
  }
@@ -932,12 +949,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
932
949
  await this.processUpdates(update, true);
933
950
  }
934
951
  if (difference instanceof types.UpdatesDifference) {
935
- await this.storage.setState(difference.state[_1_tl_object_js_1.as](types.UpdatesState));
952
+ await this.storage.setState(difference.state);
936
953
  dGap("recovered from update gap");
937
954
  break;
938
955
  }
939
956
  else if (difference instanceof types.UpdatesDifferenceSlice) {
940
- state = difference.intermediateState[_1_tl_object_js_1.as](types.UpdatesState);
957
+ state = difference.intermediateState;
941
958
  }
942
959
  else {
943
960
  (0, _0_control_js_1.UNREACHABLE)();
@@ -1390,7 +1407,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1390
1407
  }
1391
1408
  else {
1392
1409
  const stickerSet = await this.invoke(new functions.MessagesGetStickerSet({ stickerset: inputStickerSet, hash }));
1393
- const name = stickerSet[_1_tl_object_js_1.as](types.MessagesStickerSet).set[_1_tl_object_js_1.as](types.StickerSet).shortName;
1410
+ const name = stickerSet[_1_tl_object_js_1.as](types.MessagesStickerSet).set.shortName;
1394
1411
  await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.accessHash, name);
1395
1412
  return name;
1396
1413
  }
@@ -1437,25 +1454,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1437
1454
  }
1438
1455
  return (0, _1_user_js_1.constructUser)(users[0][_1_tl_object_js_1.as](types.User));
1439
1456
  }
1457
+ // TODO: log errors
1440
1458
  async handleUpdate(update) {
1441
1459
  if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateNewChannelMessage) {
1442
1460
  if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
1443
1461
  await this.storage.setMessage((0, _0_utilities_js_1.peerToChatId)(update.message.peerId), update.message.id, update.message);
1444
1462
  }
1445
1463
  }
1446
- else if (update instanceof types.UpdateDeleteChannelMessages) {
1447
- for (const message of update.messages) {
1448
- await this.storage.setMessage((0, _0_utilities_js_1.getChannelChatId)(update.channelId), message, null);
1449
- }
1450
- }
1451
- else if (update instanceof types.UpdateDeleteMessages) {
1452
- for (const message of update.messages) {
1453
- const chatId = await this.storage.getMessageChat(message);
1454
- if (chatId) {
1455
- await this.storage.setMessage(chatId, message, null);
1456
- }
1457
- }
1458
- }
1459
1464
  if (update instanceof types.UpdateNewMessage ||
1460
1465
  update instanceof types.UpdateNewChannelMessage ||
1461
1466
  update instanceof types.UpdateEditMessage ||
@@ -1464,6 +1469,36 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1464
1469
  const message = await (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
1465
1470
  await this.handler({ [key]: message }, resolve);
1466
1471
  }
1472
+ if (update instanceof types.UpdateDeleteMessages) {
1473
+ const deletedMessages = new Array();
1474
+ for (const messageId of update.messages) {
1475
+ const chatId = await this.storage.getMessageChat(messageId);
1476
+ if (chatId) {
1477
+ const message = await this.storage.getMessage(chatId, messageId);
1478
+ if (message != null) {
1479
+ deletedMessages.push(await (0, _3_message_js_1.constructMessage)(message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
1480
+ }
1481
+ await this.storage.setMessage(chatId, messageId, null);
1482
+ }
1483
+ }
1484
+ if (deletedMessages.length > 0) {
1485
+ await this.handler({ deletedMessages: deletedMessages }, resolve);
1486
+ }
1487
+ }
1488
+ else if (update instanceof types.UpdateDeleteChannelMessages) {
1489
+ const chatId = (0, _0_utilities_js_1.getChannelChatId)(update.channelId);
1490
+ const deletedMessages = new Array();
1491
+ for (const messageId of update.messages) {
1492
+ const message = await this.storage.getMessage(chatId, messageId);
1493
+ if (message) {
1494
+ deletedMessages.push(await (0, _3_message_js_1.constructMessage)(message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
1495
+ }
1496
+ await this.storage.setMessage(chatId, messageId, null);
1497
+ }
1498
+ if (deletedMessages.length > 0) {
1499
+ await this.handler({ deletedMessages: deletedMessages }, resolve);
1500
+ }
1501
+ }
1467
1502
  }
1468
1503
  use(middleware) {
1469
1504
  const handler = this.handler;
@@ -1477,7 +1512,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1477
1512
  });
1478
1513
  };
1479
1514
  }
1480
- on(filter, handler) {
1515
+ on(
1516
+ // deno-lint-ignore no-explicit-any
1517
+ filter, handler) {
1481
1518
  const type = typeof filter === "string" ? filter : filter[0];
1482
1519
  const keys = Array.isArray(filter) ? filter.slice(1) : [];
1483
1520
  this.use((update, next) => {
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.0.988";
8
+ export declare const APP_VERSION = "MTKruto 0.0.990";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 161;
83
- exports.APP_VERSION = "MTKruto 0.0.988";
83
+ exports.APP_VERSION = "MTKruto 0.0.990";
84
84
  // @ts-ignore: lib
85
85
  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;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];