@mtkruto/node 0.1.128 → 0.1.129

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.128";
7
+ export declare const APP_VERSION = "MTKruto 0.1.129";
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.128";
56
+ export const APP_VERSION = "MTKruto 0.1.129";
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];
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
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
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- 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;
12
+ 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_updateOrAddChat, _Client_removeChat, _Client_updatePinnedChats, _Client_fetchChats;
13
13
  import { contentType, debug, gunzip, Mutex } from "../0_deps.js";
14
14
  import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
15
15
  import { as, functions, getChannelChatId, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
@@ -996,6 +996,9 @@ export class Client extends ClientAbstract {
996
996
  else if (chat instanceof types.Chat) {
997
997
  await this.storage.setEntity(chat);
998
998
  }
999
+ else if (chat instanceof types.ChannelForbidden || chat instanceof types.ChatForbidden) {
1000
+ await this.storage.removeEntity(chat);
1001
+ }
999
1002
  }
1000
1003
  }, _Client_processUsers = async function _Client_processUsers(users) {
1001
1004
  for (const user of users) {
@@ -1152,6 +1155,14 @@ export class Client extends ClientAbstract {
1152
1155
  }
1153
1156
  else if (update instanceof types.UpdateUserName) {
1154
1157
  await this.storage.updateUsernames("user", update.user_id, update.usernames.map((v) => v.username));
1158
+ const peer = new types.PeerUser(update);
1159
+ const entity = await this[getEntity](peer);
1160
+ if (entity != null) {
1161
+ entity.usernames = update.usernames;
1162
+ entity.first_name = update.first_name;
1163
+ entity.last_name = update.last_name;
1164
+ await this.storage.setEntity(entity);
1165
+ }
1155
1166
  }
1156
1167
  else if (update instanceof types.UpdatePtsChanged) {
1157
1168
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "updatePtsChanged");
@@ -1178,7 +1189,7 @@ export class Client extends ClientAbstract {
1178
1189
  }
1179
1190
  }
1180
1191
  /// If there were any Update, they will be passed to the update handling queue.
1181
- if (update instanceof types._Update) {
1192
+ if (update instanceof types._Update || update instanceof types.UpdateShortMessage || update instanceof types.UpdateShortChatMessage || update instanceof types.UpdateShortSentMessage) {
1182
1193
  updatesToHandle.push(update);
1183
1194
  }
1184
1195
  }
@@ -2347,7 +2358,9 @@ export class Client extends ClientAbstract {
2347
2358
  }
2348
2359
  if (messages.length < limit) {
2349
2360
  d("have only %d messages but need %d more", messages.length, limit - messages.length);
2350
- offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
2361
+ if (messages.length > 0) {
2362
+ offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
2363
+ }
2351
2364
  const result = await this.api.messages.getHistory({
2352
2365
  peer: peer,
2353
2366
  offset_id: offsetId,
@@ -2390,7 +2403,7 @@ async function _Client_handleUpdate(update) {
2390
2403
  silent: update.silent,
2391
2404
  id: update.id,
2392
2405
  from_id: update.out ? new types.PeerUser({ user_id: await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getSelfId).call(this).then(BigInt) }) : new types.PeerUser({ user_id: update.user_id }),
2393
- peer_id: new types.PeerChat({ chat_id: update.user_id }),
2406
+ peer_id: new types.PeerUser({ user_id: update.user_id }),
2394
2407
  message: update.message,
2395
2408
  date: update.date,
2396
2409
  fwd_from: update.fwd_from,
@@ -2493,6 +2506,39 @@ async function _Client_handleUpdate(update) {
2493
2506
  if (update instanceof types.UpdatePinnedDialogs) {
2494
2507
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
2495
2508
  }
2509
+ if (update instanceof types.UpdateChannel) {
2510
+ const peer = new types.PeerChannel(update);
2511
+ const channel = await this[getEntity](peer);
2512
+ if (channel != null && "left" in channel && channel.left) {
2513
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
2514
+ }
2515
+ else if (channel instanceof types.ChannelForbidden) {
2516
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
2517
+ }
2518
+ else if (channel instanceof types.Channel) {
2519
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
2520
+ }
2521
+ }
2522
+ else if (update instanceof types.UpdateChat) { // TODO: handle deactivated (migration)
2523
+ const peer = new types.PeerChat(update);
2524
+ const chat = await this[getEntity](peer);
2525
+ if (chat != null && "left" in chat && chat.left) {
2526
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
2527
+ }
2528
+ else if (chat instanceof types.ChatForbidden) {
2529
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, peerToChatId(peer));
2530
+ }
2531
+ else if (chat instanceof types.Chat) {
2532
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
2533
+ }
2534
+ }
2535
+ else if (update instanceof types.UpdateUser || update instanceof types.UpdateUserName) {
2536
+ const peer = new types.PeerUser(update);
2537
+ const chat = await this[getEntity](peer);
2538
+ if (chat != null) {
2539
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, peerToChatId(peer));
2540
+ }
2541
+ }
2496
2542
  }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
2497
2543
  if (params?.replyMarkup) {
2498
2544
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
@@ -2564,12 +2610,12 @@ async function _Client_setMyInfo(info) {
2564
2610
  catch {
2565
2611
  return;
2566
2612
  }
2567
- const chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
2613
+ const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2568
2614
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
2569
2615
  __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
2570
2616
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
2571
2617
  });
2572
- }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false) {
2618
+ }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
2573
2619
  try {
2574
2620
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
2575
2621
  }
@@ -2597,7 +2643,9 @@ async function _Client_setMyInfo(info) {
2597
2643
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
2598
2644
  await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
2599
2645
  }
2600
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2646
+ if (sendUpdate) {
2647
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2648
+ }
2601
2649
  return;
2602
2650
  }
2603
2651
  const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
@@ -2615,13 +2663,17 @@ async function _Client_setMyInfo(info) {
2615
2663
  }
2616
2664
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
2617
2665
  }
2618
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2666
+ if (sendUpdate) {
2667
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2668
+ }
2619
2669
  return;
2620
2670
  }
2621
2671
  if (chat) {
2622
2672
  chat.order = getChatOrder(undefined, chat.pinned);
2623
2673
  chat.lastMessage = undefined;
2624
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2674
+ if (sendUpdate) {
2675
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2676
+ }
2625
2677
  }
2626
2678
  }, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
2627
2679
  let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
@@ -2714,6 +2766,29 @@ async function _Client_setMyInfo(info) {
2714
2766
  default:
2715
2767
  UNREACHABLE();
2716
2768
  }
2769
+ }, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
2770
+ const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2771
+ if (chat !== undefined) {
2772
+ const newChat = await constructChat2(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
2773
+ if (newChat != null) {
2774
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
2775
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2776
+ }
2777
+ }
2778
+ else {
2779
+ const chat = await constructChat3(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
2780
+ if (chat != null) {
2781
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
2782
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
2783
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
2784
+ }
2785
+ }
2786
+ }, _Client_removeChat = async function _Client_removeChat(chatId) {
2787
+ const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2788
+ if (chat !== undefined) {
2789
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
2790
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2791
+ }
2717
2792
  }, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
2718
2793
  const listId = update.folder_id ?? 0;
2719
2794
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this, update.folder_id);
@@ -42,13 +42,12 @@ export declare abstract class Storage {
42
42
  getLastMessage(chatId: number): Promise<enums.Message | null>;
43
43
  setChannelPts(channelId: bigint, pts: number): Promise<void>;
44
44
  getChannelPts(channelId: bigint): MaybePromise<number | null>;
45
- setEntity(peer: types.Channel): Promise<void>;
46
- setEntity(peer: types.Chat): Promise<void>;
47
- setEntity(peer: types.User): Promise<void>;
48
- getEntity(type: "channel", id: bigint): Promise<types.Channel | null>;
49
- getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
45
+ setEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
46
+ removeEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
47
+ getEntity(type: "channel", id: bigint): Promise<types.Channel | types.ChannelForbidden | null>;
48
+ getEntity(type: "chat", id: bigint): Promise<types.Chat | types.ChatForbidden | null>;
50
49
  getEntity(type: "user", id: bigint): Promise<types.User | null>;
51
- getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
50
+ getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden | types.User | null>;
52
51
  setAccountType(type: "user" | "bot"): Promise<void>;
53
52
  getAccountType(): MaybePromise<"bot" | "user" | null>;
54
53
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
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
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
12
+ var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId, _Storage_getEntityType;
13
13
  import { bigIntFromBuffer, rleDecode, rleEncode, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
14
14
  import { serialize, TLReader, types } from "../2_tl.js";
15
15
  const KPARTS__DC = ["dc"];
@@ -131,9 +131,13 @@ export class Storage {
131
131
  getChannelPts(channelId) {
132
132
  return this.get(KPARTS__CHANNEL_PTS(channelId));
133
133
  }
134
- async setEntity(peer) {
135
- const type = peer instanceof types.Channel ? "channel" : peer instanceof types.Chat ? "chat" : peer instanceof types.User ? "user" : UNREACHABLE();
136
- await this.set(KPARTS__PEER(type, peer.id), rleEncode(peer[serialize]()));
134
+ async setEntity(entity) {
135
+ const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
136
+ await this.set(KPARTS__PEER(type, entity.id), rleEncode(entity[serialize]()));
137
+ }
138
+ async removeEntity(entity) {
139
+ const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
140
+ await this.set(KPARTS__PEER(type, entity.id), null);
137
141
  }
138
142
  async getEntity(type, id) {
139
143
  const peer_ = await this.get(KPARTS__PEER(type, id));
@@ -259,4 +263,17 @@ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storag
259
263
  else {
260
264
  __classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
261
265
  }
266
+ }, _Storage_getEntityType = function _Storage_getEntityType(entity) {
267
+ if (entity instanceof types.Channel || entity instanceof types.ChannelForbidden) {
268
+ return "channel";
269
+ }
270
+ else if (entity instanceof types.Chat || entity instanceof types.ChatForbidden) {
271
+ return "chat";
272
+ }
273
+ else if (entity instanceof types.User) {
274
+ return "user";
275
+ }
276
+ else {
277
+ UNREACHABLE();
278
+ }
262
279
  };
@@ -3,8 +3,8 @@ import { types } from "../2_tl.js";
3
3
  import { ChatID } from "./0_chat_id.js";
4
4
  export interface EntityGetter {
5
5
  (peer: types.PeerUser): MaybePromise<types.User | null>;
6
- (peer: types.PeerChat): MaybePromise<types.Chat | null>;
7
- (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
6
+ (peer: types.PeerChat): MaybePromise<types.Chat | types.ChatForbidden | null>;
7
+ (peer: types.PeerChannel): MaybePromise<types.Channel | types.ChannelForbidden | null>;
8
8
  }
9
9
  export interface InputPeerGetter {
10
10
  (id: ChatID): Promise<types.InputPeerUser | types.InputPeerChannel | types.InputPeerChat>;
@@ -68,5 +68,5 @@ export declare namespace ChatP {
68
68
  /** This object represents a chat. */
69
69
  export type ChatP = ChatP.Private | ChatP.Group | ChatP.Supergroup | ChatP.Channel;
70
70
  export declare function constructChatP(chat: types.User): ChatP.Private;
71
- export declare function constructChatP(chat: types.Chat): ChatP.Group;
72
- export declare function constructChatP(chat: types.Channel): ChatP.Supergroup | ChatP.Channel;
71
+ export declare function constructChatP(chat: types.Chat | types.ChatForbidden): ChatP.Group;
72
+ export declare function constructChatP(chat: types.Channel | types.ChannelForbidden): ChatP.Supergroup | ChatP.Channel;
@@ -22,21 +22,33 @@ export function constructChatP(chat) {
22
22
  }
23
23
  return cleanObject(chat_);
24
24
  }
25
- else if (chat instanceof types.Chat) {
25
+ else if (chat instanceof types.Chat || chat instanceof types.ChatForbidden) {
26
26
  const id = Number(-chat.id);
27
27
  const chat_ = {
28
28
  id,
29
29
  type: "group",
30
30
  color: getColorFromPeerId(id),
31
31
  title: chat.title,
32
- isCreator: chat.creator || false,
32
+ isCreator: false,
33
33
  };
34
+ if (chat instanceof types.Chat) {
35
+ chat_.isCreator = chat.creator || false;
36
+ }
34
37
  return cleanObject(chat_);
35
38
  }
36
- else if (chat instanceof types.Channel) {
39
+ else if (chat instanceof types.Channel || types.ChannelForbidden) {
37
40
  let chat_;
38
- const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
39
41
  const id = ZERO_CHANNEL_ID + -Number(chat.id);
42
+ if (chat instanceof types.ChannelForbidden) {
43
+ const { title } = chat;
44
+ if (chat.megagroup) {
45
+ return { id, color: getColorFromPeerId(id), title, type: "supergroup", isScam: false, isFake: false, isVerified: false, isRestricted: false, isForum: false };
46
+ }
47
+ else {
48
+ return { id, color: getColorFromPeerId(id), title, type: "channel", isScam: false, isFake: false, isVerified: false, isRestricted: false };
49
+ }
50
+ }
51
+ const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
40
52
  if (chat.megagroup) {
41
53
  chat_ = {
42
54
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtkruto/node",
3
- "version": "0.1.128",
3
+ "version": "0.1.129",
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.128";
7
+ export declare const APP_VERSION = "MTKruto 0.1.129";
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.128";
82
+ exports.APP_VERSION = "MTKruto 0.1.129";
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];
@@ -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_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");
@@ -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
  }
@@ -2352,7 +2363,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
2352
2363
  }
2353
2364
  if (messages.length < limit) {
2354
2365
  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
2366
+ if (messages.length > 0) {
2367
+ offsetId = messages[messages.length - 1].id; // TODO: track id of oldest message and don't send requests for it
2368
+ }
2356
2369
  const result = await this.api.messages.getHistory({
2357
2370
  peer: peer,
2358
2371
  offset_id: offsetId,
@@ -2396,7 +2409,7 @@ async function _Client_handleUpdate(update) {
2396
2409
  silent: update.silent,
2397
2410
  id: update.id,
2398
2411
  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 }),
2412
+ peer_id: new _2_tl_js_1.types.PeerUser({ user_id: update.user_id }),
2400
2413
  message: update.message,
2401
2414
  date: update.date,
2402
2415
  fwd_from: update.fwd_from,
@@ -2499,6 +2512,39 @@ async function _Client_handleUpdate(update) {
2499
2512
  if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
2500
2513
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatePinnedChats).call(this, update);
2501
2514
  }
2515
+ if (update instanceof _2_tl_js_1.types.UpdateChannel) {
2516
+ const peer = new _2_tl_js_1.types.PeerChannel(update);
2517
+ const channel = await this[getEntity](peer);
2518
+ if (channel != null && "left" in channel && channel.left) {
2519
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2520
+ }
2521
+ else if (channel instanceof _2_tl_js_1.types.ChannelForbidden) {
2522
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2523
+ }
2524
+ else if (channel instanceof _2_tl_js_1.types.Channel) {
2525
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2526
+ }
2527
+ }
2528
+ else if (update instanceof _2_tl_js_1.types.UpdateChat) { // TODO: handle deactivated (migration)
2529
+ const peer = new _2_tl_js_1.types.PeerChat(update);
2530
+ const chat = await this[getEntity](peer);
2531
+ if (chat != null && "left" in chat && chat.left) {
2532
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2533
+ }
2534
+ else if (chat instanceof _2_tl_js_1.types.ChatForbidden) {
2535
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_removeChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2536
+ }
2537
+ else if (chat instanceof _2_tl_js_1.types.Chat) {
2538
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2539
+ }
2540
+ }
2541
+ else if (update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName) {
2542
+ const peer = new _2_tl_js_1.types.PeerUser(update);
2543
+ const chat = await this[getEntity](peer);
2544
+ if (chat != null) {
2545
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updateOrAddChat).call(this, (0, _2_tl_js_1.peerToChatId)(peer));
2546
+ }
2547
+ }
2502
2548
  }, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
2503
2549
  if (params?.replyMarkup) {
2504
2550
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertBot).call(this, "replyMarkup");
@@ -2570,12 +2616,12 @@ async function _Client_setMyInfo(info) {
2570
2616
  catch {
2571
2617
  return;
2572
2618
  }
2573
- const chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
2619
+ const [chat] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2574
2620
  const update = chat === undefined ? { deletedChat: { chatId } } : added ? { newChat: chat } : { editedChat: chat };
2575
2621
  __classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
2576
2622
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
2577
2623
  });
2578
- }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false) {
2624
+ }, _Client_reassignChatLastMessage = async function _Client_reassignChatLastMessage(chatId, add = false, sendUpdate = true) {
2579
2625
  try {
2580
2626
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_assertUser).call(this, "");
2581
2627
  }
@@ -2603,7 +2649,9 @@ async function _Client_setMyInfo(info) {
2603
2649
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
2604
2650
  await this.storage.setChat(listId, chatId, chat.pinned, chat.lastMessage?.id ?? 0, chat.lastMessage?.date ?? new Date(0));
2605
2651
  }
2606
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2652
+ if (sendUpdate) {
2653
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2654
+ }
2607
2655
  return;
2608
2656
  }
2609
2657
  const message = await this.getHistory(chatId, { limit: 1 }).then((v) => v[0]);
@@ -2621,13 +2669,17 @@ async function _Client_setMyInfo(info) {
2621
2669
  }
2622
2670
  __classPrivateFieldGet(this, _Client_chats, "f").set(chatId, chat);
2623
2671
  }
2624
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2672
+ if (sendUpdate) {
2673
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, !chat);
2674
+ }
2625
2675
  return;
2626
2676
  }
2627
2677
  if (chat) {
2628
2678
  chat.order = (0, _3_types_js_1.getChatOrder)(undefined, chat.pinned);
2629
2679
  chat.lastMessage = undefined;
2630
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2680
+ if (sendUpdate) {
2681
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2682
+ }
2631
2683
  }
2632
2684
  }, _Client_getChatAnywhere = function _Client_getChatAnywhere(chatId) {
2633
2685
  let chat = __classPrivateFieldGet(this, _Client_chats, "f").get(chatId);
@@ -2720,6 +2772,29 @@ async function _Client_setMyInfo(info) {
2720
2772
  default:
2721
2773
  (0, _1_utilities_js_1.UNREACHABLE)();
2722
2774
  }
2775
+ }, _Client_updateOrAddChat = async function _Client_updateOrAddChat(chatId) {
2776
+ const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2777
+ if (chat !== undefined) {
2778
+ const newChat = await (0, _3_types_js_1.constructChat2)(chatId, chat.pinned, chat.lastMessage, this[getEntity].bind(this));
2779
+ if (newChat != null) {
2780
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).set(chatId, newChat);
2781
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2782
+ }
2783
+ }
2784
+ else {
2785
+ const chat = await (0, _3_types_js_1.constructChat3)(chatId, -1, -1, this[getEntity].bind(this), this.getMessage.bind(this));
2786
+ if (chat != null) {
2787
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, 0).set(chatId, chat);
2788
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_reassignChatLastMessage).call(this, chatId, false, false);
2789
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, true);
2790
+ }
2791
+ }
2792
+ }, _Client_removeChat = async function _Client_removeChat(chatId) {
2793
+ const [chat, listId] = __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatAnywhere).call(this, chatId);
2794
+ if (chat !== undefined) {
2795
+ __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChatList).call(this, listId).delete(chatId);
2796
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendChatUpdate).call(this, chatId, false);
2797
+ }
2723
2798
  }, _Client_updatePinnedChats = async function _Client_updatePinnedChats(update) {
2724
2799
  const listId = update.folder_id ?? 0;
2725
2800
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchPinnedChats).call(this, update.folder_id);
@@ -42,13 +42,12 @@ export declare abstract class Storage {
42
42
  getLastMessage(chatId: number): Promise<enums.Message | null>;
43
43
  setChannelPts(channelId: bigint, pts: number): Promise<void>;
44
44
  getChannelPts(channelId: bigint): MaybePromise<number | null>;
45
- setEntity(peer: types.Channel): Promise<void>;
46
- setEntity(peer: types.Chat): Promise<void>;
47
- setEntity(peer: types.User): Promise<void>;
48
- getEntity(type: "channel", id: bigint): Promise<types.Channel | null>;
49
- getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
45
+ setEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
46
+ removeEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
47
+ getEntity(type: "channel", id: bigint): Promise<types.Channel | types.ChannelForbidden | null>;
48
+ getEntity(type: "chat", id: bigint): Promise<types.Chat | types.ChatForbidden | null>;
50
49
  getEntity(type: "user", id: bigint): Promise<types.User | null>;
51
- getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
50
+ getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden | types.User | null>;
52
51
  setAccountType(type: "user" | "bot"): Promise<void>;
53
52
  getAccountType(): MaybePromise<"bot" | "user" | null>;
54
53
  updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
@@ -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 _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
13
+ var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId, _Storage_getEntityType;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Storage = void 0;
16
16
  const _1_utilities_js_1 = require("../1_utilities.js");
@@ -134,9 +134,13 @@ class Storage {
134
134
  getChannelPts(channelId) {
135
135
  return this.get(KPARTS__CHANNEL_PTS(channelId));
136
136
  }
137
- async setEntity(peer) {
138
- const type = peer instanceof _2_tl_js_1.types.Channel ? "channel" : peer instanceof _2_tl_js_1.types.Chat ? "chat" : peer instanceof _2_tl_js_1.types.User ? "user" : (0, _1_utilities_js_1.UNREACHABLE)();
139
- await this.set(KPARTS__PEER(type, peer.id), (0, _1_utilities_js_1.rleEncode)(peer[_2_tl_js_1.serialize]()));
137
+ async setEntity(entity) {
138
+ const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
139
+ await this.set(KPARTS__PEER(type, entity.id), (0, _1_utilities_js_1.rleEncode)(entity[_2_tl_js_1.serialize]()));
140
+ }
141
+ async removeEntity(entity) {
142
+ const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
143
+ await this.set(KPARTS__PEER(type, entity.id), null);
140
144
  }
141
145
  async getEntity(type, id) {
142
146
  const peer_ = await this.get(KPARTS__PEER(type, id));
@@ -263,4 +267,17 @@ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storag
263
267
  else {
264
268
  __classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
265
269
  }
270
+ }, _Storage_getEntityType = function _Storage_getEntityType(entity) {
271
+ if (entity instanceof _2_tl_js_1.types.Channel || entity instanceof _2_tl_js_1.types.ChannelForbidden) {
272
+ return "channel";
273
+ }
274
+ else if (entity instanceof _2_tl_js_1.types.Chat || entity instanceof _2_tl_js_1.types.ChatForbidden) {
275
+ return "chat";
276
+ }
277
+ else if (entity instanceof _2_tl_js_1.types.User) {
278
+ return "user";
279
+ }
280
+ else {
281
+ (0, _1_utilities_js_1.UNREACHABLE)();
282
+ }
266
283
  };
@@ -3,8 +3,8 @@ import { types } from "../2_tl.js";
3
3
  import { ChatID } from "./0_chat_id.js";
4
4
  export interface EntityGetter {
5
5
  (peer: types.PeerUser): MaybePromise<types.User | null>;
6
- (peer: types.PeerChat): MaybePromise<types.Chat | null>;
7
- (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
6
+ (peer: types.PeerChat): MaybePromise<types.Chat | types.ChatForbidden | null>;
7
+ (peer: types.PeerChannel): MaybePromise<types.Channel | types.ChannelForbidden | null>;
8
8
  }
9
9
  export interface InputPeerGetter {
10
10
  (id: ChatID): Promise<types.InputPeerUser | types.InputPeerChannel | types.InputPeerChat>;
@@ -68,5 +68,5 @@ export declare namespace ChatP {
68
68
  /** This object represents a chat. */
69
69
  export type ChatP = ChatP.Private | ChatP.Group | ChatP.Supergroup | ChatP.Channel;
70
70
  export declare function constructChatP(chat: types.User): ChatP.Private;
71
- export declare function constructChatP(chat: types.Chat): ChatP.Group;
72
- export declare function constructChatP(chat: types.Channel): ChatP.Supergroup | ChatP.Channel;
71
+ export declare function constructChatP(chat: types.Chat | types.ChatForbidden): ChatP.Group;
72
+ export declare function constructChatP(chat: types.Channel | types.ChannelForbidden): ChatP.Supergroup | ChatP.Channel;
@@ -25,21 +25,33 @@ function constructChatP(chat) {
25
25
  }
26
26
  return (0, _1_utilities_js_1.cleanObject)(chat_);
27
27
  }
28
- else if (chat instanceof _2_tl_js_1.types.Chat) {
28
+ else if (chat instanceof _2_tl_js_1.types.Chat || chat instanceof _2_tl_js_1.types.ChatForbidden) {
29
29
  const id = Number(-chat.id);
30
30
  const chat_ = {
31
31
  id,
32
32
  type: "group",
33
33
  color: (0, _1_utilities_js_1.getColorFromPeerId)(id),
34
34
  title: chat.title,
35
- isCreator: chat.creator || false,
35
+ isCreator: false,
36
36
  };
37
+ if (chat instanceof _2_tl_js_1.types.Chat) {
38
+ chat_.isCreator = chat.creator || false;
39
+ }
37
40
  return (0, _1_utilities_js_1.cleanObject)(chat_);
38
41
  }
39
- else if (chat instanceof _2_tl_js_1.types.Channel) {
42
+ else if (chat instanceof _2_tl_js_1.types.Channel || _2_tl_js_1.types.ChannelForbidden) {
40
43
  let chat_;
41
- const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
42
44
  const id = _1_utilities_js_1.ZERO_CHANNEL_ID + -Number(chat.id);
45
+ if (chat instanceof _2_tl_js_1.types.ChannelForbidden) {
46
+ const { title } = chat;
47
+ if (chat.megagroup) {
48
+ return { id, color: (0, _1_utilities_js_1.getColorFromPeerId)(id), title, type: "supergroup", isScam: false, isFake: false, isVerified: false, isRestricted: false, isForum: false };
49
+ }
50
+ else {
51
+ return { id, color: (0, _1_utilities_js_1.getColorFromPeerId)(id), title, type: "channel", isScam: false, isFake: false, isVerified: false, isRestricted: false };
52
+ }
53
+ }
54
+ const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
43
55
  if (chat.megagroup) {
44
56
  chat_ = {
45
57
  id,