@mtkruto/node 0.0.906 → 0.0.920

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 (115) hide show
  1. package/esm/{types/utilities → client}/0_html.d.ts +1 -1
  2. package/esm/{types/utilities → client}/0_html.js +2 -2
  3. package/esm/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  4. package/esm/client/{utilities/0_message.js → 0_message.js} +10 -10
  5. package/esm/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  6. package/esm/client/{utilities/0_password.js → 0_password.js} +5 -5
  7. package/{script/client/client_abstract.d.ts → esm/client/1_client_abstract.d.ts} +6 -5
  8. package/esm/client/{client_abstract.js → 1_client_abstract.js} +10 -4
  9. package/esm/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  10. package/esm/client/{client_plain.js → 2_client_plain.js} +2 -2
  11. package/esm/client/{client.d.ts → 3_client.d.ts} +7 -5
  12. package/esm/client/{client.js → 3_client.js} +145 -83
  13. package/{script/connection/connection_web_socket.d.ts → esm/connection/1_connection_web_socket.d.ts} +1 -1
  14. package/esm/constants.d.ts +2 -2
  15. package/esm/constants.js +1 -1
  16. package/esm/deps.d.ts +1 -2
  17. package/esm/deps.js +0 -1
  18. package/esm/mod.d.ts +13 -13
  19. package/esm/mod.js +13 -13
  20. package/esm/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
  21. package/{script/storage/storage_local_storage.d.ts → esm/storage/1_storage_local_storage.d.ts} +1 -1
  22. package/esm/storage/{storage_local_storage.js → 1_storage_local_storage.js} +1 -1
  23. package/{script/storage/storage_memory.d.ts → esm/storage/1_storage_memory.d.ts} +1 -1
  24. package/esm/storage/{storage_memory.js → 1_storage_memory.js} +1 -1
  25. package/esm/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  26. package/esm/storage/{storage_session_storage.js → 1_storage_session_storage.js} +1 -1
  27. package/esm/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  28. package/esm/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  29. package/esm/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  30. package/esm/transport/{transport_abridged.js → 1_transport_abridged.js} +2 -2
  31. package/esm/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  32. package/esm/transport/{transport_intermediate.js → 1_transport_intermediate.js} +2 -2
  33. package/{script/transport/transport_provider.d.ts → esm/transport/2_transport_provider.d.ts} +2 -2
  34. package/esm/transport/{transport_provider.js → 2_transport_provider.js} +2 -2
  35. package/esm/types/!0_file_id.d.ts +77 -0
  36. package/esm/types/!0_file_id.js +325 -0
  37. package/esm/types/0_chat_photo.d.ts +7 -14
  38. package/esm/types/0_chat_photo.js +32 -17
  39. package/esm/types/1_chat.js +4 -4
  40. package/esm/types/1_user.js +2 -2
  41. package/esm/types/3_message.js +9 -0
  42. package/esm/utilities/0_base64.d.ts +2 -0
  43. package/esm/utilities/0_base64.js +9 -0
  44. package/esm/utilities/0_rle.d.ts +2 -0
  45. package/esm/utilities/0_rle.js +49 -0
  46. package/package.json +1 -1
  47. package/script/{types/utilities → client}/0_html.d.ts +1 -1
  48. package/script/{types/utilities → client}/0_html.js +2 -2
  49. package/script/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  50. package/script/client/{utilities/0_message.js → 0_message.js} +10 -10
  51. package/script/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  52. package/script/client/{utilities/0_password.js → 0_password.js} +5 -5
  53. package/script/client/0_password_test.d.ts +1 -0
  54. package/{esm/client/client_abstract.d.ts → script/client/1_client_abstract.d.ts} +6 -5
  55. package/script/client/{client_abstract.js → 1_client_abstract.js} +10 -4
  56. package/script/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  57. package/script/client/{client_plain.js → 2_client_plain.js} +3 -3
  58. package/script/client/{client.d.ts → 3_client.d.ts} +7 -5
  59. package/script/client/{client.js → 3_client.js} +146 -84
  60. package/{esm/connection/connection_web_socket.d.ts → script/connection/1_connection_web_socket.d.ts} +1 -1
  61. package/script/constants.d.ts +2 -2
  62. package/script/constants.js +1 -1
  63. package/script/deps.d.ts +1 -2
  64. package/script/deps.js +1 -3
  65. package/script/mod.d.ts +13 -13
  66. package/script/mod.js +13 -13
  67. package/script/storage/{storage.d.ts → 0_storage.d.ts} +1 -1
  68. package/{esm/storage/storage_local_storage.d.ts → script/storage/1_storage_local_storage.d.ts} +1 -1
  69. package/script/storage/{storage_local_storage.js → 1_storage_local_storage.js} +2 -2
  70. package/{esm/storage/storage_memory.d.ts → script/storage/1_storage_memory.d.ts} +1 -1
  71. package/script/storage/{storage_memory.js → 1_storage_memory.js} +2 -2
  72. package/script/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  73. package/script/storage/{storage_session_storage.js → 1_storage_session_storage.js} +2 -2
  74. package/script/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  75. package/script/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  76. package/script/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  77. package/script/transport/{transport_abridged.js → 1_transport_abridged.js} +3 -3
  78. package/script/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  79. package/script/transport/{transport_intermediate.js → 1_transport_intermediate.js} +3 -3
  80. package/{esm/transport/transport_provider.d.ts → script/transport/2_transport_provider.d.ts} +2 -2
  81. package/script/transport/{transport_provider.js → 2_transport_provider.js} +4 -4
  82. package/script/types/!0_file_id.d.ts +77 -0
  83. package/script/types/!0_file_id.js +329 -0
  84. package/script/types/0_chat_photo.d.ts +7 -14
  85. package/script/types/0_chat_photo.js +33 -18
  86. package/script/types/1_chat.js +4 -4
  87. package/script/types/1_user.js +2 -2
  88. package/script/types/3_message.js +9 -0
  89. package/script/utilities/0_base64.d.ts +2 -0
  90. package/script/utilities/0_base64.js +14 -0
  91. package/script/utilities/0_rle.d.ts +2 -0
  92. package/script/utilities/0_rle.js +54 -0
  93. package/script/utilities/0_rle_test.d.ts +1 -0
  94. package/esm/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
  95. package/esm/deps/deno.land/x/q@v0.0.1/mod.js +0 -71
  96. package/script/deps/deno.land/x/q@v0.0.1/mod.d.ts +0 -6
  97. package/script/deps/deno.land/x/q@v0.0.1/mod.js +0 -75
  98. /package/esm/client/{utilities/0_password_test.d.ts → 0_password_test.d.ts} +0 -0
  99. /package/esm/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  100. /package/esm/connection/{connection.js → 0_connection.js} +0 -0
  101. /package/esm/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  102. /package/esm/storage/{storage.js → 0_storage.js} +0 -0
  103. /package/esm/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  104. /package/esm/transport/{transport.js → 0_transport.js} +0 -0
  105. /package/esm/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  106. /package/esm/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
  107. /package/{script/client/utilities/0_password_test.d.ts → esm/utilities/0_rle_test.d.ts} +0 -0
  108. /package/script/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  109. /package/script/connection/{connection.js → 0_connection.js} +0 -0
  110. /package/script/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  111. /package/script/storage/{storage.js → 0_storage.js} +0 -0
  112. /package/script/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  113. /package/script/transport/{transport.js → 0_transport.js} +0 -0
  114. /package/script/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  115. /package/script/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultTransportProvider = void 0;
4
- const connection_web_socket_js_1 = require("../connection/connection_web_socket.js");
5
- const transport_intermediate_js_1 = require("./transport_intermediate.js");
4
+ const _1_connection_web_socket_js_1 = require("../connection/1_connection_web_socket.js");
5
+ const _1_transport_intermediate_js_1 = require("./1_transport_intermediate.js");
6
6
  const dcToNameMap = {
7
7
  "1": "pluto",
8
8
  "1-test": "pluto",
@@ -20,8 +20,8 @@ const defaultTransportProvider = ({ initialDc, wss }) => {
20
20
  dc ??= initialDc;
21
21
  wss ??= typeof location !== "undefined" && location.protocol == "http:" ? false : true;
22
22
  const url = `${wss ? "wss" : "ws"}://${dcToNameMap[dc]}${cdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
23
- const connection = new connection_web_socket_js_1.ConnectionWebSocket(url);
24
- const transport = new transport_intermediate_js_1.TransportIntermediate(connection, true);
23
+ const connection = new _1_connection_web_socket_js_1.ConnectionWebSocket(url);
24
+ const transport = new _1_transport_intermediate_js_1.TransportIntermediate(connection, true);
25
25
  const dcId = Number(dc[0]) + (dc.endsWith("-test") ? 10000 : 0) * (cdn ? -1 : 1);
26
26
  return { connection, transport, dcId };
27
27
  },
@@ -0,0 +1,77 @@
1
+ export declare enum FileType {
2
+ Thumbnail = 0,
3
+ ChatPhoto = 1,
4
+ Photo = 2,
5
+ Voice = 3,
6
+ Video = 4,
7
+ Document = 5,
8
+ Encrypted = 6,
9
+ Temp = 7,
10
+ Sticker = 8,
11
+ Audio = 9,
12
+ Animation = 10,
13
+ EncryptedThumbnail = 11,
14
+ Wallpaper = 12,
15
+ VideoNote = 13,
16
+ SecureRaw = 14,
17
+ Secure = 15,
18
+ Background = 16,
19
+ DocumentAsFile = 17
20
+ }
21
+ export declare enum ThumbnailSource {
22
+ Legacy = 0,
23
+ Thumbnail = 1,
24
+ ChatPhotoSmall = 2,
25
+ ChatPhotoBig = 3,
26
+ StickerSetThumbnail = 4
27
+ }
28
+ interface FileIDParams {
29
+ fileReference?: Uint8Array;
30
+ url?: string;
31
+ mediaId?: bigint;
32
+ accessHash?: bigint;
33
+ volumeId?: bigint;
34
+ thumbnailSource?: ThumbnailSource;
35
+ thumbnailFileType?: FileType;
36
+ thumbnailSize?: string;
37
+ secret?: bigint;
38
+ localId?: number;
39
+ chatId?: number;
40
+ chatAccessHash?: bigint;
41
+ stickerSetId?: bigint;
42
+ stickerSetAccessHash?: bigint;
43
+ }
44
+ export declare class FileID {
45
+ readonly fileType: FileType;
46
+ readonly dcId: number;
47
+ readonly params: FileIDParams;
48
+ static MAJOR: number;
49
+ static MINOR: number;
50
+ readonly major: number;
51
+ readonly minor: number;
52
+ constructor(major: number | null | undefined, minor: number | null | undefined, fileType: FileType, dcId: number, params: FileIDParams);
53
+ static decode(fileId: string): FileID;
54
+ encode(major?: number, minor?: number): string;
55
+ }
56
+ export declare enum FileUniqueType {
57
+ Web = 0,
58
+ Photo = 1,
59
+ Document = 2,
60
+ Secure = 3,
61
+ Encrypted = 4,
62
+ Temp = 5
63
+ }
64
+ interface FileUniqueParams {
65
+ url?: string;
66
+ mediaId?: bigint;
67
+ volumeId?: bigint;
68
+ localId?: number;
69
+ }
70
+ export declare class FileUniqueID {
71
+ private readonly fileUniqueType;
72
+ private readonly params;
73
+ constructor(fileUniqueType: FileUniqueType, params: FileUniqueParams);
74
+ static decode(fileId: string): FileUniqueID;
75
+ encode(): string;
76
+ }
77
+ export {};
@@ -0,0 +1,329 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileUniqueID = exports.FileUniqueType = exports.FileID = exports.ThumbnailSource = exports.FileType = void 0;
4
+ // Direct port from Pyrogram
5
+ const _0_base64_js_1 = require("../utilities/0_base64.js");
6
+ const _0_control_js_1 = require("../utilities/0_control.js");
7
+ const _0_rle_js_1 = require("../utilities/0_rle.js");
8
+ const _0_tl_raw_writer_js_1 = require("../tl/0_tl_raw_writer.js");
9
+ const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
10
+ var FileType;
11
+ (function (FileType) {
12
+ FileType[FileType["Thumbnail"] = 0] = "Thumbnail";
13
+ FileType[FileType["ChatPhoto"] = 1] = "ChatPhoto";
14
+ FileType[FileType["Photo"] = 2] = "Photo";
15
+ FileType[FileType["Voice"] = 3] = "Voice";
16
+ FileType[FileType["Video"] = 4] = "Video";
17
+ FileType[FileType["Document"] = 5] = "Document";
18
+ FileType[FileType["Encrypted"] = 6] = "Encrypted";
19
+ FileType[FileType["Temp"] = 7] = "Temp";
20
+ FileType[FileType["Sticker"] = 8] = "Sticker";
21
+ FileType[FileType["Audio"] = 9] = "Audio";
22
+ FileType[FileType["Animation"] = 10] = "Animation";
23
+ FileType[FileType["EncryptedThumbnail"] = 11] = "EncryptedThumbnail";
24
+ FileType[FileType["Wallpaper"] = 12] = "Wallpaper";
25
+ FileType[FileType["VideoNote"] = 13] = "VideoNote";
26
+ FileType[FileType["SecureRaw"] = 14] = "SecureRaw";
27
+ FileType[FileType["Secure"] = 15] = "Secure";
28
+ FileType[FileType["Background"] = 16] = "Background";
29
+ FileType[FileType["DocumentAsFile"] = 17] = "DocumentAsFile";
30
+ })(FileType = exports.FileType || (exports.FileType = {}));
31
+ const PHOTO_TYPES = [FileType.Thumbnail, FileType.ChatPhoto, FileType.Photo, FileType.EncryptedThumbnail];
32
+ const DOCUMENT_TYPES = Object.keys(FileType).map(Number).filter((v) => !isNaN(v)).filter((v) => !PHOTO_TYPES.includes(v));
33
+ var ThumbnailSource;
34
+ (function (ThumbnailSource) {
35
+ ThumbnailSource[ThumbnailSource["Legacy"] = 0] = "Legacy";
36
+ ThumbnailSource[ThumbnailSource["Thumbnail"] = 1] = "Thumbnail";
37
+ ThumbnailSource[ThumbnailSource["ChatPhotoSmall"] = 2] = "ChatPhotoSmall";
38
+ ThumbnailSource[ThumbnailSource["ChatPhotoBig"] = 3] = "ChatPhotoBig";
39
+ ThumbnailSource[ThumbnailSource["StickerSetThumbnail"] = 4] = "StickerSetThumbnail";
40
+ })(ThumbnailSource = exports.ThumbnailSource || (exports.ThumbnailSource = {}));
41
+ const WEB_LOCATION_FLAG = 1 << 24;
42
+ const FILE_REFERENCE_FLAG = 1 << 25;
43
+ class FileID {
44
+ constructor(major = FileID.MAJOR, minor = FileID.MINOR, fileType, dcId, params) {
45
+ Object.defineProperty(this, "fileType", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: fileType
50
+ });
51
+ Object.defineProperty(this, "dcId", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: dcId
56
+ });
57
+ Object.defineProperty(this, "params", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: params
62
+ });
63
+ Object.defineProperty(this, "major", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, "minor", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ if (major == null) {
76
+ this.major = FileID.MAJOR;
77
+ }
78
+ else {
79
+ this.major = major;
80
+ }
81
+ if (minor == null) {
82
+ this.minor = FileID.MINOR;
83
+ }
84
+ else {
85
+ this.minor = minor;
86
+ }
87
+ this.params.thumbnailSize ??= "";
88
+ }
89
+ static decode(fileId) {
90
+ const decoded = (0, _0_rle_js_1.rleDecode)((0, _0_base64_js_1.base64DecodeUrlSafe)(fileId));
91
+ const major = decoded[decoded.length - 1];
92
+ let minor;
93
+ let buffer;
94
+ if (major < 4) {
95
+ minor = 0;
96
+ buffer = decoded.slice(0, -1);
97
+ }
98
+ else {
99
+ minor = decoded[decoded.length - 2];
100
+ buffer = decoded.slice(0, -2);
101
+ }
102
+ const reader = new _0_tl_raw_reader_js_1.TLRawReader(buffer);
103
+ let fileType = reader.readInt32();
104
+ const dcId = reader.readInt32();
105
+ const hasWebLocation = Boolean(fileType & WEB_LOCATION_FLAG);
106
+ const hasFileReference = Boolean(fileType & FILE_REFERENCE_FLAG);
107
+ fileType &= ~WEB_LOCATION_FLAG;
108
+ fileType &= ~FILE_REFERENCE_FLAG;
109
+ if (hasWebLocation) {
110
+ const url = reader.readString();
111
+ const accessHash = reader.readInt64();
112
+ return new FileID(major, minor, fileType, dcId, { url, accessHash });
113
+ }
114
+ let fileReference = new Uint8Array();
115
+ if (hasFileReference) {
116
+ fileReference = reader.readBytes();
117
+ }
118
+ const mediaId = reader.readInt64();
119
+ const accessHash = reader.readInt64();
120
+ if (PHOTO_TYPES.includes(fileType)) {
121
+ const volumeId = reader.readInt64();
122
+ let thumbnailSource = 0;
123
+ if (major >= 4) {
124
+ thumbnailSource = reader.readInt32(false);
125
+ }
126
+ switch (thumbnailSource) {
127
+ case ThumbnailSource.Legacy: {
128
+ const secret = reader.readInt64();
129
+ const localId = reader.readInt32();
130
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, secret, localId });
131
+ }
132
+ case ThumbnailSource.Thumbnail: {
133
+ const thumbnailFileType = reader.readInt32();
134
+ const thumbnailSize = String.fromCharCode(reader.readInt32());
135
+ const localId = reader.readInt32();
136
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, thumbnailFileType, thumbnailSize, localId });
137
+ }
138
+ case ThumbnailSource.ChatPhotoSmall:
139
+ case ThumbnailSource.ChatPhotoBig: {
140
+ const chatId = Number(reader.readInt64());
141
+ const chatAccessHash = reader.readInt64();
142
+ const localId = reader.readInt32();
143
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, chatId: Number(chatId), chatAccessHash, localId });
144
+ }
145
+ case ThumbnailSource.StickerSetThumbnail: {
146
+ const stickerSetId = reader.readInt64();
147
+ const stickerSetAccessHash = reader.readInt64();
148
+ const localId = reader.readInt32();
149
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, stickerSetId, stickerSetAccessHash, localId });
150
+ }
151
+ default:
152
+ (0, _0_control_js_1.UNREACHABLE)();
153
+ }
154
+ }
155
+ else if (DOCUMENT_TYPES.includes(fileType)) {
156
+ return new FileID(minor, major, fileType, dcId, { fileReference, mediaId, accessHash });
157
+ }
158
+ else {
159
+ (0, _0_control_js_1.UNREACHABLE)();
160
+ }
161
+ }
162
+ encode(major, minor) {
163
+ major ??= this.major;
164
+ minor ??= this.minor;
165
+ const writer = new _0_tl_raw_writer_js_1.TLRawWriter();
166
+ let fileType = this.fileType;
167
+ if (this.params.url) {
168
+ fileType |= WEB_LOCATION_FLAG;
169
+ }
170
+ if (this.params.fileReference) {
171
+ fileType |= FILE_REFERENCE_FLAG;
172
+ }
173
+ writer.writeInt32(fileType);
174
+ writer.writeInt32(this.dcId);
175
+ if (this.params.url) {
176
+ writer.writeString(this.params.url);
177
+ }
178
+ if (this.params.fileReference) {
179
+ writer.writeBytes(this.params.fileReference);
180
+ }
181
+ if (this.params.mediaId == undefined || this.params.accessHash == undefined) {
182
+ (0, _0_control_js_1.UNREACHABLE)();
183
+ }
184
+ writer.writeInt64(this.params.mediaId);
185
+ writer.writeInt64(this.params.accessHash);
186
+ if (PHOTO_TYPES.includes(this.fileType)) {
187
+ if (this.params.volumeId == undefined || this.params.thumbnailSize == undefined || this.params.localId == undefined) {
188
+ (0, _0_control_js_1.UNREACHABLE)();
189
+ }
190
+ writer.writeInt64(this.params.volumeId);
191
+ if (major >= 4) {
192
+ writer.writeInt32(Number(this.params.thumbnailSource));
193
+ }
194
+ switch (this.params.thumbnailSource) {
195
+ case ThumbnailSource.Legacy:
196
+ if (this.params.secret == undefined) {
197
+ (0, _0_control_js_1.UNREACHABLE)();
198
+ }
199
+ writer.writeInt64(this.params.secret);
200
+ writer.writeInt32(this.params.localId);
201
+ break;
202
+ case ThumbnailSource.Thumbnail:
203
+ if (this.params.thumbnailFileType == undefined || this.params.thumbnailSize == undefined) {
204
+ (0, _0_control_js_1.UNREACHABLE)();
205
+ }
206
+ writer.writeInt32(Number(this.params.thumbnailFileType));
207
+ writer.writeInt32(this.params.thumbnailSize.charCodeAt(0));
208
+ writer.writeInt32(this.params.localId);
209
+ break;
210
+ case ThumbnailSource.ChatPhotoSmall:
211
+ case ThumbnailSource.ChatPhotoBig:
212
+ if (this.params.chatId == undefined || this.params.chatAccessHash == undefined) {
213
+ (0, _0_control_js_1.UNREACHABLE)();
214
+ }
215
+ writer.writeInt64(BigInt(this.params.chatId));
216
+ writer.writeInt64(this.params.chatAccessHash);
217
+ writer.writeInt32(this.params.localId);
218
+ break;
219
+ case ThumbnailSource.StickerSetThumbnail:
220
+ if (this.params.stickerSetId == undefined || this.params.stickerSetAccessHash == undefined) {
221
+ (0, _0_control_js_1.UNREACHABLE)();
222
+ }
223
+ writer.writeInt64(this.params.stickerSetId);
224
+ writer.writeInt64(this.params.stickerSetAccessHash);
225
+ writer.writeInt32(this.params.localId);
226
+ break;
227
+ default:
228
+ (0, _0_control_js_1.UNREACHABLE)();
229
+ }
230
+ }
231
+ else if (DOCUMENT_TYPES.includes(this.fileType)) {
232
+ writer.writeInt32(minor);
233
+ writer.writeInt32(major);
234
+ }
235
+ else {
236
+ (0, _0_control_js_1.UNREACHABLE)();
237
+ }
238
+ writer.write(new Uint8Array([minor, major]));
239
+ return (0, _0_base64_js_1.base64EncodeUrlSafe)((0, _0_rle_js_1.rleEncode)(writer.buffer));
240
+ }
241
+ }
242
+ Object.defineProperty(FileID, "MAJOR", {
243
+ enumerable: true,
244
+ configurable: true,
245
+ writable: true,
246
+ value: 4
247
+ });
248
+ Object.defineProperty(FileID, "MINOR", {
249
+ enumerable: true,
250
+ configurable: true,
251
+ writable: true,
252
+ value: 30
253
+ });
254
+ exports.FileID = FileID;
255
+ var FileUniqueType;
256
+ (function (FileUniqueType) {
257
+ FileUniqueType[FileUniqueType["Web"] = 0] = "Web";
258
+ FileUniqueType[FileUniqueType["Photo"] = 1] = "Photo";
259
+ FileUniqueType[FileUniqueType["Document"] = 2] = "Document";
260
+ FileUniqueType[FileUniqueType["Secure"] = 3] = "Secure";
261
+ FileUniqueType[FileUniqueType["Encrypted"] = 4] = "Encrypted";
262
+ FileUniqueType[FileUniqueType["Temp"] = 5] = "Temp";
263
+ })(FileUniqueType = exports.FileUniqueType || (exports.FileUniqueType = {}));
264
+ class FileUniqueID {
265
+ constructor(fileUniqueType, params) {
266
+ Object.defineProperty(this, "fileUniqueType", {
267
+ enumerable: true,
268
+ configurable: true,
269
+ writable: true,
270
+ value: fileUniqueType
271
+ });
272
+ Object.defineProperty(this, "params", {
273
+ enumerable: true,
274
+ configurable: true,
275
+ writable: true,
276
+ value: params
277
+ });
278
+ }
279
+ static decode(fileId) {
280
+ const reader = new _0_tl_raw_reader_js_1.TLRawReader((0, _0_rle_js_1.rleDecode)((0, _0_base64_js_1.base64DecodeUrlSafe)(fileId)));
281
+ const fileUniqueType = reader.readInt32();
282
+ switch (fileUniqueType) {
283
+ case FileUniqueType.Web: {
284
+ const url = reader.readString();
285
+ return new FileUniqueID(fileUniqueType, { url });
286
+ }
287
+ case FileUniqueType.Photo: {
288
+ const volumeId = reader.readInt64();
289
+ const localId = reader.readInt32();
290
+ return new FileUniqueID(fileUniqueType, { volumeId, localId });
291
+ }
292
+ case FileUniqueType.Document: {
293
+ const mediaId = reader.readInt64();
294
+ return new FileUniqueID(fileUniqueType, { mediaId });
295
+ }
296
+ default:
297
+ (0, _0_control_js_1.UNREACHABLE)();
298
+ }
299
+ }
300
+ encode() {
301
+ const writer = new _0_tl_raw_writer_js_1.TLRawWriter();
302
+ writer.writeInt32(this.fileUniqueType);
303
+ switch (this.fileUniqueType) {
304
+ case FileUniqueType.Web:
305
+ if (this.params.url == undefined) {
306
+ (0, _0_control_js_1.UNREACHABLE)();
307
+ }
308
+ writer.writeString(this.params.url);
309
+ break;
310
+ case FileUniqueType.Photo:
311
+ if (this.params.volumeId == undefined || this.params.localId == undefined) {
312
+ (0, _0_control_js_1.UNREACHABLE)();
313
+ }
314
+ writer.writeInt64(this.params.volumeId);
315
+ writer.writeInt32(this.params.localId);
316
+ break;
317
+ case FileUniqueType.Document:
318
+ if (this.params.mediaId == undefined) {
319
+ (0, _0_control_js_1.UNREACHABLE)();
320
+ }
321
+ writer.writeInt64(this.params.mediaId);
322
+ break;
323
+ default:
324
+ (0, _0_control_js_1.UNREACHABLE)();
325
+ }
326
+ return (0, _0_base64_js_1.base64EncodeUrlSafe)((0, _0_rle_js_1.rleEncode)(writer.buffer));
327
+ }
328
+ }
329
+ exports.FileUniqueID = FileUniqueID;
@@ -1,24 +1,17 @@
1
1
  import * as types from "../tl/2_types.js";
2
- export declare enum ChatPhotoType {
3
- Chat = "chat",
4
- User = "user"
5
- }
6
2
  export declare namespace ChatPhoto {
7
3
  interface Base {
8
- type: ChatPhotoType;
4
+ smallFileId: string;
5
+ smallFileUniqueId: string;
6
+ bigFileId: string;
7
+ bigFileUniqueId: string;
9
8
  hasVideo: boolean;
10
- photoId: bigint;
11
- strippedThumb?: Uint8Array;
12
- dcId: number;
13
9
  }
14
10
  interface User extends Base {
15
- type: ChatPhotoType;
16
11
  personal: boolean;
17
12
  }
18
- interface Chat extends Base {
19
- type: ChatPhotoType;
20
- }
13
+ type Chat = Base;
21
14
  }
22
15
  export type ChatPhoto = ChatPhoto.User | ChatPhoto.Chat;
23
- export declare function constructChatPhoto(photo: types.ChatPhoto): ChatPhoto.Chat;
24
- export declare function constructChatPhoto(photo: types.UserProfilePhoto): ChatPhoto.User;
16
+ export declare function constructChatPhoto(photo: types.ChatPhoto, chatId: number, chatAccessHash: bigint): ChatPhoto.Chat;
17
+ export declare function constructChatPhoto(photo: types.UserProfilePhoto, chatId: number, chatAccessHash: bigint): ChatPhoto.User;
@@ -23,32 +23,47 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.constructChatPhoto = exports.ChatPhotoType = void 0;
26
+ exports.constructChatPhoto = void 0;
27
27
  const types = __importStar(require("../tl/2_types.js"));
28
- var ChatPhotoType;
29
- (function (ChatPhotoType) {
30
- ChatPhotoType["Chat"] = "chat";
31
- ChatPhotoType["User"] = "user";
32
- })(ChatPhotoType = exports.ChatPhotoType || (exports.ChatPhotoType = {}));
33
- function constructChatPhoto(photo) {
34
- const { hasVideo = false, photoId, strippedThumb, dcId } = photo;
28
+ const _0_file_id_js_1 = require("./!0_file_id.js");
29
+ function constructChatPhoto(photo, chatId, chatAccessHash) {
30
+ const smallFileId = new _0_file_id_js_1.FileID(null, null, _0_file_id_js_1.FileType.ChatPhoto, photo.dcId, {
31
+ mediaId: photo.photoId,
32
+ thumbnailSource: _0_file_id_js_1.ThumbnailSource.ChatPhotoSmall,
33
+ chatId,
34
+ chatAccessHash,
35
+ accessHash: 0n,
36
+ volumeId: 0n,
37
+ localId: 0,
38
+ }).encode();
39
+ const smallFileUniqueId = new _0_file_id_js_1.FileUniqueID(_0_file_id_js_1.FileUniqueType.Document, { mediaId: photo.photoId }).encode();
40
+ const bigFileId = new _0_file_id_js_1.FileID(null, null, _0_file_id_js_1.FileType.ChatPhoto, photo.dcId, {
41
+ mediaId: photo.photoId,
42
+ thumbnailSource: _0_file_id_js_1.ThumbnailSource.ChatPhotoBig,
43
+ chatId,
44
+ chatAccessHash,
45
+ accessHash: 0n,
46
+ volumeId: 0n,
47
+ localId: 0,
48
+ }).encode();
49
+ const bigFileUniqueId = new _0_file_id_js_1.FileUniqueID(_0_file_id_js_1.FileUniqueType.Document, { mediaId: photo.photoId }).encode();
35
50
  if (photo instanceof types.ChatPhoto) {
36
51
  return {
37
- type: ChatPhotoType.Chat,
38
- hasVideo,
39
- photoId,
40
- strippedThumb,
41
- dcId,
52
+ smallFileId,
53
+ smallFileUniqueId,
54
+ bigFileId,
55
+ bigFileUniqueId,
56
+ hasVideo: photo.hasVideo || false,
42
57
  };
43
58
  }
44
59
  else {
45
60
  return {
46
- type: ChatPhotoType.User,
47
61
  personal: photo.personal || false,
48
- hasVideo,
49
- photoId,
50
- strippedThumb,
51
- dcId,
62
+ smallFileId,
63
+ smallFileUniqueId,
64
+ bigFileId,
65
+ bigFileUniqueId,
66
+ hasVideo: photo.hasVideo || false,
52
67
  };
53
68
  }
54
69
  }
@@ -29,8 +29,8 @@ const _0_control_js_1 = require("../utilities/0_control.js");
29
29
  const _0_object_js_1 = require("../utilities/0_object.js");
30
30
  const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
31
31
  const types = __importStar(require("../tl/2_types.js"));
32
+ const _0_id_color_js_1 = require("./!0_id_color.js");
32
33
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
33
- const _0_id_color_js_1 = require("./utilities/0_id_color.js");
34
34
  var ChatType;
35
35
  (function (ChatType) {
36
36
  ChatType["Private"] = "private";
@@ -58,7 +58,7 @@ function constructChat(chat) {
58
58
  chat_.restrictionReason = chat.restrictionReason?.map((v) => v[_1_tl_object_js_1.as](types.RestrictionReason));
59
59
  }
60
60
  if (chat.photo instanceof types.UserProfilePhoto) {
61
- chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo);
61
+ chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo, chat_.id, chat.accessHash ?? 0n);
62
62
  }
63
63
  return (0, _0_object_js_1.cleanObject)(chat_);
64
64
  }
@@ -72,7 +72,7 @@ function constructChat(chat) {
72
72
  isCreator: chat.creator || false,
73
73
  };
74
74
  if (chat.photo instanceof types.ChatPhoto) {
75
- chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo);
75
+ chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo, chat_.id, 0n);
76
76
  }
77
77
  return (0, _0_object_js_1.cleanObject)(chat_);
78
78
  }
@@ -112,7 +112,7 @@ function constructChat(chat) {
112
112
  chat_.restrictionReason = chat.restrictionReason?.map((v) => v[_1_tl_object_js_1.as](types.RestrictionReason));
113
113
  }
114
114
  if (chat.photo instanceof types.ChatPhoto) {
115
- chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo);
115
+ chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo, chat_.id, chat.accessHash ?? 0n);
116
116
  }
117
117
  return (0, _0_object_js_1.cleanObject)(chat_);
118
118
  }
@@ -27,8 +27,8 @@ exports.constructUser = void 0;
27
27
  const _0_object_js_1 = require("../utilities/0_object.js");
28
28
  const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
29
29
  const types = __importStar(require("../tl/2_types.js"));
30
+ const _0_id_color_js_1 = require("./!0_id_color.js");
30
31
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
31
- const _0_id_color_js_1 = require("./utilities/0_id_color.js");
32
32
  function constructUser(user_) {
33
33
  const id = Number(user_.id);
34
34
  const user = {
@@ -48,7 +48,7 @@ function constructUser(user_) {
48
48
  addedToAttachmentMenu: user_.attachMenuEnabled || false,
49
49
  };
50
50
  if (user_.photo instanceof types.UserProfilePhoto) {
51
- user.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(user_.photo);
51
+ user.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(user_.photo, user.id, user_.accessHash ?? 0n);
52
52
  }
53
53
  return (0, _0_object_js_1.cleanObject)(user);
54
54
  }
@@ -90,6 +90,15 @@ async function constructMessage(message_, getEntity, getMessage) {
90
90
  (0, _0_control_js_1.UNREACHABLE)();
91
91
  }
92
92
  }
93
+ else if (message_.fromId instanceof types.PeerChannel) {
94
+ const entity = await getEntity(message_.fromId);
95
+ if (entity) {
96
+ message.senderChat = (0, _1_chat_js_1.constructChat)(entity);
97
+ }
98
+ else {
99
+ (0, _0_control_js_1.UNREACHABLE)();
100
+ }
101
+ }
93
102
  if (message_.message) {
94
103
  if (message_.media == undefined) {
95
104
  message.text = message_.message;
@@ -0,0 +1,2 @@
1
+ export declare function base64EncodeUrlSafe(data: ArrayBuffer | string): string;
2
+ export declare function base64DecodeUrlSafe(data: string): Uint8Array;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.base64DecodeUrlSafe = exports.base64EncodeUrlSafe = void 0;
4
+ const deps_js_1 = require("../deps.js");
5
+ // TODO: test
6
+ function base64EncodeUrlSafe(data) {
7
+ return (0, deps_js_1.base64Encode)(data).replace(/=*$/, "").replaceAll("+", "-").replaceAll("/", "_");
8
+ }
9
+ exports.base64EncodeUrlSafe = base64EncodeUrlSafe;
10
+ function base64DecodeUrlSafe(data) {
11
+ data = data.replaceAll("_", "/").replaceAll("-", "+");
12
+ return (0, deps_js_1.base64Decode)(data + "=".repeat(data.length % 4));
13
+ }
14
+ exports.base64DecodeUrlSafe = base64DecodeUrlSafe;
@@ -0,0 +1,2 @@
1
+ export declare function rleEncode(s: Uint8Array): Uint8Array;
2
+ export declare function rleDecode(s: Uint8Array): Uint8Array;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rleDecode = exports.rleEncode = void 0;
4
+ function rleEncode(s) {
5
+ const r = new Array();
6
+ let n = 0;
7
+ for (const b of s) {
8
+ if (!b) {
9
+ if (n == 255) {
10
+ r.push(0);
11
+ r.push(n);
12
+ n = 1;
13
+ }
14
+ else {
15
+ n++;
16
+ }
17
+ }
18
+ else {
19
+ if (n) {
20
+ r.push(0);
21
+ r.push(n);
22
+ n = 0;
23
+ }
24
+ r.push(b);
25
+ }
26
+ }
27
+ if (n) {
28
+ r.push(0);
29
+ r.push(n);
30
+ }
31
+ return new Uint8Array(r);
32
+ }
33
+ exports.rleEncode = rleEncode;
34
+ function rleDecode(s) {
35
+ const r = new Array();
36
+ let z = false;
37
+ for (const b of s) {
38
+ if (!b) {
39
+ z = true;
40
+ continue;
41
+ }
42
+ if (z) {
43
+ for (let i = 0; i < b; i++) {
44
+ r.push(0);
45
+ }
46
+ z = false;
47
+ }
48
+ else {
49
+ r.push(b);
50
+ }
51
+ }
52
+ return new Uint8Array(r);
53
+ }
54
+ exports.rleDecode = rleDecode;