/
Abstract.ts
151 lines (127 loc) · 3.94 KB
/
Abstract.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import type { AuthKey } from "../crypto/AuthKey";
import type { EntityLike } from "../define";
import { Api } from "../tl";
export abstract class Session {
/**
* Creates a clone of this session file
* @param toInstance {Session|null}
* @returns {Session}
*/
/* CONTEST
clone(toInstance = null) {
return toInstance || new this.constructor()
}*/
/**
* Sets the information of the data center address and port that
* the library should connect to, as well as the data center ID,
* which is currently unused.
* @param dcId {number}
* @param serverAddress {string}
* @param port {number}
*/
abstract setDC(dcId: number, serverAddress: string, port: number): void;
/**
* Returns the currently-used data center ID.
*/
abstract get dcId(): number;
/**
* Returns the server address where the library should connect to.
*/
abstract get serverAddress(): string;
/**
* Returns the port to which the library should connect to.
*/
abstract get port(): number;
/**
* Returns an ``AuthKey`` instance associated with the saved
* data center, or `undefined` if a new one should be generated.
*/
abstract get authKey(): AuthKey | undefined;
/**
* Sets the ``AuthKey`` to be used for the saved data center.
* @param value
*/
abstract set authKey(value: AuthKey | undefined);
/**
* Called before using the session
*/
abstract load(): Promise<void>;
/**
* sets auth key for a dc
*/
abstract setAuthKey(authKey?: AuthKey, dcId?: number): void;
/**
* gets auth key for a dc
*/
abstract getAuthKey(dcId?: number): AuthKey | undefined;
/**
* Turns the given key into an ``InputPeer`` (e.g. ``InputPeerUser``).
* The library uses this method whenever an ``InputPeer`` is needed
* to suit several purposes (e.g. user only provided its ID or wishes
* to use a cached username to avoid extra RPC).
*/
abstract getInputEntity(key: EntityLike): Api.TypeInputPeer;
/**
* Returns an ID of the takeout process initialized for this session,
* or `None` if there's no were any unfinished takeout requests.
*/
/*CONTEST
get takeoutId() {
throw new Error('Not Implemented')
}
*/
/**
* Sets the ID of the unfinished takeout process for this session.
* @param value
*/
/*CONTEST
set takeoutId(value) {
throw new Error('Not Implemented')
}
*/
/**
* Returns the ``UpdateState`` associated with the given `entity_id`.
* If the `entity_id` is 0, it should return the ``UpdateState`` for
* no specific channel (the "general" state). If no state is known
* it should ``return None``.
* @param entityId
*/
/*CONTEST
getUpdateState(entityId) {
throw new Error('Not Implemented')
}
*/
/**
* Sets the given ``UpdateState`` for the specified `entity_id`, which
* should be 0 if the ``UpdateState`` is the "general" state (and not
* for any specific channel).
* @param entityId
* @param state
*/
/*CONTEST
setUpdateState(entityId, state) {
throw new Error('Not Implemented')
}
*/
/**
* Called on client disconnection. Should be used to
* free any used resources. Can be left empty if none.
*/
abstract close(): void;
/**
* called whenever important properties change. It should
* make persist the relevant session information to disk.
*/
abstract save(): void;
/**
* Called upon client.log_out(). Should delete the stored
* information from disk since it's not valid anymore.
*/
abstract delete(): void;
/**
* Processes the input ``TLObject`` or ``list`` and saves
* whatever information is relevant (e.g., ID or access hash).
* @param tlo
*/
abstract processEntities(tlo: any): void;
}