@mtkruto/node 0.1.128 → 0.1.130

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 (43) hide show
  1. package/esm/0_deps.d.ts +1 -0
  2. package/esm/0_deps.js +9 -0
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/5_client.d.ts +17 -3
  6. package/esm/client/5_client.js +310 -79
  7. package/esm/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
  8. package/esm/deps/deno.land/std@0.209.0/media_types/extension.js +26 -0
  9. package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
  10. package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +31 -0
  11. package/esm/storage/0_storage.d.ts +8 -7
  12. package/esm/storage/0_storage.js +39 -9
  13. package/esm/tl/0_tl_raw_reader.js +1 -1
  14. package/esm/tl/3_utilities.d.ts +1 -0
  15. package/esm/tl/3_utilities.js +11 -0
  16. package/esm/types/1__getters.d.ts +3 -2
  17. package/esm/types/1_chat_p.d.ts +2 -2
  18. package/esm/types/1_chat_p.js +16 -4
  19. package/esm/types/1_sticker.js +5 -4
  20. package/esm/types/4_chat.d.ts +3 -2
  21. package/esm/types/4_chat.js +16 -27
  22. package/package.json +1 -1
  23. package/script/0_deps.d.ts +1 -0
  24. package/script/0_deps.js +11 -1
  25. package/script/4_constants.d.ts +1 -1
  26. package/script/4_constants.js +1 -1
  27. package/script/client/5_client.d.ts +17 -3
  28. package/script/client/5_client.js +307 -76
  29. package/script/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
  30. package/script/deps/deno.land/std@0.209.0/media_types/extension.js +30 -0
  31. package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
  32. package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +35 -0
  33. package/script/storage/0_storage.d.ts +8 -7
  34. package/script/storage/0_storage.js +39 -9
  35. package/script/tl/0_tl_raw_reader.js +1 -1
  36. package/script/tl/3_utilities.d.ts +1 -0
  37. package/script/tl/3_utilities.js +13 -1
  38. package/script/types/1__getters.d.ts +3 -2
  39. package/script/types/1_chat_p.d.ts +2 -2
  40. package/script/types/1_chat_p.js +16 -4
  41. package/script/types/1_sticker.js +4 -3
  42. package/script/types/4_chat.d.ts +3 -2
  43. package/script/types/4_chat.js +17 -27
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
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
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updatePinnedChats, _Client_fetchChats;
13
+ var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo, _Client_resolveFileId, _Client_sendMedia, _Client_sendChatUpdate, _Client_reassignChatLastMessage, _Client_chats, _Client_archivedChats, _Client_chatsLoadedFromStorage, _Client_tryGetChatId, _Client_getChatAnywhere, _Client_getChatList, _Client_loadChatsFromStorage, _Client_getLoadedChats, _Client_pinnedChats, _Client_pinnedArchiveChats, _Client_storageHadPinnedChats, _Client_pinnedChatsLoaded, _Client_loadPinnedChats, _Client_fetchPinnedChats, _Client_getPinnedChats, _Client_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Client = exports.ConnectionError = exports.restartAuth = exports.skipInvoke = exports.handleMigrationError = void 0;
16
16
  const _0_deps_js_1 = require("../0_deps.js");
@@ -522,7 +522,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
522
522
  throw new Error(`${source}: not a bot client`);
523
523
  }
524
524
  }, _Client_fetchState = async function _Client_fetchState(source) {
525
- const state = await this.invoke(new _2_tl_js_1.functions.updates.getState());
525
+ const state = await this.api.updates.getState();
526
526
  __classPrivateFieldSet(this, _Client_updateState, state, "f");
527
527
  d("state fetched [%s]", source);
528
528
  }, exports.handleMigrationError)](err) {
@@ -588,7 +588,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
588
588
  if (typeof params === "string") {
589
589
  while (true) {
590
590
  try {
591
- const auth = await this.invoke(new _2_tl_js_1.functions.auth.importBotAuthorization({ api_id: this.apiId, api_hash: this.apiHash, bot_auth_token: params, flags: 0 }));
591
+ const auth = await this.api.auth.importBotAuthorization({ api_id: this.apiId, api_hash: this.apiHash, bot_auth_token: params, flags: 0 });
592
592
  __classPrivateFieldSet(this, _Client_selfId, Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.auth.Authorization).user.id), "f");
593
593
  await this.storage.setAccountType("bot");
594
594
  break;
@@ -610,7 +610,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
610
610
  return;
611
611
  }
612
612
  if (params instanceof _2_tl_js_1.types.auth.ExportedAuthorization) {
613
- await this.invoke(new _2_tl_js_1.functions.auth.importAuthorization({ id: params.id, bytes: params.bytes }));
613
+ await this.api.auth.importAuthorization({ id: params.id, bytes: params.bytes });
614
614
  dAuth("authorization imported");
615
615
  return;
616
616
  }
@@ -621,12 +621,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
621
621
  while (true) {
622
622
  try {
623
623
  phone = typeof params.phone === "string" ? params.phone : await params.phone();
624
- const sendCode = () => this.invoke(new _2_tl_js_1.functions.auth.sendCode({
624
+ const sendCode = () => this.api.auth.sendCode({
625
625
  phone_number: phone,
626
626
  api_id: this.apiId,
627
627
  api_hash: this.apiHash,
628
628
  settings: new _2_tl_js_1.types.CodeSettings(),
629
- })).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.auth.SentCode));
629
+ }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.auth.SentCode));
630
630
  try {
631
631
  sentCode = await sendCode();
632
632
  }
@@ -656,11 +656,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
656
656
  code: while (true) {
657
657
  const code = typeof params.code === "string" ? params.code : await params.code();
658
658
  try {
659
- const auth = await this.invoke(new _2_tl_js_1.functions.auth.signIn({
659
+ const auth = await this.api.auth.signIn({
660
660
  phone_number: phone,
661
661
  phone_code: code,
662
662
  phone_code_hash: sentCode.phone_code_hash,
663
- }));
663
+ });
664
664
  __classPrivateFieldSet(this, _Client_selfId, Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.auth.Authorization).user.id), "f");
665
665
  await this.storage.setAccountType("user");
666
666
  dAuth("authorized as user");
@@ -682,14 +682,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
682
682
  throw err;
683
683
  }
684
684
  password: while (true) {
685
- const ap = await this.invoke(new _2_tl_js_1.functions.account.getPassword());
685
+ const ap = await this.api.account.getPassword();
686
686
  if (!(ap.current_algo instanceof _2_tl_js_1.types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow)) {
687
687
  throw new Error(`Handling ${ap.current_algo?.[_2_tl_js_1.name]} not implemented`);
688
688
  }
689
689
  try {
690
690
  const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
691
691
  const input = await (0, _0_password_js_1.checkPassword)(password, ap);
692
- const auth = await this.invoke(new _2_tl_js_1.functions.auth.checkPassword({ password: input }));
692
+ const auth = await this.api.auth.checkPassword({ password: input });
693
693
  __classPrivateFieldSet(this, _Client_selfId, Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.auth.Authorization).user.id), "f");
694
694
  await this.storage.setAccountType("user");
695
695
  dAuth("authorized as user");
@@ -737,7 +737,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
737
737
  return this.invoke(function_, true);
738
738
  }
739
739
  async getUserAccessHash(userId) {
740
- const users = await this.invoke(new _2_tl_js_1.functions.users.getUsers({ id: [new _2_tl_js_1.types.InputUser({ user_id: userId, access_hash: 0n })] }));
740
+ const users = await this.api.users.getUsers({ id: [new _2_tl_js_1.types.InputUser({ user_id: userId, access_hash: 0n })] });
741
741
  return users[0]?.[_2_tl_js_1.as](_2_tl_js_1.types.User).access_hash ?? 0n;
742
742
  }
743
743
  async getInputPeer(id) {
@@ -755,7 +755,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
755
755
  }
756
756
  [(_Client_initConnection = async function _Client_initConnection() {
757
757
  if (!__classPrivateFieldGet(this, _Client_connectionInited, "f")) {
758
- await this.invoke(new _2_tl_js_1.functions.initConnection({
758
+ await this.api.initConnection({
759
759
  api_id: this.apiId,
760
760
  app_version: this.appVersion,
761
761
  device_model: this.deviceModel,
@@ -767,7 +767,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
767
767
  }),
768
768
  system_lang_code: this.systemLangCode,
769
769
  system_version: this.systemVersion,
770
- }));
770
+ });
771
771
  __classPrivateFieldSet(this, _Client_connectionInited, true, "f");
772
772
  d("connection inited");
773
773
  }
@@ -910,7 +910,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
910
910
  reject(__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f")?.signal.reason);
911
911
  };
912
912
  });
913
- await this.invoke(new _2_tl_js_1.functions.ping_delay_disconnect({ ping_id: (0, _1_utilities_js_1.getRandomId)(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 }));
913
+ await this.api.ping_delay_disconnect({ ping_id: (0, _1_utilities_js_1.getRandomId)(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 });
914
914
  if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * 60 * 1000) {
915
915
  (0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "lastUpdates"));
916
916
  }
@@ -920,20 +920,20 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
920
920
  }
921
921
  }
922
922
  }, _Client_invoke = async function _Client_invoke(function_, noWait) {
923
- if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
924
- if (__classPrivateFieldGet(this, _Client_autoStart, "f") && !__classPrivateFieldGet(this, _Client_autoStarted, "f")) {
925
- await this.start();
926
- }
927
- else {
928
- throw new ConnectionError("Not connected");
929
- }
930
- }
931
- if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
932
- (0, _1_utilities_js_1.UNREACHABLE)();
933
- }
934
923
  let n = 1;
935
924
  while (true) {
936
925
  try {
926
+ if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
927
+ if (__classPrivateFieldGet(this, _Client_autoStart, "f") && !__classPrivateFieldGet(this, _Client_autoStarted, "f")) {
928
+ await this.start();
929
+ }
930
+ else {
931
+ throw new ConnectionError("Not connected");
932
+ }
933
+ }
934
+ if (!__classPrivateFieldGet(this, _Client_auth, "f") || !this.transport) {
935
+ (0, _1_utilities_js_1.UNREACHABLE)();
936
+ }
937
937
  let seqNo = __classPrivateFieldGet(this, _Client_state, "f").seqNo * 2;
938
938
  if (!(function_ instanceof _2_tl_js_1.functions.ping) && !(function_ instanceof _2_tl_js_1.types.Msgs_ack)) {
939
939
  seqNo++;
@@ -1001,6 +1001,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1001
1001
  else if (chat instanceof _2_tl_js_1.types.Chat) {
1002
1002
  await this.storage.setEntity(chat);
1003
1003
  }
1004
+ else if (chat instanceof _2_tl_js_1.types.ChannelForbidden || chat instanceof _2_tl_js_1.types.ChatForbidden) {
1005
+ await this.storage.removeEntity(chat);
1006
+ }
1004
1007
  }
1005
1008
  }, _Client_processUsers = async function _Client_processUsers(users) {
1006
1009
  for (const user of users) {
@@ -1157,6 +1160,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1157
1160
  }
1158
1161
  else if (update instanceof _2_tl_js_1.types.UpdateUserName) {
1159
1162
  await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
1163
+ const peer = new _2_tl_js_1.types.PeerUser(update);
1164
+ const entity = await this[getEntity](peer);
1165
+ if (entity != null) {
1166
+ entity.usernames = update.usernames;
1167
+ entity.first_name = update.first_name;
1168
+ entity.last_name = update.last_name;
1169
+ await this.storage.setEntity(entity);
1170
+ }
1160
1171
  }
1161
1172
  else if (update instanceof _2_tl_js_1.types.UpdatePtsChanged) {
1162
1173
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
@@ -1183,7 +1194,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1183
1194
  }
1184
1195
  }
1185
1196
  /// If there were any Update, they will be passed to the update handling queue.
1186
- if (update instanceof _2_tl_js_1.types._Update) {
1197
+ if (update instanceof _2_tl_js_1.types._Update || update instanceof _2_tl_js_1.types.UpdateShortMessage || update instanceof _2_tl_js_1.types.UpdateShortChatMessage || update instanceof _2_tl_js_1.types.UpdateShortSentMessage) {
1187
1198
  updatesToHandle.push(update);
1188
1199
  }
1189
1200
  }
@@ -1225,7 +1236,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1225
1236
  try {
1226
1237
  let state = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
1227
1238
  while (true) {
1228
- const difference = await this.invoke(new _2_tl_js_1.functions.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 }));
1239
+ const difference = await this.api.updates.getDifference({ pts: state.pts, date: state.date, qts: state.qts ?? 0 });
1229
1240
  if (difference instanceof _2_tl_js_1.types.updates.Difference || difference instanceof _2_tl_js_1.types.updates.DifferenceSlice) {
1230
1241
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1231
1242
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
@@ -1274,12 +1285,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1274
1285
  let pts = pts_ == null ? 1 : pts_;
1275
1286
  while (true) {
1276
1287
  const { access_hash } = await this.getInputPeer(_1_utilities_js_1.ZERO_CHANNEL_ID + -Number(channelId)).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerChannel));
1277
- const difference = await this.invoke(new _2_tl_js_1.functions.updates.getChannelDifference({
1288
+ const difference = await this.api.updates.getChannelDifference({
1278
1289
  pts,
1279
1290
  channel: new _2_tl_js_1.types.InputChannel({ channel_id: channelId, access_hash }),
1280
1291
  filter: new _2_tl_js_1.types.ChannelMessagesFilterEmpty(),
1281
1292
  limit: await this.storage.getAccountType() == "user" ? _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_USER : _4_constants_js_1.CHANNEL_DIFFERENCE_LIMIT_BOT,
1282
- }));
1293
+ });
1283
1294
  if (difference instanceof _2_tl_js_1.types.updates.ChannelDifference) {
1284
1295
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
1285
1296
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
@@ -1316,7 +1327,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1316
1327
  }
1317
1328
  }
1318
1329
  }, _Client_getChannelAccessHash = async function _Client_getChannelAccessHash(channelId) {
1319
- const channels = await this.invoke(new _2_tl_js_1.functions.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel({ channel_id: channelId, access_hash: 0n })] }));
1330
+ const channels = await this.api.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel({ channel_id: channelId, access_hash: 0n })] });
1320
1331
  return channels.chats[0][_2_tl_js_1.as](_2_tl_js_1.types.Channel).access_hash ?? 0n;
1321
1332
  }, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
1322
1333
  if (typeof id === "string") {
@@ -1334,7 +1345,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1334
1345
  }
1335
1346
  }
1336
1347
  else {
1337
- const resolved = await this.invoke(new _2_tl_js_1.functions.contacts.resolveUsername({ username: id }));
1348
+ const resolved = await this.api.contacts.resolveUsername({ username: id });
1338
1349
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, resolved.chats);
1339
1350
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, resolved.users);
1340
1351
  if (resolved.peer instanceof _2_tl_js_1.types.PeerUser) {
@@ -1456,7 +1467,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1456
1467
  const replyToMsgId = params?.replyToMessageId;
1457
1468
  const topMsgId = params?.messageThreadId;
1458
1469
  const sendAs = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveSendAs).call(this, params);
1459
- const result = await this.invoke(new _2_tl_js_1.functions.messages.sendMessage({
1470
+ const result = await this.api.messages.sendMessage({
1460
1471
  peer,
1461
1472
  random_id: randomId,
1462
1473
  message,
@@ -1467,7 +1478,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1467
1478
  send_as: sendAs,
1468
1479
  entities,
1469
1480
  reply_markup: replyMarkup,
1470
- }));
1481
+ });
1471
1482
  const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1472
1483
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message_, "text");
1473
1484
  }
@@ -1482,14 +1493,14 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1482
1493
  */
1483
1494
  async editMessageText(chatId, messageId, text, params) {
1484
1495
  const [message, entities] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, text, params);
1485
- const result = await this.invoke(new _2_tl_js_1.functions.messages.editMessage({
1496
+ const result = await this.api.messages.editMessage({
1486
1497
  id: messageId,
1487
1498
  peer: await this.getInputPeer(chatId),
1488
1499
  entities,
1489
1500
  message,
1490
1501
  no_webpage: params?.disableWebPagePreview ? true : undefined,
1491
1502
  reply_markup: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params),
1492
- }));
1503
+ });
1493
1504
  const message_ = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1494
1505
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message_, "text");
1495
1506
  }
@@ -1572,15 +1583,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1572
1583
  }
1573
1584
  if (shouldFetch) {
1574
1585
  if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
1575
- messages_ = await this.invoke(new _2_tl_js_1.functions.channels.getMessages({
1586
+ messages_ = await this.api.channels.getMessages({
1576
1587
  channel: new _2_tl_js_1.types.InputChannel(peer),
1577
1588
  id: messageIds.map((v) => new _2_tl_js_1.types.InputMessageID({ id: v })),
1578
- })).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.ChannelMessages).messages);
1589
+ }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.ChannelMessages).messages);
1579
1590
  }
1580
1591
  else {
1581
- messages_ = await this.invoke(new _2_tl_js_1.functions.messages.getMessages({
1592
+ messages_ = await this.api.messages.getMessages({
1582
1593
  id: messageIds.map((v) => new _2_tl_js_1.types.InputMessageID({ id: v })),
1583
- })).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.Messages).messages);
1594
+ }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.Messages).messages);
1584
1595
  }
1585
1596
  }
1586
1597
  const messages = new Array();
@@ -1624,14 +1635,17 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1624
1635
  * ```
1625
1636
  * @returns A generator yielding the contents of the file.
1626
1637
  */
1627
- async download(fileId, params) {
1638
+ async *download(fileId, params) {
1628
1639
  const fileId_ = _3_types_js_1.FileID.decode(fileId);
1629
1640
  switch (fileId_.fileType) {
1630
1641
  case _3_types_js_1.FileType.ChatPhoto: {
1631
1642
  const big = fileId_.params.thumbnailSource == _3_types_js_1.ThumbnailSource.ChatPhotoBig;
1632
1643
  const peer = await this.getInputPeer(fileId_.params.chatId);
1633
1644
  const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.params.mediaId });
1634
- return __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params);
1645
+ for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1646
+ yield chunk;
1647
+ }
1648
+ break;
1635
1649
  }
1636
1650
  case _3_types_js_1.FileType.Photo: {
1637
1651
  if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
@@ -1643,7 +1657,26 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1643
1657
  file_reference: fileId_.params.fileReference,
1644
1658
  thumb_size: fileId_.params.thumbnailSize,
1645
1659
  });
1646
- return __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params);
1660
+ for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1661
+ yield chunk;
1662
+ }
1663
+ break;
1664
+ }
1665
+ case _3_types_js_1.FileType.Document:
1666
+ case _3_types_js_1.FileType.Sticker: {
1667
+ if (fileId_.params.mediaId == undefined || fileId_.params.accessHash == undefined || fileId_.params.fileReference == undefined || fileId_.params.thumbnailSize == undefined) {
1668
+ (0, _1_utilities_js_1.UNREACHABLE)();
1669
+ }
1670
+ const location = new _2_tl_js_1.types.InputDocumentFileLocation({
1671
+ id: fileId_.params.mediaId,
1672
+ access_hash: fileId_.params.accessHash,
1673
+ file_reference: fileId_.params.fileReference,
1674
+ thumb_size: fileId_.params.thumbnailSize,
1675
+ });
1676
+ for await (const chunk of __classPrivateFieldGet(this, _Client_instances, "m", _Client_downloadInner).call(this, location, fileId_.dcId, params)) {
1677
+ yield chunk;
1678
+ }
1679
+ break;
1647
1680
  }
1648
1681
  default:
1649
1682
  (0, _1_utilities_js_1.UNREACHABLE)();
@@ -1684,7 +1717,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1684
1717
  client.invoke.use(async (ctx, next) => {
1685
1718
  if (ctx.error instanceof _4_errors_js_1.AuthKeyUnregistered) {
1686
1719
  try {
1687
- const exportedAuth = await this.invoke(new _2_tl_js_1.functions.auth.exportAuthorization({ dc_id: dcId }));
1720
+ const exportedAuth = await this.api.auth.exportAuthorization({ dc_id: dcId });
1688
1721
  await client.authorize(exportedAuth);
1689
1722
  return true;
1690
1723
  }
@@ -1727,7 +1760,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1727
1760
  return maybeStickerSetName[0];
1728
1761
  }
1729
1762
  else {
1730
- const stickerSet = await this.invoke(new _2_tl_js_1.functions.messages.getStickerSet({ stickerset: inputStickerSet, hash }));
1763
+ const stickerSet = await this.api.messages.getStickerSet({ stickerset: inputStickerSet, hash });
1731
1764
  const name = stickerSet[_2_tl_js_1.as](_2_tl_js_1.types.messages.StickerSet).set.short_name;
1732
1765
  await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.access_hash, name);
1733
1766
  return name;
@@ -1743,7 +1776,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1743
1776
  * @returns The forwarded messages.
1744
1777
  */
1745
1778
  async forwardMessages(from, to, messageIds, params) {
1746
- const result = await this.invoke(new _2_tl_js_1.functions.messages.forwardMessages({
1779
+ const result = await this.api.messages.forwardMessages({
1747
1780
  from_peer: await this.getInputPeer(from),
1748
1781
  to_peer: await this.getInputPeer(to),
1749
1782
  id: messageIds,
@@ -1754,7 +1787,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1754
1787
  send_as: params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined,
1755
1788
  drop_author: params?.dropSenderName || undefined,
1756
1789
  drop_media_captions: params?.dropCaption || undefined,
1757
- }));
1790
+ });
1758
1791
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, to, result);
1759
1792
  }
1760
1793
  /**
@@ -1775,7 +1808,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1775
1808
  * @method
1776
1809
  */
1777
1810
  async getMe() {
1778
- const users = await this.invoke(new _2_tl_js_1.functions.users.getUsers({ id: [new _2_tl_js_1.types.InputUserSelf()] }));
1811
+ const users = await this.api.users.getUsers({ id: [new _2_tl_js_1.types.InputUserSelf()] });
1779
1812
  if (users.length < 1) {
1780
1813
  (0, _1_utilities_js_1.UNREACHABLE)();
1781
1814
  }
@@ -1791,12 +1824,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1791
1824
  */
1792
1825
  async answerCallbackQuery(id, params) {
1793
1826
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "answerCallbackQuery");
1794
- await this.invoke(new _2_tl_js_1.functions.messages.setBotCallbackAnswer({
1827
+ await this.api.messages.setBotCallbackAnswer({
1795
1828
  query_id: BigInt(id),
1796
1829
  cache_time: params?.cacheTime ?? 0,
1797
1830
  message: params?.text,
1798
1831
  alert: params?.alert ? true : undefined,
1799
- }));
1832
+ });
1800
1833
  }
1801
1834
  /**
1802
1835
  * Send a poll.
@@ -1838,7 +1871,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1838
1871
  solution,
1839
1872
  solution_entities: solutionEntities,
1840
1873
  });
1841
- const result = await this.invoke(new _2_tl_js_1.functions.messages.sendMedia({
1874
+ const result = await this.api.messages.sendMedia({
1842
1875
  peer,
1843
1876
  random_id: randomId,
1844
1877
  silent,
@@ -1848,7 +1881,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1848
1881
  send_as: sendAs,
1849
1882
  media,
1850
1883
  message: "",
1851
- }));
1884
+ });
1852
1885
  const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
1853
1886
  return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "poll");
1854
1887
  }
@@ -1899,7 +1932,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1899
1932
  default:
1900
1933
  throw new Error("Invalid chat action: " + action);
1901
1934
  }
1902
- await this.invoke(new _2_tl_js_1.functions.messages.setTyping({ peer: await this.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId }));
1935
+ await this.api.messages.setTyping({ peer: await this.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId });
1903
1936
  }
1904
1937
  /**
1905
1938
  * Upload a file.
@@ -1999,20 +2032,20 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1999
2032
  * @param commands The commands to set.
2000
2033
  */
2001
2034
  async setMyCommands(commands, params) {
2002
- await this.invoke(new _2_tl_js_1.functions.bots.setBotCommands({
2035
+ await this.api.bots.setBotCommands({
2003
2036
  commands: commands.map((v) => new _2_tl_js_1.types.BotCommand(v)),
2004
2037
  lang_code: params?.languageCode ?? "",
2005
2038
  scope: await (0, _3_types_js_1.botCommandScopeToTlObject)(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
2006
- }));
2039
+ });
2007
2040
  }
2008
2041
  /**
2009
2042
  * Get the bot's commands in the given scope and/or language. Bot-only.
2010
2043
  */
2011
2044
  async getMyCommands(params) {
2012
- const commands_ = await this.invoke(new _2_tl_js_1.functions.bots.getBotCommands({
2045
+ const commands_ = await this.api.bots.getBotCommands({
2013
2046
  lang_code: params?.languageCode ?? "",
2014
2047
  scope: await (0, _3_types_js_1.botCommandScopeToTlObject)(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
2015
- }));
2048
+ });
2016
2049
  return commands_.map((v) => ({ command: v.command, description: v.description }));
2017
2050
  }
2018
2051
  /**
@@ -2023,7 +2056,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2023
2056
  * @param results The results to answer with.
2024
2057
  */
2025
2058
  async answerInlineQuery(id, results, params) {
2026
- await this.invoke(new _2_tl_js_1.functions.messages.setInlineBotResults({
2059
+ await this.api.messages.setInlineBotResults({
2027
2060
  query_id: BigInt(id),
2028
2061
  results: await Promise.all(results.map((v) => (0, _3_types_js_1.inlineQueryResultToTlObject)(v, __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).bind(this), __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this)))),
2029
2062
  cache_time: params?.cacheTime ?? 300,
@@ -2032,7 +2065,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2032
2065
  switch_pm: params?.button && params.button.startParameter ? new _2_tl_js_1.types.InlineBotSwitchPM({ text: params.button.text, start_param: params.button.startParameter }) : undefined,
2033
2066
  gallery: params?.isGallery ? true : undefined,
2034
2067
  next_offset: params?.nextOffset,
2035
- }));
2068
+ });
2036
2069
  }
2037
2070
  use(...middleware) {
2038
2071
  const composer = new _4_composer_js_1.Composer(...middleware);
@@ -2184,10 +2217,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2184
2217
  async deleteMessages(chatId, messageIds, params) {
2185
2218
  const peer = await this.getInputPeer(chatId);
2186
2219
  if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
2187
- await this.invoke(new _2_tl_js_1.functions.channels.deleteMessages({ channel: new _2_tl_js_1.types.InputChannel(peer), id: messageIds }));
2220
+ await this.api.channels.deleteMessages({ channel: new _2_tl_js_1.types.InputChannel(peer), id: messageIds });
2188
2221
  }
2189
2222
  else {
2190
- await this.invoke(new _2_tl_js_1.functions.messages.deleteMessages({ id: messageIds, revoke: params?.onlyForMe ? undefined : true }));
2223
+ await this.api.messages.deleteMessages({ id: messageIds, revoke: params?.onlyForMe ? undefined : true });
2191
2224
  }
2192
2225
  }
2193
2226
  /**
@@ -2294,7 +2327,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2294
2327
  return { messages, cdn };
2295
2328
  }
2296
2329
  /**
2297
- * Get chats.
2330
+ * Get chats from a chat list.
2298
2331
  *
2299
2332
  * @method
2300
2333
  */
@@ -2326,6 +2359,76 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2326
2359
  chats = chats.slice(0, limit);
2327
2360
  return chats;
2328
2361
  }
2362
+ /**
2363
+ * Get a chat.
2364
+ *
2365
+ * @method
2366
+ */
2367
+ async getChat(chatId) {
2368
+ if (await this.storage.getAccountType() == "user") {
2369
+ let maybeChatId = null;
2370
+ if (typeof chatId === "number") {
2371
+ maybeChatId = chatId;
2372
+ }
2373
+ else if (typeof chatId === "string") {
2374
+ maybeChatId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_tryGetChatId).call(this, (0, _0_utilities_js_1.getUsername)(chatId));
2375
+ }
2376
+ else {
2377
+ (0, _1_utilities_js_1.UNREACHABLE)();
2378
+ }
2379
+ if (maybeChatId != null) {
2380
+ const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, maybeChatId);
2381
+ if (chat !== undefined) {
2382
+ return chat;
2383
+ }
2384
+ }
2385
+ }
2386
+ let inputPeer = null;
2387
+ if (typeof chatId === "number") {
2388
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId, -1, undefined, this[getEntity].bind(this));
2389
+ if (chat != null) {
2390
+ return chat;
2391
+ }
2392
+ }
2393
+ else {
2394
+ inputPeer = await this.getInputPeer(chatId);
2395
+ const chatId_ = (0, _2_tl_js_1.peerToChatId)(inputPeer);
2396
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId_, -1, undefined, this[getEntity].bind(this));
2397
+ if (chat != null) {
2398
+ return chat;
2399
+ }
2400
+ }
2401
+ if (inputPeer == null) {
2402
+ inputPeer = await this.getInputPeer(chatId);
2403
+ }
2404
+ if (inputPeer instanceof _2_tl_js_1.types.InputPeerChat) {
2405
+ const chats = await this.api.messages.getChats({ id: [inputPeer.chat_id] }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.Chats));
2406
+ const chat = chats.chats[0];
2407
+ if (chat instanceof _2_tl_js_1.types.ChatEmpty) {
2408
+ (0, _1_utilities_js_1.UNREACHABLE)();
2409
+ }
2410
+ return (0, _3_types_js_1.constructChat2)(chat, -1, undefined);
2411
+ }
2412
+ else if (inputPeer instanceof _2_tl_js_1.types.InputPeerChannel) {
2413
+ const channels = await this.api.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel(inputPeer)] });
2414
+ const channel = channels.chats[0];
2415
+ if (channel instanceof _2_tl_js_1.types.ChatEmpty) {
2416
+ (0, _1_utilities_js_1.UNREACHABLE)();
2417
+ }
2418
+ return (0, _3_types_js_1.constructChat2)(channel, -1, undefined);
2419
+ }
2420
+ else if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser) {
2421
+ const users = await this.api.users.getUsers({ id: [new _2_tl_js_1.types.InputUser(inputPeer)] });
2422
+ const user = users[0];
2423
+ if (user instanceof _2_tl_js_1.types.UserEmpty) {
2424
+ (0, _1_utilities_js_1.UNREACHABLE)();
2425
+ }
2426
+ return (0, _3_types_js_1.constructChat2)(user, -1, undefined);
2427
+ }
2428
+ else {
2429
+ (0, _1_utilities_js_1.UNREACHABLE)();
2430
+ }
2431
+ }
2329
2432
  /**
2330
2433
  * Get chat history.
2331
2434
  *
@@ -2352,7 +2455,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2352
2455
  }
2353
2456
  if (messages.length < limit) {
2354
2457
  d("have only %d messages but need %d more", messages.length, limit - messages.length);
2355
- offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
2458
+ if (messages.length > 0) {
2459
+ offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
2460
+ }
2356
2461
  const result = await this.api.messages.getHistory({
2357
2462
  peer: peer,
2358
2463
  offset_id: offsetId,
@@ -2373,6 +2478,53 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2373
2478
  }
2374
2479
  return messages;
2375
2480
  }
2481
+ /**
2482
+ * Get custom emoji documents for download.
2483
+ *
2484
+ * @param id Identifier of one or more of custom emojis.
2485
+ * @method
2486
+ */
2487
+ async getCustomEmojiDocuments(id) {
2488
+ id = Array.isArray(id) ? id : [id];
2489
+ if (!id.length) {
2490
+ throw new Error("No custom emoji ID provided");
2491
+ }
2492
+ const documents = new Array();
2493
+ let shouldFetch = false;
2494
+ for (const [i, id_] of id.entries()) {
2495
+ const maybeDocument = await this.storage.getCustomEmojiDocument(BigInt(id_));
2496
+ if (maybeDocument != null && Date.now() - maybeDocument[1].getTime() <= 30 * 60 * 1000) {
2497
+ const document_ = maybeDocument[0];
2498
+ const fileUniqueId = new _3_types_js_1.FileUniqueID(_3_types_js_1.FileUniqueType.Document, { mediaId: document_.id }).encode();
2499
+ const fileId = new _3_types_js_1.FileID(null, null, _3_types_js_1.FileType.Document, document_.dc_id, {
2500
+ mediaId: document_.id,
2501
+ accessHash: document_.access_hash,
2502
+ fileReference: document_.file_reference,
2503
+ }).encode();
2504
+ const document = (0, _3_types_js_1.constructDocument)(document_, new _2_tl_js_1.types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${(0, _0_deps_js_1.extension)(document_.mime_type)}` }), fileId, fileUniqueId);
2505
+ documents.push(document);
2506
+ }
2507
+ else {
2508
+ shouldFetch = true;
2509
+ break;
2510
+ }
2511
+ }
2512
+ if (!shouldFetch) {
2513
+ return documents;
2514
+ }
2515
+ const documents_ = await this.api.messages.getCustomEmojiDocuments({ document_id: id.map(BigInt) }).then((v) => v.map((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.Document)));
2516
+ for (const [i, document_] of documents_.entries()) {
2517
+ const fileUniqueId = new _3_types_js_1.FileUniqueID(_3_types_js_1.FileUniqueType.Document, { mediaId: document_.id }).encode();
2518
+ const fileId = new _3_types_js_1.FileID(null, null, _3_types_js_1.FileType.Document, document_.dc_id, {
2519
+ mediaId: document_.id,
2520
+ accessHash: document_.access_hash,
2521
+ fileReference: document_.file_reference,
2522
+ }).encode();
2523
+ const document = (0, _3_types_js_1.constructDocument)(document_, new _2_tl_js_1.types.DocumentAttributeFilename({ file_name: `${id[i] ?? "customEmoji"}.${(0, _0_deps_js_1.extension)(document_.mime_type)}` }), fileId, fileUniqueId);
2524
+ documents.push(document);
2525
+ }
2526
+ return documents;
2527
+ }
2376
2528
  }
2377
2529
  exports.Client = Client;
2378
2530
  _a = Client, _Client_getMe = async function _Client_getMe() {
@@ -2396,7 +2548,7 @@ async function _Client_handleUpdate(update) {
2396
2548
  silent: update.silent,
2397
2549
  id: update.id,
2398
2550
  from_id: update.out ? new _2_tl_js_1.types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
2399
- peer_id: new _2_tl_js_1.types.PeerChat({ chat_id: update.user_id }),
2551
+ peer_id: new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
2400
2552
  message: update.message,
2401
2553
  date: update.date,
2402
2554
  fwd_from: update.fwd_from,
@@ -2499,6 +2651,39 @@ async function _Client_handleUpdate(update) {
2499
2651
  if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
2500
2652
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
2501
2653
  }
2654
+ if (update instanceof _2_tl_js_1.types.UpdateChannel) {
2655
+ const peer = new _2_tl_js_1.types.PeerChannel(update);
2656
+ const channel = await this[getEntity](peer);
2657
+ if (channel != null && "left" in channel && channel.left) {
2658
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2659
+ }
2660
+ else if (channel instanceof _2_tl_js_1.types.ChannelForbidden) {
2661
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2662
+ }
2663
+ else if (channel instanceof _2_tl_js_1.types.Channel) {
2664
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2665
+ }
2666
+ }
2667
+ else if (update instanceof _2_tl_js_1.types.UpdateChat) { // TODO: handle deactivated (migration)
2668
+ const peer = new _2_tl_js_1.types.PeerChat(update);
2669
+ const chat = await this[getEntity](peer);
2670
+ if (chat != null && "left" in chat && chat.left) {
2671
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2672
+ }
2673
+ else if (chat instanceof _2_tl_js_1.types.ChatForbidden) {
2674
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2675
+ }
2676
+ else if (chat instanceof _2_tl_js_1.types.Chat) {
2677
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2678
+ }
2679
+ }
2680
+ else if (update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName) {
2681
+ const peer = new _2_tl_js_1.types.PeerUser(update);
2682
+ const chat = await this[getEntity](peer);
2683
+ if (chat != null) {
2684
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2685
+ }
2686
+ }
2502
2687
  }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
2503
2688
  if (params?.replyMarkup) {
2504
2689
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
@@ -2512,9 +2697,9 @@ async function _Client_handleUpdate(update) {
2512
2697
  }, _Client_setMyInfo =
2513
2698
  //#endregion
2514
2699
  async function _Client_setMyInfo(info) {
2515
- await this.invoke(new _2_tl_js_1.functions.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info }));
2700
+ await this.api.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info });
2516
2701
  }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
2517
- return this.invoke(new _2_tl_js_1.functions.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" }));
2702
+ return this.api.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" });
2518
2703
  }, _Client_resolveFileId = function _Client_resolveFileId(maybeFileId, expectedFileType) {
2519
2704
  let fileId = null;
2520
2705
  try {
@@ -2550,7 +2735,7 @@ async function _Client_setMyInfo(info) {
2550
2735
  const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
2551
2736
  const caption = parseResult === undefined ? undefined : parseResult[0];
2552
2737
  const captionEntities = parseResult === undefined ? undefined : parseResult[1];
2553
- const result = await this.invoke(new _2_tl_js_1.functions.messages.sendMedia({
2738
+ const result = await this.api.messages.sendMedia({
2554
2739
  peer,
2555
2740
  random_id: randomId,
2556
2741
  silent,
@@ -2561,7 +2746,7 @@ async function _Client_setMyInfo(info) {
2561
2746
  media,
2562
2747
  message: caption ?? "",
2563
2748
  entities: captionEntities,
2564
- }));
2749
+ });
2565
2750
  return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
2566
2751
  }, _Client_sendChatUpdate = async function _Client_sendChatUpdate(chatId, added) {
2567
2752
  try {
@@ -2570,12 +2755,12 @@ async function _Client_setMyInfo(info) {
2570
2755
  catch {
2571
2756
  return;
2572
2757
  }
2573
- const chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
2758
+ const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2574
2759
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
2575
2760
  __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
2576
2761
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
2577
2762
  });
2578
- }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false) {
2763
+ }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
2579
2764
  try {
2580
2765
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
2581
2766
  }
@@ -2596,14 +2781,16 @@ async function _Client_setMyInfo(info) {
2596
2781
  }
2597
2782
  else {
2598
2783
  const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
2599
- const chat = await (0, _3_types_js_1.constructChat2)(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
2784
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
2600
2785
  if (chat == null) {
2601
2786
  (0, _1_utilities_js_1.UNREACHABLE)();
2602
2787
  }
2603
2788
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
2604
2789
  await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
2605
2790
  }
2606
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2791
+ if (sendUpdate) {
2792
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2793
+ }
2607
2794
  return;
2608
2795
  }
2609
2796
  const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
@@ -2615,20 +2802,41 @@ async function _Client_setMyInfo(info) {
2615
2802
  }
2616
2803
  else {
2617
2804
  const pinnedChats = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getPinnedChats).call(this, listId);
2618
- const chat = await (0, _3_types_js_1.constructChat2)(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
2805
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId, pinnedChats.indexOf(chatId), message, this[getEntity].bind(this));
2619
2806
  if (chat == null) {
2620
2807
  (0, _1_utilities_js_1.UNREACHABLE)();
2621
2808
  }
2622
2809
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
2623
2810
  }
2624
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2811
+ if (sendUpdate) {
2812
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2813
+ }
2625
2814
  return;
2626
2815
  }
2627
2816
  if (chat) {
2628
2817
  chat.order = (0, _3_types_js_1.getChatOrder)(undefined, chat.pinned);
2629
2818
  chat.lastMessage = undefined;
2630
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2819
+ if (sendUpdate) {
2820
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2821
+ }
2822
+ }
2823
+ }, _Client_tryGetChatId = function _Client_tryGetChatId(username) {
2824
+ username = username.toLowerCase();
2825
+ for (const chat of __classPrivateFieldGet(this, _Client_chats, "f").values()) {
2826
+ if ("username" in chat) {
2827
+ if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
2828
+ return chat.id;
2829
+ }
2830
+ }
2831
+ }
2832
+ for (const chat of __classPrivateFieldGet(this, _Client_archivedChats, "f").values()) {
2833
+ if ("username" in chat) {
2834
+ if (chat.username === username || chat.also?.some((v) => v.toLowerCase() === username)) {
2835
+ return chat.id;
2836
+ }
2837
+ }
2631
2838
  }
2839
+ return null;
2632
2840
  }, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
2633
2841
  let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
2634
2842
  if (chat) {
@@ -2652,14 +2860,14 @@ async function _Client_setMyInfo(info) {
2652
2860
  const chats = await this.storage.getChats(0);
2653
2861
  const archivedChats = await this.storage.getChats(1);
2654
2862
  for (const { chatId, pinned, topMessageId } of chats) {
2655
- const chat = await (0, _3_types_js_1.constructChat3)(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
2863
+ const chat = await (0, _3_types_js_1.constructChat4)(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
2656
2864
  if (chat == null) {
2657
2865
  continue;
2658
2866
  }
2659
2867
  __classPrivateFieldGet(this, _Client_chats, "f").set(chat.id, chat);
2660
2868
  }
2661
2869
  for (const { chatId, pinned, topMessageId } of archivedChats) {
2662
- const chat = await (0, _3_types_js_1.constructChat3)(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
2870
+ const chat = await (0, _3_types_js_1.constructChat4)(chatId, pinned, topMessageId, this[getEntity].bind(this), this.getMessage.bind(this));
2663
2871
  if (chat == null) {
2664
2872
  continue;
2665
2873
  }
@@ -2720,6 +2928,29 @@ async function _Client_setMyInfo(info) {
2720
2928
  default:
2721
2929
  (0, _1_utilities_js_1.UNREACHABLE)();
2722
2930
  }
2931
+ }, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
2932
+ const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2933
+ if (chat !== undefined) {
2934
+ const newChat = await (0, _3_types_js_1.constructChat3)(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
2935
+ if (newChat != null) {
2936
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
2937
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2938
+ }
2939
+ }
2940
+ else {
2941
+ const chat = await (0, _3_types_js_1.constructChat4)(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
2942
+ if (chat != null) {
2943
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
2944
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
2945
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
2946
+ }
2947
+ }
2948
+ }, _Client_removeChat = async function _Client_removeChat(chatId) {
2949
+ const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2950
+ if (chat !== undefined) {
2951
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
2952
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2953
+ }
2723
2954
  }, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
2724
2955
  const listId = update.folder_id ?? 0;
2725
2956
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this, update.folder_id);