@mtkruto/node 0.0.956 → 0.0.958
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/client/3_client.d.ts +12 -1
- package/esm/client/3_client.js +39 -17
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/storage/0_storage.d.ts +10 -17
- package/esm/storage/0_storage.js +40 -133
- package/esm/storage/0_utilities.d.ts +13 -0
- package/esm/storage/0_utilities.js +62 -0
- package/esm/storage/1_storage_indexed_db.d.ts +3 -3
- package/esm/storage/1_storage_indexed_db.js +4 -3
- package/esm/storage/1_storage_local_storage.d.ts +3 -3
- package/esm/storage/1_storage_local_storage.js +13 -6
- package/esm/storage/1_storage_memory.d.ts +4 -4
- package/esm/storage/1_storage_memory.js +4 -2
- package/esm/storage/1_storage_session_storage.d.ts +3 -3
- package/esm/storage/1_storage_session_storage.js +13 -6
- package/package.json +1 -1
- package/script/client/3_client.d.ts +12 -1
- package/script/client/3_client.js +39 -17
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/storage/0_storage.d.ts +10 -17
- package/script/storage/0_storage.js +40 -133
- package/script/storage/0_utilities.d.ts +13 -0
- package/script/storage/0_utilities.js +68 -0
- package/script/storage/1_storage_indexed_db.d.ts +3 -3
- package/script/storage/1_storage_indexed_db.js +4 -3
- package/script/storage/1_storage_local_storage.d.ts +3 -3
- package/script/storage/1_storage_local_storage.js +13 -6
- package/script/storage/1_storage_memory.d.ts +4 -4
- package/script/storage/1_storage_memory.js +4 -2
- package/script/storage/1_storage_session_storage.d.ts +3 -3
- package/script/storage/1_storage_session_storage.js +13 -6
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Storage } from "./0_storage.js";
|
|
2
|
+
import { fromString, toString } from "./0_utilities.js";
|
|
2
3
|
export class StorageSessionStorage extends Storage {
|
|
3
4
|
constructor(prefix) {
|
|
4
5
|
if (typeof sessionStorage === "undefined") {
|
|
@@ -20,14 +21,20 @@ export class StorageSessionStorage extends Storage {
|
|
|
20
21
|
}
|
|
21
22
|
init() {
|
|
22
23
|
}
|
|
23
|
-
get(
|
|
24
|
-
key = this.prefix +
|
|
25
|
-
|
|
24
|
+
get(key_) {
|
|
25
|
+
const key = this.prefix + toString(key_);
|
|
26
|
+
const value = sessionStorage.getItem(key);
|
|
27
|
+
if (value != null) {
|
|
28
|
+
return fromString(value);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
|
-
set(
|
|
28
|
-
key = this.prefix +
|
|
34
|
+
set(key_, value) {
|
|
35
|
+
const key = this.prefix + toString(key_);
|
|
29
36
|
if (value != null) {
|
|
30
|
-
sessionStorage.setItem(key, value);
|
|
37
|
+
sessionStorage.setItem(key, toString(value));
|
|
31
38
|
}
|
|
32
39
|
else {
|
|
33
40
|
sessionStorage.removeItem(key);
|
package/package.json
CHANGED
|
@@ -59,6 +59,14 @@ export interface ClientParams {
|
|
|
59
59
|
*/
|
|
60
60
|
systemVersion?: string;
|
|
61
61
|
}
|
|
62
|
+
export interface ForwardMessagesParams {
|
|
63
|
+
messageThreadId?: number;
|
|
64
|
+
disableNotification?: boolean;
|
|
65
|
+
protectContent?: boolean;
|
|
66
|
+
sendAs?: number | string;
|
|
67
|
+
dropSenderName?: boolean;
|
|
68
|
+
dropCaption?: boolean;
|
|
69
|
+
}
|
|
62
70
|
export declare class Client extends ClientAbstract {
|
|
63
71
|
readonly storage: Storage;
|
|
64
72
|
readonly apiId: number;
|
|
@@ -152,6 +160,7 @@ export declare class Client extends ClientAbstract {
|
|
|
152
160
|
[getEntity](peer: types.PeerChat): Promise<types.Chat | null>;
|
|
153
161
|
[getEntity](peer: types.PeerChannel): Promise<types.Channel | null>;
|
|
154
162
|
processResult(result: ReadObject): Promise<void>;
|
|
163
|
+
private updatesToMessages;
|
|
155
164
|
sendMessage(chatId: number | string, text: string, params?: {
|
|
156
165
|
parseMode?: ParseMode;
|
|
157
166
|
entities?: MessageEntity[];
|
|
@@ -162,10 +171,12 @@ export declare class Client extends ClientAbstract {
|
|
|
162
171
|
messageThreadId?: number;
|
|
163
172
|
sendAs?: number | string;
|
|
164
173
|
replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
|
|
165
|
-
}): Promise<
|
|
174
|
+
}): Promise<Message>;
|
|
166
175
|
getMessages(chatId: number | string, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
|
|
167
176
|
getMessage(chatId: number | string, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
|
|
168
177
|
private downloadInner;
|
|
169
178
|
download(fileId_: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
|
|
170
179
|
[getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
|
|
180
|
+
forwardMessages(from: number | string, to: number | string, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
|
|
181
|
+
forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
|
|
171
182
|
}
|
|
@@ -1067,6 +1067,26 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1067
1067
|
await this.processUsers(result.users);
|
|
1068
1068
|
}
|
|
1069
1069
|
}
|
|
1070
|
+
async updatesToMessages(chatId, updates) {
|
|
1071
|
+
const messages = new Array();
|
|
1072
|
+
if (updates instanceof types.Updates) {
|
|
1073
|
+
for (const update of updates.updates) {
|
|
1074
|
+
if (update instanceof types.UpdateNewMessage) {
|
|
1075
|
+
messages.push(await (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
|
|
1076
|
+
}
|
|
1077
|
+
else if (update instanceof types.UpdateNewChannelMessage) {
|
|
1078
|
+
messages.push(await (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this)));
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
else if (updates instanceof types.UpdateShortSentMessage || updates instanceof types.UpdateShortSentMessage) {
|
|
1083
|
+
const message = await this.getMessage(chatId, updates.id);
|
|
1084
|
+
if (message != null) {
|
|
1085
|
+
messages.push(message);
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
return messages;
|
|
1089
|
+
}
|
|
1070
1090
|
async sendMessage(chatId, text, params) {
|
|
1071
1091
|
const entities_ = params?.entities ?? [];
|
|
1072
1092
|
const parseMode = params?.parseMode ?? this.parseMode;
|
|
@@ -1125,23 +1145,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1125
1145
|
entities,
|
|
1126
1146
|
replyMarkup,
|
|
1127
1147
|
}));
|
|
1128
|
-
|
|
1129
|
-
for (const update of result.updates) {
|
|
1130
|
-
if (update instanceof types.UpdateNewMessage) {
|
|
1131
|
-
return (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1132
|
-
}
|
|
1133
|
-
else if (update instanceof types.UpdateNewChannelMessage) {
|
|
1134
|
-
return (0, _3_message_js_1.constructMessage)(update.message, this[exports.getEntity].bind(this), this.getMessage.bind(this), this[exports.getStickerSetName].bind(this));
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
else if (result instanceof types.UpdateShortSentMessage || result instanceof types.UpdateShortSentMessage) {
|
|
1139
|
-
const message = await this.getMessage(chatId, result.id);
|
|
1140
|
-
if (message != null) {
|
|
1141
|
-
return message;
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
(0, _0_control_js_1.UNREACHABLE)();
|
|
1148
|
+
return await this.updatesToMessages(chatId, result).then((v) => v[0]);
|
|
1145
1149
|
}
|
|
1146
1150
|
async getMessages(chatId, messageIds) {
|
|
1147
1151
|
const peer = await this.getInputPeer(chatId);
|
|
@@ -1243,5 +1247,23 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1243
1247
|
return name;
|
|
1244
1248
|
}
|
|
1245
1249
|
}
|
|
1250
|
+
async forwardMessages(from, to, messageIds, params) {
|
|
1251
|
+
const result = await this.invoke(new functions.MessagesForwardMessages({
|
|
1252
|
+
fromPeer: await this.getInputPeer(from),
|
|
1253
|
+
toPeer: await this.getInputPeer(to),
|
|
1254
|
+
id: messageIds,
|
|
1255
|
+
randomId: messageIds.map(() => (0, _0_bigint_js_1.getRandomId)()),
|
|
1256
|
+
silent: params?.disableNotification || undefined,
|
|
1257
|
+
topMsgId: params?.messageThreadId,
|
|
1258
|
+
noforwards: params?.disableNotification || undefined,
|
|
1259
|
+
sendAs: params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined,
|
|
1260
|
+
dropAuthor: params?.dropSenderName || undefined,
|
|
1261
|
+
dropMediaCaptions: params?.dropCaption || undefined,
|
|
1262
|
+
}));
|
|
1263
|
+
return await this.updatesToMessages(to, result);
|
|
1264
|
+
}
|
|
1265
|
+
async forwardMessage(from, to, messageId, params) {
|
|
1266
|
+
return await this.forwardMessages(from, to, [messageId], params).then((v) => v[0]);
|
|
1267
|
+
}
|
|
1246
1268
|
}
|
|
1247
1269
|
exports.Client = Client;
|
package/script/constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
|
4
4
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
5
|
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 158;
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.958";
|
|
8
8
|
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
9
|
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
package/script/constants.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
|
|
|
88
88
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
89
89
|
exports.DEFAULT_INITIAL_DC = "2-test";
|
|
90
90
|
exports.LAYER = 158;
|
|
91
|
-
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
91
|
+
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.958";
|
|
92
92
|
// @ts-ignore: lib
|
|
93
93
|
exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
94
94
|
exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -1,33 +1,28 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
2
|
import { DC } from "../transport/2_transport_provider.js";
|
|
3
3
|
import * as types from "../tl/2_types.js";
|
|
4
|
+
export type StorageKeyPart = string | number | bigint | Uint8Array;
|
|
4
5
|
export declare abstract class Storage {
|
|
5
6
|
private _authKeyId;
|
|
6
7
|
abstract init(): MaybePromise<void>;
|
|
7
|
-
abstract set(key:
|
|
8
|
-
abstract get(key:
|
|
8
|
+
abstract set(key: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
|
|
9
|
+
abstract get<T>(key: readonly StorageKeyPart[]): MaybePromise<T | null>;
|
|
9
10
|
setDc(dc: DC | null): MaybePromise<void>;
|
|
10
|
-
getDc():
|
|
11
|
+
getDc(): MaybePromise<DC | null>;
|
|
11
12
|
private resetAuthKeyId;
|
|
12
13
|
getAuthKey(): Promise<Uint8Array | null>;
|
|
13
14
|
setAuthKey(authKey: Uint8Array | null): Promise<void>;
|
|
14
15
|
get authKeyId(): bigint | null;
|
|
15
|
-
private readonly channelAccessHash__;
|
|
16
16
|
setChannelAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
|
|
17
|
-
getChannelAccessHash(id: bigint):
|
|
18
|
-
private readonly userAccessHash__;
|
|
17
|
+
getChannelAccessHash(id: bigint): MaybePromise<bigint | null>;
|
|
19
18
|
setUserAccessHash(id: bigint, accessHash: bigint): MaybePromise<void>;
|
|
20
|
-
getUserAccessHash(id: bigint):
|
|
21
|
-
private readonly username__;
|
|
19
|
+
getUserAccessHash(id: bigint): MaybePromise<bigint | null>;
|
|
22
20
|
updateUsernames(type: "user" | "channel", id: bigint, usernames: string[]): Promise<void>;
|
|
23
|
-
getUsername(username: string):
|
|
24
|
-
private readonly state__;
|
|
21
|
+
getUsername(username: string): MaybePromise<["channel" | "user", bigint, Date] | null>;
|
|
25
22
|
setState(state: types.UpdatesState): Promise<void>;
|
|
26
23
|
getState(): Promise<types.UpdatesState | null>;
|
|
27
|
-
private readonly channelPts__;
|
|
28
24
|
setChannelPts(channelId: bigint, pts: number): Promise<void>;
|
|
29
|
-
getChannelPts(channelId: bigint):
|
|
30
|
-
private readonly peer__;
|
|
25
|
+
getChannelPts(channelId: bigint): MaybePromise<number | null>;
|
|
31
26
|
setEntity(peer: types.Channel): Promise<void>;
|
|
32
27
|
setEntity(peer: types.Chat): Promise<void>;
|
|
33
28
|
setEntity(peer: types.User): Promise<void>;
|
|
@@ -35,10 +30,8 @@ export declare abstract class Storage {
|
|
|
35
30
|
getEntity(type: "chat", id: bigint): Promise<types.Chat | null>;
|
|
36
31
|
getEntity(type: "user", id: bigint): Promise<types.User | null>;
|
|
37
32
|
getEntity(type: "channel" | "chat" | "user", id: bigint): Promise<types.Channel | types.Chat | types.User | null>;
|
|
38
|
-
private readonly accountType__;
|
|
39
33
|
setAccountType(type: "user" | "bot"): Promise<void>;
|
|
40
|
-
getAccountType():
|
|
41
|
-
private readonly stickerSetName__;
|
|
34
|
+
getAccountType(): MaybePromise<"bot" | "user" | null>;
|
|
42
35
|
updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
|
|
43
|
-
getStickerSetName(id: bigint, accessHash: bigint):
|
|
36
|
+
getStickerSetName(id: bigint, accessHash: bigint): MaybePromise<[string, Date] | null>;
|
|
44
37
|
}
|
|
@@ -24,14 +24,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Storage = void 0;
|
|
27
|
-
const deps_js_1 = require("../deps.js");
|
|
28
27
|
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
29
28
|
const _0_hash_js_1 = require("../utilities/0_hash.js");
|
|
30
29
|
const _0_bigint_js_1 = require("../utilities/0_bigint.js");
|
|
31
30
|
const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
|
|
32
31
|
const types = __importStar(require("../tl/2_types.js"));
|
|
33
32
|
const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
|
|
34
|
-
const
|
|
33
|
+
const KPARTS__DC = ["dc"];
|
|
34
|
+
const KPARTS__AUTH_KEY = ["authKey"];
|
|
35
|
+
const KPARTS__CHANNEL_ACCESS_HASH = (v) => ["channelAccessHash", v];
|
|
36
|
+
const KPARTS__USER_ACCESS_HASH = (v) => ["userAccessHash", v];
|
|
37
|
+
const KPARTS__USERNAME = (v) => ["username", v];
|
|
38
|
+
const KPARTS__STATE = ["state"];
|
|
39
|
+
const KPARTS__CHANNEL_PTS = (v) => ["channelPts", v];
|
|
40
|
+
const KPARTS__PEER = (type, id) => ["peer", type, id];
|
|
41
|
+
const KPARTS__ACCOUNT_TYPE = ["accountType"];
|
|
42
|
+
const KPARTS__STICKER_SET_NAME = (id, accessHash) => ["stickerSetName", id, accessHash];
|
|
35
43
|
class Storage {
|
|
36
44
|
constructor() {
|
|
37
45
|
Object.defineProperty(this, "_authKeyId", {
|
|
@@ -40,60 +48,12 @@ class Storage {
|
|
|
40
48
|
writable: true,
|
|
41
49
|
value: null
|
|
42
50
|
});
|
|
43
|
-
Object.defineProperty(this, "channelAccessHash__", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
configurable: true,
|
|
46
|
-
writable: true,
|
|
47
|
-
value: "channelAccessHash__"
|
|
48
|
-
});
|
|
49
|
-
Object.defineProperty(this, "userAccessHash__", {
|
|
50
|
-
enumerable: true,
|
|
51
|
-
configurable: true,
|
|
52
|
-
writable: true,
|
|
53
|
-
value: "userAccessHash__"
|
|
54
|
-
});
|
|
55
|
-
Object.defineProperty(this, "username__", {
|
|
56
|
-
enumerable: true,
|
|
57
|
-
configurable: true,
|
|
58
|
-
writable: true,
|
|
59
|
-
value: "username__"
|
|
60
|
-
});
|
|
61
|
-
Object.defineProperty(this, "state__", {
|
|
62
|
-
enumerable: true,
|
|
63
|
-
configurable: true,
|
|
64
|
-
writable: true,
|
|
65
|
-
value: "state__"
|
|
66
|
-
});
|
|
67
|
-
Object.defineProperty(this, "channelPts__", {
|
|
68
|
-
enumerable: true,
|
|
69
|
-
configurable: true,
|
|
70
|
-
writable: true,
|
|
71
|
-
value: "channelPts__"
|
|
72
|
-
});
|
|
73
|
-
Object.defineProperty(this, "peer__", {
|
|
74
|
-
enumerable: true,
|
|
75
|
-
configurable: true,
|
|
76
|
-
writable: true,
|
|
77
|
-
value: "peer__"
|
|
78
|
-
});
|
|
79
|
-
Object.defineProperty(this, "accountType__", {
|
|
80
|
-
enumerable: true,
|
|
81
|
-
configurable: true,
|
|
82
|
-
writable: true,
|
|
83
|
-
value: "accountType__"
|
|
84
|
-
});
|
|
85
|
-
Object.defineProperty(this, "stickerSetName__", {
|
|
86
|
-
enumerable: true,
|
|
87
|
-
configurable: true,
|
|
88
|
-
writable: true,
|
|
89
|
-
value: "stickerSetName__"
|
|
90
|
-
});
|
|
91
51
|
}
|
|
92
52
|
setDc(dc) {
|
|
93
|
-
return this.set(
|
|
53
|
+
return this.set(KPARTS__DC, dc);
|
|
94
54
|
}
|
|
95
|
-
|
|
96
|
-
return
|
|
55
|
+
getDc() {
|
|
56
|
+
return this.get(KPARTS__DC);
|
|
97
57
|
}
|
|
98
58
|
async resetAuthKeyId(authKey) {
|
|
99
59
|
if (authKey != null) {
|
|
@@ -104,105 +64,65 @@ class Storage {
|
|
|
104
64
|
}
|
|
105
65
|
}
|
|
106
66
|
async getAuthKey() {
|
|
107
|
-
const
|
|
108
|
-
const authKey = authKey_ == null ? null : new Uint8Array(authKey_.split(/([0-9a-f]{2})/).filter((v) => v).map((v) => parseInt(v, 16)));
|
|
67
|
+
const authKey = await this.get(KPARTS__AUTH_KEY);
|
|
109
68
|
await this.resetAuthKeyId(authKey);
|
|
110
69
|
return authKey;
|
|
111
70
|
}
|
|
112
71
|
async setAuthKey(authKey) {
|
|
113
|
-
await this.set(
|
|
72
|
+
await this.set(KPARTS__AUTH_KEY, authKey);
|
|
114
73
|
await this.resetAuthKeyId(authKey);
|
|
115
74
|
}
|
|
116
75
|
get authKeyId() {
|
|
117
76
|
return this._authKeyId;
|
|
118
77
|
}
|
|
119
78
|
setChannelAccessHash(id, accessHash) {
|
|
120
|
-
return this.set(
|
|
79
|
+
return this.set(KPARTS__CHANNEL_ACCESS_HASH(id), accessHash);
|
|
121
80
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (accessHash != null) {
|
|
125
|
-
return BigInt(accessHash);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
81
|
+
getChannelAccessHash(id) {
|
|
82
|
+
return this.get(KPARTS__CHANNEL_ACCESS_HASH(id));
|
|
130
83
|
}
|
|
131
84
|
setUserAccessHash(id, accessHash) {
|
|
132
|
-
return this.set(
|
|
85
|
+
return this.set(KPARTS__USER_ACCESS_HASH(id), accessHash);
|
|
133
86
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (accessHash != null) {
|
|
137
|
-
return BigInt(accessHash);
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
87
|
+
getUserAccessHash(id) {
|
|
88
|
+
return this.get(KPARTS__USER_ACCESS_HASH(id));
|
|
142
89
|
}
|
|
143
90
|
async updateUsernames(type, id, usernames) {
|
|
144
91
|
for (let username of usernames) {
|
|
145
92
|
username = username.toLowerCase();
|
|
146
|
-
await this.set(
|
|
93
|
+
await this.set(KPARTS__USERNAME(username), [type, String(id), new Date()]);
|
|
147
94
|
}
|
|
148
95
|
}
|
|
149
|
-
|
|
96
|
+
getUsername(username) {
|
|
150
97
|
username = username.toLowerCase();
|
|
151
|
-
|
|
152
|
-
if (username_ != null) {
|
|
153
|
-
const [type, id, updatedAt] = JSON.parse(username_);
|
|
154
|
-
return [type, BigInt(id), new Date(updatedAt)];
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
98
|
+
return this.get(KPARTS__USERNAME(username));
|
|
159
99
|
}
|
|
160
100
|
async setState(state) {
|
|
161
|
-
await this.set(
|
|
162
|
-
date: state.date,
|
|
163
|
-
pts: state.pts,
|
|
164
|
-
qts: state.qts,
|
|
165
|
-
seq: state.seq,
|
|
166
|
-
unreadCount: state.unreadCount,
|
|
167
|
-
}));
|
|
101
|
+
await this.set(KPARTS__STATE, state[_1_tl_object_js_1.serialize]());
|
|
168
102
|
}
|
|
169
103
|
async getState() {
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
return new types.UpdatesState({
|
|
174
|
-
date: state_.date,
|
|
175
|
-
pts: state_.pts,
|
|
176
|
-
qts: state_.qts,
|
|
177
|
-
seq: state_.seq,
|
|
178
|
-
unreadCount: state_.unreadCount,
|
|
179
|
-
});
|
|
104
|
+
const state = await this.get(KPARTS__STATE);
|
|
105
|
+
if (state != null) {
|
|
106
|
+
return new _3_tl_reader_js_1.TLReader(state).readObject();
|
|
180
107
|
}
|
|
181
108
|
else {
|
|
182
109
|
return null;
|
|
183
110
|
}
|
|
184
111
|
}
|
|
185
112
|
async setChannelPts(channelId, pts) {
|
|
186
|
-
await this.set(
|
|
113
|
+
await this.set(KPARTS__CHANNEL_PTS(channelId), pts);
|
|
187
114
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (pts != null) {
|
|
191
|
-
return Number(pts);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
115
|
+
getChannelPts(channelId) {
|
|
116
|
+
return this.get(KPARTS__CHANNEL_PTS(channelId));
|
|
196
117
|
}
|
|
197
118
|
async setEntity(peer) {
|
|
198
119
|
const type = peer instanceof types.Channel ? "channel" : peer instanceof types.Chat ? "chat" : peer instanceof types.User ? "user" : (0, _0_control_js_1.UNREACHABLE)();
|
|
199
|
-
await this.set(
|
|
120
|
+
await this.set(KPARTS__PEER(type, peer.id), peer[_1_tl_object_js_1.serialize]());
|
|
200
121
|
}
|
|
201
122
|
async getEntity(type, id) {
|
|
202
|
-
const peer_ = await this.get(
|
|
123
|
+
const peer_ = await this.get(KPARTS__PEER(type, id));
|
|
203
124
|
if (peer_ != null) {
|
|
204
|
-
|
|
205
|
-
return reader.readObject();
|
|
125
|
+
return new _3_tl_reader_js_1.TLReader(peer_).readObject();
|
|
206
126
|
}
|
|
207
127
|
else {
|
|
208
128
|
return null;
|
|
@@ -218,31 +138,18 @@ class Storage {
|
|
|
218
138
|
throw err;
|
|
219
139
|
}
|
|
220
140
|
else {
|
|
221
|
-
await this.set(
|
|
141
|
+
await this.set(KPARTS__ACCOUNT_TYPE, type);
|
|
222
142
|
}
|
|
223
143
|
}
|
|
224
144
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
if (accountType != null) {
|
|
228
|
-
return accountType;
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
(0, _0_control_js_1.UNREACHABLE)();
|
|
232
|
-
}
|
|
145
|
+
getAccountType() {
|
|
146
|
+
return this.get(KPARTS__ACCOUNT_TYPE);
|
|
233
147
|
}
|
|
234
148
|
async updateStickerSetName(id, accessHash, name) {
|
|
235
|
-
await this.set(
|
|
149
|
+
await this.set(KPARTS__STICKER_SET_NAME(id, accessHash), [name, new Date()]);
|
|
236
150
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (stickerSetName_ != null) {
|
|
240
|
-
const [name, updatedAt] = JSON.parse(stickerSetName_);
|
|
241
|
-
return [name, new Date(updatedAt)];
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
return null;
|
|
245
|
-
}
|
|
151
|
+
getStickerSetName(id, accessHash) {
|
|
152
|
+
return this.get(KPARTS__STICKER_SET_NAME(id, accessHash));
|
|
246
153
|
}
|
|
247
154
|
}
|
|
248
155
|
exports.Storage = Storage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StorageKeyPart } from "./0_storage.js";
|
|
2
|
+
export declare enum ValueType {
|
|
3
|
+
Boolean = 0,
|
|
4
|
+
Number = 1,
|
|
5
|
+
String = 2,
|
|
6
|
+
BigInt = 3,
|
|
7
|
+
Date = 4,
|
|
8
|
+
Uint8Array = 5,
|
|
9
|
+
Array = 6
|
|
10
|
+
}
|
|
11
|
+
export declare function toString(value: unknown): string;
|
|
12
|
+
export declare function fromString<T>(string: string): any;
|
|
13
|
+
export declare function fixKey(key: StorageKeyPart[]): (string | number | Uint8Array)[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fixKey = exports.fromString = exports.toString = exports.ValueType = void 0;
|
|
4
|
+
const deps_js_1 = require("../deps.js");
|
|
5
|
+
const _0_control_js_1 = require("../utilities/0_control.js");
|
|
6
|
+
var ValueType;
|
|
7
|
+
(function (ValueType) {
|
|
8
|
+
ValueType[ValueType["Boolean"] = 0] = "Boolean";
|
|
9
|
+
ValueType[ValueType["Number"] = 1] = "Number";
|
|
10
|
+
ValueType[ValueType["String"] = 2] = "String";
|
|
11
|
+
ValueType[ValueType["BigInt"] = 3] = "BigInt";
|
|
12
|
+
ValueType[ValueType["Date"] = 4] = "Date";
|
|
13
|
+
ValueType[ValueType["Uint8Array"] = 5] = "Uint8Array";
|
|
14
|
+
ValueType[ValueType["Array"] = 6] = "Array";
|
|
15
|
+
})(ValueType = exports.ValueType || (exports.ValueType = {}));
|
|
16
|
+
function toString(value) {
|
|
17
|
+
if (typeof value === "boolean") {
|
|
18
|
+
return JSON.stringify([ValueType.Boolean, value]);
|
|
19
|
+
}
|
|
20
|
+
else if (typeof value === "number") {
|
|
21
|
+
return JSON.stringify([ValueType.Number, value]);
|
|
22
|
+
}
|
|
23
|
+
else if (typeof value === "string") {
|
|
24
|
+
return JSON.stringify([ValueType.String, value]);
|
|
25
|
+
}
|
|
26
|
+
else if (typeof value == "bigint") {
|
|
27
|
+
return JSON.stringify([ValueType.BigInt, String(value)]);
|
|
28
|
+
}
|
|
29
|
+
else if (value instanceof Date) {
|
|
30
|
+
return JSON.stringify([ValueType.Date, value.getTime()]);
|
|
31
|
+
}
|
|
32
|
+
else if (value instanceof Uint8Array) {
|
|
33
|
+
return JSON.stringify([ValueType.Uint8Array, (0, deps_js_1.base64Encode)(value)]);
|
|
34
|
+
}
|
|
35
|
+
else if (Array.isArray(value)) {
|
|
36
|
+
return JSON.stringify([ValueType.Array, value.map(toString)]);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.toString = toString;
|
|
43
|
+
function fromString(string) {
|
|
44
|
+
const [type, value] = JSON.parse(string);
|
|
45
|
+
if (type == ValueType.Boolean || type == ValueType.Number || type == ValueType.String) {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
else if (type == ValueType.BigInt) {
|
|
49
|
+
return BigInt(value);
|
|
50
|
+
}
|
|
51
|
+
else if (type == ValueType.Date) {
|
|
52
|
+
return new Date(value);
|
|
53
|
+
}
|
|
54
|
+
else if (type == ValueType.Uint8Array) {
|
|
55
|
+
return (0, deps_js_1.base64Decode)(value);
|
|
56
|
+
}
|
|
57
|
+
else if (type == ValueType.Array) {
|
|
58
|
+
return value.map(fromString);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.fromString = fromString;
|
|
65
|
+
function fixKey(key) {
|
|
66
|
+
return key.map((v) => typeof v === "bigint" ? String(v) : v);
|
|
67
|
+
}
|
|
68
|
+
exports.fixKey = fixKey;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Storage } from "./0_storage.js";
|
|
1
|
+
import { Storage, StorageKeyPart } from "./0_storage.js";
|
|
2
2
|
export declare class StorageIndexedDB extends Storage {
|
|
3
3
|
readonly name: string;
|
|
4
4
|
database: IDBDatabase | null;
|
|
5
5
|
constructor(name: string);
|
|
6
6
|
init(): Promise<void>;
|
|
7
|
-
set(k:
|
|
8
|
-
get(k:
|
|
7
|
+
set(k: StorageKeyPart[], v: unknown): Promise<void>;
|
|
8
|
+
get<T>(k: StorageKeyPart[]): Promise<T | null>;
|
|
9
9
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageIndexedDB = void 0;
|
|
4
4
|
const _0_storage_js_1 = require("./0_storage.js");
|
|
5
|
+
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
5
6
|
const VERSION = 1;
|
|
6
7
|
const KV_OBJECT_STORE = "kv";
|
|
7
8
|
class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
@@ -47,10 +48,10 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
47
48
|
// deno-lint-ignore no-explicit-any
|
|
48
49
|
let tx;
|
|
49
50
|
if (v == null) {
|
|
50
|
-
tx = store.delete(k);
|
|
51
|
+
tx = store.delete((0, _0_utilities_js_1.fixKey)(k));
|
|
51
52
|
}
|
|
52
53
|
else {
|
|
53
|
-
tx = store.put(v, k);
|
|
54
|
+
tx = store.put(v, (0, _0_utilities_js_1.fixKey)(k));
|
|
54
55
|
}
|
|
55
56
|
return new Promise((res, rej) => {
|
|
56
57
|
tx.onerror = rej;
|
|
@@ -66,7 +67,7 @@ class StorageIndexedDB extends _0_storage_js_1.Storage {
|
|
|
66
67
|
const tx = this.database
|
|
67
68
|
.transaction(KV_OBJECT_STORE, "readonly")
|
|
68
69
|
.objectStore(KV_OBJECT_STORE)
|
|
69
|
-
.get(k);
|
|
70
|
+
.get((0, _0_utilities_js_1.fixKey)(k));
|
|
70
71
|
return new Promise((res, rej) => {
|
|
71
72
|
tx.onerror = rej;
|
|
72
73
|
tx.onsuccess = () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MaybePromise } from "../utilities/0_types.js";
|
|
2
|
-
import { Storage } from "./0_storage.js";
|
|
2
|
+
import { Storage, StorageKeyPart } from "./0_storage.js";
|
|
3
3
|
export declare class StorageLocalStorage extends Storage implements Storage {
|
|
4
4
|
private readonly prefix;
|
|
5
5
|
constructor(prefix: string);
|
|
6
6
|
init(): void;
|
|
7
|
-
get(
|
|
8
|
-
set(
|
|
7
|
+
get(key_: readonly StorageKeyPart[]): any;
|
|
8
|
+
set(key_: readonly StorageKeyPart[], value: unknown): MaybePromise<void>;
|
|
9
9
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StorageLocalStorage = void 0;
|
|
4
4
|
const _0_storage_js_1 = require("./0_storage.js");
|
|
5
|
+
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
5
6
|
class StorageLocalStorage extends _0_storage_js_1.Storage {
|
|
6
7
|
constructor(prefix) {
|
|
7
8
|
if (typeof localStorage === "undefined") {
|
|
@@ -23,14 +24,20 @@ class StorageLocalStorage extends _0_storage_js_1.Storage {
|
|
|
23
24
|
}
|
|
24
25
|
init() {
|
|
25
26
|
}
|
|
26
|
-
get(
|
|
27
|
-
key = this.prefix +
|
|
28
|
-
|
|
27
|
+
get(key_) {
|
|
28
|
+
const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
|
|
29
|
+
const value = localStorage.getItem(key);
|
|
30
|
+
if (value != null) {
|
|
31
|
+
return (0, _0_utilities_js_1.fromString)(value);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
29
36
|
}
|
|
30
|
-
set(
|
|
31
|
-
key = this.prefix +
|
|
37
|
+
set(key_, value) {
|
|
38
|
+
const key = this.prefix + (0, _0_utilities_js_1.toString)(key_);
|
|
32
39
|
if (value != null) {
|
|
33
|
-
localStorage.setItem(key, value);
|
|
40
|
+
localStorage.setItem(key, (0, _0_utilities_js_1.toString)(value));
|
|
34
41
|
}
|
|
35
42
|
else {
|
|
36
43
|
localStorage.removeItem(key);
|