@mtcute/core 0.29.6 → 0.30.0

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 (118) hide show
  1. package/client.cjs +8 -0
  2. package/client.js +8 -0
  3. package/highlevel/client.d.cts +23 -7
  4. package/highlevel/client.d.ts +23 -7
  5. package/highlevel/methods/bots/answer-bot-guest-chat-query.cjs +26 -0
  6. package/highlevel/methods/bots/answer-bot-guest-chat-query.d.cts +12 -0
  7. package/highlevel/methods/bots/answer-bot-guest-chat-query.d.ts +12 -0
  8. package/highlevel/methods/bots/answer-bot-guest-chat-query.js +21 -0
  9. package/highlevel/methods/chats/join-chat.cjs +38 -16
  10. package/highlevel/methods/chats/join-chat.d.cts +20 -6
  11. package/highlevel/methods/chats/join-chat.d.ts +20 -6
  12. package/highlevel/methods/chats/join-chat.js +38 -16
  13. package/highlevel/methods/chats/save-draft.d.cts +4 -1
  14. package/highlevel/methods/chats/save-draft.d.ts +4 -1
  15. package/highlevel/methods/messages/send-copy-group.cjs +5 -9
  16. package/highlevel/methods/messages/send-copy-group.js +5 -9
  17. package/highlevel/methods.d.cts +3 -0
  18. package/highlevel/methods.d.ts +3 -0
  19. package/highlevel/storage/service/peers.cjs +2 -0
  20. package/highlevel/storage/service/peers.js +2 -0
  21. package/highlevel/types/files/utils.d.cts +1 -1
  22. package/highlevel/types/files/utils.d.ts +1 -1
  23. package/highlevel/types/media/poll.cjs +14 -0
  24. package/highlevel/types/media/poll.d.cts +6 -0
  25. package/highlevel/types/media/poll.d.ts +6 -0
  26. package/highlevel/types/media/poll.js +14 -0
  27. package/highlevel/types/messages/index.d.cts +1 -0
  28. package/highlevel/types/messages/index.d.ts +1 -0
  29. package/highlevel/types/messages/message.cjs +15 -1
  30. package/highlevel/types/messages/message.d.cts +8 -0
  31. package/highlevel/types/messages/message.d.ts +8 -0
  32. package/highlevel/types/messages/message.js +15 -1
  33. package/highlevel/types/messages/rich-message.cjs +50 -0
  34. package/highlevel/types/messages/rich-message.d.cts +18 -0
  35. package/highlevel/types/messages/rich-message.d.ts +18 -0
  36. package/highlevel/types/messages/rich-message.js +45 -0
  37. package/highlevel/types/peers/chat-permissions.cjs +6 -0
  38. package/highlevel/types/peers/chat-permissions.d.cts +4 -0
  39. package/highlevel/types/peers/chat-permissions.d.ts +4 -0
  40. package/highlevel/types/peers/chat-permissions.js +6 -0
  41. package/highlevel/types/peers/full-chat.cjs +6 -0
  42. package/highlevel/types/peers/full-chat.d.cts +2 -0
  43. package/highlevel/types/peers/full-chat.d.ts +2 -0
  44. package/highlevel/types/peers/full-chat.js +6 -0
  45. package/highlevel/types/peers/user.cjs +8 -0
  46. package/highlevel/types/peers/user.d.cts +4 -0
  47. package/highlevel/types/peers/user.d.ts +4 -0
  48. package/highlevel/types/peers/user.js +8 -0
  49. package/highlevel/types/updates/bot-guest-chat-query.cjs +39 -0
  50. package/highlevel/types/updates/bot-guest-chat-query.d.cts +21 -0
  51. package/highlevel/types/updates/bot-guest-chat-query.d.ts +21 -0
  52. package/highlevel/types/updates/bot-guest-chat-query.js +34 -0
  53. package/highlevel/types/updates/index.d.cts +5 -1
  54. package/highlevel/types/updates/index.d.ts +5 -1
  55. package/highlevel/types/updates/parse-update.cjs +3 -0
  56. package/highlevel/types/updates/parse-update.js +3 -0
  57. package/highlevel/types/updates/user-typing-update.cjs +2 -0
  58. package/highlevel/types/updates/user-typing-update.js +2 -0
  59. package/highlevel/updates/manager.cjs +214 -3
  60. package/highlevel/updates/manager.d.cts +1 -0
  61. package/highlevel/updates/manager.d.ts +1 -0
  62. package/highlevel/updates/manager.js +214 -3
  63. package/highlevel/utils/inspectable.cjs +1 -0
  64. package/highlevel/utils/inspectable.d.cts +1 -0
  65. package/highlevel/utils/inspectable.d.ts +1 -0
  66. package/highlevel/utils/inspectable.js +1 -0
  67. package/index.cjs +4 -0
  68. package/index.js +4 -0
  69. package/methods.cjs +2 -0
  70. package/methods.js +2 -0
  71. package/network/flood-control.cjs +149 -0
  72. package/network/flood-control.d.cts +79 -0
  73. package/network/flood-control.d.ts +79 -0
  74. package/network/flood-control.js +144 -0
  75. package/network/flood-control.test.d.cts +1 -0
  76. package/network/flood-control.test.d.ts +1 -0
  77. package/network/mtproto-session.cjs +1 -21
  78. package/network/mtproto-session.d.cts +1 -5
  79. package/network/mtproto-session.d.ts +1 -5
  80. package/network/mtproto-session.js +2 -22
  81. package/network/multi-session-connection.cjs +26 -16
  82. package/network/multi-session-connection.d.cts +1 -1
  83. package/network/multi-session-connection.d.ts +1 -1
  84. package/network/multi-session-connection.js +26 -16
  85. package/network/multi-session-connection.test.d.cts +1 -0
  86. package/network/multi-session-connection.test.d.ts +1 -0
  87. package/network/network-manager.cjs +3 -2
  88. package/network/network-manager.d.cts +12 -0
  89. package/network/network-manager.d.ts +12 -0
  90. package/network/network-manager.js +3 -2
  91. package/network/persistent-connection.cjs +25 -1
  92. package/network/persistent-connection.d.cts +5 -0
  93. package/network/persistent-connection.d.ts +5 -0
  94. package/network/persistent-connection.js +25 -1
  95. package/network/session-connection.cjs +5 -10
  96. package/network/session-connection.d.cts +0 -2
  97. package/network/session-connection.d.ts +0 -2
  98. package/network/session-connection.js +5 -10
  99. package/package.json +1 -1
  100. package/tl/api-schema.json +1 -1
  101. package/tl/binary/reader.cjs +257 -62
  102. package/tl/binary/reader.js +257 -62
  103. package/tl/binary/writer.cjs +837 -212
  104. package/tl/binary/writer.js +837 -212
  105. package/tl/compat/reader.cjs +31 -0
  106. package/tl/compat/reader.js +31 -0
  107. package/tl/index.d.cts +2478 -186
  108. package/tl/index.d.ts +2478 -186
  109. package/tl/inner-tl.cjs +34 -10
  110. package/tl/inner-tl.js +34 -10
  111. package/utils/binary/compat.cjs +84 -0
  112. package/utils/binary/compat.js +84 -0
  113. package/utils/index.d.cts +1 -0
  114. package/utils/index.d.ts +1 -0
  115. package/utils/long-utils.cjs +10 -0
  116. package/utils/long-utils.js +10 -0
  117. package/utils.cjs +7 -0
  118. package/utils.js +8 -1
@@ -76,6 +76,10 @@ class User {
76
76
  get isBusinessBot() {
77
77
  return this.raw.botBusiness;
78
78
  }
79
+ /** Whether this bot can approve join requests */
80
+ get isBotGuard() {
81
+ return this.raw.botGuard;
82
+ }
79
83
  /** Whether this user is a bot that has access to all messages */
80
84
  get isBotWithHistory() {
81
85
  return this.raw.botChatHistory;
@@ -111,6 +115,10 @@ class User {
111
115
  get canBotManageBots() {
112
116
  return this.raw.botCanManageBots;
113
117
  }
118
+ /** Whether this bot supports bot guest chats */
119
+ get isBotWithGuestChat() {
120
+ return this.raw.botGuestchat;
121
+ }
114
122
  /** Whether this user has been verified by Telegram */
115
123
  get isVerified() {
116
124
  return this.raw.verified;
@@ -0,0 +1,39 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[@mtcute/core] CommonJS bundles are deprecated. They will be removed completely in one of the upcoming releases. No support is provided for CommonJS users. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[@mtcute/core] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const memoize = require("../../utils/memoize.cjs");
9
+ const message = require("../messages/message.cjs");
10
+ const inspectable = require("../../utils/inspectable.cjs");
11
+ class BotGuestChatQuery {
12
+ constructor(raw, _peers) {
13
+ this.raw = raw;
14
+ this._peers = _peers;
15
+ }
16
+ /**
17
+ * Unique query ID
18
+ */
19
+ get id() {
20
+ return this.raw.queryId;
21
+ }
22
+ /**
23
+ * Message containing the query that was sent to the bot
24
+ */
25
+ get message() {
26
+ return new message.Message(this.raw.message, this._peers);
27
+ }
28
+ /** Message that {@link message} is a reply to, if available */
29
+ get replyToMessage() {
30
+ if (!this.message.replyToMessage || !this.raw.referenceMessages) return null;
31
+ if (!this.message.replyToMessage.originIs("same_chat")) return null;
32
+ const replyToId = this.message.replyToMessage.id;
33
+ const raw = this.raw.referenceMessages.find((it) => it.id === replyToId);
34
+ return raw ? new message.Message(raw, this._peers) : null;
35
+ }
36
+ }
37
+ const BotGuestChatQuery$1 = /* @__PURE__ */ memoize.memoizeGetters(BotGuestChatQuery, ["message", "replyToMessage"]);
38
+ const BotGuestChatQuery$2 = /* @__PURE__ */ inspectable.makeInspectable(BotGuestChatQuery$1);
39
+ exports.BotGuestChatQuery = BotGuestChatQuery$2;
@@ -0,0 +1,21 @@
1
+ import { tl } from '../../../tl/index.js';
2
+ import { PeersIndex } from '../peers/index.js';
3
+ import { Message } from '../messages/message.js';
4
+ /**
5
+ * Query received in a bot guest chat
6
+ */
7
+ export declare class BotGuestChatQuery {
8
+ readonly raw: tl.RawUpdateBotGuestChatQuery;
9
+ readonly _peers: PeersIndex;
10
+ constructor(raw: tl.RawUpdateBotGuestChatQuery, _peers: PeersIndex);
11
+ /**
12
+ * Unique query ID
13
+ */
14
+ get id(): tl.Long;
15
+ /**
16
+ * Message containing the query that was sent to the bot
17
+ */
18
+ get message(): Message;
19
+ /** Message that {@link message} is a reply to, if available */
20
+ get replyToMessage(): Message | null;
21
+ }
@@ -0,0 +1,21 @@
1
+ import { tl } from '../../../tl/index.js';
2
+ import { PeersIndex } from '../peers/index.js';
3
+ import { Message } from '../messages/message.js';
4
+ /**
5
+ * Query received in a bot guest chat
6
+ */
7
+ export declare class BotGuestChatQuery {
8
+ readonly raw: tl.RawUpdateBotGuestChatQuery;
9
+ readonly _peers: PeersIndex;
10
+ constructor(raw: tl.RawUpdateBotGuestChatQuery, _peers: PeersIndex);
11
+ /**
12
+ * Unique query ID
13
+ */
14
+ get id(): tl.Long;
15
+ /**
16
+ * Message containing the query that was sent to the bot
17
+ */
18
+ get message(): Message;
19
+ /** Message that {@link message} is a reply to, if available */
20
+ get replyToMessage(): Message | null;
21
+ }
@@ -0,0 +1,34 @@
1
+ import { memoizeGetters } from "../../utils/memoize.js";
2
+ import { Message as Message$2 } from "../messages/message.js";
3
+ import { makeInspectable } from "../../utils/inspectable.js";
4
+ class BotGuestChatQuery {
5
+ constructor(raw, _peers) {
6
+ this.raw = raw;
7
+ this._peers = _peers;
8
+ }
9
+ /**
10
+ * Unique query ID
11
+ */
12
+ get id() {
13
+ return this.raw.queryId;
14
+ }
15
+ /**
16
+ * Message containing the query that was sent to the bot
17
+ */
18
+ get message() {
19
+ return new Message$2(this.raw.message, this._peers);
20
+ }
21
+ /** Message that {@link message} is a reply to, if available */
22
+ get replyToMessage() {
23
+ if (!this.message.replyToMessage || !this.raw.referenceMessages) return null;
24
+ if (!this.message.replyToMessage.originIs("same_chat")) return null;
25
+ const replyToId = this.message.replyToMessage.id;
26
+ const raw = this.raw.referenceMessages.find((it) => it.id === replyToId);
27
+ return raw ? new Message$2(raw, this._peers) : null;
28
+ }
29
+ }
30
+ const BotGuestChatQuery$1 = /* @__PURE__ */ memoizeGetters(BotGuestChatQuery, ["message", "replyToMessage"]);
31
+ const BotGuestChatQuery$2 = /* @__PURE__ */ makeInspectable(BotGuestChatQuery$1);
32
+ export {
33
+ BotGuestChatQuery$2 as BotGuestChatQuery
34
+ };
@@ -1,5 +1,6 @@
1
1
  import { BusinessConnection, Message } from '../../types/index.js';
2
2
  import { BotChatJoinRequestUpdate } from './bot-chat-join-request.js';
3
+ import { BotGuestChatQuery } from './bot-guest-chat-query.js';
3
4
  import { BotReactionCountUpdate, BotReactionUpdate } from './bot-reaction.js';
4
5
  import { BotStoppedUpdate } from './bot-stopped.js';
5
6
  import { BusinessMessage } from './business-message.js';
@@ -19,7 +20,7 @@ import { StoryUpdate } from './story-update.js';
19
20
  import { UserStatusUpdate } from './user-status-update.js';
20
21
  import { UserTypingUpdate } from './user-typing-update.js';
21
22
  export type { ChatMemberUpdateType } from './chat-member-update.js';
22
- export { BotChatJoinRequestUpdate, BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChatJoinRequestUpdate, ChatMemberUpdate, ChosenInlineResult, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, PollUpdate, PollVoteUpdate, PreCheckoutQuery, StoryUpdate, UserStatusUpdate, UserTypingUpdate, };
23
+ export { BotChatJoinRequestUpdate, BotGuestChatQuery, BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChatJoinRequestUpdate, ChatMemberUpdate, ChosenInlineResult, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, PollUpdate, PollVoteUpdate, PreCheckoutQuery, StoryUpdate, UserStatusUpdate, UserTypingUpdate, };
23
24
  export type ParsedUpdate = {
24
25
  name: 'new_message';
25
26
  data: Message;
@@ -38,6 +39,9 @@ export type ParsedUpdate = {
38
39
  } | {
39
40
  name: 'inline_query';
40
41
  data: InlineQuery;
42
+ } | {
43
+ name: 'bot_guest_chat_query';
44
+ data: BotGuestChatQuery;
41
45
  } | {
42
46
  name: 'chosen_inline_result';
43
47
  data: ChosenInlineResult;
@@ -1,5 +1,6 @@
1
1
  import { BusinessConnection, Message } from '../../types/index.js';
2
2
  import { BotChatJoinRequestUpdate } from './bot-chat-join-request.js';
3
+ import { BotGuestChatQuery } from './bot-guest-chat-query.js';
3
4
  import { BotReactionCountUpdate, BotReactionUpdate } from './bot-reaction.js';
4
5
  import { BotStoppedUpdate } from './bot-stopped.js';
5
6
  import { BusinessMessage } from './business-message.js';
@@ -19,7 +20,7 @@ import { StoryUpdate } from './story-update.js';
19
20
  import { UserStatusUpdate } from './user-status-update.js';
20
21
  import { UserTypingUpdate } from './user-typing-update.js';
21
22
  export type { ChatMemberUpdateType } from './chat-member-update.js';
22
- export { BotChatJoinRequestUpdate, BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChatJoinRequestUpdate, ChatMemberUpdate, ChosenInlineResult, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, PollUpdate, PollVoteUpdate, PreCheckoutQuery, StoryUpdate, UserStatusUpdate, UserTypingUpdate, };
23
+ export { BotChatJoinRequestUpdate, BotGuestChatQuery, BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChatJoinRequestUpdate, ChatMemberUpdate, ChosenInlineResult, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, PollUpdate, PollVoteUpdate, PreCheckoutQuery, StoryUpdate, UserStatusUpdate, UserTypingUpdate, };
23
24
  export type ParsedUpdate = {
24
25
  name: 'new_message';
25
26
  data: Message;
@@ -38,6 +39,9 @@ export type ParsedUpdate = {
38
39
  } | {
39
40
  name: 'inline_query';
40
41
  data: InlineQuery;
42
+ } | {
43
+ name: 'bot_guest_chat_query';
44
+ data: BotGuestChatQuery;
41
45
  } | {
42
46
  name: 'chosen_inline_result';
43
47
  data: ChosenInlineResult;
@@ -7,6 +7,7 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
8
  const callbackQuery = require("./callback-query.cjs");
9
9
  const botChatJoinRequest = require("./bot-chat-join-request.cjs");
10
+ const botGuestChatQuery = require("./bot-guest-chat-query.cjs");
10
11
  const botReaction = require("./bot-reaction.cjs");
11
12
  const botStopped = require("./bot-stopped.cjs");
12
13
  const businessMessage = require("./business-message.cjs");
@@ -43,6 +44,8 @@ function _parseUpdate({ update, peers }) {
43
44
  return { name: "chat_member", data: new chatMemberUpdate.ChatMemberUpdate(update, peers) };
44
45
  case "updateBotInlineQuery":
45
46
  return { name: "inline_query", data: new inlineQuery.InlineQuery(update, peers) };
47
+ case "updateBotGuestChatQuery":
48
+ return { name: "bot_guest_chat_query", data: new botGuestChatQuery.BotGuestChatQuery(update, peers) };
46
49
  case "updateBotInlineSend":
47
50
  return { name: "chosen_inline_result", data: new chosenInlineResult.ChosenInlineResult(update, peers) };
48
51
  case "updateBotCallbackQuery":
@@ -1,5 +1,6 @@
1
1
  import { BusinessCallbackQuery as BusinessCallbackQuery$2, InlineCallbackQuery as InlineCallbackQuery$2, CallbackQuery as CallbackQuery$2 } from "./callback-query.js";
2
2
  import { BotChatJoinRequestUpdate as BotChatJoinRequestUpdate$2 } from "./bot-chat-join-request.js";
3
+ import { BotGuestChatQuery as BotGuestChatQuery$2 } from "./bot-guest-chat-query.js";
3
4
  import { BotReactionCountUpdate as BotReactionCountUpdate$2, BotReactionUpdate as BotReactionUpdate$2 } from "./bot-reaction.js";
4
5
  import { BotStoppedUpdate as BotStoppedUpdate$2 } from "./bot-stopped.js";
5
6
  import { BusinessMessage } from "./business-message.js";
@@ -36,6 +37,8 @@ function _parseUpdate({ update, peers }) {
36
37
  return { name: "chat_member", data: new ChatMemberUpdate$2(update, peers) };
37
38
  case "updateBotInlineQuery":
38
39
  return { name: "inline_query", data: new InlineQuery$2(update, peers) };
40
+ case "updateBotGuestChatQuery":
41
+ return { name: "bot_guest_chat_query", data: new BotGuestChatQuery$2(update, peers) };
39
42
  case "updateBotInlineSend":
40
43
  return { name: "chosen_inline_result", data: new ChosenInlineResult$2(update, peers) };
41
44
  case "updateBotCallbackQuery":
@@ -65,6 +65,8 @@ class UserTypingUpdate {
65
65
  switch (this.raw.action._) {
66
66
  case "sendMessageTypingAction":
67
67
  case "sendMessageTextDraftAction":
68
+ case "inputSendMessageRichMessageDraftAction":
69
+ case "sendMessageRichMessageDraftAction":
68
70
  return "typing";
69
71
  case "sendMessageCancelAction":
70
72
  return "cancel";
@@ -58,6 +58,8 @@ class UserTypingUpdate {
58
58
  switch (this.raw.action._) {
59
59
  case "sendMessageTypingAction":
60
60
  case "sendMessageTextDraftAction":
61
+ case "inputSendMessageRichMessageDraftAction":
62
+ case "sendMessageRichMessageDraftAction":
61
63
  return "typing";
62
64
  case "sendMessageCancelAction":
63
65
  return "cancel";
@@ -21,6 +21,178 @@ const innerTl = require("../../tl/inner-tl.cjs");
21
21
  const WARN_EVERY = 100;
22
22
  const KEEP_ALIVE_INTERVAL = 15 * 60 * 1e3;
23
23
  const UPDATES_TOO_LONG = { _: "updatesTooLong" };
24
+ function collectRichTextPeerIds(text, peers) {
25
+ if (!text) return;
26
+ switch (text._) {
27
+ case "textEmpty":
28
+ case "textPlain":
29
+ case "textEmail":
30
+ case "textPhone":
31
+ case "textImage":
32
+ case "textMath":
33
+ case "textCustomEmoji":
34
+ break;
35
+ case "textBold":
36
+ case "textItalic":
37
+ case "textUnderline":
38
+ case "textStrike":
39
+ case "textFixed":
40
+ case "textUrl":
41
+ case "textSubscript":
42
+ case "textSuperscript":
43
+ case "textMarked":
44
+ case "textAnchor":
45
+ case "textSpoiler":
46
+ case "textMention":
47
+ case "textHashtag":
48
+ case "textBotCommand":
49
+ case "textCashtag":
50
+ case "textAutoUrl":
51
+ case "textAutoEmail":
52
+ case "textAutoPhone":
53
+ case "textBankCard":
54
+ case "textDate":
55
+ collectRichTextPeerIds(text.text, peers);
56
+ break;
57
+ case "textConcat":
58
+ for (const child of text.texts) collectRichTextPeerIds(child, peers);
59
+ break;
60
+ case "textMentionName":
61
+ peers.add(text.userId);
62
+ collectRichTextPeerIds(text.text, peers);
63
+ break;
64
+ default:
65
+ utils$1.assertNever();
66
+ }
67
+ }
68
+ function collectPageCaptionPeerIds(caption, peers) {
69
+ if (!caption) return;
70
+ collectRichTextPeerIds(caption.text, peers);
71
+ collectRichTextPeerIds(caption.credit, peers);
72
+ }
73
+ function collectPageBlockPeerIds(block, peers) {
74
+ if (!block) return;
75
+ switch (block._) {
76
+ case "pageBlockUnsupported":
77
+ case "pageBlockDivider":
78
+ case "pageBlockAnchor":
79
+ case "pageBlockMath":
80
+ break;
81
+ case "pageBlockTitle":
82
+ case "pageBlockSubtitle":
83
+ case "pageBlockHeader":
84
+ case "pageBlockSubheader":
85
+ case "pageBlockParagraph":
86
+ case "pageBlockPreformatted":
87
+ case "pageBlockFooter":
88
+ case "pageBlockKicker":
89
+ case "pageBlockThinking":
90
+ case "pageBlockHeading1":
91
+ case "pageBlockHeading2":
92
+ case "pageBlockHeading3":
93
+ case "pageBlockHeading4":
94
+ case "pageBlockHeading5":
95
+ case "pageBlockHeading6":
96
+ collectRichTextPeerIds(block.text, peers);
97
+ break;
98
+ case "pageBlockAuthorDate":
99
+ collectRichTextPeerIds(block.author, peers);
100
+ break;
101
+ case "pageBlockList":
102
+ for (const item of block.items) collectPageListItemPeerIds(item, peers);
103
+ break;
104
+ case "pageBlockOrderedList":
105
+ for (const item of block.items) collectPageListOrderedItemPeerIds(item, peers);
106
+ break;
107
+ case "pageBlockBlockquote":
108
+ case "pageBlockPullquote":
109
+ collectRichTextPeerIds(block.text, peers);
110
+ collectRichTextPeerIds(block.caption, peers);
111
+ break;
112
+ case "pageBlockPhoto":
113
+ case "pageBlockVideo":
114
+ case "pageBlockEmbed":
115
+ case "pageBlockAudio":
116
+ case "pageBlockMap":
117
+ case "inputPageBlockMap":
118
+ collectPageCaptionPeerIds(block.caption, peers);
119
+ break;
120
+ case "pageBlockCover":
121
+ collectPageBlockPeerIds(block.cover, peers);
122
+ break;
123
+ case "pageBlockEmbedPost":
124
+ for (const child of block.blocks) collectPageBlockPeerIds(child, peers);
125
+ collectPageCaptionPeerIds(block.caption, peers);
126
+ break;
127
+ case "pageBlockCollage":
128
+ case "pageBlockSlideshow":
129
+ for (const child of block.items) collectPageBlockPeerIds(child, peers);
130
+ collectPageCaptionPeerIds(block.caption, peers);
131
+ break;
132
+ case "pageBlockChannel":
133
+ switch (block.channel._) {
134
+ case "chatEmpty":
135
+ case "chat":
136
+ case "chatForbidden":
137
+ peers.add(peerUtils.getMarkedPeerId(block.channel.id, "chat"));
138
+ break;
139
+ case "channel":
140
+ case "channelForbidden":
141
+ peers.add(peerUtils.getMarkedPeerId(block.channel.id, "channel"));
142
+ break;
143
+ default:
144
+ utils$1.assertNever(block.channel);
145
+ }
146
+ break;
147
+ case "pageBlockTable":
148
+ collectRichTextPeerIds(block.title, peers);
149
+ for (const row of block.rows) {
150
+ for (const cell of row.cells) collectRichTextPeerIds(cell.text, peers);
151
+ }
152
+ break;
153
+ case "pageBlockDetails":
154
+ for (const child of block.blocks) collectPageBlockPeerIds(child, peers);
155
+ collectRichTextPeerIds(block.title, peers);
156
+ break;
157
+ case "pageBlockRelatedArticles":
158
+ collectRichTextPeerIds(block.title, peers);
159
+ break;
160
+ case "pageBlockBlockquoteBlocks":
161
+ for (const child of block.blocks) collectPageBlockPeerIds(child, peers);
162
+ collectRichTextPeerIds(block.caption, peers);
163
+ break;
164
+ default:
165
+ utils$1.assertNever();
166
+ }
167
+ }
168
+ function collectPageListItemPeerIds(item, peers) {
169
+ switch (item._) {
170
+ case "pageListItemText":
171
+ collectRichTextPeerIds(item.text, peers);
172
+ break;
173
+ case "pageListItemBlocks":
174
+ for (const block of item.blocks) collectPageBlockPeerIds(block, peers);
175
+ break;
176
+ default:
177
+ utils$1.assertNever();
178
+ }
179
+ }
180
+ function collectPageListOrderedItemPeerIds(item, peers) {
181
+ switch (item._) {
182
+ case "pageListOrderedItemText":
183
+ collectRichTextPeerIds(item.text, peers);
184
+ break;
185
+ case "pageListOrderedItemBlocks":
186
+ for (const block of item.blocks) collectPageBlockPeerIds(block, peers);
187
+ break;
188
+ default:
189
+ utils$1.assertNever();
190
+ }
191
+ }
192
+ function collectRichMessagePeerIds(richMessage, peers) {
193
+ if (!richMessage) return;
194
+ for (const block of richMessage.blocks) collectPageBlockPeerIds(block, peers);
195
+ }
24
196
  class UpdatesManager {
25
197
  constructor(client, params = {}) {
26
198
  this.client = client;
@@ -93,6 +265,9 @@ class UpdatesManager {
93
265
  cptsMod = /* @__PURE__ */ new Map();
94
266
  channelDiffTimeouts = /* @__PURE__ */ new Map();
95
267
  channelsOpened = /* @__PURE__ */ new Map();
268
+ // channels we got CHANNEL_PRIVATE for when fetching diff — skip gap handling.
269
+ // invalidated when an updateChannel for that channel arrives
270
+ inaccessibleChannels = /* @__PURE__ */ new Set();
96
271
  log;
97
272
  _onCatchingUp = () => {
98
273
  };
@@ -114,6 +289,7 @@ class UpdatesManager {
114
289
  this.stopLoop();
115
290
  this.cpts.clear();
116
291
  this.cptsMod.clear();
292
+ this.inaccessibleChannels.clear();
117
293
  this.pts = this.qts = this.date = this.seq = void 0;
118
294
  }
119
295
  async prepare() {
@@ -489,6 +665,7 @@ class UpdatesManager {
489
665
  return missing;
490
666
  }
491
667
  if (!await fetchPeer(msg.viaBotId)) return missing;
668
+ if (!await fetchPeer(msg.guestchatViaFrom)) return missing;
492
669
  if (msg.entities) {
493
670
  for (const ent of msg.entities) {
494
671
  if (ent._ === "messageEntityMentionName") {
@@ -496,6 +673,13 @@ class UpdatesManager {
496
673
  }
497
674
  }
498
675
  }
676
+ if (msg.richMessage) {
677
+ const richMessagePeers = /* @__PURE__ */ new Set();
678
+ collectRichMessagePeerIds(msg.richMessage, richMessagePeers);
679
+ for (const peer of richMessagePeers) {
680
+ if (!await fetchPeer(peer)) return missing;
681
+ }
682
+ }
499
683
  if (msg.media) {
500
684
  switch (msg.media._) {
501
685
  case "messageMediaContact":
@@ -545,6 +729,13 @@ class UpdatesManager {
545
729
  }
546
730
  }
547
731
  }
732
+ if ("richMessage" in upd.draft && upd.draft.richMessage) {
733
+ const richMessagePeers = /* @__PURE__ */ new Set();
734
+ collectRichMessagePeerIds(upd.draft.richMessage, richMessagePeers);
735
+ for (const peer of richMessagePeers) {
736
+ if (!await fetchPeer(peer)) return missing;
737
+ }
738
+ }
548
739
  }
549
740
  return missing;
550
741
  }
@@ -567,7 +758,13 @@ class UpdatesManager {
567
758
  store(msg.fromId);
568
759
  if (msg._ === "message") {
569
760
  store(msg.viaBotId);
761
+ store(msg.guestchatViaFrom);
570
762
  store(msg.fwdFrom?.fromId);
763
+ if (msg.richMessage) {
764
+ const richMessagePeers = /* @__PURE__ */ new Set();
765
+ collectRichMessagePeerIds(msg.richMessage, richMessagePeers);
766
+ store([...richMessagePeers]);
767
+ }
571
768
  if (msg.media) {
572
769
  switch (msg.media._) {
573
770
  case "messageMediaWebPage":
@@ -732,14 +929,20 @@ class UpdatesManager {
732
929
  channelId,
733
930
  this._fetchChannelDifference(channelId, fallbackPts).catch((err) => {
734
931
  this.log.warn("error fetching difference for %d: %e", channelId, err);
735
- if (innerTl.RpcError.is("PERSISTENT_TIMESTAMP_INVALID")) {
932
+ if (innerTl.RpcError.is(err, "PERSISTENT_TIMESTAMP_INVALID")) {
736
933
  this.log.warn("received PERSISTENT_TIMESTAMP_INVALID, resetting channel pts value");
737
934
  this.cpts.delete(channelId);
738
935
  this.cptsMod.delete(channelId);
739
936
  }
937
+ if (innerTl.RpcError.is(err, "CHANNEL_PRIVATE") || innerTl.RpcError.is(err, "CHANNEL_INVALID")) {
938
+ this.log.debug("channel %d is inaccessible, skipping gap fills until updateChannel", channelId);
939
+ this.inaccessibleChannels.add(channelId);
940
+ this.cpts.delete(channelId);
941
+ this.cptsMod.delete(channelId);
942
+ }
740
943
  }).then((ok) => {
741
944
  requestedDiff.delete(channelId);
742
- if (!ok) {
945
+ if (!ok && !this.inaccessibleChannels.has(channelId)) {
743
946
  this.log.debug("channel difference for %d failed, falling back to common diff", channelId);
744
947
  this._fetchDifferenceLater(requestedDiff);
745
948
  }
@@ -940,6 +1143,13 @@ class UpdatesManager {
940
1143
  }
941
1144
  break;
942
1145
  }
1146
+ case "updateChannel": {
1147
+ const channel = pending.peers.chat(upd.channelId);
1148
+ if (channel._ !== "channelForbidden") {
1149
+ this.inaccessibleChannels.delete(upd.channelId);
1150
+ }
1151
+ break;
1152
+ }
943
1153
  case "updateConfig":
944
1154
  client.mt.network.config.update(true).catch((err) => client.onError.emit(utils.unknownToError(err)));
945
1155
  break;
@@ -1257,7 +1467,8 @@ class UpdatesManager {
1257
1467
  );
1258
1468
  continue;
1259
1469
  }
1260
- if (diff < 0) {
1470
+ const isInaccessibleChannel = pending.channelId && this.inaccessibleChannels.has(pending.channelId);
1471
+ if (diff < 0 && !isInaccessibleChannel) {
1261
1472
  if (diff > -3) {
1262
1473
  log.debug(
1263
1474
  "postponing %s for 0.5s (cid = %d) because small gap detected (by pts: exp %d, got %d, diff=%d)",
@@ -39,6 +39,7 @@ export declare class UpdatesManager {
39
39
  cptsMod: Map<number, number>;
40
40
  channelDiffTimeouts: Map<number, timers.Timer>;
41
41
  channelsOpened: Map<number, number>;
42
+ inaccessibleChannels: Set<number>;
42
43
  log: Logger;
43
44
  private _onCatchingUp;
44
45
  private _channelPtsLimit;
@@ -39,6 +39,7 @@ export declare class UpdatesManager {
39
39
  cptsMod: Map<number, number>;
40
40
  channelDiffTimeouts: Map<number, timers.Timer>;
41
41
  channelsOpened: Map<number, number>;
42
+ inaccessibleChannels: Set<number>;
42
43
  log: Logger;
43
44
  private _onCatchingUp;
44
45
  private _channelPtsLimit;