@mtkruto/node 0.0.936 → 0.0.938

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.
@@ -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[as](types.Message).peerId[as](types.PeerChannel).channelId : update.channelId;
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[as](types.Message).peerId[as](types.PeerChannel).channelId : update.channelId;
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[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
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[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
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_[as](types.Message), this[getEntity].bind(this), null, this[getStickerSetName].bind(this)));
1117
+ messages.push(await constructMessage(message_, this[getEntity].bind(this), null, this[getStickerSetName].bind(this)));
1118
1118
  }
1119
1119
  return messages;
1120
1120
  }
@@ -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.936";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.938";
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.936";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.938";
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];
@@ -0,0 +1,8 @@
1
+ export interface Location {
2
+ latitude: number;
3
+ longitude: number;
4
+ horizontalAccuracy?: number;
5
+ livePeriod?: number;
6
+ heading?: number;
7
+ proximityAlertRadius?: number;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Location } from "./0_location.js";
3
+ export interface Venue {
4
+ location: Location;
5
+ title: string;
6
+ address: string;
7
+ foursquareId?: string;
8
+ foursquareType?: string;
9
+ }
10
+ export declare function constructVenue(media_: types.MessageMediaVenue): Venue;
@@ -0,0 +1,16 @@
1
+ import { as } from "../mod.js";
2
+ import * as types from "../tl/2_types.js";
3
+ export function constructVenue(media_) {
4
+ const geo = media_.geo[as](types.GeoPoint);
5
+ return {
6
+ location: {
7
+ latitude: geo.lat,
8
+ longitude: geo.long,
9
+ horizontalAccuracy: geo.accuracyRadius,
10
+ },
11
+ title: media_.title,
12
+ address: media_.address,
13
+ foursquareId: media_.venueId,
14
+ foursquareType: media_.venueType,
15
+ };
16
+ }
@@ -18,6 +18,7 @@ import { Voice } from "./0_voice.js";
18
18
  import { Dice } from "./0_dice.js";
19
19
  import { Contact } from "./0_contact.js";
20
20
  import { Game } from "./2_game.js";
21
+ import { Venue } from "./0_venue.js";
21
22
  /** This object represents a message. */
22
23
  export interface Message {
23
24
  /** Unique message identifier inside this chat */
@@ -55,7 +56,7 @@ export interface Message {
55
56
  /** Optional. Date the message was last edited in Unix time */
56
57
  editDate?: Date;
57
58
  /** Optional. True, if the message can't be forwarded */
58
- hasProtectedContent: boolean;
59
+ hasProtectedContent?: boolean;
59
60
  /** Optional. The unique identifier of a media message group this message belongs to */
60
61
  mediaGroupId?: string;
61
62
  /** Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
@@ -86,11 +87,15 @@ export interface Message {
86
87
  videoNote?: VideoNote;
87
88
  contact?: Contact;
88
89
  game?: Game;
90
+ venue?: Venue;
89
91
  }
90
- export declare function constructMessage(message_: types.Message, getEntity: {
92
+ interface EntityGetter {
91
93
  (peer: types.PeerUser): MaybePromise<types.User | null>;
92
94
  (peer: types.PeerChat): MaybePromise<types.Chat | null>;
93
95
  (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
94
- }, getMessage: {
96
+ }
97
+ type MessageGetter = {
95
98
  (chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
96
- } | null, getStickerSetName: StickerSetNameGetter): Promise<Message>;
99
+ } | null;
100
+ export declare function constructMessage(message_: types.TypeMessage, getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<Message>;
101
+ export {};
@@ -21,8 +21,61 @@ import { constructDice } from "./0_dice.js";
21
21
  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
+ import { constructVenue } from "./0_venue.js";
24
25
  const d = debug("types/Message");
26
+ async function getSender(message_, getEntity) {
27
+ if (message_.fromId instanceof types.PeerUser) {
28
+ const entity = await getEntity(message_.fromId);
29
+ if (entity) {
30
+ return { from: constructUser(entity) };
31
+ }
32
+ else {
33
+ UNREACHABLE();
34
+ }
35
+ }
36
+ else if (message_.fromId instanceof types.PeerChannel) {
37
+ const entity = await getEntity(message_.fromId);
38
+ if (entity) {
39
+ return { senderChat: constructChat(entity) };
40
+ }
41
+ else {
42
+ UNREACHABLE();
43
+ }
44
+ }
45
+ }
46
+ async function getReply(message_, chat, getMessage) {
47
+ if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
48
+ let isTopicMessage = false;
49
+ if (message_.replyTo.forumTopic) {
50
+ isTopicMessage = true;
51
+ }
52
+ const replyToMessage = await getMessage(chat.id, message_.replyTo.replyToMsgId);
53
+ if (replyToMessage) {
54
+ return { replyToMessage, threadId: message_.replyTo.replyToTopId, isTopicMessage };
55
+ }
56
+ else {
57
+ d("couldn't get replied message");
58
+ }
59
+ }
60
+ else {
61
+ return {};
62
+ }
63
+ }
64
+ async function constructServiceMessage(message_, chat, getEntity, getMessage) {
65
+ const message = {
66
+ id: message_.id,
67
+ chat: chat,
68
+ date: new Date(message_.date * 1000),
69
+ isTopicMessage: false,
70
+ };
71
+ Object.assign(message, await getReply(message_, chat, getMessage));
72
+ Object.assign(message, await getSender(message_, getEntity));
73
+ return message;
74
+ }
25
75
  export async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
76
+ if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
77
+ UNREACHABLE();
78
+ }
26
79
  let chat_ = null;
27
80
  if (message_.peerId instanceof types.PeerUser) {
28
81
  const entity = await getEntity(message_.peerId);
@@ -54,37 +107,25 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
54
107
  else {
55
108
  UNREACHABLE();
56
109
  }
110
+ if (message_ instanceof types.MessageService) {
111
+ return await constructServiceMessage(message_, chat_, getEntity, getMessage);
112
+ }
57
113
  const message = {
58
114
  id: message_.id,
59
115
  chat: chat_,
116
+ date: new Date(message_.date * 1000),
60
117
  views: message_.views,
61
118
  isTopicMessage: false,
62
119
  hasProtectedContent: message_.noforwards || false,
63
120
  };
121
+ Object.assign(message, await getReply(message_, chat_, getMessage));
122
+ Object.assign(message, await getSender(message_, getEntity));
64
123
  if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
65
124
  message.hasMediaSpoiler = message_.media.spoiler || false;
66
125
  }
67
126
  if (message_.groupedId != undefined) {
68
127
  message.mediaGroupId = String(message_.groupedId);
69
128
  }
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
129
  if (message_.message) {
89
130
  if (message_.media == undefined) {
90
131
  message.text = message_.message;
@@ -101,7 +142,6 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
101
142
  message.captionEntities = message_.entities.map(constructMessageEntity).filter((v) => v);
102
143
  }
103
144
  }
104
- message.date = new Date(message_.date * 1000);
105
145
  if (message_.editDate != undefined) {
106
146
  message.editDate = new Date(message_.editDate * 1000);
107
147
  }
@@ -122,19 +162,6 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
122
162
  UNREACHABLE();
123
163
  }
124
164
  }
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
165
  if (message_.viaBotId != undefined) {
139
166
  const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
140
167
  if (viaBot) {
@@ -243,6 +270,9 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
243
270
  else if (message_.media instanceof types.MessageMediaGame) {
244
271
  message.game = constructGame(message_.media);
245
272
  }
273
+ else if (message_.media instanceof types.MessageMediaVenue) {
274
+ message.venue = constructVenue(message_.media);
275
+ }
246
276
  else {
247
277
  console.log(message_.media);
248
278
  // not implemented
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.936",
5
+ "version": "0.0.938",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -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[_1_tl_object_js_1.as](types.Message).peerId[_1_tl_object_js_1.as](types.PeerChannel).channelId : update.channelId;
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[_1_tl_object_js_1.as](types.Message).peerId[_1_tl_object_js_1.as](types.PeerChannel).channelId : update.channelId;
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[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
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[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
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_[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this), null, this[exports.getStickerSetName].bind(this)));
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
  }
@@ -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.936";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.938";
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 = "";
@@ -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.936";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.938";
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];
@@ -0,0 +1,8 @@
1
+ export interface Location {
2
+ latitude: number;
3
+ longitude: number;
4
+ horizontalAccuracy?: number;
5
+ livePeriod?: number;
6
+ heading?: number;
7
+ proximityAlertRadius?: number;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,10 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Location } from "./0_location.js";
3
+ export interface Venue {
4
+ location: Location;
5
+ title: string;
6
+ address: string;
7
+ foursquareId?: string;
8
+ foursquareType?: string;
9
+ }
10
+ export declare function constructVenue(media_: types.MessageMediaVenue): Venue;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.constructVenue = void 0;
27
+ const mod_js_1 = require("../mod.js");
28
+ const types = __importStar(require("../tl/2_types.js"));
29
+ function constructVenue(media_) {
30
+ const geo = media_.geo[mod_js_1.as](types.GeoPoint);
31
+ return {
32
+ location: {
33
+ latitude: geo.lat,
34
+ longitude: geo.long,
35
+ horizontalAccuracy: geo.accuracyRadius,
36
+ },
37
+ title: media_.title,
38
+ address: media_.address,
39
+ foursquareId: media_.venueId,
40
+ foursquareType: media_.venueType,
41
+ };
42
+ }
43
+ exports.constructVenue = constructVenue;
@@ -18,6 +18,7 @@ import { Voice } from "./0_voice.js";
18
18
  import { Dice } from "./0_dice.js";
19
19
  import { Contact } from "./0_contact.js";
20
20
  import { Game } from "./2_game.js";
21
+ import { Venue } from "./0_venue.js";
21
22
  /** This object represents a message. */
22
23
  export interface Message {
23
24
  /** Unique message identifier inside this chat */
@@ -55,7 +56,7 @@ export interface Message {
55
56
  /** Optional. Date the message was last edited in Unix time */
56
57
  editDate?: Date;
57
58
  /** Optional. True, if the message can't be forwarded */
58
- hasProtectedContent: boolean;
59
+ hasProtectedContent?: boolean;
59
60
  /** Optional. The unique identifier of a media message group this message belongs to */
60
61
  mediaGroupId?: string;
61
62
  /** Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator */
@@ -86,11 +87,15 @@ export interface Message {
86
87
  videoNote?: VideoNote;
87
88
  contact?: Contact;
88
89
  game?: Game;
90
+ venue?: Venue;
89
91
  }
90
- export declare function constructMessage(message_: types.Message, getEntity: {
92
+ interface EntityGetter {
91
93
  (peer: types.PeerUser): MaybePromise<types.User | null>;
92
94
  (peer: types.PeerChat): MaybePromise<types.Chat | null>;
93
95
  (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
94
- }, getMessage: {
96
+ }
97
+ type MessageGetter = {
95
98
  (chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
96
- } | null, getStickerSetName: StickerSetNameGetter): Promise<Message>;
99
+ } | null;
100
+ export declare function constructMessage(message_: types.TypeMessage, getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<Message>;
101
+ export {};
@@ -47,8 +47,61 @@ const _0_dice_js_1 = require("./0_dice.js");
47
47
  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
+ const _0_venue_js_1 = require("./0_venue.js");
50
51
  const d = (0, deps_js_1.debug)("types/Message");
52
+ async function getSender(message_, getEntity) {
53
+ if (message_.fromId instanceof types.PeerUser) {
54
+ const entity = await getEntity(message_.fromId);
55
+ if (entity) {
56
+ return { from: (0, _1_user_js_1.constructUser)(entity) };
57
+ }
58
+ else {
59
+ (0, _0_control_js_1.UNREACHABLE)();
60
+ }
61
+ }
62
+ else if (message_.fromId instanceof types.PeerChannel) {
63
+ const entity = await getEntity(message_.fromId);
64
+ if (entity) {
65
+ return { senderChat: (0, _1_chat_js_1.constructChat)(entity) };
66
+ }
67
+ else {
68
+ (0, _0_control_js_1.UNREACHABLE)();
69
+ }
70
+ }
71
+ }
72
+ async function getReply(message_, chat, getMessage) {
73
+ if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
74
+ let isTopicMessage = false;
75
+ if (message_.replyTo.forumTopic) {
76
+ isTopicMessage = true;
77
+ }
78
+ const replyToMessage = await getMessage(chat.id, message_.replyTo.replyToMsgId);
79
+ if (replyToMessage) {
80
+ return { replyToMessage, threadId: message_.replyTo.replyToTopId, isTopicMessage };
81
+ }
82
+ else {
83
+ d("couldn't get replied message");
84
+ }
85
+ }
86
+ else {
87
+ return {};
88
+ }
89
+ }
90
+ async function constructServiceMessage(message_, chat, getEntity, getMessage) {
91
+ const message = {
92
+ id: message_.id,
93
+ chat: chat,
94
+ date: new Date(message_.date * 1000),
95
+ isTopicMessage: false,
96
+ };
97
+ Object.assign(message, await getReply(message_, chat, getMessage));
98
+ Object.assign(message, await getSender(message_, getEntity));
99
+ return message;
100
+ }
51
101
  async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
102
+ if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
103
+ (0, _0_control_js_1.UNREACHABLE)();
104
+ }
52
105
  let chat_ = null;
53
106
  if (message_.peerId instanceof types.PeerUser) {
54
107
  const entity = await getEntity(message_.peerId);
@@ -80,37 +133,25 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
80
133
  else {
81
134
  (0, _0_control_js_1.UNREACHABLE)();
82
135
  }
136
+ if (message_ instanceof types.MessageService) {
137
+ return await constructServiceMessage(message_, chat_, getEntity, getMessage);
138
+ }
83
139
  const message = {
84
140
  id: message_.id,
85
141
  chat: chat_,
142
+ date: new Date(message_.date * 1000),
86
143
  views: message_.views,
87
144
  isTopicMessage: false,
88
145
  hasProtectedContent: message_.noforwards || false,
89
146
  };
147
+ Object.assign(message, await getReply(message_, chat_, getMessage));
148
+ Object.assign(message, await getSender(message_, getEntity));
90
149
  if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
91
150
  message.hasMediaSpoiler = message_.media.spoiler || false;
92
151
  }
93
152
  if (message_.groupedId != undefined) {
94
153
  message.mediaGroupId = String(message_.groupedId);
95
154
  }
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
155
  if (message_.message) {
115
156
  if (message_.media == undefined) {
116
157
  message.text = message_.message;
@@ -127,7 +168,6 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
127
168
  message.captionEntities = message_.entities.map(_0_message_entity_js_1.constructMessageEntity).filter((v) => v);
128
169
  }
129
170
  }
130
- message.date = new Date(message_.date * 1000);
131
171
  if (message_.editDate != undefined) {
132
172
  message.editDate = new Date(message_.editDate * 1000);
133
173
  }
@@ -148,19 +188,6 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
148
188
  (0, _0_control_js_1.UNREACHABLE)();
149
189
  }
150
190
  }
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
191
  if (message_.viaBotId != undefined) {
165
192
  const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
166
193
  if (viaBot) {
@@ -269,6 +296,9 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
269
296
  else if (message_.media instanceof types.MessageMediaGame) {
270
297
  message.game = (0, _2_game_js_1.constructGame)(message_.media);
271
298
  }
299
+ else if (message_.media instanceof types.MessageMediaVenue) {
300
+ message.venue = (0, _0_venue_js_1.constructVenue)(message_.media);
301
+ }
272
302
  else {
273
303
  console.log(message_.media);
274
304
  // not implemented