@imessaging/telegram-mtproto 0.8.8 → 0.8.9
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.8.
|
|
3
|
+
"version": "0.8.9",
|
|
4
4
|
"description": "Telegram MTProto user-account transport for imessaging",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"messaging",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"test": "bun test"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@imessaging/core": "^0.8.
|
|
34
|
+
"@imessaging/core": "^0.8.9",
|
|
35
35
|
"big-integer": "^1.6.52"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -7,6 +7,8 @@ import type {
|
|
|
7
7
|
DraftTransport,
|
|
8
8
|
MessageDraft,
|
|
9
9
|
OutgoingObserverTransport,
|
|
10
|
+
OutgoingReadReceipt,
|
|
11
|
+
OutgoingReadReceiptTransport,
|
|
10
12
|
ButtonPress,
|
|
11
13
|
ButtonPressTransport,
|
|
12
14
|
IncomingAttachment,
|
|
@@ -119,6 +121,7 @@ export class TelegramMtprotoTransport
|
|
|
119
121
|
ButtonPressTransport,
|
|
120
122
|
IncomingMessageTransport,
|
|
121
123
|
OutgoingObserverTransport,
|
|
124
|
+
OutgoingReadReceiptTransport,
|
|
122
125
|
PhoneLookupTransport,
|
|
123
126
|
ReactionTransport,
|
|
124
127
|
ReadReceiptTransport,
|
|
@@ -137,6 +140,10 @@ export class TelegramMtprotoTransport
|
|
|
137
140
|
private outgoingListener: ((event: unknown) => void) | null = null;
|
|
138
141
|
private readonly outgoingEdits = new OutgoingDispatcher();
|
|
139
142
|
private outgoingEditListener: ((event: unknown) => void) | null = null;
|
|
143
|
+
private readonly outgoingReads = new Set<
|
|
144
|
+
(receipt: OutgoingReadReceipt) => void | Promise<void>
|
|
145
|
+
>();
|
|
146
|
+
private outgoingReadListener: ((event: unknown) => void) | null = null;
|
|
140
147
|
/**
|
|
141
148
|
* Что отправил и поправил сам транспорт: «чат:сообщение» → когда. Своё приходит тем же обновлением
|
|
142
149
|
* out=true, что и отправленное человеком с телефона, и без этой памяти их не различить.
|
|
@@ -426,6 +433,46 @@ export class TelegramMtprotoTransport
|
|
|
426
433
|
};
|
|
427
434
|
}
|
|
428
435
|
|
|
436
|
+
/** Прочтение собеседником наших исходящих сообщений. */
|
|
437
|
+
onOutgoingRead(handler: (receipt: OutgoingReadReceipt) => void | Promise<void>): () => void {
|
|
438
|
+
this.outgoingReads.add(handler);
|
|
439
|
+
if (this.outgoingReadListener === null) {
|
|
440
|
+
this.outgoingReadListener = (event: unknown): void => {
|
|
441
|
+
if (event instanceof Api.UpdateReadHistoryOutbox) {
|
|
442
|
+
try {
|
|
443
|
+
const { chatId } = peerToChat(event.peer);
|
|
444
|
+
const receipt: OutgoingReadReceipt = {
|
|
445
|
+
chatId,
|
|
446
|
+
maxMessageId: event.maxId.toString(),
|
|
447
|
+
readAt: new Date(),
|
|
448
|
+
};
|
|
449
|
+
for (const fn of this.outgoingReads) void fn(receipt);
|
|
450
|
+
} catch {
|
|
451
|
+
// неизвестный пир
|
|
452
|
+
}
|
|
453
|
+
} else if (event instanceof Api.UpdateReadChannelOutbox) {
|
|
454
|
+
try {
|
|
455
|
+
const receipt: OutgoingReadReceipt = {
|
|
456
|
+
chatId: `-100${event.channelId.toString()}`,
|
|
457
|
+
maxMessageId: event.maxId.toString(),
|
|
458
|
+
readAt: new Date(),
|
|
459
|
+
};
|
|
460
|
+
for (const fn of this.outgoingReads) void fn(receipt);
|
|
461
|
+
} catch {
|
|
462
|
+
// неизвестный канал
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
this.client.addEventHandler(this.outgoingReadListener);
|
|
467
|
+
}
|
|
468
|
+
return () => {
|
|
469
|
+
this.outgoingReads.delete(handler);
|
|
470
|
+
if (this.outgoingReads.size > 0 || this.outgoingReadListener === null) return;
|
|
471
|
+
this.client.removeEventHandler(this.outgoingReadListener, undefined as never);
|
|
472
|
+
this.outgoingReadListener = null;
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
429
476
|
private async dispatchOwn(
|
|
430
477
|
dispatcher: OutgoingDispatcher,
|
|
431
478
|
own: Map<string, number>,
|