@mtkruto/node 0.0.936 → 0.0.937
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/esm/client/3_client.js +5 -5
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/types/3_message.d.ts +7 -4
- package/esm/types/3_message.js +58 -32
- package/package.json +1 -1
- package/script/client/3_client.js +5 -5
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/types/3_message.d.ts +7 -4
- package/script/types/3_message.js +58 -32
package/esm/client/3_client.js
CHANGED
|
@@ -635,7 +635,7 @@ export class Client extends ClientAbstract {
|
|
|
635
635
|
(update instanceof types.UpdateDeleteChannelMessages) ||
|
|
636
636
|
(update instanceof types.UpdateEditChannelMessage) ||
|
|
637
637
|
(update instanceof types.UpdateChannelWebPage))) {
|
|
638
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message
|
|
638
|
+
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peerId[as](types.PeerChannel).channelId : update.channelId;
|
|
639
639
|
let localPts = await this.storage.getChannelPts(channelId);
|
|
640
640
|
if (!localPts) {
|
|
641
641
|
localPts = update.pts - update.ptsCount;
|
|
@@ -683,7 +683,7 @@ export class Client extends ClientAbstract {
|
|
|
683
683
|
(update instanceof types.UpdateDeleteChannelMessages) ||
|
|
684
684
|
(update instanceof types.UpdateEditChannelMessage) ||
|
|
685
685
|
(update instanceof types.UpdateChannelWebPage)) {
|
|
686
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message
|
|
686
|
+
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peerId[as](types.PeerChannel).channelId : update.channelId;
|
|
687
687
|
await this.recoverChannelUpdateGap(channelId, "applyUpdate");
|
|
688
688
|
}
|
|
689
689
|
else if ((update instanceof types.UpdateNewMessage) ||
|
|
@@ -1083,10 +1083,10 @@ export class Client extends ClientAbstract {
|
|
|
1083
1083
|
if (result instanceof types.Updates) {
|
|
1084
1084
|
for (const update of result.updates) {
|
|
1085
1085
|
if (update instanceof types.UpdateNewMessage) {
|
|
1086
|
-
return constructMessage(update.message
|
|
1086
|
+
return constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
1087
1087
|
}
|
|
1088
1088
|
else if (update instanceof types.UpdateNewChannelMessage) {
|
|
1089
|
-
return constructMessage(update.message
|
|
1089
|
+
return constructMessage(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
1090
1090
|
}
|
|
1091
1091
|
}
|
|
1092
1092
|
}
|
|
@@ -1114,7 +1114,7 @@ export class Client extends ClientAbstract {
|
|
|
1114
1114
|
}
|
|
1115
1115
|
const messages = new Array();
|
|
1116
1116
|
for (const message_ of messages_.messages) {
|
|
1117
|
-
messages.push(await constructMessage(message_
|
|
1117
|
+
messages.push(await constructMessage(message_, this[getEntity].bind(this), null, this[getStickerSetName].bind(this)));
|
|
1118
1118
|
}
|
|
1119
1119
|
return messages;
|
|
1120
1120
|
}
|
package/esm/constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
|
4
4
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
5
|
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 158;
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.937";
|
|
8
8
|
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
9
|
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
package/esm/constants.js
CHANGED
|
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
|
|
|
62
62
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
63
63
|
export const DEFAULT_INITIAL_DC = "2-test";
|
|
64
64
|
export const LAYER = 158;
|
|
65
|
-
export const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
65
|
+
export const DEFAULT_APP_VERSION = "MTKruto 0.0.937";
|
|
66
66
|
// @ts-ignore: lib
|
|
67
67
|
export const DEFAULT_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;
|
|
68
68
|
export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/esm/types/3_message.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export interface Message {
|
|
|
55
55
|
/** Optional. Date the message was last edited in Unix time */
|
|
56
56
|
editDate?: Date;
|
|
57
57
|
/** Optional. True, if the message can't be forwarded */
|
|
58
|
-
hasProtectedContent
|
|
58
|
+
hasProtectedContent?: boolean;
|
|
59
59
|
/** Optional. The unique identifier of a media message group this message belongs to */
|
|
60
60
|
mediaGroupId?: string;
|
|
61
61
|
/** Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
|
|
@@ -87,10 +87,13 @@ export interface Message {
|
|
|
87
87
|
contact?: Contact;
|
|
88
88
|
game?: Game;
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
interface EntityGetter {
|
|
91
91
|
(peer: types.PeerUser): MaybePromise<types.User | null>;
|
|
92
92
|
(peer: types.PeerChat): MaybePromise<types.Chat | null>;
|
|
93
93
|
(peer: types.PeerChannel): MaybePromise<types.Channel | null>;
|
|
94
|
-
}
|
|
94
|
+
}
|
|
95
|
+
type MessageGetter = {
|
|
95
96
|
(chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
|
|
96
|
-
} | null
|
|
97
|
+
} | null;
|
|
98
|
+
export declare function constructMessage(message_: types.TypeMessage, getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<Message>;
|
|
99
|
+
export {};
|
package/esm/types/3_message.js
CHANGED
|
@@ -22,7 +22,59 @@ import { FileID, FileType, FileUniqueID, FileUniqueType } from "./!0_file_id.js"
|
|
|
22
22
|
import { constructContact } from "./0_contact.js";
|
|
23
23
|
import { constructGame } from "./2_game.js";
|
|
24
24
|
const d = debug("types/Message");
|
|
25
|
+
async function getSender(message_, getEntity) {
|
|
26
|
+
if (message_.fromId instanceof types.PeerUser) {
|
|
27
|
+
const entity = await getEntity(message_.fromId);
|
|
28
|
+
if (entity) {
|
|
29
|
+
return { from: constructUser(entity) };
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
UNREACHABLE();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else if (message_.fromId instanceof types.PeerChannel) {
|
|
36
|
+
const entity = await getEntity(message_.fromId);
|
|
37
|
+
if (entity) {
|
|
38
|
+
return { senderChat: constructChat(entity) };
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
UNREACHABLE();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function getReply(message_, chat, getMessage) {
|
|
46
|
+
if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
|
|
47
|
+
let isTopicMessage = false;
|
|
48
|
+
if (message_.replyTo.forumTopic) {
|
|
49
|
+
isTopicMessage = true;
|
|
50
|
+
}
|
|
51
|
+
const replyToMessage = await getMessage(chat.id, message_.replyTo.replyToMsgId);
|
|
52
|
+
if (replyToMessage) {
|
|
53
|
+
return { replyToMessage, threadId: message_.replyTo.replyToTopId, isTopicMessage };
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
d("couldn't get replied message");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function constructServiceMessage(message_, chat, getEntity, getMessage) {
|
|
64
|
+
const message = {
|
|
65
|
+
id: message_.id,
|
|
66
|
+
chat: chat,
|
|
67
|
+
date: new Date(message_.date * 1000),
|
|
68
|
+
isTopicMessage: false,
|
|
69
|
+
};
|
|
70
|
+
Object.assign(message, await getReply(message_, chat, getMessage));
|
|
71
|
+
Object.assign(message, await getSender(message_, getEntity));
|
|
72
|
+
return message;
|
|
73
|
+
}
|
|
25
74
|
export async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
|
|
75
|
+
if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
|
|
76
|
+
UNREACHABLE();
|
|
77
|
+
}
|
|
26
78
|
let chat_ = null;
|
|
27
79
|
if (message_.peerId instanceof types.PeerUser) {
|
|
28
80
|
const entity = await getEntity(message_.peerId);
|
|
@@ -54,37 +106,25 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
|
|
|
54
106
|
else {
|
|
55
107
|
UNREACHABLE();
|
|
56
108
|
}
|
|
109
|
+
if (message_ instanceof types.MessageService) {
|
|
110
|
+
return await constructServiceMessage(message_, chat_, getEntity, getMessage);
|
|
111
|
+
}
|
|
57
112
|
const message = {
|
|
58
113
|
id: message_.id,
|
|
59
114
|
chat: chat_,
|
|
115
|
+
date: new Date(message_.date * 1000),
|
|
60
116
|
views: message_.views,
|
|
61
117
|
isTopicMessage: false,
|
|
62
118
|
hasProtectedContent: message_.noforwards || false,
|
|
63
119
|
};
|
|
120
|
+
Object.assign(message, await getReply(message_, chat_, getMessage));
|
|
121
|
+
Object.assign(message, await getSender(message_, getEntity));
|
|
64
122
|
if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
|
|
65
123
|
message.hasMediaSpoiler = message_.media.spoiler || false;
|
|
66
124
|
}
|
|
67
125
|
if (message_.groupedId != undefined) {
|
|
68
126
|
message.mediaGroupId = String(message_.groupedId);
|
|
69
127
|
}
|
|
70
|
-
if (message_.fromId instanceof types.PeerUser) {
|
|
71
|
-
const entity = await getEntity(message_.fromId);
|
|
72
|
-
if (entity) {
|
|
73
|
-
message.from = constructUser(entity);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
UNREACHABLE();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (message_.fromId instanceof types.PeerChannel) {
|
|
80
|
-
const entity = await getEntity(message_.fromId);
|
|
81
|
-
if (entity) {
|
|
82
|
-
message.senderChat = constructChat(entity);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
UNREACHABLE();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
128
|
if (message_.message) {
|
|
89
129
|
if (message_.media == undefined) {
|
|
90
130
|
message.text = message_.message;
|
|
@@ -101,7 +141,6 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
|
|
|
101
141
|
message.captionEntities = message_.entities.map(constructMessageEntity).filter((v) => v);
|
|
102
142
|
}
|
|
103
143
|
}
|
|
104
|
-
message.date = new Date(message_.date * 1000);
|
|
105
144
|
if (message_.editDate != undefined) {
|
|
106
145
|
message.editDate = new Date(message_.editDate * 1000);
|
|
107
146
|
}
|
|
@@ -122,19 +161,6 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
|
|
|
122
161
|
UNREACHABLE();
|
|
123
162
|
}
|
|
124
163
|
}
|
|
125
|
-
if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
|
|
126
|
-
if (message_.replyTo.forumTopic) {
|
|
127
|
-
message.isTopicMessage = true;
|
|
128
|
-
}
|
|
129
|
-
const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
|
|
130
|
-
if (replyToMessage) {
|
|
131
|
-
message.replyToMessage = replyToMessage;
|
|
132
|
-
message.threadId = message_.replyTo.replyToTopId;
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
d("couldn't get replied message");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
164
|
if (message_.viaBotId != undefined) {
|
|
139
165
|
const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
|
|
140
166
|
if (viaBot) {
|
package/package.json
CHANGED
|
@@ -661,7 +661,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
661
661
|
(update instanceof types.UpdateDeleteChannelMessages) ||
|
|
662
662
|
(update instanceof types.UpdateEditChannelMessage) ||
|
|
663
663
|
(update instanceof types.UpdateChannelWebPage))) {
|
|
664
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message
|
|
664
|
+
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peerId[_1_tl_object_js_1.as](types.PeerChannel).channelId : update.channelId;
|
|
665
665
|
let localPts = await this.storage.getChannelPts(channelId);
|
|
666
666
|
if (!localPts) {
|
|
667
667
|
localPts = update.pts - update.ptsCount;
|
|
@@ -709,7 +709,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
709
709
|
(update instanceof types.UpdateDeleteChannelMessages) ||
|
|
710
710
|
(update instanceof types.UpdateEditChannelMessage) ||
|
|
711
711
|
(update instanceof types.UpdateChannelWebPage)) {
|
|
712
|
-
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message
|
|
712
|
+
const channelId = update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditChannelMessage ? update.message.peerId[_1_tl_object_js_1.as](types.PeerChannel).channelId : update.channelId;
|
|
713
713
|
await this.recoverChannelUpdateGap(channelId, "applyUpdate");
|
|
714
714
|
}
|
|
715
715
|
else if ((update instanceof types.UpdateNewMessage) ||
|
|
@@ -1109,10 +1109,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1109
1109
|
if (result instanceof types.Updates) {
|
|
1110
1110
|
for (const update of result.updates) {
|
|
1111
1111
|
if (update instanceof types.UpdateNewMessage) {
|
|
1112
|
-
return (0, _3_message_js_1.constructMessage)(update.message
|
|
1112
|
+
return (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1113
1113
|
}
|
|
1114
1114
|
else if (update instanceof types.UpdateNewChannelMessage) {
|
|
1115
|
-
return (0, _3_message_js_1.constructMessage)(update.message
|
|
1115
|
+
return (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1116
1116
|
}
|
|
1117
1117
|
}
|
|
1118
1118
|
}
|
|
@@ -1140,7 +1140,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1140
1140
|
}
|
|
1141
1141
|
const messages = new Array();
|
|
1142
1142
|
for (const message_ of messages_.messages) {
|
|
1143
|
-
messages.push(await (0, _3_message_js_1.constructMessage)(message_
|
|
1143
|
+
messages.push(await (0, _3_message_js_1.constructMessage)(message_, this[exports.getEntity].bind(this), null, this[exports.getStickerSetName].bind(this)));
|
|
1144
1144
|
}
|
|
1145
1145
|
return messages;
|
|
1146
1146
|
}
|
package/script/constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
|
4
4
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
5
|
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 158;
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.937";
|
|
8
8
|
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
9
|
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
package/script/constants.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
|
|
|
88
88
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
89
89
|
exports.DEFAULT_INITIAL_DC = "2-test";
|
|
90
90
|
exports.LAYER = 158;
|
|
91
|
-
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
91
|
+
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.937";
|
|
92
92
|
// @ts-ignore: lib
|
|
93
93
|
exports.DEFAULT_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;
|
|
94
94
|
exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -55,7 +55,7 @@ export interface Message {
|
|
|
55
55
|
/** Optional. Date the message was last edited in Unix time */
|
|
56
56
|
editDate?: Date;
|
|
57
57
|
/** Optional. True, if the message can't be forwarded */
|
|
58
|
-
hasProtectedContent
|
|
58
|
+
hasProtectedContent?: boolean;
|
|
59
59
|
/** Optional. The unique identifier of a media message group this message belongs to */
|
|
60
60
|
mediaGroupId?: string;
|
|
61
61
|
/** Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
|
|
@@ -87,10 +87,13 @@ export interface Message {
|
|
|
87
87
|
contact?: Contact;
|
|
88
88
|
game?: Game;
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
interface EntityGetter {
|
|
91
91
|
(peer: types.PeerUser): MaybePromise<types.User | null>;
|
|
92
92
|
(peer: types.PeerChat): MaybePromise<types.Chat | null>;
|
|
93
93
|
(peer: types.PeerChannel): MaybePromise<types.Channel | null>;
|
|
94
|
-
}
|
|
94
|
+
}
|
|
95
|
+
type MessageGetter = {
|
|
95
96
|
(chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
|
|
96
|
-
} | null
|
|
97
|
+
} | null;
|
|
98
|
+
export declare function constructMessage(message_: types.TypeMessage, getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<Message>;
|
|
99
|
+
export {};
|
|
@@ -48,7 +48,59 @@ const _0_file_id_js_1 = require("./!0_file_id.js");
|
|
|
48
48
|
const _0_contact_js_1 = require("./0_contact.js");
|
|
49
49
|
const _2_game_js_1 = require("./2_game.js");
|
|
50
50
|
const d = (0, deps_js_1.debug)("types/Message");
|
|
51
|
+
async function getSender(message_, getEntity) {
|
|
52
|
+
if (message_.fromId instanceof types.PeerUser) {
|
|
53
|
+
const entity = await getEntity(message_.fromId);
|
|
54
|
+
if (entity) {
|
|
55
|
+
return { from: (0, _1_user_js_1.constructUser)(entity) };
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else if (message_.fromId instanceof types.PeerChannel) {
|
|
62
|
+
const entity = await getEntity(message_.fromId);
|
|
63
|
+
if (entity) {
|
|
64
|
+
return { senderChat: (0, _1_chat_js_1.constructChat)(entity) };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function getReply(message_, chat, getMessage) {
|
|
72
|
+
if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
|
|
73
|
+
let isTopicMessage = false;
|
|
74
|
+
if (message_.replyTo.forumTopic) {
|
|
75
|
+
isTopicMessage = true;
|
|
76
|
+
}
|
|
77
|
+
const replyToMessage = await getMessage(chat.id, message_.replyTo.replyToMsgId);
|
|
78
|
+
if (replyToMessage) {
|
|
79
|
+
return { replyToMessage, threadId: message_.replyTo.replyToTopId, isTopicMessage };
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
d("couldn't get replied message");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function constructServiceMessage(message_, chat, getEntity, getMessage) {
|
|
90
|
+
const message = {
|
|
91
|
+
id: message_.id,
|
|
92
|
+
chat: chat,
|
|
93
|
+
date: new Date(message_.date * 1000),
|
|
94
|
+
isTopicMessage: false,
|
|
95
|
+
};
|
|
96
|
+
Object.assign(message, await getReply(message_, chat, getMessage));
|
|
97
|
+
Object.assign(message, await getSender(message_, getEntity));
|
|
98
|
+
return message;
|
|
99
|
+
}
|
|
51
100
|
async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
|
|
101
|
+
if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
|
|
102
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
103
|
+
}
|
|
52
104
|
let chat_ = null;
|
|
53
105
|
if (message_.peerId instanceof types.PeerUser) {
|
|
54
106
|
const entity = await getEntity(message_.peerId);
|
|
@@ -80,37 +132,25 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
80
132
|
else {
|
|
81
133
|
(0, _0_control_js_1.UNREACHABLE)();
|
|
82
134
|
}
|
|
135
|
+
if (message_ instanceof types.MessageService) {
|
|
136
|
+
return await constructServiceMessage(message_, chat_, getEntity, getMessage);
|
|
137
|
+
}
|
|
83
138
|
const message = {
|
|
84
139
|
id: message_.id,
|
|
85
140
|
chat: chat_,
|
|
141
|
+
date: new Date(message_.date * 1000),
|
|
86
142
|
views: message_.views,
|
|
87
143
|
isTopicMessage: false,
|
|
88
144
|
hasProtectedContent: message_.noforwards || false,
|
|
89
145
|
};
|
|
146
|
+
Object.assign(message, await getReply(message_, chat_, getMessage));
|
|
147
|
+
Object.assign(message, await getSender(message_, getEntity));
|
|
90
148
|
if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
|
|
91
149
|
message.hasMediaSpoiler = message_.media.spoiler || false;
|
|
92
150
|
}
|
|
93
151
|
if (message_.groupedId != undefined) {
|
|
94
152
|
message.mediaGroupId = String(message_.groupedId);
|
|
95
153
|
}
|
|
96
|
-
if (message_.fromId instanceof types.PeerUser) {
|
|
97
|
-
const entity = await getEntity(message_.fromId);
|
|
98
|
-
if (entity) {
|
|
99
|
-
message.from = (0, _1_user_js_1.constructUser)(entity);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
(0, _0_control_js_1.UNREACHABLE)();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
else if (message_.fromId instanceof types.PeerChannel) {
|
|
106
|
-
const entity = await getEntity(message_.fromId);
|
|
107
|
-
if (entity) {
|
|
108
|
-
message.senderChat = (0, _1_chat_js_1.constructChat)(entity);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
(0, _0_control_js_1.UNREACHABLE)();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
154
|
if (message_.message) {
|
|
115
155
|
if (message_.media == undefined) {
|
|
116
156
|
message.text = message_.message;
|
|
@@ -127,7 +167,6 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
127
167
|
message.captionEntities = message_.entities.map(_0_message_entity_js_1.constructMessageEntity).filter((v) => v);
|
|
128
168
|
}
|
|
129
169
|
}
|
|
130
|
-
message.date = new Date(message_.date * 1000);
|
|
131
170
|
if (message_.editDate != undefined) {
|
|
132
171
|
message.editDate = new Date(message_.editDate * 1000);
|
|
133
172
|
}
|
|
@@ -148,19 +187,6 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
148
187
|
(0, _0_control_js_1.UNREACHABLE)();
|
|
149
188
|
}
|
|
150
189
|
}
|
|
151
|
-
if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
|
|
152
|
-
if (message_.replyTo.forumTopic) {
|
|
153
|
-
message.isTopicMessage = true;
|
|
154
|
-
}
|
|
155
|
-
const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
|
|
156
|
-
if (replyToMessage) {
|
|
157
|
-
message.replyToMessage = replyToMessage;
|
|
158
|
-
message.threadId = message_.replyTo.replyToTopId;
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
d("couldn't get replied message");
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
190
|
if (message_.viaBotId != undefined) {
|
|
165
191
|
const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
|
|
166
192
|
if (viaBot) {
|