@mtkruto/node 0.1.157 → 0.1.161

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 (83) hide show
  1. package/esm/4_constants.d.ts +2 -2
  2. package/esm/4_constants.js +2 -2
  3. package/esm/client/1_composer.d.ts +2 -2
  4. package/esm/client/1_composer.js +4 -4
  5. package/esm/client/1_file_manager.js +53 -56
  6. package/esm/client/2_message_manager.js +8 -11
  7. package/esm/client/4_client.d.ts +2 -2
  8. package/esm/client/4_client.js +4 -4
  9. package/esm/tl/2_types.d.ts +596 -1
  10. package/esm/tl/2_types.js +1824 -319
  11. package/esm/tl/3_functions.d.ts +374 -2
  12. package/esm/tl/3_functions.js +943 -31
  13. package/esm/types/0__file_id.d.ts +79 -54
  14. package/esm/types/0__file_id.js +259 -277
  15. package/esm/types/0_chat_photo.js +15 -21
  16. package/esm/types/0_giveaway_parameters.d.ts +5 -0
  17. package/esm/types/0_login_url.d.ts +4 -0
  18. package/esm/types/0_message_reference.d.ts +2 -0
  19. package/esm/types/0_price_tag.d.ts +2 -0
  20. package/esm/types/0_thumbnail.js +16 -14
  21. package/esm/types/1_giveaway.d.ts +2 -0
  22. package/esm/types/1_inline_query_result_button.d.ts +3 -0
  23. package/esm/types/1_photo.js +20 -14
  24. package/esm/types/1_poll.d.ts +13 -0
  25. package/esm/types/1_reaction_count.d.ts +2 -0
  26. package/esm/types/1_reply_quote.d.ts +3 -0
  27. package/esm/types/1_user.d.ts +13 -13
  28. package/esm/types/2_chosen_inline_result.d.ts +5 -0
  29. package/esm/types/2_game.d.ts +6 -0
  30. package/esm/types/2_game.js +11 -7
  31. package/esm/types/2_inactive_chat.d.ts +3 -0
  32. package/esm/types/2_inline_query.d.ts +6 -0
  33. package/esm/types/2_message_interactions.d.ts +5 -0
  34. package/esm/types/2_message_reaction_count.d.ts +4 -0
  35. package/esm/types/2_message_reactions.d.ts +7 -0
  36. package/esm/types/2_story_content.js +4 -7
  37. package/esm/types/4_inline_query_result.js +5 -5
  38. package/esm/types/4_message.js +24 -19
  39. package/esm/types/5_callback_query.d.ts +7 -0
  40. package/esm/utilities/0_buffer.d.ts +1 -1
  41. package/esm/utilities/0_buffer.js +26 -24
  42. package/package.json +1 -1
  43. package/script/4_constants.d.ts +2 -2
  44. package/script/4_constants.js +2 -2
  45. package/script/client/1_composer.d.ts +2 -2
  46. package/script/client/1_composer.js +4 -4
  47. package/script/client/1_file_manager.js +52 -55
  48. package/script/client/2_message_manager.js +6 -9
  49. package/script/client/4_client.d.ts +2 -2
  50. package/script/client/4_client.js +4 -4
  51. package/script/tl/2_types.d.ts +596 -1
  52. package/script/tl/2_types.js +1904 -345
  53. package/script/tl/3_functions.d.ts +374 -2
  54. package/script/tl/3_functions.js +977 -41
  55. package/script/types/0__file_id.d.ts +79 -54
  56. package/script/types/0__file_id.js +263 -280
  57. package/script/types/0_chat_photo.js +14 -20
  58. package/script/types/0_giveaway_parameters.d.ts +5 -0
  59. package/script/types/0_login_url.d.ts +4 -0
  60. package/script/types/0_message_reference.d.ts +2 -0
  61. package/script/types/0_price_tag.d.ts +2 -0
  62. package/script/types/0_thumbnail.js +15 -13
  63. package/script/types/1_giveaway.d.ts +2 -0
  64. package/script/types/1_inline_query_result_button.d.ts +3 -0
  65. package/script/types/1_photo.js +19 -13
  66. package/script/types/1_poll.d.ts +13 -0
  67. package/script/types/1_reaction_count.d.ts +2 -0
  68. package/script/types/1_reply_quote.d.ts +3 -0
  69. package/script/types/1_user.d.ts +13 -13
  70. package/script/types/2_chosen_inline_result.d.ts +5 -0
  71. package/script/types/2_game.d.ts +6 -0
  72. package/script/types/2_game.js +10 -6
  73. package/script/types/2_inactive_chat.d.ts +3 -0
  74. package/script/types/2_inline_query.d.ts +6 -0
  75. package/script/types/2_message_interactions.d.ts +5 -0
  76. package/script/types/2_message_reaction_count.d.ts +4 -0
  77. package/script/types/2_message_reactions.d.ts +7 -0
  78. package/script/types/2_story_content.js +3 -6
  79. package/script/types/4_inline_query_result.js +4 -4
  80. package/script/types/4_message.js +23 -18
  81. package/script/types/5_callback_query.d.ts +7 -0
  82. package/script/utilities/0_buffer.d.ts +1 -1
  83. package/script/utilities/0_buffer.js +26 -24
@@ -1,14 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FileUniqueID = exports.FileUniqueType = exports.FileID = exports.ThumbnailSource = exports.FileType = void 0;
3
+ exports.toUniqueFileId = exports.serializeFileId = exports.deserializeFileId = exports.PhotoSourceType = exports.FileType = void 0;
4
4
  const _1_utilities_js_1 = require("../1_utilities.js");
5
5
  const _2_tl_js_1 = require("../2_tl.js");
6
+ const NEXT_VERSION = 53;
7
+ const PERSISTENT_ID_VERSION = 4;
8
+ const WEB_LOCATION_FLAG = 1 << 24;
9
+ const FILE_REFERENCE_FLAG = 1 << 25;
6
10
  var FileType;
7
11
  (function (FileType) {
8
12
  FileType[FileType["Thumbnail"] = 0] = "Thumbnail";
9
- FileType[FileType["ChatPhoto"] = 1] = "ChatPhoto";
13
+ FileType[FileType["ProfilePhoto"] = 1] = "ProfilePhoto";
10
14
  FileType[FileType["Photo"] = 2] = "Photo";
11
- FileType[FileType["Voice"] = 3] = "Voice";
15
+ FileType[FileType["VoiceNote"] = 3] = "VoiceNote";
12
16
  FileType[FileType["Video"] = 4] = "Video";
13
17
  FileType[FileType["Document"] = 5] = "Document";
14
18
  FileType[FileType["Encrypted"] = 6] = "Encrypted";
@@ -19,307 +23,286 @@ var FileType;
19
23
  FileType[FileType["EncryptedThumbnail"] = 11] = "EncryptedThumbnail";
20
24
  FileType[FileType["Wallpaper"] = 12] = "Wallpaper";
21
25
  FileType[FileType["VideoNote"] = 13] = "VideoNote";
22
- FileType[FileType["SecureRaw"] = 14] = "SecureRaw";
23
- FileType[FileType["Secure"] = 15] = "Secure";
26
+ FileType[FileType["SecureDecrypted"] = 14] = "SecureDecrypted";
27
+ FileType[FileType["SecureEncrypted"] = 15] = "SecureEncrypted";
24
28
  FileType[FileType["Background"] = 16] = "Background";
25
29
  FileType[FileType["DocumentAsFile"] = 17] = "DocumentAsFile";
30
+ FileType[FileType["Ringtone"] = 18] = "Ringtone";
31
+ FileType[FileType["CallLog"] = 19] = "CallLog";
32
+ FileType[FileType["PhotoStory"] = 20] = "PhotoStory";
33
+ FileType[FileType["VideoStory"] = 21] = "VideoStory";
34
+ FileType[FileType["Size"] = 22] = "Size";
35
+ FileType[FileType["None"] = 23] = "None";
26
36
  })(FileType || (exports.FileType = FileType = {}));
27
- const PHOTO_TYPES = [FileType.Thumbnail, FileType.ChatPhoto, FileType.Photo, FileType.EncryptedThumbnail];
28
- const DOCUMENT_TYPES = Object.keys(FileType).map(Number).filter((v) => !isNaN(v)).filter((v) => !PHOTO_TYPES.includes(v));
29
- var ThumbnailSource;
30
- (function (ThumbnailSource) {
31
- ThumbnailSource[ThumbnailSource["Legacy"] = 0] = "Legacy";
32
- ThumbnailSource[ThumbnailSource["Thumbnail"] = 1] = "Thumbnail";
33
- ThumbnailSource[ThumbnailSource["ChatPhotoSmall"] = 2] = "ChatPhotoSmall";
34
- ThumbnailSource[ThumbnailSource["ChatPhotoBig"] = 3] = "ChatPhotoBig";
35
- ThumbnailSource[ThumbnailSource["StickerSetThumbnail"] = 4] = "StickerSetThumbnail";
36
- })(ThumbnailSource || (exports.ThumbnailSource = ThumbnailSource = {}));
37
- const WEB_LOCATION_FLAG = 1 << 24;
38
- const FILE_REFERENCE_FLAG = 1 << 25;
39
- class FileID {
40
- constructor(major = FileID.MAJOR, minor = FileID.MINOR, fileType, dcId, params) {
41
- Object.defineProperty(this, "fileType", {
42
- enumerable: true,
43
- configurable: true,
44
- writable: true,
45
- value: fileType
46
- });
47
- Object.defineProperty(this, "dcId", {
48
- enumerable: true,
49
- configurable: true,
50
- writable: true,
51
- value: dcId
52
- });
53
- Object.defineProperty(this, "params", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: params
58
- });
59
- Object.defineProperty(this, "major", {
60
- enumerable: true,
61
- configurable: true,
62
- writable: true,
63
- value: void 0
64
- });
65
- Object.defineProperty(this, "minor", {
66
- enumerable: true,
67
- configurable: true,
68
- writable: true,
69
- value: void 0
70
- });
71
- if (major == null) {
72
- this.major = FileID.MAJOR;
37
+ var FileTypeClass;
38
+ (function (FileTypeClass) {
39
+ FileTypeClass[FileTypeClass["Photo"] = 0] = "Photo";
40
+ FileTypeClass[FileTypeClass["Document"] = 1] = "Document";
41
+ FileTypeClass[FileTypeClass["Secure"] = 2] = "Secure";
42
+ FileTypeClass[FileTypeClass["Encrypted"] = 3] = "Encrypted";
43
+ FileTypeClass[FileTypeClass["Temp"] = 4] = "Temp";
44
+ })(FileTypeClass || (FileTypeClass = {}));
45
+ var PhotoSourceType;
46
+ (function (PhotoSourceType) {
47
+ PhotoSourceType[PhotoSourceType["Legacy"] = 0] = "Legacy";
48
+ PhotoSourceType[PhotoSourceType["Thumbnail"] = 1] = "Thumbnail";
49
+ PhotoSourceType[PhotoSourceType["ChatPhotoSmall"] = 2] = "ChatPhotoSmall";
50
+ PhotoSourceType[PhotoSourceType["ChatPhotoBig"] = 3] = "ChatPhotoBig";
51
+ PhotoSourceType[PhotoSourceType["StickerSetThumbnail"] = 4] = "StickerSetThumbnail";
52
+ PhotoSourceType[PhotoSourceType["FullLegacy"] = 5] = "FullLegacy";
53
+ PhotoSourceType[PhotoSourceType["ChatPhotoSmallLegacy"] = 6] = "ChatPhotoSmallLegacy";
54
+ PhotoSourceType[PhotoSourceType["ChatPhotoBigLegacy"] = 7] = "ChatPhotoBigLegacy";
55
+ PhotoSourceType[PhotoSourceType["StickerSetThumbnailLegacy"] = 8] = "StickerSetThumbnailLegacy";
56
+ PhotoSourceType[PhotoSourceType["StickerSetThumbnailVersion"] = 9] = "StickerSetThumbnailVersion";
57
+ })(PhotoSourceType || (exports.PhotoSourceType = PhotoSourceType = {}));
58
+ function deserializePhotoSource(reader) {
59
+ const type = reader.readInt32();
60
+ switch (type) {
61
+ case PhotoSourceType.Legacy:
62
+ return { type, secret: reader.readInt64() };
63
+ case PhotoSourceType.Thumbnail:
64
+ return { type, fileType: reader.readInt32(), thumbnailType: reader.readInt32() };
65
+ case PhotoSourceType.ChatPhotoSmall:
66
+ case PhotoSourceType.ChatPhotoBig: {
67
+ const chatId = reader.readInt64();
68
+ const chatAccessHash = reader.readInt64();
69
+ return { type, chatId, chatAccessHash };
73
70
  }
74
- else {
75
- this.major = major;
71
+ case PhotoSourceType.StickerSetThumbnail: {
72
+ const stickerSetId = reader.readInt64();
73
+ const stickerSetAccessHash = reader.readInt64();
74
+ return { type, stickerSetId, stickerSetAccessHash };
76
75
  }
77
- if (minor == null) {
78
- this.minor = FileID.MINOR;
79
- }
80
- else {
81
- this.minor = minor;
82
- }
83
- this.params.thumbnailSize ??= "";
84
- }
85
- static decode(fileId) {
86
- const decoded = (0, _1_utilities_js_1.rleDecode)((0, _1_utilities_js_1.base64DecodeUrlSafe)(fileId));
87
- const major = decoded[decoded.length - 1];
88
- let minor;
89
- let buffer;
90
- if (major < 4) {
91
- minor = 0;
92
- buffer = decoded.subarray(0, -1);
93
- }
94
- else {
95
- minor = decoded[decoded.length - 2];
96
- buffer = decoded.subarray(0, -2);
97
- }
98
- const reader = new _2_tl_js_1.TLReader(buffer);
99
- let fileType = reader.readInt32();
100
- const dcId = reader.readInt32();
101
- const hasWebLocation = Boolean(fileType & WEB_LOCATION_FLAG);
102
- const hasFileReference = Boolean(fileType & FILE_REFERENCE_FLAG);
103
- fileType &= ~WEB_LOCATION_FLAG;
104
- fileType &= ~FILE_REFERENCE_FLAG;
105
- if (hasWebLocation) {
106
- const url = reader.readString();
107
- const accessHash = reader.readInt64();
108
- return new FileID(major, minor, fileType, dcId, { url, accessHash });
109
- }
110
- let fileReference = new Uint8Array();
111
- if (hasFileReference) {
112
- fileReference = reader.readBytes();
113
- }
114
- const mediaId = reader.readInt64();
115
- const accessHash = reader.readInt64();
116
- if (PHOTO_TYPES.includes(fileType)) {
76
+ case PhotoSourceType.FullLegacy: {
117
77
  const volumeId = reader.readInt64();
118
- let thumbnailSource = 0;
119
- if (major >= 4) {
120
- thumbnailSource = reader.readInt32(false);
121
- }
122
- switch (thumbnailSource) {
123
- case ThumbnailSource.Legacy: {
124
- const secret = reader.readInt64();
125
- const localId = reader.readInt32();
126
- return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, secret, localId });
127
- }
128
- case ThumbnailSource.Thumbnail: {
129
- const thumbnailFileType = reader.readInt32();
130
- const thumbnailSize = String.fromCharCode(reader.readInt32());
131
- const localId = reader.readInt32();
132
- return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, thumbnailFileType, thumbnailSize, localId });
133
- }
134
- case ThumbnailSource.ChatPhotoSmall:
135
- case ThumbnailSource.ChatPhotoBig: {
136
- const chatId = Number(reader.readInt64());
137
- const chatAccessHash = reader.readInt64();
138
- const localId = reader.readInt32();
139
- return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, chatId: Number(chatId), chatAccessHash, localId });
140
- }
141
- case ThumbnailSource.StickerSetThumbnail: {
142
- const stickerSetId = reader.readInt64();
143
- const stickerSetAccessHash = reader.readInt64();
144
- const localId = reader.readInt32();
145
- return new FileID(major, minor, fileType, dcId, { fileReference, mediaId, accessHash, volumeId, thumbnailSource, stickerSetId, stickerSetAccessHash, localId });
146
- }
147
- default:
148
- (0, _1_utilities_js_1.UNREACHABLE)();
149
- }
150
- }
151
- else if (DOCUMENT_TYPES.includes(fileType)) {
152
- return new FileID(minor, major, fileType, dcId, { fileReference, mediaId, accessHash });
78
+ const localId = reader.readInt32();
79
+ const secret = reader.readInt64();
80
+ return { type, volumeId, localId, secret };
153
81
  }
154
- else {
155
- (0, _1_utilities_js_1.UNREACHABLE)();
82
+ case PhotoSourceType.ChatPhotoSmallLegacy:
83
+ case PhotoSourceType.ChatPhotoBigLegacy:
84
+ case PhotoSourceType.StickerSetThumbnailLegacy: {
85
+ const volumeId = reader.readInt64();
86
+ const localId = reader.readInt32();
87
+ return { type, volumeId, localId };
156
88
  }
89
+ case PhotoSourceType.StickerSetThumbnailVersion:
90
+ return { type, version: reader.readInt32() };
157
91
  }
158
- encode(major, minor) {
159
- major ??= this.major;
160
- minor ??= this.minor;
161
- const writer = new _2_tl_js_1.TLWriter();
162
- let fileType = this.fileType;
163
- if (this.params.url) {
164
- fileType |= WEB_LOCATION_FLAG;
165
- }
166
- if (this.params.fileReference) {
167
- fileType |= FILE_REFERENCE_FLAG;
168
- }
169
- writer.writeInt32(fileType);
170
- writer.writeInt32(this.dcId);
171
- if (this.params.url) {
172
- writer.writeString(this.params.url);
173
- }
174
- if (this.params.fileReference) {
175
- writer.writeBytes(this.params.fileReference);
176
- }
177
- if (this.params.mediaId == undefined || this.params.accessHash == undefined) {
92
+ }
93
+ function serializePhotoSource(photoSource, writer) {
94
+ writer.writeInt32(photoSource.type);
95
+ switch (photoSource.type) {
96
+ case PhotoSourceType.Legacy:
97
+ writer.writeInt64(photoSource.secret);
98
+ break;
99
+ case PhotoSourceType.Thumbnail:
100
+ writer.writeInt32(photoSource.fileType);
101
+ writer.writeInt32(photoSource.thumbnailType);
102
+ break;
103
+ case PhotoSourceType.ChatPhotoSmall:
104
+ case PhotoSourceType.ChatPhotoBig:
105
+ writer.writeInt64(photoSource.chatId);
106
+ writer.writeInt64(photoSource.chatAccessHash);
107
+ break;
108
+ case PhotoSourceType.StickerSetThumbnail:
109
+ writer.writeInt64(photoSource.stickerSetId);
110
+ writer.writeInt64(photoSource.stickerSetAccessHash);
111
+ break;
112
+ case PhotoSourceType.FullLegacy:
113
+ writer.writeInt64(photoSource.volumeId);
114
+ writer.writeInt32(photoSource.localId);
115
+ writer.writeInt64(photoSource.secret);
116
+ break;
117
+ case PhotoSourceType.ChatPhotoSmallLegacy:
118
+ case PhotoSourceType.ChatPhotoBigLegacy:
119
+ case PhotoSourceType.StickerSetThumbnailLegacy:
120
+ writer.writeInt64(photoSource.volumeId);
121
+ writer.writeInt32(photoSource.localId);
122
+ break;
123
+ case PhotoSourceType.StickerSetThumbnailVersion:
124
+ writer.writeInt32(photoSource.version);
125
+ break;
126
+ default:
178
127
  (0, _1_utilities_js_1.UNREACHABLE)();
179
- }
180
- writer.writeInt64(this.params.mediaId);
181
- writer.writeInt64(this.params.accessHash);
182
- if (PHOTO_TYPES.includes(this.fileType)) {
183
- if (this.params.volumeId == undefined || this.params.thumbnailSize == undefined || this.params.localId == undefined) {
128
+ }
129
+ }
130
+ function getPhotoSourceCompareType(source) {
131
+ switch (source.type) {
132
+ case PhotoSourceType.Legacy:
133
+ break;
134
+ case PhotoSourceType.Thumbnail: {
135
+ const type = source.thumbnailType;
136
+ if (!(0 <= type && type <= 127)) {
184
137
  (0, _1_utilities_js_1.UNREACHABLE)();
185
138
  }
186
- writer.writeInt64(this.params.volumeId);
187
- if (major >= 4) {
188
- writer.writeInt32(Number(this.params.thumbnailSource));
139
+ if (type == "a".charCodeAt(0)) {
140
+ return 0;
189
141
  }
190
- switch (this.params.thumbnailSource) {
191
- case ThumbnailSource.Legacy:
192
- if (this.params.secret == undefined) {
193
- (0, _1_utilities_js_1.UNREACHABLE)();
194
- }
195
- writer.writeInt64(this.params.secret);
196
- writer.writeInt32(this.params.localId);
197
- break;
198
- case ThumbnailSource.Thumbnail:
199
- if (this.params.thumbnailFileType == undefined || this.params.thumbnailSize == undefined) {
200
- (0, _1_utilities_js_1.UNREACHABLE)();
201
- }
202
- writer.writeInt32(Number(this.params.thumbnailFileType));
203
- writer.writeInt32(this.params.thumbnailSize.charCodeAt(0));
204
- writer.writeInt32(this.params.localId);
205
- break;
206
- case ThumbnailSource.ChatPhotoSmall:
207
- case ThumbnailSource.ChatPhotoBig:
208
- if (this.params.chatId == undefined || this.params.chatAccessHash == undefined) {
209
- (0, _1_utilities_js_1.UNREACHABLE)();
210
- }
211
- writer.writeInt64(BigInt(this.params.chatId));
212
- writer.writeInt64(this.params.chatAccessHash);
213
- writer.writeInt32(this.params.localId);
214
- break;
215
- case ThumbnailSource.StickerSetThumbnail:
216
- if (this.params.stickerSetId == undefined || this.params.stickerSetAccessHash == undefined) {
217
- (0, _1_utilities_js_1.UNREACHABLE)();
218
- }
219
- writer.writeInt64(this.params.stickerSetId);
220
- writer.writeInt64(this.params.stickerSetAccessHash);
221
- writer.writeInt32(this.params.localId);
222
- break;
223
- default:
224
- (0, _1_utilities_js_1.UNREACHABLE)();
142
+ if (type == "c".charCodeAt(0)) {
143
+ return 1;
225
144
  }
145
+ return type + 5;
226
146
  }
227
- else if (DOCUMENT_TYPES.includes(this.fileType)) {
228
- writer.writeInt32(minor);
229
- writer.writeInt32(major);
230
- }
231
- else {
147
+ case PhotoSourceType.ChatPhotoSmall:
148
+ return 0;
149
+ case PhotoSourceType.ChatPhotoBig:
150
+ return 1;
151
+ case PhotoSourceType.StickerSetThumbnail:
152
+ break;
153
+ case PhotoSourceType.FullLegacy:
154
+ case PhotoSourceType.ChatPhotoSmallLegacy:
155
+ case PhotoSourceType.ChatPhotoBigLegacy:
156
+ case PhotoSourceType.StickerSetThumbnailLegacy:
157
+ return 3;
158
+ case PhotoSourceType.StickerSetThumbnailVersion:
159
+ return 2;
160
+ default:
161
+ break;
162
+ }
163
+ (0, _1_utilities_js_1.UNREACHABLE)();
164
+ }
165
+ function writePhotoSourceUniqueId(photoSource, writer) {
166
+ const compareType = getPhotoSourceCompareType(photoSource);
167
+ if (compareType != 2 && compareType != 3) {
168
+ writer.write(new Uint8Array([compareType]));
169
+ return;
170
+ }
171
+ if (compareType == 2) {
172
+ writer.write(new Uint8Array([0x02]));
173
+ }
174
+ writer.writeInt64("volumeId" in photoSource ? photoSource.volumeId : "stickerSetId" in photoSource ? photoSource.stickerSetId : (0, _1_utilities_js_1.UNREACHABLE)());
175
+ writer.writeInt32("localId" in photoSource ? photoSource.localId : "version" in photoSource ? photoSource.version : (0, _1_utilities_js_1.UNREACHABLE)());
176
+ }
177
+ function getFileTypeClass(fileType) {
178
+ switch (fileType) {
179
+ case FileType.Photo:
180
+ case FileType.ProfilePhoto:
181
+ case FileType.Thumbnail:
182
+ case FileType.EncryptedThumbnail:
183
+ case FileType.Wallpaper:
184
+ case FileType.PhotoStory:
185
+ return FileTypeClass.Photo;
186
+ case FileType.Video:
187
+ case FileType.VoiceNote:
188
+ case FileType.Document:
189
+ case FileType.Sticker:
190
+ case FileType.Audio:
191
+ case FileType.Animation:
192
+ case FileType.VideoNote:
193
+ case FileType.Background:
194
+ case FileType.DocumentAsFile:
195
+ case FileType.Ringtone:
196
+ case FileType.CallLog:
197
+ case FileType.VideoStory:
198
+ return FileTypeClass.Document;
199
+ case FileType.SecureDecrypted:
200
+ case FileType.SecureEncrypted:
201
+ return FileTypeClass.Secure;
202
+ case FileType.Encrypted:
203
+ return FileTypeClass.Encrypted;
204
+ case FileType.Temp:
205
+ return FileTypeClass.Temp;
206
+ case FileType.None:
207
+ case FileType.Size:
208
+ default:
232
209
  (0, _1_utilities_js_1.UNREACHABLE)();
233
- }
234
- writer.write(new Uint8Array([minor, major]));
235
- return (0, _1_utilities_js_1.base64EncodeUrlSafe)((0, _1_utilities_js_1.rleEncode)(writer.buffer));
236
210
  }
237
211
  }
238
- exports.FileID = FileID;
239
- Object.defineProperty(FileID, "MAJOR", {
240
- enumerable: true,
241
- configurable: true,
242
- writable: true,
243
- value: 4
244
- });
245
- Object.defineProperty(FileID, "MINOR", {
246
- enumerable: true,
247
- configurable: true,
248
- writable: true,
249
- value: 30
250
- });
251
- var FileUniqueType;
252
- (function (FileUniqueType) {
253
- FileUniqueType[FileUniqueType["Web"] = 0] = "Web";
254
- FileUniqueType[FileUniqueType["Photo"] = 1] = "Photo";
255
- FileUniqueType[FileUniqueType["Document"] = 2] = "Document";
256
- FileUniqueType[FileUniqueType["Secure"] = 3] = "Secure";
257
- FileUniqueType[FileUniqueType["Encrypted"] = 4] = "Encrypted";
258
- FileUniqueType[FileUniqueType["Temp"] = 5] = "Temp";
259
- })(FileUniqueType || (exports.FileUniqueType = FileUniqueType = {}));
260
- class FileUniqueID {
261
- constructor(fileUniqueType, params) {
262
- Object.defineProperty(this, "fileUniqueType", {
263
- enumerable: true,
264
- configurable: true,
265
- writable: true,
266
- value: fileUniqueType
267
- });
268
- Object.defineProperty(this, "params", {
269
- enumerable: true,
270
- configurable: true,
271
- writable: true,
272
- value: params
273
- });
212
+ function isWeb(fileType) {
213
+ return !!(fileType & WEB_LOCATION_FLAG);
214
+ }
215
+ function hasFileReference(fileType) {
216
+ return !!(fileType && FILE_REFERENCE_FLAG);
217
+ }
218
+ function deserializeFileId(fileId) {
219
+ const reader = new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)((0, _1_utilities_js_1.base64DecodeUrlSafe)(fileId)));
220
+ if (reader.buffer[reader.buffer.length - 1] != PERSISTENT_ID_VERSION) {
221
+ throw new Error("Unsupported version");
274
222
  }
275
- static decode(fileId) {
276
- const reader = new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)((0, _1_utilities_js_1.base64DecodeUrlSafe)(fileId)));
277
- const fileUniqueType = reader.readInt32();
278
- switch (fileUniqueType) {
279
- case FileUniqueType.Web: {
280
- const url = reader.readString();
281
- return new FileUniqueID(fileUniqueType, { url });
282
- }
283
- case FileUniqueType.Photo: {
284
- const volumeId = reader.readInt64();
285
- const localId = reader.readInt32();
286
- return new FileUniqueID(fileUniqueType, { volumeId, localId });
287
- }
288
- case FileUniqueType.Document: {
289
- const mediaId = reader.readInt64();
290
- return new FileUniqueID(fileUniqueType, { mediaId });
291
- }
292
- default:
293
- (0, _1_utilities_js_1.UNREACHABLE)();
223
+ const originalType = reader.readInt32();
224
+ const type = ((originalType & ~WEB_LOCATION_FLAG) & ~FILE_REFERENCE_FLAG);
225
+ const dcId = reader.readInt32();
226
+ if (isWeb(originalType)) {
227
+ const url = reader.readString();
228
+ const accessHash = reader.readInt64();
229
+ return { type, dcId, location: { type: "web", url, accessHash } };
230
+ }
231
+ const fileReference = hasFileReference(originalType) ? reader.readBytes() : undefined;
232
+ const id = reader.readInt64();
233
+ const accessHash = reader.readInt64();
234
+ if (getFileTypeClass(type) == FileTypeClass.Photo) {
235
+ const source = deserializePhotoSource(reader);
236
+ return { type, dcId, fileReference, location: { type: "photo", id, accessHash, source } };
237
+ }
238
+ else {
239
+ return { type, dcId, fileReference, location: { type: "common", id, accessHash } };
240
+ }
241
+ }
242
+ exports.deserializeFileId = deserializeFileId;
243
+ function serializeFileId(fileId) {
244
+ const writer = new _2_tl_js_1.TLWriter();
245
+ let type = fileId.type;
246
+ if (fileId.fileReference) {
247
+ type |= FILE_REFERENCE_FLAG;
248
+ }
249
+ if (fileId.location.type == "web") {
250
+ type |= WEB_LOCATION_FLAG;
251
+ }
252
+ writer.writeInt32(type);
253
+ writer.writeInt32(fileId.dcId);
254
+ if (fileId.location.type == "web") {
255
+ writer.writeString(fileId.location.url);
256
+ writer.writeInt64(fileId.location.accessHash);
257
+ }
258
+ else {
259
+ if (fileId.fileReference) {
260
+ writer.writeBytes(fileId.fileReference);
294
261
  }
262
+ writer.writeInt64(fileId.location.id);
263
+ writer.writeInt64(fileId.location.accessHash);
264
+ if (fileId.location.type == "photo") {
265
+ serializePhotoSource(fileId.location.source, writer);
266
+ }
267
+ }
268
+ writer.write(new Uint8Array([NEXT_VERSION - 1, PERSISTENT_ID_VERSION]));
269
+ return (0, _1_utilities_js_1.base64EncodeUrlSafe)((0, _1_utilities_js_1.rleEncode)(writer.buffer));
270
+ }
271
+ exports.serializeFileId = serializeFileId;
272
+ function toUniqueFileId(fileId) {
273
+ const writer = new _2_tl_js_1.TLWriter();
274
+ const type = fileId.location.type == "web" ? 0 : (getFileTypeClass(fileId.type) + 1);
275
+ writer.writeInt32(type);
276
+ if (fileId.location.type == "web") {
277
+ writer.writeString(fileId.location.url);
295
278
  }
296
- encode() {
297
- const writer = new _2_tl_js_1.TLWriter();
298
- writer.writeInt32(this.fileUniqueType);
299
- switch (this.fileUniqueType) {
300
- case FileUniqueType.Web:
301
- if (this.params.url == undefined) {
302
- (0, _1_utilities_js_1.UNREACHABLE)();
303
- }
304
- writer.writeString(this.params.url);
279
+ else if (fileId.location.type == "common") {
280
+ writer.writeInt64(fileId.location.id);
281
+ }
282
+ else {
283
+ switch (fileId.location.source.type) {
284
+ case PhotoSourceType.Legacy:
285
+ case PhotoSourceType.StickerSetThumbnail:
286
+ (0, _1_utilities_js_1.UNREACHABLE)();
287
+ /* falls through */
288
+ case PhotoSourceType.FullLegacy:
289
+ case PhotoSourceType.ChatPhotoSmallLegacy:
290
+ case PhotoSourceType.ChatPhotoBigLegacy:
291
+ case PhotoSourceType.StickerSetThumbnailLegacy:
292
+ writer.writeInt64(fileId.location.id);
293
+ writePhotoSourceUniqueId(fileId.location.source, writer);
305
294
  break;
306
- case FileUniqueType.Photo:
307
- if (this.params.volumeId == undefined || this.params.localId == undefined) {
308
- (0, _1_utilities_js_1.UNREACHABLE)();
309
- }
310
- writer.writeInt64(this.params.volumeId);
311
- writer.writeInt32(this.params.localId);
295
+ case PhotoSourceType.ChatPhotoSmall:
296
+ case PhotoSourceType.ChatPhotoBig:
297
+ case PhotoSourceType.Thumbnail:
298
+ writer.writeInt64(fileId.location.id);
299
+ writePhotoSourceUniqueId(fileId.location.source, writer);
312
300
  break;
313
- case FileUniqueType.Document:
314
- if (this.params.mediaId == undefined) {
315
- (0, _1_utilities_js_1.UNREACHABLE)();
316
- }
317
- writer.writeInt64(this.params.mediaId);
301
+ case PhotoSourceType.StickerSetThumbnailVersion:
302
+ writePhotoSourceUniqueId(fileId.location.source, writer);
318
303
  break;
319
- default:
320
- (0, _1_utilities_js_1.UNREACHABLE)();
321
304
  }
322
- return (0, _1_utilities_js_1.base64EncodeUrlSafe)((0, _1_utilities_js_1.rleEncode)(writer.buffer));
323
305
  }
306
+ return (0, _1_utilities_js_1.base64EncodeUrlSafe)((0, _1_utilities_js_1.rleEncode)(writer.buffer));
324
307
  }
325
- exports.FileUniqueID = FileUniqueID;
308
+ exports.toUniqueFileId = toUniqueFileId;
@@ -4,26 +4,20 @@ exports.constructChatPhoto = void 0;
4
4
  const _2_tl_js_1 = require("../2_tl.js");
5
5
  const _0__file_id_js_1 = require("./0__file_id.js");
6
6
  function constructChatPhoto(photo, chatId, chatAccessHash) {
7
- const smallFileId = new _0__file_id_js_1.FileID(null, null, _0__file_id_js_1.FileType.ChatPhoto, photo.dc_id, {
8
- mediaId: photo.photo_id,
9
- thumbnailSource: _0__file_id_js_1.ThumbnailSource.ChatPhotoSmall,
10
- chatId,
11
- chatAccessHash,
12
- accessHash: 0n,
13
- volumeId: 0n,
14
- localId: 0,
15
- }).encode();
16
- const smallFileUniqueId = new _0__file_id_js_1.FileUniqueID(_0__file_id_js_1.FileUniqueType.Document, { mediaId: photo.photo_id }).encode();
17
- const bigFileId = new _0__file_id_js_1.FileID(null, null, _0__file_id_js_1.FileType.ChatPhoto, photo.dc_id, {
18
- mediaId: photo.photo_id,
19
- thumbnailSource: _0__file_id_js_1.ThumbnailSource.ChatPhotoBig,
20
- chatId,
21
- chatAccessHash,
22
- accessHash: 0n,
23
- volumeId: 0n,
24
- localId: 0,
25
- }).encode();
26
- const bigFileUniqueId = new _0__file_id_js_1.FileUniqueID(_0__file_id_js_1.FileUniqueType.Document, { mediaId: photo.photo_id }).encode();
7
+ const smallFileId_ = {
8
+ type: _0__file_id_js_1.FileType.ProfilePhoto,
9
+ dcId: photo.dc_id,
10
+ location: { type: "photo", id: photo.photo_id, accessHash: 0n, source: { type: _0__file_id_js_1.PhotoSourceType.ChatPhotoSmall, chatId: BigInt(chatId), chatAccessHash } },
11
+ };
12
+ const smallFileId = (0, _0__file_id_js_1.serializeFileId)(smallFileId_);
13
+ const smallFileUniqueId = (0, _0__file_id_js_1.toUniqueFileId)(smallFileId_);
14
+ const bigFileId_ = {
15
+ type: _0__file_id_js_1.FileType.ProfilePhoto,
16
+ dcId: photo.dc_id,
17
+ location: { type: "photo", id: photo.photo_id, accessHash: 0n, source: { type: _0__file_id_js_1.PhotoSourceType.ChatPhotoBig, chatId: BigInt(chatId), chatAccessHash } },
18
+ };
19
+ const bigFileId = (0, _0__file_id_js_1.serializeFileId)(bigFileId_);
20
+ const bigFileUniqueId = (0, _0__file_id_js_1.toUniqueFileId)(bigFileId_);
27
21
  if (photo instanceof _2_tl_js_1.types.ChatPhoto) {
28
22
  return {
29
23
  smallFileId,
@@ -1,10 +1,15 @@
1
1
  import { types } from "../2_tl.js";
2
2
  /** Giveaway parameters. */
3
3
  export interface GiveawayParameters {
4
+ /** The identifier of the chat that will be boosted for the duration of the given away Premium subscriptions. */
4
5
  boostedChatId: number;
6
+ /** The identifiers of additional chats that the user must subscribe to in order to be eligible for the prizes. */
5
7
  additionalChatIds: number[];
8
+ /** The point of time in which the winners will be chosen. */
6
9
  winnerSelectionDate: Date;
10
+ /** Whether only new members of the chats will be eligible for the prizes. */
7
11
  onlyNewMembers: boolean;
12
+ /** A list of countries that are eligible for the prizes. */
8
13
  countries: string[];
9
14
  }
10
15
  export declare function constructGiveawayParameters(g: types.MessageMediaGiveaway): GiveawayParameters;