@mtkruto/node 0.0.905 → 0.0.910

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 (99) 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/esm/client/{client_abstract.d.ts → 1_client_abstract.d.ts} +5 -5
  8. package/esm/client/{client_abstract.js → 1_client_abstract.js} +1 -1
  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} +3 -3
  12. package/esm/client/{client.js → 3_client.js} +7 -7
  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/mod.d.ts +13 -13
  17. package/esm/mod.js +13 -13
  18. package/{script/storage/storage.d.ts → esm/storage/0_storage.d.ts} +1 -1
  19. package/{script/storage/storage_local_storage.d.ts → esm/storage/1_storage_local_storage.d.ts} +1 -1
  20. package/esm/storage/{storage_local_storage.js → 1_storage_local_storage.js} +1 -1
  21. package/{script/storage/storage_memory.d.ts → esm/storage/1_storage_memory.d.ts} +1 -1
  22. package/esm/storage/{storage_memory.js → 1_storage_memory.js} +1 -1
  23. package/esm/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  24. package/esm/storage/{storage_session_storage.js → 1_storage_session_storage.js} +1 -1
  25. package/esm/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  26. package/esm/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  27. package/esm/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  28. package/esm/transport/{transport_abridged.js → 1_transport_abridged.js} +2 -2
  29. package/esm/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  30. package/esm/transport/{transport_intermediate.js → 1_transport_intermediate.js} +2 -2
  31. package/{script/transport/transport_provider.d.ts → esm/transport/2_transport_provider.d.ts} +2 -2
  32. package/esm/transport/{transport_provider.js → 2_transport_provider.js} +2 -2
  33. package/esm/types/!0_file_id.d.ts +77 -0
  34. package/esm/types/!0_file_id.js +372 -0
  35. package/esm/types/0_chat_photo.d.ts +7 -15
  36. package/esm/types/0_chat_photo.js +30 -17
  37. package/esm/types/1_chat.d.ts +1 -0
  38. package/esm/types/1_chat.js +25 -6
  39. package/esm/types/1_user.js +2 -2
  40. package/esm/types/3_message.js +12 -0
  41. package/package.json +1 -1
  42. package/script/{types/utilities → client}/0_html.d.ts +1 -1
  43. package/script/{types/utilities → client}/0_html.js +2 -2
  44. package/script/client/{utilities/0_message.d.ts → 0_message.d.ts} +2 -2
  45. package/script/client/{utilities/0_message.js → 0_message.js} +10 -10
  46. package/script/client/{utilities/0_password.d.ts → 0_password.d.ts} +2 -2
  47. package/script/client/{utilities/0_password.js → 0_password.js} +5 -5
  48. package/script/client/{client_abstract.d.ts → 1_client_abstract.d.ts} +5 -5
  49. package/script/client/{client_abstract.js → 1_client_abstract.js} +2 -2
  50. package/script/client/{client_plain.d.ts → 2_client_plain.d.ts} +1 -1
  51. package/script/client/{client_plain.js → 2_client_plain.js} +3 -3
  52. package/script/client/{client.d.ts → 3_client.d.ts} +3 -3
  53. package/script/client/{client.js → 3_client.js} +10 -10
  54. package/{esm/connection/connection_web_socket.d.ts → script/connection/1_connection_web_socket.d.ts} +1 -1
  55. package/script/constants.d.ts +2 -2
  56. package/script/constants.js +1 -1
  57. package/script/mod.d.ts +13 -13
  58. package/script/mod.js +13 -13
  59. package/{esm/storage/storage.d.ts → script/storage/0_storage.d.ts} +1 -1
  60. package/{esm/storage/storage_local_storage.d.ts → script/storage/1_storage_local_storage.d.ts} +1 -1
  61. package/script/storage/{storage_local_storage.js → 1_storage_local_storage.js} +2 -2
  62. package/{esm/storage/storage_memory.d.ts → script/storage/1_storage_memory.d.ts} +1 -1
  63. package/script/storage/{storage_memory.js → 1_storage_memory.js} +2 -2
  64. package/script/storage/{storage_session_storage.d.ts → 1_storage_session_storage.d.ts} +1 -1
  65. package/script/storage/{storage_session_storage.js → 1_storage_session_storage.js} +2 -2
  66. package/script/transport/{utilities/0_obfuscation.d.ts → 0_obfuscation.d.ts} +2 -2
  67. package/script/transport/{utilities/0_obfuscation.js → 0_obfuscation.js} +3 -3
  68. package/script/transport/{transport_abridged.d.ts → 1_transport_abridged.d.ts} +2 -2
  69. package/script/transport/{transport_abridged.js → 1_transport_abridged.js} +3 -3
  70. package/script/transport/{transport_intermediate.d.ts → 1_transport_intermediate.d.ts} +2 -2
  71. package/script/transport/{transport_intermediate.js → 1_transport_intermediate.js} +3 -3
  72. package/{esm/transport/transport_provider.d.ts → script/transport/2_transport_provider.d.ts} +2 -2
  73. package/script/transport/{transport_provider.js → 2_transport_provider.js} +4 -4
  74. package/script/types/!0_file_id.d.ts +77 -0
  75. package/script/types/!0_file_id.js +376 -0
  76. package/script/types/0_chat_photo.d.ts +7 -15
  77. package/script/types/0_chat_photo.js +31 -18
  78. package/script/types/1_chat.d.ts +1 -0
  79. package/script/types/1_chat.js +25 -6
  80. package/script/types/1_user.js +2 -2
  81. package/script/types/3_message.js +12 -0
  82. /package/esm/client/{utilities/0_password_test.d.ts → 0_password_test.d.ts} +0 -0
  83. /package/esm/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  84. /package/esm/connection/{connection.js → 0_connection.js} +0 -0
  85. /package/esm/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  86. /package/esm/storage/{storage.js → 0_storage.js} +0 -0
  87. /package/esm/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  88. /package/esm/transport/{transport.js → 0_transport.js} +0 -0
  89. /package/esm/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  90. /package/esm/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
  91. /package/script/client/{utilities/0_password_test.d.ts → 0_password_test.d.ts} +0 -0
  92. /package/script/connection/{connection.d.ts → 0_connection.d.ts} +0 -0
  93. /package/script/connection/{connection.js → 0_connection.js} +0 -0
  94. /package/script/connection/{connection_web_socket.js → 1_connection_web_socket.js} +0 -0
  95. /package/script/storage/{storage.js → 0_storage.js} +0 -0
  96. /package/script/transport/{transport.d.ts → 0_transport.d.ts} +0 -0
  97. /package/script/transport/{transport.js → 0_transport.js} +0 -0
  98. /package/script/types/{utilities/0_id_color.d.ts → !0_id_color.d.ts} +0 -0
  99. /package/script/types/{utilities/0_id_color.js → !0_id_color.js} +0 -0
@@ -0,0 +1,372 @@
1
+ // Direct port from Pyrogram
2
+ import { base64Decode as base64Decode_, base64Encode as base64Encode_ } from "../deps.js";
3
+ import { UNREACHABLE } from "../utilities/0_control.js";
4
+ import { TLRawWriter } from "../tl/0_tl_raw_writer.js";
5
+ import { TLRawReader } from "../tl/0_tl_raw_reader.js";
6
+ function base64Encode(data) {
7
+ return base64Encode_(data).replace(/=*$/, "");
8
+ }
9
+ function base64Decode(data) {
10
+ return base64Decode_(data + "=".repeat(-data.length % 4));
11
+ }
12
+ export var FileType;
13
+ (function (FileType) {
14
+ FileType[FileType["Thumbnail"] = 0] = "Thumbnail";
15
+ FileType[FileType["ChatPhoto"] = 1] = "ChatPhoto";
16
+ FileType[FileType["Photo"] = 2] = "Photo";
17
+ FileType[FileType["Voice"] = 3] = "Voice";
18
+ FileType[FileType["Video"] = 4] = "Video";
19
+ FileType[FileType["Document"] = 5] = "Document";
20
+ FileType[FileType["Encrypted"] = 6] = "Encrypted";
21
+ FileType[FileType["Temp"] = 7] = "Temp";
22
+ FileType[FileType["Sticker"] = 8] = "Sticker";
23
+ FileType[FileType["Audio"] = 9] = "Audio";
24
+ FileType[FileType["Animation"] = 10] = "Animation";
25
+ FileType[FileType["EncryptedThumbnail"] = 11] = "EncryptedThumbnail";
26
+ FileType[FileType["Wallpaper"] = 12] = "Wallpaper";
27
+ FileType[FileType["VideoNote"] = 13] = "VideoNote";
28
+ FileType[FileType["SecureRaw"] = 14] = "SecureRaw";
29
+ FileType[FileType["Secure"] = 15] = "Secure";
30
+ FileType[FileType["Background"] = 16] = "Background";
31
+ FileType[FileType["DocumentAsFile"] = 17] = "DocumentAsFile";
32
+ })(FileType || (FileType = {}));
33
+ const PHOTO_TYPES = [FileType.Thumbnail, FileType.ChatPhoto, FileType.Photo, FileType.EncryptedThumbnail];
34
+ const DOCUMENT_TYPES = Object.keys(FileType).map(Number).filter((v) => !isNaN(v)).filter((v) => !PHOTO_TYPES.includes(v));
35
+ export var ThumbnailSource;
36
+ (function (ThumbnailSource) {
37
+ ThumbnailSource[ThumbnailSource["Legacy"] = 0] = "Legacy";
38
+ ThumbnailSource[ThumbnailSource["Thumbnail"] = 1] = "Thumbnail";
39
+ ThumbnailSource[ThumbnailSource["ChatPhotoSmall"] = 2] = "ChatPhotoSmall";
40
+ ThumbnailSource[ThumbnailSource["ChatPhotoBig"] = 3] = "ChatPhotoBig";
41
+ ThumbnailSource[ThumbnailSource["StickerSetThumbnail"] = 4] = "StickerSetThumbnail";
42
+ })(ThumbnailSource || (ThumbnailSource = {}));
43
+ const WEB_LOCATION_FLAG = 1 << 24;
44
+ const FILE_REFERENCE_FLAG = 1 << 25;
45
+ function rleEncode(s) {
46
+ const r = new Array();
47
+ let n = 0;
48
+ for (const b of s) {
49
+ if (!b) {
50
+ n++;
51
+ }
52
+ else {
53
+ if (n) {
54
+ r.push(0);
55
+ r.push(n);
56
+ n = 0;
57
+ }
58
+ r.push(b);
59
+ }
60
+ }
61
+ if (n) {
62
+ r.push(0);
63
+ r.push(n);
64
+ }
65
+ return new Uint8Array(r);
66
+ }
67
+ function rleDecode(s) {
68
+ const r = new Array();
69
+ let z = false;
70
+ for (const b of s) {
71
+ if (!b) {
72
+ z = true;
73
+ continue;
74
+ }
75
+ if (z) {
76
+ for (let i = 0; i < b; i++) {
77
+ r.push(0);
78
+ }
79
+ z = false;
80
+ }
81
+ else {
82
+ r.push(b);
83
+ }
84
+ }
85
+ return new Uint8Array(r);
86
+ }
87
+ class FileID {
88
+ constructor(major = FileID.MAJOR, minor = FileID.MINOR, fileType, dcId, params) {
89
+ Object.defineProperty(this, "fileType", {
90
+ enumerable: true,
91
+ configurable: true,
92
+ writable: true,
93
+ value: fileType
94
+ });
95
+ Object.defineProperty(this, "dcId", {
96
+ enumerable: true,
97
+ configurable: true,
98
+ writable: true,
99
+ value: dcId
100
+ });
101
+ Object.defineProperty(this, "params", {
102
+ enumerable: true,
103
+ configurable: true,
104
+ writable: true,
105
+ value: params
106
+ });
107
+ Object.defineProperty(this, "major", {
108
+ enumerable: true,
109
+ configurable: true,
110
+ writable: true,
111
+ value: void 0
112
+ });
113
+ Object.defineProperty(this, "minor", {
114
+ enumerable: true,
115
+ configurable: true,
116
+ writable: true,
117
+ value: void 0
118
+ });
119
+ if (major == null) {
120
+ this.major = FileID.MAJOR;
121
+ }
122
+ else {
123
+ this.major = major;
124
+ }
125
+ if (minor == null) {
126
+ this.minor = FileID.MINOR;
127
+ }
128
+ else {
129
+ this.minor = minor;
130
+ }
131
+ this.params.thumbnailSize ??= "";
132
+ }
133
+ static decode(fileId) {
134
+ const decoded = rleDecode(base64Decode(fileId));
135
+ const major = decoded[decoded.length - 1];
136
+ let minor;
137
+ let buffer;
138
+ if (major < 4) {
139
+ minor = 0;
140
+ buffer = decoded.slice(0, -1);
141
+ }
142
+ else {
143
+ minor = decoded[decoded.length - 2];
144
+ buffer = decoded.slice(0, -2);
145
+ }
146
+ const reader = new TLRawReader(buffer);
147
+ let fileType = reader.readInt32();
148
+ const dcId = reader.readInt32();
149
+ const hasWebLocation = Boolean(fileType & WEB_LOCATION_FLAG);
150
+ const hasFileReference = Boolean(fileType & FILE_REFERENCE_FLAG);
151
+ fileType &= ~WEB_LOCATION_FLAG;
152
+ fileType &= ~FILE_REFERENCE_FLAG;
153
+ if (hasWebLocation) {
154
+ const url = reader.readString();
155
+ const accessHash = reader.readInt64();
156
+ return new FileID(major, minor, fileType, dcId, { url, accessHash });
157
+ }
158
+ let fileReference = new Uint8Array();
159
+ if (hasFileReference) {
160
+ fileReference = reader.readBytes();
161
+ }
162
+ const mediaId = reader.readInt64();
163
+ const accessHash = reader.readInt64();
164
+ if (PHOTO_TYPES.includes(fileType)) {
165
+ const volumeId = reader.readInt64();
166
+ let thumbnailSource = 0;
167
+ if (major >= 4) {
168
+ thumbnailSource = reader.readInt32();
169
+ }
170
+ switch (thumbnailSource) {
171
+ case ThumbnailSource.Legacy: {
172
+ const secret = reader.readInt64();
173
+ const localId = reader.readInt32();
174
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, secret, localId });
175
+ }
176
+ case ThumbnailSource.Thumbnail: {
177
+ const thumbnailFileType = reader.readInt32();
178
+ const thumbnailSize = String.fromCharCode(reader.readInt32());
179
+ const localId = reader.readInt32();
180
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, thumbnailFileType, thumbnailSize, localId });
181
+ }
182
+ case ThumbnailSource.ChatPhotoSmall:
183
+ case ThumbnailSource.ChatPhotoBig: {
184
+ const chatId = reader.readInt64();
185
+ const chatAccessHash = reader.readInt64();
186
+ const localId = reader.readInt32();
187
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, chatId, chatAccessHash, localId });
188
+ }
189
+ case ThumbnailSource.StickerSetThumbnail: {
190
+ const stickerSetId = reader.readInt64();
191
+ const stickerSetAccessHash = reader.readInt64();
192
+ const localId = reader.readInt32();
193
+ return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, stickerSetId, stickerSetAccessHash, localId });
194
+ }
195
+ default:
196
+ UNREACHABLE();
197
+ }
198
+ }
199
+ else if (DOCUMENT_TYPES.includes(fileType)) {
200
+ return new FileID(minor, major, fileType, dcId, { fileReference, mediaId, accessHash });
201
+ }
202
+ else {
203
+ UNREACHABLE();
204
+ }
205
+ }
206
+ encode(major, minor) {
207
+ major ??= this.major;
208
+ minor ??= this.minor;
209
+ const writer = new TLRawWriter();
210
+ let fileType = this.fileType;
211
+ if (this.params.url) {
212
+ fileType |= WEB_LOCATION_FLAG;
213
+ }
214
+ if (this.params.fileReference) {
215
+ fileType |= FILE_REFERENCE_FLAG;
216
+ }
217
+ writer.writeInt32(fileType);
218
+ writer.writeInt32(this.dcId);
219
+ if (this.params.url) {
220
+ writer.writeString(this.params.url);
221
+ }
222
+ if (this.params.fileReference) {
223
+ writer.writeBytes(this.params.fileReference);
224
+ }
225
+ if (this.params.mediaId == undefined || this.params.accessHash == undefined) {
226
+ UNREACHABLE();
227
+ }
228
+ writer.writeInt64(this.params.mediaId);
229
+ writer.writeInt64(this.params.accessHash);
230
+ if (PHOTO_TYPES.includes(this.fileType)) {
231
+ if (this.params.volumeId == undefined || this.params.thumbnailSize == undefined || this.params.localId == undefined) {
232
+ UNREACHABLE();
233
+ }
234
+ writer.writeInt64(this.params.volumeId);
235
+ if (major > 4) {
236
+ writer.writeInt32(Number(this.params.thumbnailSource));
237
+ }
238
+ switch (this.params.thumbnailSource) {
239
+ case ThumbnailSource.Legacy:
240
+ if (this.params.secret == undefined) {
241
+ UNREACHABLE();
242
+ }
243
+ writer.writeInt64(this.params.secret);
244
+ writer.writeInt32(this.params.localId);
245
+ break;
246
+ case ThumbnailSource.Thumbnail:
247
+ if (this.params.thumbnailFileType == undefined || this.params.thumbnailSize == undefined) {
248
+ UNREACHABLE();
249
+ }
250
+ writer.writeInt32(Number(this.params.thumbnailFileType));
251
+ writer.writeInt32(this.params.thumbnailSize.charCodeAt(0));
252
+ writer.writeInt32(this.params.localId);
253
+ break;
254
+ case ThumbnailSource.ChatPhotoSmall:
255
+ case ThumbnailSource.ChatPhotoBig:
256
+ if (this.params.chatId == undefined || this.params.chatAccessHash == undefined) {
257
+ UNREACHABLE();
258
+ }
259
+ writer.writeInt64(this.params.chatId);
260
+ writer.writeInt64(this.params.chatAccessHash);
261
+ writer.writeInt32(this.params.localId);
262
+ break;
263
+ case ThumbnailSource.StickerSetThumbnail:
264
+ if (this.params.stickerSetId == undefined || this.params.stickerSetAccessHash == undefined) {
265
+ UNREACHABLE();
266
+ }
267
+ writer.writeInt64(this.params.stickerSetId);
268
+ writer.writeInt64(this.params.stickerSetAccessHash);
269
+ writer.writeInt32(this.params.localId);
270
+ break;
271
+ default:
272
+ UNREACHABLE();
273
+ }
274
+ }
275
+ else if (DOCUMENT_TYPES.includes(this.fileType)) {
276
+ writer.writeInt32(minor);
277
+ writer.writeInt32(major);
278
+ }
279
+ else {
280
+ UNREACHABLE();
281
+ }
282
+ writer.write(new Uint8Array([minor, major]));
283
+ return base64Encode(rleEncode(writer.buffer));
284
+ }
285
+ }
286
+ Object.defineProperty(FileID, "MAJOR", {
287
+ enumerable: true,
288
+ configurable: true,
289
+ writable: true,
290
+ value: 4
291
+ });
292
+ Object.defineProperty(FileID, "MINOR", {
293
+ enumerable: true,
294
+ configurable: true,
295
+ writable: true,
296
+ value: 30
297
+ });
298
+ export { FileID };
299
+ export var FileUniqueType;
300
+ (function (FileUniqueType) {
301
+ FileUniqueType[FileUniqueType["Web"] = 0] = "Web";
302
+ FileUniqueType[FileUniqueType["Photo"] = 1] = "Photo";
303
+ FileUniqueType[FileUniqueType["Document"] = 2] = "Document";
304
+ FileUniqueType[FileUniqueType["Secure"] = 3] = "Secure";
305
+ FileUniqueType[FileUniqueType["Encrypted"] = 4] = "Encrypted";
306
+ FileUniqueType[FileUniqueType["Temp"] = 5] = "Temp";
307
+ })(FileUniqueType || (FileUniqueType = {}));
308
+ export class FileUniqueID {
309
+ constructor(fileUniqueType, params) {
310
+ Object.defineProperty(this, "fileUniqueType", {
311
+ enumerable: true,
312
+ configurable: true,
313
+ writable: true,
314
+ value: fileUniqueType
315
+ });
316
+ Object.defineProperty(this, "params", {
317
+ enumerable: true,
318
+ configurable: true,
319
+ writable: true,
320
+ value: params
321
+ });
322
+ }
323
+ static decode(fileId) {
324
+ const reader = new TLRawReader(rleDecode(base64Decode(fileId)));
325
+ const fileUniqueType = reader.readInt32();
326
+ switch (fileUniqueType) {
327
+ case FileUniqueType.Web: {
328
+ const url = reader.readString();
329
+ return new FileUniqueID(fileUniqueType, { url });
330
+ }
331
+ case FileUniqueType.Photo: {
332
+ const volumeId = reader.readInt64();
333
+ const localId = reader.readInt32();
334
+ return new FileUniqueID(fileUniqueType, { volumeId, localId });
335
+ }
336
+ case FileUniqueType.Document: {
337
+ const mediaId = reader.readInt64();
338
+ return new FileUniqueID(fileUniqueType, { mediaId });
339
+ }
340
+ default:
341
+ UNREACHABLE();
342
+ }
343
+ }
344
+ encode() {
345
+ const writer = new TLRawWriter();
346
+ writer.writeInt32(this.fileUniqueType);
347
+ switch (this.fileUniqueType) {
348
+ case FileUniqueType.Web:
349
+ if (this.params.url == undefined) {
350
+ UNREACHABLE();
351
+ }
352
+ writer.writeString(this.params.url);
353
+ break;
354
+ case FileUniqueType.Photo:
355
+ if (this.params.volumeId == undefined || this.params.localId == undefined) {
356
+ UNREACHABLE();
357
+ }
358
+ writer.writeInt64(this.params.volumeId);
359
+ writer.writeInt32(this.params.localId);
360
+ break;
361
+ case FileUniqueType.Document:
362
+ if (this.params.mediaId == undefined) {
363
+ UNREACHABLE();
364
+ }
365
+ writer.writeInt64(this.params.mediaId);
366
+ break;
367
+ default:
368
+ UNREACHABLE();
369
+ }
370
+ return base64Encode(rleEncode(writer.buffer));
371
+ }
372
+ }
@@ -1,24 +1,16 @@
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;
9
- hasVideo: boolean;
10
- photoId: bigint;
11
- strippedThumb?: Uint8Array;
12
- dcId: number;
4
+ smallFileId: string;
5
+ smallFileUniqueId: string;
6
+ bigFileId: string;
7
+ bigFileUniqueId: string;
13
8
  }
14
9
  interface User extends Base {
15
- type: ChatPhotoType;
16
10
  personal: boolean;
17
11
  }
18
- interface Chat extends Base {
19
- type: ChatPhotoType;
20
- }
12
+ type Chat = Base;
21
13
  }
22
14
  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;
15
+ export declare function constructChatPhoto(photo: types.ChatPhoto, chatId: number, chatAccessHash: bigint): ChatPhoto.Chat;
16
+ export declare function constructChatPhoto(photo: types.UserProfilePhoto, chatId: number, chatAccessHash: bigint): ChatPhoto.User;
@@ -1,28 +1,41 @@
1
1
  import * as types from "../tl/2_types.js";
2
- export var ChatPhotoType;
3
- (function (ChatPhotoType) {
4
- ChatPhotoType["Chat"] = "chat";
5
- ChatPhotoType["User"] = "user";
6
- })(ChatPhotoType || (ChatPhotoType = {}));
7
- export function constructChatPhoto(photo) {
8
- const { hasVideo = false, photoId, strippedThumb, dcId } = photo;
2
+ import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./!0_file_id.js";
3
+ export function constructChatPhoto(photo, chatId, chatAccessHash) {
4
+ const smallFileId = new FileID(null, null, FileType.ChatPhoto, photo.dcId, {
5
+ mediaId: photo.photoId,
6
+ thumbnailSource: ThumbnailSource.ChatPhotoSmall,
7
+ chatId: BigInt(chatId),
8
+ chatAccessHash,
9
+ accessHash: 0n,
10
+ volumeId: 0n,
11
+ localId: 0,
12
+ }).encode();
13
+ const smallFileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: photo.photoId }).encode();
14
+ const bigFileId = new FileID(null, null, FileType.ChatPhoto, photo.dcId, {
15
+ mediaId: photo.photoId,
16
+ thumbnailSource: ThumbnailSource.ChatPhotoBig,
17
+ chatId: BigInt(chatId),
18
+ chatAccessHash,
19
+ accessHash: 0n,
20
+ volumeId: 0n,
21
+ localId: 0,
22
+ }).encode();
23
+ const bigFileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: photo.photoId }).encode();
9
24
  if (photo instanceof types.ChatPhoto) {
10
25
  return {
11
- type: ChatPhotoType.Chat,
12
- hasVideo,
13
- photoId,
14
- strippedThumb,
15
- dcId,
26
+ smallFileId,
27
+ smallFileUniqueId,
28
+ bigFileId,
29
+ bigFileUniqueId,
16
30
  };
17
31
  }
18
32
  else {
19
33
  return {
20
- type: ChatPhotoType.User,
21
34
  personal: photo.personal || false,
22
- hasVideo,
23
- photoId,
24
- strippedThumb,
25
- dcId,
35
+ smallFileId,
36
+ smallFileUniqueId,
37
+ bigFileId,
38
+ bigFileUniqueId,
26
39
  };
27
40
  }
28
41
  }
@@ -53,6 +53,7 @@ export declare namespace Chat {
53
53
  }
54
54
  interface Supergroup extends ChannelBase {
55
55
  type: ChatType.Supergroup;
56
+ isForum: boolean;
56
57
  }
57
58
  }
58
59
  export type Chat = Chat.Private | Chat.Group | Chat.Supergroup | Chat.Channel;
@@ -3,8 +3,8 @@ import { UNREACHABLE } from "../utilities/0_control.js";
3
3
  import { cleanObject } from "../utilities/0_object.js";
4
4
  import { as } from "../tl/1_tl_object.js";
5
5
  import * as types from "../tl/2_types.js";
6
+ import { getIdColor } from "./!0_id_color.js";
6
7
  import { constructChatPhoto } from "./0_chat_photo.js";
7
- import { getIdColor } from "./utilities/0_id_color.js";
8
8
  export var ChatType;
9
9
  (function (ChatType) {
10
10
  ChatType["Private"] = "private";
@@ -32,7 +32,7 @@ export function constructChat(chat) {
32
32
  chat_.restrictionReason = chat.restrictionReason?.map((v) => v[as](types.RestrictionReason));
33
33
  }
34
34
  if (chat.photo instanceof types.UserProfilePhoto) {
35
- chat_.photo = constructChatPhoto(chat.photo);
35
+ chat_.photo = constructChatPhoto(chat.photo, chat_.id, chat.accessHash ?? 0n);
36
36
  }
37
37
  return cleanObject(chat_);
38
38
  }
@@ -46,7 +46,7 @@ export function constructChat(chat) {
46
46
  isCreator: chat.creator || false,
47
47
  };
48
48
  if (chat.photo instanceof types.ChatPhoto) {
49
- chat_.photo = constructChatPhoto(chat.photo);
49
+ chat_.photo = constructChatPhoto(chat.photo, chat_.id, 0n);
50
50
  }
51
51
  return cleanObject(chat_);
52
52
  }
@@ -55,11 +55,30 @@ export function constructChat(chat) {
55
55
  const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
56
56
  const id = ZERO_CHANNEL_ID + -Number(chat.id);
57
57
  if (chat.megagroup) {
58
- chat_ = { id, idColor: getIdColor(id), type: ChatType.Supergroup, title, isScam, isFake, isVerified, isRestricted };
58
+ chat_ = {
59
+ id,
60
+ idColor: getIdColor(id),
61
+ type: ChatType.Supergroup,
62
+ title,
63
+ isScam,
64
+ isFake,
65
+ isVerified,
66
+ isRestricted,
67
+ isForum: chat.forum || false,
68
+ };
59
69
  }
60
70
  else {
61
71
  const id = ZERO_CHANNEL_ID + -Number(chat.id);
62
- chat_ = { id, idColor: getIdColor(id), type: ChatType.Channel, title, isScam, isFake, isVerified, isRestricted };
72
+ chat_ = {
73
+ id,
74
+ idColor: getIdColor(id),
75
+ type: ChatType.Channel,
76
+ title,
77
+ isScam,
78
+ isFake,
79
+ isVerified,
80
+ isRestricted,
81
+ };
63
82
  }
64
83
  chat_.username = chat.username;
65
84
  chat_.also = chat.usernames?.map((v) => v[as](types.Username)).map((v) => v.username);
@@ -67,7 +86,7 @@ export function constructChat(chat) {
67
86
  chat_.restrictionReason = chat.restrictionReason?.map((v) => v[as](types.RestrictionReason));
68
87
  }
69
88
  if (chat.photo instanceof types.ChatPhoto) {
70
- chat_.photo = constructChatPhoto(chat.photo);
89
+ chat_.photo = constructChatPhoto(chat.photo, chat_.id, chat.accessHash ?? 0n);
71
90
  }
72
91
  return cleanObject(chat_);
73
92
  }
@@ -1,8 +1,8 @@
1
1
  import { cleanObject } from "../utilities/0_object.js";
2
2
  import { as } from "../tl/1_tl_object.js";
3
3
  import * as types from "../tl/2_types.js";
4
+ import { getIdColor } from "./!0_id_color.js";
4
5
  import { constructChatPhoto } from "./0_chat_photo.js";
5
- import { getIdColor } from "./utilities/0_id_color.js";
6
6
  export function constructUser(user_) {
7
7
  const id = Number(user_.id);
8
8
  const user = {
@@ -22,7 +22,7 @@ export function constructUser(user_) {
22
22
  addedToAttachmentMenu: user_.attachMenuEnabled || false,
23
23
  };
24
24
  if (user_.photo instanceof types.UserProfilePhoto) {
25
- user.photo = constructChatPhoto(user_.photo);
25
+ user.photo = constructChatPhoto(user_.photo, user.id, user_.accessHash ?? 0n);
26
26
  }
27
27
  return cleanObject(user);
28
28
  }
@@ -64,6 +64,18 @@ export async function constructMessage(message_, getEntity, getMessage) {
64
64
  UNREACHABLE();
65
65
  }
66
66
  }
67
+ else if (message_.fromId instanceof types.PeerChannel) {
68
+ const entity = await getEntity(message_.fromId);
69
+ if (entity) {
70
+ message.senderChat = constructChat(entity);
71
+ }
72
+ else {
73
+ UNREACHABLE();
74
+ }
75
+ }
76
+ else {
77
+ UNREACHABLE();
78
+ }
67
79
  if (message_.message) {
68
80
  if (message_.media == undefined) {
69
81
  message.text = message_.message;
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.905",
5
+ "version": "0.0.910",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -1,2 +1,2 @@
1
- import { MessageEntity } from "../0_message_entity.js";
1
+ import { MessageEntity } from "../types/0_message_entity.js";
2
2
  export declare function parseHtml(html: string): readonly [string, MessageEntity[]];
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseHtml = void 0;
4
- const deps_js_1 = require("../../deps.js");
5
- const _0_message_entity_js_1 = require("../0_message_entity.js");
4
+ const deps_js_1 = require("../deps.js");
5
+ const _0_message_entity_js_1 = require("../types/0_message_entity.js");
6
6
  function parseHtml(html) {
7
7
  let text = "";
8
8
  const entities = new Array();
@@ -1,5 +1,5 @@
1
- import { Message } from "../../tl/6_message.js";
2
- import { MessageContainer } from "../../tl/7_message_container.js";
1
+ import { Message } from "../tl/6_message.js";
2
+ import { MessageContainer } from "../tl/7_message_container.js";
3
3
  export declare function getMessageId(): bigint;
4
4
  export declare function packUnencryptedMessage(data: Uint8Array): Uint8Array;
5
5
  export declare function unpackUnencryptedMessage(buffer: Uint8Array): {
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.decryptMessage = exports.encryptMessage = exports.unpackUnencryptedMessage = exports.packUnencryptedMessage = exports.getMessageId = void 0;
4
- const deps_js_1 = require("../../deps.js");
5
- const _0_tl_raw_reader_js_1 = require("../../tl/0_tl_raw_reader.js");
6
- const _0_tl_raw_writer_js_1 = require("../../tl/0_tl_raw_writer.js");
7
- const _1_tl_object_js_1 = require("../../tl/1_tl_object.js");
8
- const _3_tl_reader_js_1 = require("../../tl/3_tl_reader.js");
9
- const _5_rpc_result_js_1 = require("../../tl/5_rpc_result.js");
10
- const _6_message_js_1 = require("../../tl/6_message.js");
11
- const _7_message_container_js_1 = require("../../tl/7_message_container.js");
12
- const _0_buffer_js_1 = require("../../utilities/0_buffer.js");
13
- const _0_hash_js_1 = require("../../utilities/0_hash.js");
4
+ const deps_js_1 = require("../deps.js");
5
+ const _0_tl_raw_reader_js_1 = require("../tl/0_tl_raw_reader.js");
6
+ const _0_tl_raw_writer_js_1 = require("../tl/0_tl_raw_writer.js");
7
+ const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
8
+ const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
9
+ const _5_rpc_result_js_1 = require("../tl/5_rpc_result.js");
10
+ const _6_message_js_1 = require("../tl/6_message.js");
11
+ const _7_message_container_js_1 = require("../tl/7_message_container.js");
12
+ const _0_buffer_js_1 = require("../utilities/0_buffer.js");
13
+ const _0_hash_js_1 = require("../utilities/0_hash.js");
14
14
  let lastMsgId = 0n;
15
15
  function getMessageId() {
16
16
  const now = new Date().getTime() / 1000 + 0;
@@ -1,5 +1,5 @@
1
- import * as types from "../../tl/2_types.js";
2
- import { sha256 } from "../../utilities/0_hash.js";
1
+ import * as types from "../tl/2_types.js";
2
+ import { sha256 } from "../utilities/0_hash.js";
3
3
  export declare function isSafePrime(primeBytes: Uint8Array, g: number): boolean;
4
4
  export declare const h: typeof sha256;
5
5
  export declare const sh: (data: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;
@@ -24,11 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.checkPassword = exports.pad = exports.isGoodModExpFirst = exports.ph2 = exports.pbkdf2 = exports.ph1 = exports.sh = exports.h = exports.isSafePrime = void 0;
27
- const dntShim = __importStar(require("../../_dnt.shims.js"));
28
- const types = __importStar(require("../../tl/2_types.js"));
29
- const _0_buffer_js_1 = require("../../utilities/0_buffer.js");
30
- const _0_hash_js_1 = require("../../utilities/0_hash.js");
31
- const _0_bigint_js_1 = require("../../utilities/0_bigint.js");
27
+ const dntShim = __importStar(require("../_dnt.shims.js"));
28
+ const types = __importStar(require("../tl/2_types.js"));
29
+ const _0_buffer_js_1 = require("../utilities/0_buffer.js");
30
+ const _0_hash_js_1 = require("../utilities/0_hash.js");
31
+ const _0_bigint_js_1 = require("../utilities/0_bigint.js");
32
32
  function isSafePrime(primeBytes, g) {
33
33
  // deno-fmt-ignore
34
34
  const goodPrime = new Uint8Array([