@mtkruto/node 0.1.500 → 0.1.600

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 (91) hide show
  1. package/esm/3_types.d.ts +6 -1
  2. package/esm/3_types.js +6 -1
  3. package/esm/client/0_params.d.ts +28 -6
  4. package/esm/client/1_file_manager.d.ts +5 -1
  5. package/esm/client/1_file_manager.js +50 -49
  6. package/esm/client/2_video_chat_manager.d.ts +43 -0
  7. package/esm/client/2_video_chat_manager.js +194 -0
  8. package/esm/client/3_callback_query_manager.js +1 -0
  9. package/esm/client/3_chat_list_manager.d.ts +3 -3
  10. package/esm/client/3_chat_list_manager.js +75 -98
  11. package/esm/client/3_inline_query_manager.js +1 -0
  12. package/esm/client/4_client.d.ts +67 -3
  13. package/esm/client/4_client.js +92 -3
  14. package/esm/storage/0_storage.d.ts +14 -0
  15. package/esm/storage/0_storage.js +39 -2
  16. package/esm/tl/3_utilities.d.ts +1 -1
  17. package/esm/tl/3_utilities.js +3 -3
  18. package/esm/types/0_birthday.d.ts +27 -0
  19. package/esm/types/0_birthday.js +26 -0
  20. package/esm/types/0_giveaway_parameters.d.ts +1 -1
  21. package/esm/types/0_live_stream_channel.d.ts +30 -0
  22. package/esm/types/0_live_stream_channel.js +26 -0
  23. package/esm/types/0_opening_hours.d.ts +25 -0
  24. package/esm/types/0_opening_hours.js +25 -0
  25. package/esm/types/0_video_chat.d.ts +60 -0
  26. package/esm/types/0_video_chat.js +53 -0
  27. package/esm/types/1_chat_p.d.ts +4 -0
  28. package/esm/types/1_chat_p.js +1 -0
  29. package/esm/types/2_business_connection.d.ts +6 -0
  30. package/esm/types/2_chat.d.ts +62 -0
  31. package/esm/types/2_chat.js +66 -0
  32. package/esm/types/2_inactive_chat.d.ts +1 -1
  33. package/esm/types/2_invite_link.d.ts +1 -1
  34. package/esm/types/2_message_reaction_count.d.ts +1 -1
  35. package/esm/types/2_message_reactions.d.ts +1 -1
  36. package/esm/types/3_chat_member_updated.d.ts +1 -1
  37. package/esm/types/4_message.d.ts +3 -3
  38. package/esm/types/5_chat_list_item.d.ts +35 -0
  39. package/esm/types/5_chat_list_item.js +86 -0
  40. package/esm/types/6_update.d.ts +14 -5
  41. package/esm/types/_file_id.d.ts +1 -0
  42. package/esm/utilities/0_bigint.d.ts +1 -0
  43. package/esm/utilities/0_bigint.js +7 -3
  44. package/package.json +1 -1
  45. package/script/3_types.d.ts +6 -1
  46. package/script/3_types.js +6 -1
  47. package/script/client/0_params.d.ts +28 -6
  48. package/script/client/1_file_manager.d.ts +5 -1
  49. package/script/client/1_file_manager.js +50 -49
  50. package/script/client/2_video_chat_manager.d.ts +43 -0
  51. package/script/client/2_video_chat_manager.js +198 -0
  52. package/script/client/3_callback_query_manager.js +1 -0
  53. package/script/client/3_chat_list_manager.d.ts +3 -3
  54. package/script/client/3_chat_list_manager.js +72 -95
  55. package/script/client/3_inline_query_manager.js +1 -0
  56. package/script/client/4_client.d.ts +67 -3
  57. package/script/client/4_client.js +92 -3
  58. package/script/storage/0_storage.d.ts +14 -0
  59. package/script/storage/0_storage.js +39 -2
  60. package/script/tl/3_utilities.d.ts +1 -1
  61. package/script/tl/3_utilities.js +3 -3
  62. package/script/types/0_birthday.d.ts +27 -0
  63. package/script/types/0_birthday.js +30 -0
  64. package/script/types/0_giveaway_parameters.d.ts +1 -1
  65. package/script/types/0_live_stream_channel.d.ts +30 -0
  66. package/script/types/0_live_stream_channel.js +30 -0
  67. package/script/types/0_opening_hours.d.ts +25 -0
  68. package/script/types/0_opening_hours.js +29 -0
  69. package/script/types/0_video_chat.d.ts +60 -0
  70. package/script/types/0_video_chat.js +57 -0
  71. package/script/types/1_chat_p.d.ts +4 -0
  72. package/script/types/1_chat_p.js +1 -0
  73. package/script/types/2_business_connection.d.ts +6 -0
  74. package/script/types/2_chat.d.ts +62 -0
  75. package/script/types/2_chat.js +70 -0
  76. package/script/types/2_inactive_chat.d.ts +1 -1
  77. package/script/types/2_invite_link.d.ts +1 -1
  78. package/script/types/2_message_reaction_count.d.ts +1 -1
  79. package/script/types/2_message_reactions.d.ts +1 -1
  80. package/script/types/3_chat_member_updated.d.ts +1 -1
  81. package/script/types/4_message.d.ts +3 -3
  82. package/script/types/5_chat_list_item.d.ts +35 -0
  83. package/script/types/5_chat_list_item.js +94 -0
  84. package/script/types/6_update.d.ts +14 -5
  85. package/script/types/_file_id.d.ts +1 -0
  86. package/script/utilities/0_bigint.d.ts +1 -0
  87. package/script/utilities/0_bigint.js +7 -3
  88. package/esm/types/5_chat.d.ts +0 -59
  89. package/esm/types/5_chat.js +0 -126
  90. package/script/types/5_chat.d.ts +0 -59
  91. package/script/types/5_chat.js +0 -134
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ /**
3
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
4
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
5
+ *
6
+ * This file is part of MTKruto.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Lesser General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.constructVideoChat = void 0;
23
+ const _1_utilities_js_1 = require("../1_utilities.js");
24
+ const _2_tl_js_1 = require("../2_tl.js");
25
+ function constructVideoChat(call) {
26
+ const id = String(call.id);
27
+ if (call instanceof _2_tl_js_1.types.GroupCallDiscarded) {
28
+ return {
29
+ id,
30
+ duration: call.duration,
31
+ };
32
+ }
33
+ else {
34
+ const title = call.title ?? "";
35
+ const liveStream = call.rtmp_stream ? true : false;
36
+ const participantCount = call.participants_count;
37
+ if (call.schedule_date) {
38
+ return {
39
+ id,
40
+ title,
41
+ scheduledFor: (0, _1_utilities_js_1.fromUnixTimestamp)(call.schedule_date),
42
+ liveStream,
43
+ participantCount,
44
+ };
45
+ }
46
+ else {
47
+ return {
48
+ id,
49
+ title,
50
+ liveStream,
51
+ recording: call.record_video_active ? true : false,
52
+ participantCount,
53
+ };
54
+ }
55
+ }
56
+ }
57
+ exports.constructVideoChat = constructVideoChat;
@@ -41,6 +41,8 @@ export interface ChatPPrivate extends _ChatPBase {
41
41
  lastName?: string;
42
42
  /** The user's main username. */
43
43
  username?: string;
44
+ /** The user's additional usernames. */
45
+ also?: string[];
44
46
  /** Whether the user has been identified as scam. */
45
47
  isScam: boolean;
46
48
  /** Whether the user has been identified as an impersonator. */
@@ -68,6 +70,8 @@ export interface ChatPChannelBase extends _ChatPBase {
68
70
  title: string;
69
71
  /** The main username of the chat or channel. */
70
72
  username?: string;
73
+ /** The chat or channel's additional usernames. */
74
+ also?: string[];
71
75
  /** Whether the chat or channel has been identified as scam. */
72
76
  isScam: boolean;
73
77
  /** Whether the chat or channel has been identified as an impersonator. */
@@ -99,6 +99,7 @@ function constructChatP(chat) {
99
99
  };
100
100
  }
101
101
  chat_.username = chat.username ?? chat.usernames?.[0].username;
102
+ chat_.also = chat.usernames?.map((v) => v.username).filter((v) => v != chat_.username);
102
103
  if (chat_.isRestricted) {
103
104
  chat_.restrictionReason = (chat.restriction_reason ?? []).map(_0_restriction_reason_js_1.constructRestrictionReason);
104
105
  }
@@ -20,11 +20,17 @@
20
20
  import { types } from "../2_tl.js";
21
21
  import { EntityGetter } from "./_getters.js";
22
22
  import { User } from "./1_user.js";
23
+ /** A business connection. */
23
24
  export interface BusinessConnection {
25
+ /** The business connection's unique identifier. */
24
26
  id: string;
27
+ /** The business account that the connection is made with. */
25
28
  user: User;
29
+ /** The point in time in which the connection was recently updated. */
26
30
  date: Date;
31
+ /** Whether the bot can reply to older chats. */
27
32
  canReply: boolean;
33
+ /** Whether the connection is active. */
28
34
  isEnabled: boolean;
29
35
  }
30
36
  export declare function constructBusinessConnection(connection: types.BotBusinessConnection, getEntity: EntityGetter): Promise<BusinessConnection>;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ import { types } from "../2_tl.js";
21
+ import { EntityGetter } from "./_getters.js";
22
+ import { OpeningHours } from "./0_opening_hours.js";
23
+ import { ChatPChannel, ChatPGroup, ChatPPrivate, ChatPSupergroup } from "./1_chat_p.js";
24
+ import { Photo } from "./1_photo.js";
25
+ import { Location } from "./0_location.js";
26
+ import { Birthday } from "./0_birthday.js";
27
+ /** @unlisted */
28
+ export interface ChatBase {
29
+ /** The chat's photo. */
30
+ photo?: Photo;
31
+ }
32
+ /** @unlisted */
33
+ export interface ChatChannel extends ChatBase, ChatPChannel {
34
+ /** The channel's video chat ID. */
35
+ videoChatId?: string;
36
+ }
37
+ /** @unlisted */
38
+ export interface ChatSupergroup extends ChatBase, ChatPSupergroup {
39
+ /** The chat's video chat ID. */
40
+ videoChatId?: string;
41
+ }
42
+ /** @unlisted */
43
+ export interface ChatGroup extends ChatBase, ChatPGroup {
44
+ /** The chat's video chat ID. */
45
+ videoChatId?: string;
46
+ }
47
+ /** @unlisted */
48
+ export interface ChatPrivate extends ChatBase, ChatPPrivate {
49
+ /** The user's birthday. */
50
+ birthday?: Birthday;
51
+ /** The written address of the business. */
52
+ address?: string;
53
+ /** The exact location of the business. */
54
+ location?: Location;
55
+ /** The opening hours of the business. */
56
+ openingHours?: OpeningHours;
57
+ }
58
+ /**
59
+ * A chat with more fields.
60
+ */
61
+ export type Chat = ChatChannel | ChatSupergroup | ChatGroup | ChatPrivate;
62
+ export declare function constructChat(fullChat: types.UserFull | types.ChatFull | types.ChannelFull, getEntity: EntityGetter): Promise<Chat>;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
4
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
5
+ *
6
+ * This file is part of MTKruto.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Lesser General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.constructChat = void 0;
23
+ const _0_deps_js_1 = require("../0_deps.js");
24
+ const _2_tl_js_1 = require("../2_tl.js");
25
+ const _0_opening_hours_js_1 = require("./0_opening_hours.js");
26
+ const _1_chat_p_js_1 = require("./1_chat_p.js");
27
+ const _1_photo_js_1 = require("./1_photo.js");
28
+ const _0_location_js_1 = require("./0_location.js");
29
+ const _0_birthday_js_1 = require("./0_birthday.js");
30
+ const _1_utilities_js_1 = require("../1_utilities.js");
31
+ async function constructChat(fullChat, getEntity) {
32
+ if (fullChat instanceof _2_tl_js_1.types.UserFull) {
33
+ const user = await getEntity(new _2_tl_js_1.types.PeerUser({ user_id: fullChat.id }));
34
+ if (user == null)
35
+ (0, _0_deps_js_1.unreachable)();
36
+ const chatP = (0, _1_chat_p_js_1.constructChatP)(user);
37
+ return (0, _1_utilities_js_1.cleanObject)({
38
+ ...chatP,
39
+ birthday: fullChat.birthday ? (0, _0_birthday_js_1.constructBirthday)(fullChat.birthday) : undefined,
40
+ photo: fullChat.profile_photo && fullChat.profile_photo instanceof _2_tl_js_1.types.Photo ? (0, _1_photo_js_1.constructPhoto)(fullChat.profile_photo) : undefined,
41
+ address: fullChat.business_location?.address,
42
+ location: fullChat.business_location?.geo_point && fullChat.business_location.geo_point instanceof _2_tl_js_1.types.GeoPoint ? (0, _0_location_js_1.constructLocation)(fullChat.business_location.geo_point) : undefined,
43
+ openingHours: fullChat.business_work_hours ? (0, _0_opening_hours_js_1.constructOpeningHours)(fullChat.business_work_hours) : undefined,
44
+ });
45
+ }
46
+ else if (fullChat instanceof _2_tl_js_1.types.ChatFull) {
47
+ const chat = await getEntity(new _2_tl_js_1.types.PeerChat({ chat_id: fullChat.id }));
48
+ if (chat == null)
49
+ (0, _0_deps_js_1.unreachable)();
50
+ const chatP = (0, _1_chat_p_js_1.constructChatP)(chat);
51
+ return (0, _1_utilities_js_1.cleanObject)({
52
+ ...chatP,
53
+ photo: fullChat.chat_photo && fullChat.chat_photo instanceof _2_tl_js_1.types.Photo ? (0, _1_photo_js_1.constructPhoto)(fullChat.chat_photo) : undefined,
54
+ videoChatId: fullChat.call ? String(fullChat.call.id) : undefined,
55
+ });
56
+ }
57
+ else if (fullChat instanceof _2_tl_js_1.types.ChannelFull) {
58
+ const chat = await getEntity(new _2_tl_js_1.types.PeerChannel({ channel_id: fullChat.id }));
59
+ if (chat == null)
60
+ (0, _0_deps_js_1.unreachable)();
61
+ const chatP = (0, _1_chat_p_js_1.constructChatP)(chat);
62
+ return (0, _1_utilities_js_1.cleanObject)({
63
+ ...chatP,
64
+ photo: fullChat.chat_photo && fullChat.chat_photo instanceof _2_tl_js_1.types.Photo ? (0, _1_photo_js_1.constructPhoto)(fullChat.chat_photo) : undefined,
65
+ videoChatId: fullChat.call ? String(fullChat.call.id) : undefined,
66
+ });
67
+ }
68
+ (0, _0_deps_js_1.unreachable)();
69
+ }
70
+ exports.constructChat = constructChat;
@@ -21,7 +21,7 @@ import { enums } from "../2_tl.js";
21
21
  import { ChatP } from "./1_chat_p.js";
22
22
  /** An inactive chat. */
23
23
  export interface InactiveChat {
24
- /** The point of time in which the chat was last active. */
24
+ /** The time which the chat was last active. */
25
25
  lastActivity: Date;
26
26
  /** The chat that has been marked as inactive. */
27
27
  chat: ChatP;
@@ -32,7 +32,7 @@ export interface InviteLink {
32
32
  revoked: boolean;
33
33
  /** An optional title. */
34
34
  title?: string;
35
- /** The point of time in which the invite link is expired at. */
35
+ /** A point in time within the future in which the ban will be reverted. */
36
36
  expiresAt?: Date;
37
37
  /** The times the invite link can be used. */
38
38
  limit?: number;
@@ -27,7 +27,7 @@ export interface MessageReactionCount {
27
27
  chat: ChatP;
28
28
  /** The message's identifier. */
29
29
  messageId: number;
30
- /** This reaction state's point of time. */
30
+ /** The point in time in which the change was made. */
31
31
  date: Date;
32
32
  /** The reactions made to the post. */
33
33
  reactions: ReactionCount[];
@@ -32,7 +32,7 @@ export interface MessageReactions {
32
32
  user?: User;
33
33
  /** The chat that changed its reactions to the message. Unset if done on behalf of a user. */
34
34
  actorChat?: ChatP;
35
- /** The point of time in which the change was made. */
35
+ /** The point in time in which the change was made. */
36
36
  date: Date;
37
37
  /** The previous reactions. */
38
38
  oldReactions: Reaction[];
@@ -29,7 +29,7 @@ export interface ChatMemberUpdated {
29
29
  chat: ChatP;
30
30
  /** The one who made the change. */
31
31
  from: User;
32
- /** The point of time in which the chat member's status was changed. */
32
+ /** The point in time in which the chat member's status was changed. */
33
33
  date: Date;
34
34
  /** The old status of the chat member. */
35
35
  oldChatMember: ChatMember;
@@ -57,7 +57,7 @@ export interface _MessageBase {
57
57
  from?: User;
58
58
  /** The chat which the message was sent on behalf of. */
59
59
  senderChat?: ChatP;
60
- /** The point of time in which the message was sent. */
60
+ /** The point in time in which the message was sent. */
61
61
  date: Date;
62
62
  /** The chat where the message was sent to. */
63
63
  chat: ChatP;
@@ -73,7 +73,7 @@ export interface _MessageBase {
73
73
  forwardSignature?: string;
74
74
  /** The name of the original sender of the message. */
75
75
  forwardSenderName?: string;
76
- /** The point of time in which the original message was sent. */
76
+ /** The point in time in which the original message was sent. */
77
77
  forwardDate?: Date;
78
78
  /** Whether the message was sent in a topic thread. */
79
79
  isTopicMessage: boolean;
@@ -89,7 +89,7 @@ export interface _MessageBase {
89
89
  replyQuote?: ReplyQuote;
90
90
  /** The inline bot that was used to send this message. */
91
91
  viaBot?: User;
92
- /** The point of time in which the message's last edit was made. */
92
+ /** The point in time in which the message's last edit was made. */
93
93
  editDate?: Date;
94
94
  /** Whether the contents of the message is protected. */
95
95
  hasProtectedContent?: boolean;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
4
+ *
5
+ * This file is part of MTKruto.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Lesser General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
+ */
20
+ import { enums, types } from "../2_tl.js";
21
+ import { EntityGetter } from "./_getters.js";
22
+ import { ChatP } from "./1_chat_p.js";
23
+ import { StickerSetNameGetter } from "./1_sticker.js";
24
+ import { Message, MessageGetter } from "./4_message.js";
25
+ export interface ChatListItem {
26
+ chat: ChatP;
27
+ order: string;
28
+ pinned: number;
29
+ lastMessage?: Omit<Message, "replyToMessage">;
30
+ }
31
+ export declare function getChatListItemOrder(lastMessage: Omit<Message, "replyToMessage"> | undefined, pinned: number): string;
32
+ export declare function constructChatListItem(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter): Promise<ChatListItem | null>;
33
+ export declare function constructChatListItem2(entity: types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden, pinned: number, lastMessage: Omit<Message, "replyToMessage"> | undefined): ChatListItem;
34
+ export declare function constructChatListItem3(chatId: number, pinned: number, lastMessage: Omit<Message, "replyToMessage"> | undefined, getEntity: EntityGetter): Promise<ChatListItem | null>;
35
+ export declare function constructChatListItem4(dialog: enums.Dialog, dialogs: types.messages.Dialogs | types.messages.DialogsSlice, pinnedChats: number[], getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<ChatListItem>;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ /**
3
+ * MTKruto - Cross-runtime JavaScript library for building Telegram clients
4
+ * Copyright (C) 2023-2024 Roj <https://roj.im/>
5
+ *
6
+ * This file is part of MTKruto.
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU Lesser General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ * GNU Lesser General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU Lesser General Public License
19
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.constructChatListItem4 = exports.constructChatListItem3 = exports.constructChatListItem2 = exports.constructChatListItem = exports.getChatListItemOrder = void 0;
23
+ const _0_deps_js_1 = require("../0_deps.js");
24
+ const _2_tl_js_1 = require("../2_tl.js");
25
+ const _1_chat_p_js_1 = require("./1_chat_p.js");
26
+ const _4_message_js_1 = require("./4_message.js");
27
+ function getChatListItemOrder(lastMessage, pinned) {
28
+ const p = pinned == -1 ? "" : `P${100 - pinned}`;
29
+ if (!lastMessage) {
30
+ return p + "0";
31
+ }
32
+ return p + String((BigInt(Math.floor(lastMessage.date.getTime())) << 32n) + BigInt(lastMessage.id));
33
+ }
34
+ exports.getChatListItemOrder = getChatListItemOrder;
35
+ async function constructChatListItem(chatId, pinned, lastMessageId, getEntity, getMessage) {
36
+ const entity = await getEntity((0, _2_tl_js_1.chatIdToPeer)(chatId));
37
+ if (entity == null) {
38
+ return null;
39
+ }
40
+ const lastMessage_ = lastMessageId > 0 ? await getMessage(chatId, lastMessageId) : null;
41
+ const lastMessage = lastMessage_ == null ? undefined : lastMessage_;
42
+ return {
43
+ chat: (0, _1_chat_p_js_1.constructChatP)(entity),
44
+ order: getChatListItemOrder(lastMessage, pinned),
45
+ pinned,
46
+ lastMessage,
47
+ };
48
+ }
49
+ exports.constructChatListItem = constructChatListItem;
50
+ function constructChatListItem2(entity, pinned, lastMessage) {
51
+ return {
52
+ chat: (0, _1_chat_p_js_1.constructChatP)(entity),
53
+ order: getChatListItemOrder(lastMessage, pinned),
54
+ pinned,
55
+ lastMessage,
56
+ };
57
+ }
58
+ exports.constructChatListItem2 = constructChatListItem2;
59
+ async function constructChatListItem3(chatId, pinned, lastMessage, getEntity) {
60
+ const entity = await getEntity((0, _2_tl_js_1.chatIdToPeer)(chatId));
61
+ if (entity == null) {
62
+ return null;
63
+ }
64
+ return {
65
+ chat: (0, _1_chat_p_js_1.constructChatP)(entity),
66
+ order: getChatListItemOrder(lastMessage, pinned),
67
+ pinned,
68
+ lastMessage,
69
+ };
70
+ }
71
+ exports.constructChatListItem3 = constructChatListItem3;
72
+ async function constructChatListItem4(dialog, dialogs, pinnedChats, getEntity, getMessage, getStickerSetName) {
73
+ const topMessage_ = dialogs.messages.find((v) => "id" in v && v.id == dialog.top_message);
74
+ if (!topMessage_) {
75
+ (0, _0_deps_js_1.unreachable)();
76
+ }
77
+ const pinned = pinnedChats.indexOf((0, _2_tl_js_1.peerToChatId)(dialog.peer));
78
+ const lastMessage = await (0, _4_message_js_1.constructMessage)(topMessage_, getEntity, getMessage, getStickerSetName, false);
79
+ const order = getChatListItemOrder(lastMessage, pinned);
80
+ const userId = "user_id" in dialog.peer ? dialog.peer.user_id : null;
81
+ const chatId = "chat_id" in dialog.peer ? dialog.peer.chat_id : null;
82
+ const channelId = "channel_id" in dialog.peer ? dialog.peer.channel_id : null;
83
+ const chat__ = chatId != null ? dialogs.chats.find((v) => v instanceof _2_tl_js_1.types.Chat && v.id == chatId) : channelId != null ? dialogs.chats.find((v) => v instanceof _2_tl_js_1.types.Channel && v.id == channelId) : userId != null ? dialogs.users.find((v) => v instanceof _2_tl_js_1.types.User && v.id == userId) : (0, _0_deps_js_1.unreachable)();
84
+ if (!chat__) {
85
+ (0, _0_deps_js_1.unreachable)();
86
+ }
87
+ return {
88
+ chat: (0, _1_chat_p_js_1.constructChatP)(chat__),
89
+ order,
90
+ lastMessage,
91
+ pinned,
92
+ };
93
+ }
94
+ exports.constructChatListItem4 = constructChatListItem4;
@@ -31,7 +31,8 @@ import { ChatMemberUpdated } from "./3_chat_member_updated.js";
31
31
  import { Story } from "./3_story.js";
32
32
  import { Message } from "./4_message.js";
33
33
  import { CallbackQuery } from "./5_callback_query.js";
34
- import { Chat } from "./5_chat.js";
34
+ import { ChatListItem } from "./5_chat_list_item.js";
35
+ import { VideoChat } from "./0_video_chat.js";
35
36
  /**
36
37
  * A client's connection state was changed.
37
38
  *
@@ -165,14 +166,14 @@ export interface UpdateChosenInlineResult {
165
166
  */
166
167
  export interface UpdateNewChat {
167
168
  /** The newly added chat. */
168
- newChat: Chat;
169
+ newChat: ChatListItem;
169
170
  }
170
171
  /**
171
172
  * A chat in the chat list was edited. User-only.
172
173
  * @unlisted
173
174
  */
174
175
  export interface UpdateEditedChat {
175
- editedChat: Chat;
176
+ editedChat: ChatListItem;
176
177
  }
177
178
  /**
178
179
  * A chat was removed from the chat list. User-only.
@@ -242,6 +243,13 @@ export interface UpdateNewStory {
242
243
  export interface UpdateBusinessConnection {
243
244
  businessConnection: BusinessConnection;
244
245
  }
246
+ /**
247
+ * A video chat was started, scheduled, or ended.
248
+ * @unlisted
249
+ */
250
+ export interface UpdateVideoChat {
251
+ videoChat: VideoChat;
252
+ }
245
253
  /** @unlisted */
246
254
  export interface UpdateMap {
247
255
  message: UpdateNewMessage;
@@ -263,8 +271,9 @@ export interface UpdateMap {
263
271
  deletedStory: UpdateDeletedStory;
264
272
  story: UpdateNewStory;
265
273
  businessConnection: UpdateBusinessConnection;
274
+ videoChat: UpdateVideoChat;
266
275
  }
267
276
  /** @unlisted */
268
- export type UpdateIntersection<T> = T & Partial<UpdateConnectionState & UpdateAuthorizationState & UpdateNewMessage & UpdateEditedMessage & UpdateDeletedMessages & UpdateCallbackQuery & UpdateInlineQuery & UpdateChosenInlineResult & UpdateNewChat & UpdateEditedChat & UpdateDeletedChat & UpdateMessageInteractions & UpdateMessageReactionCount & UpdateMessageReactions & UpdateChatMember & UpdateMyChatMember & UpdateDeletedStory & UpdateNewStory & UpdateBusinessConnection>;
277
+ export type UpdateIntersection<T> = T & Partial<UpdateConnectionState & UpdateAuthorizationState & UpdateNewMessage & UpdateEditedMessage & UpdateDeletedMessages & UpdateCallbackQuery & UpdateInlineQuery & UpdateChosenInlineResult & UpdateNewChat & UpdateEditedChat & UpdateDeletedChat & UpdateMessageInteractions & UpdateMessageReactionCount & UpdateMessageReactions & UpdateChatMember & UpdateMyChatMember & UpdateDeletedStory & UpdateNewStory & UpdateBusinessConnection & UpdateVideoChat>;
269
278
  /** An incoming update. */
270
- export type Update = UpdateConnectionState | UpdateAuthorizationState | UpdateNewMessage | UpdateEditedMessage | UpdateDeletedMessages | UpdateCallbackQuery | UpdateInlineQuery | UpdateChosenInlineResult | UpdateNewChat | UpdateEditedChat | UpdateDeletedChat | UpdateMessageInteractions | UpdateMessageReactionCount | UpdateMessageReactions | UpdateChatMember | UpdateMyChatMember | UpdateDeletedStory | UpdateNewStory | UpdateBusinessConnection;
279
+ export type Update = UpdateConnectionState | UpdateAuthorizationState | UpdateNewMessage | UpdateEditedMessage | UpdateDeletedMessages | UpdateCallbackQuery | UpdateInlineQuery | UpdateChosenInlineResult | UpdateNewChat | UpdateEditedChat | UpdateDeletedChat | UpdateMessageInteractions | UpdateMessageReactionCount | UpdateMessageReactions | UpdateChatMember | UpdateMyChatMember | UpdateDeletedStory | UpdateNewStory | UpdateBusinessConnection | UpdateVideoChat;
@@ -110,6 +110,7 @@ type FileLocation = {
110
110
  id: bigint;
111
111
  accessHash: bigint;
112
112
  };
113
+ /** @unlisted */
113
114
  export interface FileId {
114
115
  type: FileType;
115
116
  dcId: number;
@@ -4,5 +4,6 @@ export declare function mod(n: number, m: number): number;
4
4
  export declare function bigIntFromBuffer(buffer: Uint8Array, little?: boolean, signed?: boolean): bigint;
5
5
  export declare function getRandomBigInt(byteLength: number, little?: boolean, signed?: boolean): bigint;
6
6
  /** Get a random ID. Useful when calling API functions directly. */
7
+ export declare function getRandomId(number: true): number;
7
8
  export declare function getRandomId(): bigint;
8
9
  export declare function gcd(a: bigint, b: bigint): bigint;
@@ -86,9 +86,13 @@ function getRandomBigInt(byteLength, little, signed) {
86
86
  return bigIntFromBuffer(randomBytes, little, signed);
87
87
  }
88
88
  exports.getRandomBigInt = getRandomBigInt;
89
- /** Get a random ID. Useful when calling API functions directly. */
90
- function getRandomId() {
91
- return getRandomBigInt(8, true, true);
89
+ function getRandomId(number) {
90
+ if (number) {
91
+ return Number(getRandomBigInt(4, true, true));
92
+ }
93
+ else {
94
+ return getRandomBigInt(8, true, true);
95
+ }
92
96
  }
93
97
  exports.getRandomId = getRandomId;
94
98
  function gcd(a, b) {
@@ -1,59 +0,0 @@
1
- /**
2
- * MTKruto - Cross-runtime JavaScript library for building Telegram clients
3
- * Copyright (C) 2023-2024 Roj <https://roj.im/>
4
- *
5
- * This file is part of MTKruto.
6
- *
7
- * This program is free software: you can redistribute it and/or modify
8
- * it under the terms of the GNU Lesser General Public License as published by
9
- * the Free Software Foundation, either version 3 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public License
18
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
19
- */
20
- import { enums, types } from "../2_tl.js";
21
- import { EntityGetter } from "./_getters.js";
22
- import { ChatPhotoChat, ChatPhotoUser } from "./0_chat_photo.js";
23
- import { ChatPChannel, ChatPGroup, ChatPPrivate, ChatPSupergroup } from "./1_chat_p.js";
24
- import { StickerSetNameGetter } from "./1_sticker.js";
25
- import { Message, MessageGetter } from "./4_message.js";
26
- /** @unlisted */
27
- export interface _ChatBase {
28
- order: string;
29
- lastMessage?: Omit<Message, "replyToMessage">;
30
- pinned: number;
31
- }
32
- /** @unlisted */
33
- export interface ChatChannel extends _ChatBase, ChatPChannel {
34
- also?: string[];
35
- photo?: ChatPhotoChat;
36
- }
37
- /** @unlisted */
38
- export interface ChatSupergroup extends _ChatBase, ChatPSupergroup {
39
- also?: string[];
40
- photo?: ChatPhotoChat;
41
- }
42
- /** @unlisted */
43
- export interface ChatGroup extends _ChatBase, ChatPGroup {
44
- photo?: ChatPhotoChat;
45
- }
46
- /** @unlisted */
47
- export interface ChatPrivate extends _ChatBase, ChatPPrivate {
48
- also?: string[];
49
- photo?: ChatPhotoUser;
50
- }
51
- /**
52
- * A chat with more fields.
53
- */
54
- export type Chat = ChatChannel | ChatSupergroup | ChatGroup | ChatPrivate;
55
- export declare function getChatOrder(lastMessage: Omit<Message, "replyToMessage"> | undefined, pinned: number): string;
56
- export declare function constructChat(dialog: enums.Dialog, dialogs: types.messages.Dialogs | types.messages.DialogsSlice, pinnedChats: number[], getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<Chat>;
57
- export declare function constructChat2(entity: types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden, pinned: number, lastMessage: Omit<Message, "replyToMessage"> | undefined): Chat;
58
- export declare function constructChat3(chatId: number, pinned: number, lastMessage: Omit<Message, "replyToMessage"> | undefined, getEntity: EntityGetter): Promise<Chat | null>;
59
- export declare function constructChat4(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter): Promise<Chat | null>;