@imessaging/telegram-mtproto 0.6.1 → 0.6.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@imessaging/telegram-mtproto",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Telegram MTProto user-account transport for imessaging",
5
5
  "keywords": [
6
6
  "messaging",
package/src/incoming.ts CHANGED
@@ -25,6 +25,15 @@ export type MtprotoMessageLike = {
25
25
  * `accessHash` живёт только здесь. Поле необязательное: в обновлении его может не быть.
26
26
  */
27
27
  sender?: { username?: string; accessHash?: { toString(): string } | string | number };
28
+ /**
29
+ * Пир отправителя ВМЕСТЕ с `accessHash` — так его отдаёт само обновление.
30
+ *
31
+ * Без него ответить по одному номеру нельзя: клиент знает только тех, кого уже разрешал, а
32
+ * `accessHash` из обновления больше нигде не хранится.
33
+ */
34
+ getInputSender?: () => Promise<{ userId?: { toString(): string }; accessHash?: { toString(): string } } | undefined>;
35
+ /** Отправитель целиком. Обращение к сущностям обновления, а не поход в сеть. */
36
+ getSender?: () => Promise<{ username?: string } | undefined>;
28
37
  };
29
38
 
30
39
  export type MtprotoMediaLike = {
@@ -185,9 +185,12 @@ export class TelegramMtprotoTransport
185
185
  */
186
186
  private async rememberSender(message: MtprotoMessageLike): Promise<void> {
187
187
  try {
188
- const hash = message.sender?.accessHash;
189
- if (hash === undefined || hash === null) return;
190
188
  const { chatId, chatType } = peerToChat(message.peerId);
189
+ // Спрашиваем ПИР ОБНОВЛЕНИЯ, а не поле `sender`: у живого сообщения gramJS оно ленивое и
190
+ // чаще всего пустое, а `getInputSender` берёт собеседника из карты сущностей обновления.
191
+ const input = await message.getInputSender?.();
192
+ const hash = input?.accessHash ?? message.sender?.accessHash;
193
+ if (hash === undefined || hash === null) return;
191
194
  // В группе отправитель и чат — разные пиры, и запись сложила бы одно вместо другого.
192
195
  if (chatType !== "user") return;
193
196
  const recipient = { type: "user", id: chatId } as const;
@@ -198,7 +201,7 @@ export class TelegramMtprotoTransport
198
201
  type: "user",
199
202
  id: chatId,
200
203
  accessHash: String(hash),
201
- username: message.sender?.username,
204
+ username: message.sender?.username ?? (await message.getSender?.())?.username,
202
205
  resolvedAt: new Date().toISOString(),
203
206
  },
204
207
  this.options.peerTtlSeconds,