@mtkruto/node 0.1.128 → 0.1.130
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.
- package/esm/0_deps.d.ts +1 -0
- package/esm/0_deps.js +9 -0
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/5_client.d.ts +17 -3
- package/esm/client/5_client.js +310 -79
- package/esm/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
- package/esm/deps/deno.land/std@0.209.0/media_types/extension.js +26 -0
- package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
- package/esm/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +31 -0
- package/esm/storage/0_storage.d.ts +8 -7
- package/esm/storage/0_storage.js +39 -9
- package/esm/tl/0_tl_raw_reader.js +1 -1
- package/esm/tl/3_utilities.d.ts +1 -0
- package/esm/tl/3_utilities.js +11 -0
- package/esm/types/1__getters.d.ts +3 -2
- package/esm/types/1_chat_p.d.ts +2 -2
- package/esm/types/1_chat_p.js +16 -4
- package/esm/types/1_sticker.js +5 -4
- package/esm/types/4_chat.d.ts +3 -2
- package/esm/types/4_chat.js +16 -27
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -0
- package/script/0_deps.js +11 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/5_client.d.ts +17 -3
- package/script/client/5_client.js +307 -76
- package/script/deps/deno.land/std@0.209.0/media_types/extension.d.ts +17 -0
- package/script/deps/deno.land/std@0.209.0/media_types/extension.js +30 -0
- package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.d.ts +20 -0
- package/script/deps/deno.land/std@0.209.0/media_types/extensions_by_type.js +35 -0
- package/script/storage/0_storage.d.ts +8 -7
- package/script/storage/0_storage.js +39 -9
- package/script/tl/0_tl_raw_reader.js +1 -1
- package/script/tl/3_utilities.d.ts +1 -0
- package/script/tl/3_utilities.js +13 -1
- package/script/types/1__getters.d.ts +3 -2
- package/script/types/1_chat_p.d.ts +2 -2
- package/script/types/1_chat_p.js +16 -4
- package/script/types/1_sticker.js +4 -3
- package/script/types/4_chat.d.ts +3 -2
- package/script/types/4_chat.js +17 -27
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For a given media type, return the most relevant extension, or `undefined`
|
|
3
|
+
* if no extension can be found.
|
|
4
|
+
*
|
|
5
|
+
* Extensions are returned without a leading `.`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { extension } from "https://deno.land/std@$STD_VERSION/media_types/extension.ts";
|
|
10
|
+
*
|
|
11
|
+
* extension("text/plain"); // `txt`
|
|
12
|
+
* extension("application/json"); // `json`
|
|
13
|
+
* extension("text/html; charset=UTF-8"); // `html`
|
|
14
|
+
* extension("application/foo"); // undefined
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function extension(type: string): string | undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.extension = void 0;
|
|
6
|
+
const extensions_by_type_js_1 = require("./extensions_by_type.js");
|
|
7
|
+
/**
|
|
8
|
+
* For a given media type, return the most relevant extension, or `undefined`
|
|
9
|
+
* if no extension can be found.
|
|
10
|
+
*
|
|
11
|
+
* Extensions are returned without a leading `.`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { extension } from "https://deno.land/std@$STD_VERSION/media_types/extension.ts";
|
|
16
|
+
*
|
|
17
|
+
* extension("text/plain"); // `txt`
|
|
18
|
+
* extension("application/json"); // `json`
|
|
19
|
+
* extension("text/html; charset=UTF-8"); // `html`
|
|
20
|
+
* extension("application/foo"); // undefined
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
function extension(type) {
|
|
24
|
+
const exts = (0, extensions_by_type_js_1.extensionsByType)(type);
|
|
25
|
+
if (exts) {
|
|
26
|
+
return exts[0];
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
exports.extension = extension;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { extensions } from "./_util.js";
|
|
2
|
+
export { extensions };
|
|
3
|
+
/**
|
|
4
|
+
* Returns the extensions known to be associated with the media type `type`.
|
|
5
|
+
* The returned extensions will each begin with a leading dot, as in `.html`.
|
|
6
|
+
*
|
|
7
|
+
* When `type` has no associated extensions, the function returns `undefined`.
|
|
8
|
+
*
|
|
9
|
+
* Extensions are returned without a leading `.`.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { extensionsByType } from "https://deno.land/std@$STD_VERSION/media_types/extensions_by_type.ts";
|
|
14
|
+
*
|
|
15
|
+
* extensionsByType("application/json"); // ["json", "map"]
|
|
16
|
+
* extensionsByType("text/html; charset=UTF-8"); // ["html", "htm", "shtml"]
|
|
17
|
+
* extensionsByType("application/foo"); // undefined
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function extensionsByType(type: string): string[] | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
3
|
+
// This module is browser compatible.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.extensionsByType = exports.extensions = void 0;
|
|
6
|
+
const parse_media_type_js_1 = require("./parse_media_type.js");
|
|
7
|
+
const _util_js_1 = require("./_util.js");
|
|
8
|
+
Object.defineProperty(exports, "extensions", { enumerable: true, get: function () { return _util_js_1.extensions; } });
|
|
9
|
+
/**
|
|
10
|
+
* Returns the extensions known to be associated with the media type `type`.
|
|
11
|
+
* The returned extensions will each begin with a leading dot, as in `.html`.
|
|
12
|
+
*
|
|
13
|
+
* When `type` has no associated extensions, the function returns `undefined`.
|
|
14
|
+
*
|
|
15
|
+
* Extensions are returned without a leading `.`.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { extensionsByType } from "https://deno.land/std@$STD_VERSION/media_types/extensions_by_type.ts";
|
|
20
|
+
*
|
|
21
|
+
* extensionsByType("application/json"); // ["json", "map"]
|
|
22
|
+
* extensionsByType("text/html; charset=UTF-8"); // ["html", "htm", "shtml"]
|
|
23
|
+
* extensionsByType("application/foo"); // undefined
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
function extensionsByType(type) {
|
|
27
|
+
try {
|
|
28
|
+
const [mediaType] = (0, parse_media_type_js_1.parseMediaType)(type);
|
|
29
|
+
return _util_js_1.extensions.get(mediaType);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// just swallow errors, returning undefined
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.extensionsByType = extensionsByType;
|
|
@@ -32,7 +32,7 @@ export declare abstract class Storage {
|
|
|
32
32
|
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
33
33
|
getUsername(username: string): Promise<["channel" | "user", bigint, Date] | null>;
|
|
34
34
|
setTlObject(key: readonly StorageKeyPart[], value: TLObject | null): Promise<void>;
|
|
35
|
-
|
|
35
|
+
getTlObject(keyOrBuffer: Uint8Array | readonly StorageKeyPart[]): Promise<import("../2_tl.js").ReadObject | null>;
|
|
36
36
|
setState(state: enums.updates.State): Promise<void>;
|
|
37
37
|
getState(): Promise<import("../tl/2_types.js").updates_State_ | null>;
|
|
38
38
|
setMessage(chatId: number, messageId: number, message: enums.Message | null): Promise<void>;
|
|
@@ -42,13 +42,12 @@ export declare abstract class Storage {
|
|
|
42
42
|
getLastMessage(chatId: number): Promise<enums.Message | null>;
|
|
43
43
|
setChannelPts(channelId: bigint, pts: number): Promise<void>;
|
|
44
44
|
getChannelPts(channelId: bigint): MaybePromise<number | null>;
|
|
45
|
-
setEntity(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
getEntity(type: "
|
|
49
|
-
getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
|
|
45
|
+
setEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
|
|
46
|
+
removeEntity(entity: types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden): Promise<void>;
|
|
47
|
+
getEntity(type: "channel", id: bigint): Promise<types.Channel | types.ChannelForbidden | null>;
|
|
48
|
+
getEntity(type: "chat", id: bigint): Promise<types.Chat | types.ChatForbidden | null>;
|
|
50
49
|
getEntity(type: "user", id: bigint): Promise<types.User | null>;
|
|
51
|
-
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
|
|
50
|
+
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden | types.User | null>;
|
|
52
51
|
setAccountType(type: "user" | "bot"): Promise<void>;
|
|
53
52
|
getAccountType(): MaybePromise<"bot" | "user" | null>;
|
|
54
53
|
updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
|
|
@@ -72,4 +71,6 @@ export declare abstract class Storage {
|
|
|
72
71
|
iterFileParts(id: bigint, partCount: number): AsyncGenerator<Uint8Array, void, unknown>;
|
|
73
72
|
saveFilePart(id: bigint, index: number, bytes: Uint8Array): Promise<void>;
|
|
74
73
|
setFilePartCount(id: bigint, partCount: number): Promise<void>;
|
|
74
|
+
setCustomEmojiDocument(id: bigint, document: types.Document): Promise<void>;
|
|
75
|
+
getCustomEmojiDocument(id: bigint): Promise<[import("../tl/2_types.js").Document_, Date] | null>;
|
|
75
76
|
}
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId;
|
|
13
|
+
var _Storage_instances, _Storage__authKeyId, _Storage_resetAuthKeyId, _Storage_getEntityType;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Storage = void 0;
|
|
16
16
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
@@ -35,6 +35,7 @@ const KPARTS_PINNED_CHATS = (listId) => ["pinnedChats", listId];
|
|
|
35
35
|
const KPARTS_SERVER_SALT = ["serverSalt"];
|
|
36
36
|
const KPARTS_FILE = (fileId) => ["files", fileId];
|
|
37
37
|
const KPARTS_FILE_PART = (fileId, n) => ["fileParts", fileId, n];
|
|
38
|
+
const KPARTS_CEMOJI = (id) => ["customEmojiDocuments", id];
|
|
38
39
|
class Storage {
|
|
39
40
|
constructor() {
|
|
40
41
|
_Storage_instances.add(this);
|
|
@@ -88,7 +89,7 @@ class Storage {
|
|
|
88
89
|
await this.set(key, (0, _1_utilities_js_1.rleEncode)(value[_2_tl_js_1.serialize]()));
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
async
|
|
92
|
+
async getTlObject(keyOrBuffer) {
|
|
92
93
|
const buffer = keyOrBuffer instanceof Uint8Array ? keyOrBuffer : await this.get(keyOrBuffer);
|
|
93
94
|
if (buffer != null) {
|
|
94
95
|
return new _2_tl_js_1.TLReader((0, _1_utilities_js_1.rleDecode)(buffer)).readObject();
|
|
@@ -101,7 +102,7 @@ class Storage {
|
|
|
101
102
|
await this.setTlObject(KPARTS__STATE, state);
|
|
102
103
|
}
|
|
103
104
|
async getState() {
|
|
104
|
-
return await this.
|
|
105
|
+
return await this.getTlObject(KPARTS__STATE);
|
|
105
106
|
}
|
|
106
107
|
async setMessage(chatId, messageId, message) {
|
|
107
108
|
if (chatId > _1_utilities_js_1.ZERO_CHANNEL_ID) {
|
|
@@ -120,11 +121,11 @@ class Storage {
|
|
|
120
121
|
return this.get(KPARTS_MESSAGE_REF(messageId));
|
|
121
122
|
}
|
|
122
123
|
async getMessage(chatId, messageId) {
|
|
123
|
-
return await this.
|
|
124
|
+
return await this.getTlObject(KPARTS_MESSAGE(chatId, messageId));
|
|
124
125
|
}
|
|
125
126
|
async getLastMessage(chatId) {
|
|
126
127
|
for await (const [_, buffer] of await this.getMany({ prefix: KPARTS_MESSAGES(chatId) }, { limit: 1, reverse: true })) {
|
|
127
|
-
return await this.
|
|
128
|
+
return await this.getTlObject(buffer);
|
|
128
129
|
}
|
|
129
130
|
return null;
|
|
130
131
|
}
|
|
@@ -134,9 +135,13 @@ class Storage {
|
|
|
134
135
|
getChannelPts(channelId) {
|
|
135
136
|
return this.get(KPARTS__CHANNEL_PTS(channelId));
|
|
136
137
|
}
|
|
137
|
-
async setEntity(
|
|
138
|
-
const type =
|
|
139
|
-
await this.set(KPARTS__PEER(type,
|
|
138
|
+
async setEntity(entity) {
|
|
139
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
140
|
+
await this.set(KPARTS__PEER(type, entity.id), (0, _1_utilities_js_1.rleEncode)(entity[_2_tl_js_1.serialize]()));
|
|
141
|
+
}
|
|
142
|
+
async removeEntity(entity) {
|
|
143
|
+
const type = __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getEntityType).call(this, entity);
|
|
144
|
+
await this.set(KPARTS__PEER(type, entity.id), null);
|
|
140
145
|
}
|
|
141
146
|
async getEntity(type, id) {
|
|
142
147
|
const peer_ = await this.get(KPARTS__PEER(type, id));
|
|
@@ -216,7 +221,7 @@ class Storage {
|
|
|
216
221
|
++limit;
|
|
217
222
|
const messages = new Array();
|
|
218
223
|
for await (const [_, buffer] of await this.getMany({ start: KPARTS_MESSAGE(chatId, 0), end: KPARTS_MESSAGE(chatId, offsetId) }, { limit, reverse: true })) {
|
|
219
|
-
const message = await this.
|
|
224
|
+
const message = await this.getTlObject(buffer);
|
|
220
225
|
if ("id" in message && message.id == offsetId) {
|
|
221
226
|
continue;
|
|
222
227
|
}
|
|
@@ -254,6 +259,18 @@ class Storage {
|
|
|
254
259
|
}
|
|
255
260
|
await this.set(KPARTS_FILE(id), partCount);
|
|
256
261
|
}
|
|
262
|
+
async setCustomEmojiDocument(id, document) {
|
|
263
|
+
await this.set(KPARTS_CEMOJI(id), [(0, _1_utilities_js_1.rleEncode)(document[_2_tl_js_1.serialize]()), new Date()]);
|
|
264
|
+
}
|
|
265
|
+
async getCustomEmojiDocument(id) {
|
|
266
|
+
const v = await this.get(KPARTS_CEMOJI(id));
|
|
267
|
+
if (v != null) {
|
|
268
|
+
return [await this.getTlObject([0]), v[1]];
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
257
274
|
}
|
|
258
275
|
exports.Storage = Storage;
|
|
259
276
|
_Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
|
|
@@ -263,4 +280,17 @@ _Storage__authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storag
|
|
|
263
280
|
else {
|
|
264
281
|
__classPrivateFieldSet(this, _Storage__authKeyId, null, "f");
|
|
265
282
|
}
|
|
283
|
+
}, _Storage_getEntityType = function _Storage_getEntityType(entity) {
|
|
284
|
+
if (entity instanceof _2_tl_js_1.types.Channel || entity instanceof _2_tl_js_1.types.ChannelForbidden) {
|
|
285
|
+
return "channel";
|
|
286
|
+
}
|
|
287
|
+
else if (entity instanceof _2_tl_js_1.types.Chat || entity instanceof _2_tl_js_1.types.ChatForbidden) {
|
|
288
|
+
return "chat";
|
|
289
|
+
}
|
|
290
|
+
else if (entity instanceof _2_tl_js_1.types.User) {
|
|
291
|
+
return "user";
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
295
|
+
}
|
|
266
296
|
};
|
|
@@ -38,7 +38,7 @@ class TLRawReader {
|
|
|
38
38
|
return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
|
|
39
39
|
}
|
|
40
40
|
readDouble() {
|
|
41
|
-
return new DataView(this.read(8).buffer).getFloat64(0, true);
|
|
41
|
+
return new DataView(this.read(8).buffer).getFloat64(0, true);
|
|
42
42
|
}
|
|
43
43
|
readInt128(signed = true) {
|
|
44
44
|
const buffer = this.read(128 / 8);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { enums } from "./2_types.js";
|
|
2
2
|
export declare function getChannelChatId(channelId: bigint): number;
|
|
3
3
|
export declare function peerToChatId(peer: enums.Peer | enums.InputPeer): number;
|
|
4
|
+
export declare function chatIdToPeer(chatId: number): import("./2_types.js").PeerUser_ | import("./2_types.js").PeerChat_ | import("./2_types.js").PeerChannel_;
|
package/script/tl/3_utilities.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.peerToChatId = exports.getChannelChatId = void 0;
|
|
3
|
+
exports.chatIdToPeer = exports.peerToChatId = exports.getChannelChatId = void 0;
|
|
4
4
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
5
5
|
const _2_types_js_1 = require("./2_types.js");
|
|
6
6
|
function getChannelChatId(channelId) {
|
|
@@ -22,3 +22,15 @@ function peerToChatId(peer) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.peerToChatId = peerToChatId;
|
|
25
|
+
function chatIdToPeer(chatId) {
|
|
26
|
+
if (chatId > 0) {
|
|
27
|
+
return new _2_types_js_1.types.PeerUser({ user_id: BigInt(chatId) });
|
|
28
|
+
}
|
|
29
|
+
else if (chatId > _1_utilities_js_1.ZERO_CHANNEL_ID) {
|
|
30
|
+
return new _2_types_js_1.types.PeerChat({ chat_id: BigInt(Math.abs(chatId)) });
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return new _2_types_js_1.types.PeerChannel({ channel_id: BigInt(_1_utilities_js_1.ZERO_CHANNEL_ID - chatId) });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.chatIdToPeer = chatIdToPeer;
|
|
@@ -3,8 +3,9 @@ import { types } from "../2_tl.js";
|
|
|
3
3
|
import { ChatID } from "./0_chat_id.js";
|
|
4
4
|
export interface EntityGetter {
|
|
5
5
|
(peer: types.PeerUser): MaybePromise<types.User | null>;
|
|
6
|
-
(peer: types.PeerChat): MaybePromise<types.Chat | null>;
|
|
7
|
-
(peer: types.PeerChannel): MaybePromise<types.Channel | null>;
|
|
6
|
+
(peer: types.PeerChat): MaybePromise<types.Chat | types.ChatForbidden | null>;
|
|
7
|
+
(peer: types.PeerChannel): MaybePromise<types.Channel | types.ChannelForbidden | null>;
|
|
8
|
+
(peer: types.PeerUser | types.PeerChat | types.PeerChannel): MaybePromise<types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden | null>;
|
|
8
9
|
}
|
|
9
10
|
export interface InputPeerGetter {
|
|
10
11
|
(id: ChatID): Promise<types.InputPeerUser | types.InputPeerChannel | types.InputPeerChat>;
|
|
@@ -68,5 +68,5 @@ export declare namespace ChatP {
|
|
|
68
68
|
/** This object represents a chat. */
|
|
69
69
|
export type ChatP = ChatP.Private | ChatP.Group | ChatP.Supergroup | ChatP.Channel;
|
|
70
70
|
export declare function constructChatP(chat: types.User): ChatP.Private;
|
|
71
|
-
export declare function constructChatP(chat: types.Chat): ChatP.Group;
|
|
72
|
-
export declare function constructChatP(chat: types.Channel): ChatP.Supergroup | ChatP.Channel;
|
|
71
|
+
export declare function constructChatP(chat: types.Chat | types.ChatForbidden): ChatP.Group;
|
|
72
|
+
export declare function constructChatP(chat: types.Channel | types.ChannelForbidden): ChatP.Supergroup | ChatP.Channel;
|
package/script/types/1_chat_p.js
CHANGED
|
@@ -25,21 +25,33 @@ function constructChatP(chat) {
|
|
|
25
25
|
}
|
|
26
26
|
return (0, _1_utilities_js_1.cleanObject)(chat_);
|
|
27
27
|
}
|
|
28
|
-
else if (chat instanceof _2_tl_js_1.types.Chat) {
|
|
28
|
+
else if (chat instanceof _2_tl_js_1.types.Chat || chat instanceof _2_tl_js_1.types.ChatForbidden) {
|
|
29
29
|
const id = Number(-chat.id);
|
|
30
30
|
const chat_ = {
|
|
31
31
|
id,
|
|
32
32
|
type: "group",
|
|
33
33
|
color: (0, _1_utilities_js_1.getColorFromPeerId)(id),
|
|
34
34
|
title: chat.title,
|
|
35
|
-
isCreator:
|
|
35
|
+
isCreator: false,
|
|
36
36
|
};
|
|
37
|
+
if (chat instanceof _2_tl_js_1.types.Chat) {
|
|
38
|
+
chat_.isCreator = chat.creator || false;
|
|
39
|
+
}
|
|
37
40
|
return (0, _1_utilities_js_1.cleanObject)(chat_);
|
|
38
41
|
}
|
|
39
|
-
else if (chat instanceof _2_tl_js_1.types.Channel) {
|
|
42
|
+
else if (chat instanceof _2_tl_js_1.types.Channel || _2_tl_js_1.types.ChannelForbidden) {
|
|
40
43
|
let chat_;
|
|
41
|
-
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
42
44
|
const id = _1_utilities_js_1.ZERO_CHANNEL_ID + -Number(chat.id);
|
|
45
|
+
if (chat instanceof _2_tl_js_1.types.ChannelForbidden) {
|
|
46
|
+
const { title } = chat;
|
|
47
|
+
if (chat.megagroup) {
|
|
48
|
+
return { id, color: (0, _1_utilities_js_1.getColorFromPeerId)(id), title, type: "supergroup", isScam: false, isFake: false, isVerified: false, isRestricted: false, isForum: false };
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
return { id, color: (0, _1_utilities_js_1.getColorFromPeerId)(id), title, type: "channel", isScam: false, isFake: false, isVerified: false, isRestricted: false };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
|
|
43
55
|
if (chat.megagroup) {
|
|
44
56
|
chat_ = {
|
|
45
57
|
id,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.constructSticker = void 0;
|
|
4
|
+
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
4
5
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
5
6
|
const _0_mask_position_js_1 = require("./0_mask_position.js");
|
|
6
7
|
const _0_thumbnail_js_1 = require("./0_thumbnail.js");
|
|
@@ -8,8 +9,8 @@ async function constructSticker(document, fileId, fileUniqueId, getStickerSetNam
|
|
|
8
9
|
const stickerAttribute = document.attributes.find((v) => v instanceof _2_tl_js_1.types.DocumentAttributeSticker);
|
|
9
10
|
const imageSizeAttribute = document.attributes.find((v) => v instanceof _2_tl_js_1.types.DocumentAttributeImageSize);
|
|
10
11
|
const videoAttribute = document.attributes.find((v) => v instanceof _2_tl_js_1.types.DocumentAttributeVideo);
|
|
11
|
-
const setName =
|
|
12
|
-
return {
|
|
12
|
+
const setName = stickerAttribute.stickerset instanceof _2_tl_js_1.types.InputStickerSetID ? await getStickerSetName(stickerAttribute.stickerset) : undefined;
|
|
13
|
+
return (0, _1_utilities_js_1.cleanObject)({
|
|
13
14
|
fileId,
|
|
14
15
|
fileUniqueId,
|
|
15
16
|
// TODO: custom emoji type?
|
|
@@ -26,6 +27,6 @@ async function constructSticker(document, fileId, fileUniqueId, getStickerSetNam
|
|
|
26
27
|
customEmojiId: undefined,
|
|
27
28
|
needsRepainting: undefined,
|
|
28
29
|
fileSize: Number(document.size),
|
|
29
|
-
};
|
|
30
|
+
});
|
|
30
31
|
}
|
|
31
32
|
exports.constructSticker = constructSticker;
|
package/script/types/4_chat.d.ts
CHANGED
|
@@ -29,5 +29,6 @@ export declare namespace Chat {
|
|
|
29
29
|
export type Chat = Chat.Channel | Chat.Supergroup | Chat.Group | Chat.Private;
|
|
30
30
|
export declare function getChatOrder(lastMessage: Message | undefined, pinned: number): string;
|
|
31
31
|
export declare function constructChat(dialog: enums.Dialog, dialogs: types.messages.Dialogs | types.messages.DialogsSlice, pinnedChats: number[], getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">, getStickerSetName: StickerSetNameGetter): Promise<Chat>;
|
|
32
|
-
export declare function constructChat2(
|
|
33
|
-
export declare function constructChat3(chatId: number, pinned: number,
|
|
32
|
+
export declare function constructChat2(entity: types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden, pinned: number, lastMessage: Message | undefined): Chat;
|
|
33
|
+
export declare function constructChat3(chatId: number, pinned: number, lastMessage: Message | undefined, getEntity: EntityGetter): Promise<Chat | null>;
|
|
34
|
+
export declare function constructChat4(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter<"replyToMessage">): Promise<Chat | null>;
|
package/script/types/4_chat.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.constructChat3 = exports.constructChat2 = exports.constructChat = exports.getChatOrder = void 0;
|
|
3
|
+
exports.constructChat4 = exports.constructChat3 = exports.constructChat2 = exports.constructChat = exports.getChatOrder = 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
6
|
const _1_chat_p_js_1 = require("./1_chat_p.js");
|
|
@@ -74,29 +74,8 @@ async function constructChat(dialog, dialogs, pinnedChats, getEntity, getMessage
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
exports.constructChat = constructChat;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (chatId < _1_utilities_js_1.ZERO_CHANNEL_ID) {
|
|
80
|
-
const entity = await getEntity(new _2_tl_js_1.types.PeerChannel({ channel_id: BigInt(Math.abs(chatId - _1_utilities_js_1.ZERO_CHANNEL_ID)) }));
|
|
81
|
-
if (entity != null) {
|
|
82
|
-
chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else if (chatId < 0) {
|
|
86
|
-
const entity = await getEntity(new _2_tl_js_1.types.PeerChat({ chat_id: BigInt(Math.abs(chatId)) }));
|
|
87
|
-
if (entity != null) {
|
|
88
|
-
chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const entity = await getEntity(new _2_tl_js_1.types.PeerUser({ user_id: BigInt(chatId) }));
|
|
93
|
-
if (entity != null) {
|
|
94
|
-
chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (chatPAlsoPhoto == null) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
77
|
+
function constructChat2(entity, pinned, lastMessage) {
|
|
78
|
+
const chatPAlsoPhoto = getChatPAlsoPhoto(entity);
|
|
100
79
|
const order = getChatOrder(lastMessage, pinned);
|
|
101
80
|
const { also, photo, chatP } = chatPAlsoPhoto;
|
|
102
81
|
if (chatP.type == "group") {
|
|
@@ -116,9 +95,20 @@ async function constructChat2(chatId, pinned, lastMessage, getEntity) {
|
|
|
116
95
|
}
|
|
117
96
|
}
|
|
118
97
|
exports.constructChat2 = constructChat2;
|
|
119
|
-
async function constructChat3(chatId, pinned,
|
|
98
|
+
async function constructChat3(chatId, pinned, lastMessage, getEntity) {
|
|
99
|
+
const peer = (0, _2_tl_js_1.chatIdToPeer)(chatId);
|
|
100
|
+
const entity = await getEntity(peer);
|
|
101
|
+
if (entity == null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return constructChat2(entity, pinned, lastMessage);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.constructChat3 = constructChat3;
|
|
109
|
+
async function constructChat4(chatId, pinned, lastMessageId, getEntity, getMessage) {
|
|
120
110
|
const lastMessage_ = lastMessageId > 0 ? await getMessage(chatId, lastMessageId) : null;
|
|
121
111
|
const lastMessage = lastMessage_ == null ? undefined : lastMessage_;
|
|
122
|
-
return await
|
|
112
|
+
return await constructChat3(chatId, pinned, lastMessage, getEntity);
|
|
123
113
|
}
|
|
124
|
-
exports.
|
|
114
|
+
exports.constructChat4 = constructChat4;
|