stream-chat 4.4.3-dev.2 → 5.0.0
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/README.md +4 -13
- package/dist/browser.es.js +1229 -720
- package/dist/browser.es.js.map +1 -1
- package/dist/browser.full-bundle.min.js +1 -1
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/browser.js +1229 -719
- package/dist/browser.js.map +1 -1
- package/dist/index.es.js +1229 -720
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +1229 -719
- package/dist/index.js.map +1 -1
- package/dist/types/base64.d.ts.map +1 -1
- package/dist/types/channel.d.ts +19 -15
- package/dist/types/channel.d.ts.map +1 -1
- package/dist/types/channel_state.d.ts +2 -2
- package/dist/types/channel_state.d.ts.map +1 -1
- package/dist/types/client.d.ts +25 -42
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/client_state.d.ts +2 -2
- package/dist/types/client_state.d.ts.map +1 -1
- package/dist/types/connection.d.ts +14 -49
- package/dist/types/connection.d.ts.map +1 -1
- package/dist/types/connection_fallback.d.ts +41 -0
- package/dist/types/connection_fallback.d.ts.map +1 -0
- package/dist/types/errors.d.ts +14 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/insights.d.ts +17 -10
- package/dist/types/insights.d.ts.map +1 -1
- package/dist/types/permissions.d.ts.map +1 -1
- package/dist/types/signing.d.ts +3 -3
- package/dist/types/signing.d.ts.map +1 -1
- package/dist/types/token_manager.d.ts +2 -2
- package/dist/types/token_manager.d.ts.map +1 -1
- package/dist/types/types.d.ts +94 -88
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +13 -3
- package/dist/types/utils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/base64.ts +1 -4
- package/src/channel.ts +133 -461
- package/src/channel_state.ts +31 -158
- package/src/client.ts +291 -712
- package/src/client_state.ts +2 -2
- package/src/connection.ts +146 -395
- package/src/connection_fallback.ts +205 -0
- package/src/errors.ts +58 -0
- package/src/insights.ts +38 -32
- package/src/permissions.ts +3 -24
- package/src/signing.ts +6 -17
- package/src/token_manager.ts +6 -18
- package/src/types.ts +268 -512
- package/src/utils.ts +58 -24
- package/CHANGELOG.md +0 -844
package/src/channel.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ChannelAPIResponse,
|
|
9
9
|
ChannelData,
|
|
10
10
|
ChannelFilters,
|
|
11
|
+
ChannelUpdateOptions,
|
|
11
12
|
ChannelMemberAPIResponse,
|
|
12
13
|
ChannelMemberResponse,
|
|
13
14
|
ChannelQueryOptions,
|
|
@@ -35,16 +36,17 @@ import {
|
|
|
35
36
|
QueryMembersOptions,
|
|
36
37
|
Reaction,
|
|
37
38
|
ReactionAPIResponse,
|
|
39
|
+
SearchAPIResponse,
|
|
40
|
+
SearchMessageSortBase,
|
|
38
41
|
SearchOptions,
|
|
39
42
|
SearchPayload,
|
|
40
|
-
SearchAPIResponse,
|
|
41
43
|
SendMessageAPIResponse,
|
|
42
44
|
TruncateChannelAPIResponse,
|
|
43
|
-
|
|
45
|
+
TruncateOptions,
|
|
46
|
+
UR,
|
|
44
47
|
UpdateChannelAPIResponse,
|
|
45
48
|
UserFilters,
|
|
46
49
|
UserResponse,
|
|
47
|
-
SearchMessageSortBase,
|
|
48
50
|
} from './types';
|
|
49
51
|
import { Role } from './permissions';
|
|
50
52
|
|
|
@@ -52,54 +54,27 @@ import { Role } from './permissions';
|
|
|
52
54
|
* Channel - The Channel class manages it's own state.
|
|
53
55
|
*/
|
|
54
56
|
export class Channel<
|
|
55
|
-
AttachmentType extends
|
|
56
|
-
ChannelType extends
|
|
57
|
+
AttachmentType extends UR = UR,
|
|
58
|
+
ChannelType extends UR = UR,
|
|
57
59
|
CommandType extends string = LiteralStringForUnion,
|
|
58
|
-
EventType extends
|
|
59
|
-
MessageType extends
|
|
60
|
-
ReactionType extends
|
|
61
|
-
UserType extends
|
|
60
|
+
EventType extends UR = UR,
|
|
61
|
+
MessageType extends UR = UR,
|
|
62
|
+
ReactionType extends UR = UR,
|
|
63
|
+
UserType extends UR = UR
|
|
62
64
|
> {
|
|
63
|
-
_client: StreamChat<
|
|
64
|
-
AttachmentType,
|
|
65
|
-
ChannelType,
|
|
66
|
-
CommandType,
|
|
67
|
-
EventType,
|
|
68
|
-
MessageType,
|
|
69
|
-
ReactionType,
|
|
70
|
-
UserType
|
|
71
|
-
>;
|
|
65
|
+
_client: StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
|
|
72
66
|
type: string;
|
|
73
67
|
id: string | undefined;
|
|
74
|
-
data:
|
|
75
|
-
| ChannelData<ChannelType>
|
|
76
|
-
| ChannelResponse<ChannelType, CommandType, UserType>
|
|
77
|
-
| undefined;
|
|
68
|
+
data: ChannelData<ChannelType> | ChannelResponse<ChannelType, CommandType, UserType> | undefined;
|
|
78
69
|
_data: ChannelData<ChannelType> | ChannelResponse<ChannelType, CommandType, UserType>;
|
|
79
70
|
cid: string;
|
|
80
71
|
listeners: {
|
|
81
72
|
[key: string]: (
|
|
82
73
|
| string
|
|
83
|
-
| EventHandler<
|
|
84
|
-
AttachmentType,
|
|
85
|
-
ChannelType,
|
|
86
|
-
CommandType,
|
|
87
|
-
EventType,
|
|
88
|
-
MessageType,
|
|
89
|
-
ReactionType,
|
|
90
|
-
UserType
|
|
91
|
-
>
|
|
74
|
+
| EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
|
|
92
75
|
)[];
|
|
93
76
|
};
|
|
94
|
-
state: ChannelState<
|
|
95
|
-
AttachmentType,
|
|
96
|
-
ChannelType,
|
|
97
|
-
CommandType,
|
|
98
|
-
EventType,
|
|
99
|
-
MessageType,
|
|
100
|
-
ReactionType,
|
|
101
|
-
UserType
|
|
102
|
-
>;
|
|
77
|
+
state: ChannelState<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
|
|
103
78
|
initialized: boolean;
|
|
104
79
|
lastKeyStroke?: Date;
|
|
105
80
|
lastTypingEvent: Date | null;
|
|
@@ -117,15 +92,7 @@ export class Channel<
|
|
|
117
92
|
* @return {Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>} Returns a new uninitialized channel
|
|
118
93
|
*/
|
|
119
94
|
constructor(
|
|
120
|
-
client: StreamChat<
|
|
121
|
-
AttachmentType,
|
|
122
|
-
ChannelType,
|
|
123
|
-
CommandType,
|
|
124
|
-
EventType,
|
|
125
|
-
MessageType,
|
|
126
|
-
ReactionType,
|
|
127
|
-
UserType
|
|
128
|
-
>,
|
|
95
|
+
client: StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
129
96
|
type: string,
|
|
130
97
|
id: string | undefined,
|
|
131
98
|
data: ChannelData<ChannelType>,
|
|
@@ -170,15 +137,7 @@ export class Channel<
|
|
|
170
137
|
*
|
|
171
138
|
* @return {StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>}
|
|
172
139
|
*/
|
|
173
|
-
getClient(): StreamChat<
|
|
174
|
-
AttachmentType,
|
|
175
|
-
ChannelType,
|
|
176
|
-
CommandType,
|
|
177
|
-
EventType,
|
|
178
|
-
MessageType,
|
|
179
|
-
ReactionType,
|
|
180
|
-
UserType
|
|
181
|
-
> {
|
|
140
|
+
getClient(): StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType> {
|
|
182
141
|
if (this.disconnected === true) {
|
|
183
142
|
throw Error(`You can't use a channel after client.disconnect() was called`);
|
|
184
143
|
}
|
|
@@ -209,14 +168,7 @@ export class Channel<
|
|
|
209
168
|
options?: { skip_enrich_url?: boolean; skip_push?: boolean },
|
|
210
169
|
) {
|
|
211
170
|
const sendMessageResponse = await this.getClient().post<
|
|
212
|
-
SendMessageAPIResponse<
|
|
213
|
-
AttachmentType,
|
|
214
|
-
ChannelType,
|
|
215
|
-
CommandType,
|
|
216
|
-
MessageType,
|
|
217
|
-
ReactionType,
|
|
218
|
-
UserType
|
|
219
|
-
>
|
|
171
|
+
SendMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
220
172
|
>(this._channelURL() + '/message', {
|
|
221
173
|
message,
|
|
222
174
|
...options,
|
|
@@ -234,13 +186,7 @@ export class Channel<
|
|
|
234
186
|
contentType?: string,
|
|
235
187
|
user?: UserResponse<UserType>,
|
|
236
188
|
) {
|
|
237
|
-
return this.getClient().sendFile(
|
|
238
|
-
`${this._channelURL()}/file`,
|
|
239
|
-
uri,
|
|
240
|
-
name,
|
|
241
|
-
contentType,
|
|
242
|
-
user,
|
|
243
|
-
);
|
|
189
|
+
return this.getClient().sendFile(`${this._channelURL()}/file`, uri, name, contentType, user);
|
|
244
190
|
}
|
|
245
191
|
|
|
246
192
|
sendImage(
|
|
@@ -249,13 +195,7 @@ export class Channel<
|
|
|
249
195
|
contentType?: string,
|
|
250
196
|
user?: UserResponse<UserType>,
|
|
251
197
|
) {
|
|
252
|
-
return this.getClient().sendFile(
|
|
253
|
-
`${this._channelURL()}/image`,
|
|
254
|
-
uri,
|
|
255
|
-
name,
|
|
256
|
-
contentType,
|
|
257
|
-
user,
|
|
258
|
-
);
|
|
198
|
+
return this.getClient().sendFile(`${this._channelURL()}/image`, uri, name, contentType, user);
|
|
259
199
|
}
|
|
260
200
|
|
|
261
201
|
deleteFile(url: string) {
|
|
@@ -274,27 +214,11 @@ export class Channel<
|
|
|
274
214
|
* @return {Promise<EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>>} The Server Response
|
|
275
215
|
*/
|
|
276
216
|
async sendEvent(
|
|
277
|
-
event: Event<
|
|
278
|
-
AttachmentType,
|
|
279
|
-
ChannelType,
|
|
280
|
-
CommandType,
|
|
281
|
-
EventType,
|
|
282
|
-
MessageType,
|
|
283
|
-
ReactionType,
|
|
284
|
-
UserType
|
|
285
|
-
>,
|
|
217
|
+
event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
286
218
|
) {
|
|
287
219
|
this._checkInitialized();
|
|
288
220
|
return await this.getClient().post<
|
|
289
|
-
EventAPIResponse<
|
|
290
|
-
AttachmentType,
|
|
291
|
-
ChannelType,
|
|
292
|
-
CommandType,
|
|
293
|
-
EventType,
|
|
294
|
-
MessageType,
|
|
295
|
-
ReactionType,
|
|
296
|
-
UserType
|
|
297
|
-
>
|
|
221
|
+
EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
|
|
298
222
|
>(this._channelURL() + '/event', {
|
|
299
223
|
event,
|
|
300
224
|
});
|
|
@@ -309,16 +233,7 @@ export class Channel<
|
|
|
309
233
|
* @return {Promise<SearchAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} search messages response
|
|
310
234
|
*/
|
|
311
235
|
async search(
|
|
312
|
-
query:
|
|
313
|
-
| MessageFilters<
|
|
314
|
-
AttachmentType,
|
|
315
|
-
ChannelType,
|
|
316
|
-
CommandType,
|
|
317
|
-
MessageType,
|
|
318
|
-
ReactionType,
|
|
319
|
-
UserType
|
|
320
|
-
>
|
|
321
|
-
| string,
|
|
236
|
+
query: MessageFilters<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> | string,
|
|
322
237
|
options: SearchOptions<MessageType> & {
|
|
323
238
|
client_id?: string;
|
|
324
239
|
connection_id?: string;
|
|
@@ -337,23 +252,10 @@ export class Channel<
|
|
|
337
252
|
throw Error(`Cannot specify offset with sort or next parameters`);
|
|
338
253
|
}
|
|
339
254
|
// Return a list of channels
|
|
340
|
-
const payload: SearchPayload<
|
|
341
|
-
|
|
342
|
-
ChannelType,
|
|
343
|
-
CommandType,
|
|
344
|
-
MessageType,
|
|
345
|
-
ReactionType,
|
|
346
|
-
UserType
|
|
347
|
-
> = {
|
|
348
|
-
filter_conditions: { cid: this.cid } as ChannelFilters<
|
|
349
|
-
ChannelType,
|
|
350
|
-
CommandType,
|
|
351
|
-
UserType
|
|
352
|
-
>,
|
|
255
|
+
const payload: SearchPayload<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {
|
|
256
|
+
filter_conditions: { cid: this.cid } as ChannelFilters<ChannelType, CommandType, UserType>,
|
|
353
257
|
...options,
|
|
354
|
-
sort: options.sort
|
|
355
|
-
? normalizeQuerySort<SearchMessageSortBase<MessageType>>(options.sort)
|
|
356
|
-
: undefined,
|
|
258
|
+
sort: options.sort ? normalizeQuerySort<SearchMessageSortBase<MessageType>>(options.sort) : undefined,
|
|
357
259
|
};
|
|
358
260
|
if (typeof query === 'string') {
|
|
359
261
|
payload.query = query;
|
|
@@ -366,14 +268,7 @@ export class Channel<
|
|
|
366
268
|
await this.getClient().wsPromise;
|
|
367
269
|
|
|
368
270
|
return await this.getClient().get<
|
|
369
|
-
SearchAPIResponse<
|
|
370
|
-
AttachmentType,
|
|
371
|
-
ChannelType,
|
|
372
|
-
CommandType,
|
|
373
|
-
MessageType,
|
|
374
|
-
ReactionType,
|
|
375
|
-
UserType
|
|
376
|
-
>
|
|
271
|
+
SearchAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
377
272
|
>(this.getClient().baseURL + '/search', {
|
|
378
273
|
payload,
|
|
379
274
|
});
|
|
@@ -403,19 +298,16 @@ export class Channel<
|
|
|
403
298
|
members = this.data.members;
|
|
404
299
|
}
|
|
405
300
|
// Return a list of members
|
|
406
|
-
return await this.getClient().get<ChannelMemberAPIResponse<UserType>>(
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
filter_conditions: filterConditions,
|
|
415
|
-
...options,
|
|
416
|
-
},
|
|
301
|
+
return await this.getClient().get<ChannelMemberAPIResponse<UserType>>(this.getClient().baseURL + '/members', {
|
|
302
|
+
payload: {
|
|
303
|
+
type,
|
|
304
|
+
id,
|
|
305
|
+
members,
|
|
306
|
+
sort: normalizeQuerySort(sort),
|
|
307
|
+
filter_conditions: filterConditions,
|
|
308
|
+
...options,
|
|
417
309
|
},
|
|
418
|
-
);
|
|
310
|
+
});
|
|
419
311
|
}
|
|
420
312
|
|
|
421
313
|
/**
|
|
@@ -439,14 +331,7 @@ export class Channel<
|
|
|
439
331
|
throw Error(`Reaction object is missing`);
|
|
440
332
|
}
|
|
441
333
|
return await this.getClient().post<
|
|
442
|
-
ReactionAPIResponse<
|
|
443
|
-
AttachmentType,
|
|
444
|
-
ChannelType,
|
|
445
|
-
CommandType,
|
|
446
|
-
MessageType,
|
|
447
|
-
ReactionType,
|
|
448
|
-
UserType
|
|
449
|
-
>
|
|
334
|
+
ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
450
335
|
>(this.getClient().baseURL + `/messages/${messageID}/reaction`, {
|
|
451
336
|
reaction,
|
|
452
337
|
...options,
|
|
@@ -465,36 +350,19 @@ export class Channel<
|
|
|
465
350
|
deleteReaction(messageID: string, reactionType: string, user_id?: string) {
|
|
466
351
|
this._checkInitialized();
|
|
467
352
|
if (!reactionType || !messageID) {
|
|
468
|
-
throw Error(
|
|
469
|
-
'Deleting a reaction requires specifying both the message and reaction type',
|
|
470
|
-
);
|
|
353
|
+
throw Error('Deleting a reaction requires specifying both the message and reaction type');
|
|
471
354
|
}
|
|
472
355
|
|
|
473
|
-
const url =
|
|
474
|
-
this.getClient().baseURL + `/messages/${messageID}/reaction/${reactionType}`;
|
|
356
|
+
const url = this.getClient().baseURL + `/messages/${messageID}/reaction/${reactionType}`;
|
|
475
357
|
//provided when server side request
|
|
476
358
|
if (user_id) {
|
|
477
359
|
return this.getClient().delete<
|
|
478
|
-
ReactionAPIResponse<
|
|
479
|
-
AttachmentType,
|
|
480
|
-
ChannelType,
|
|
481
|
-
CommandType,
|
|
482
|
-
MessageType,
|
|
483
|
-
ReactionType,
|
|
484
|
-
UserType
|
|
485
|
-
>
|
|
360
|
+
ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
486
361
|
>(url, { user_id });
|
|
487
362
|
}
|
|
488
363
|
|
|
489
364
|
return this.getClient().delete<
|
|
490
|
-
ReactionAPIResponse<
|
|
491
|
-
AttachmentType,
|
|
492
|
-
ChannelType,
|
|
493
|
-
CommandType,
|
|
494
|
-
MessageType,
|
|
495
|
-
ReactionType,
|
|
496
|
-
UserType
|
|
497
|
-
>
|
|
365
|
+
ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
498
366
|
>(url, {});
|
|
499
367
|
}
|
|
500
368
|
|
|
@@ -503,15 +371,13 @@ export class Channel<
|
|
|
503
371
|
*
|
|
504
372
|
* @param {ChannelData<ChannelType>} channelData The object to update the custom properties of this channel with
|
|
505
373
|
* @param {Message<AttachmentType, MessageType, UserType>} [updateMessage] Optional message object for channel members notification
|
|
506
|
-
* @param {
|
|
374
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
507
375
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
508
376
|
*/
|
|
509
377
|
async update(
|
|
510
|
-
channelData:
|
|
511
|
-
| Partial<ChannelData<ChannelType>>
|
|
512
|
-
| Partial<ChannelResponse<ChannelType, CommandType, UserType>> = {},
|
|
378
|
+
channelData: Partial<ChannelData<ChannelType>> | Partial<ChannelResponse<ChannelType, CommandType, UserType>> = {},
|
|
513
379
|
updateMessage?: Message<AttachmentType, MessageType, UserType>,
|
|
514
|
-
options?:
|
|
380
|
+
options?: ChannelUpdateOptions,
|
|
515
381
|
) {
|
|
516
382
|
// Strip out reserved names that will result in API errors.
|
|
517
383
|
const reserved = [
|
|
@@ -545,9 +411,10 @@ export class Channel<
|
|
|
545
411
|
* @return {Promise<PartialUpdateChannelAPIResponse<ChannelType,CommandType, UserType>>}
|
|
546
412
|
*/
|
|
547
413
|
async updatePartial(update: PartialUpdateChannel<ChannelType>) {
|
|
548
|
-
return await this.getClient().patch<
|
|
549
|
-
|
|
550
|
-
|
|
414
|
+
return await this.getClient().patch<PartialUpdateChannelAPIResponse<ChannelType, CommandType, UserType>>(
|
|
415
|
+
this._channelURL(),
|
|
416
|
+
update,
|
|
417
|
+
);
|
|
551
418
|
}
|
|
552
419
|
|
|
553
420
|
/**
|
|
@@ -558,14 +425,7 @@ export class Channel<
|
|
|
558
425
|
*/
|
|
559
426
|
async enableSlowMode(coolDownInterval: number) {
|
|
560
427
|
const data = await this.getClient().post<
|
|
561
|
-
UpdateChannelAPIResponse<
|
|
562
|
-
AttachmentType,
|
|
563
|
-
ChannelType,
|
|
564
|
-
CommandType,
|
|
565
|
-
MessageType,
|
|
566
|
-
ReactionType,
|
|
567
|
-
UserType
|
|
568
|
-
>
|
|
428
|
+
UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
569
429
|
>(this._channelURL(), {
|
|
570
430
|
cooldown: coolDownInterval,
|
|
571
431
|
});
|
|
@@ -580,14 +440,7 @@ export class Channel<
|
|
|
580
440
|
*/
|
|
581
441
|
async disableSlowMode() {
|
|
582
442
|
const data = await this.getClient().post<
|
|
583
|
-
UpdateChannelAPIResponse<
|
|
584
|
-
AttachmentType,
|
|
585
|
-
ChannelType,
|
|
586
|
-
CommandType,
|
|
587
|
-
MessageType,
|
|
588
|
-
ReactionType,
|
|
589
|
-
UserType
|
|
590
|
-
>
|
|
443
|
+
UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
591
444
|
>(this._channelURL(), {
|
|
592
445
|
cooldown: 0,
|
|
593
446
|
});
|
|
@@ -601,20 +454,21 @@ export class Channel<
|
|
|
601
454
|
* @return {Promise<DeleteChannelAPIResponse<ChannelType, CommandType, UserType>>} The server response
|
|
602
455
|
*/
|
|
603
456
|
async delete() {
|
|
604
|
-
return await this.getClient().delete<
|
|
605
|
-
|
|
606
|
-
|
|
457
|
+
return await this.getClient().delete<DeleteChannelAPIResponse<ChannelType, CommandType, UserType>>(
|
|
458
|
+
this._channelURL(),
|
|
459
|
+
{},
|
|
460
|
+
);
|
|
607
461
|
}
|
|
608
462
|
|
|
609
463
|
/**
|
|
610
464
|
* truncate - Removes all messages from the channel
|
|
611
|
-
*
|
|
612
|
-
* @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType>>} The server response
|
|
465
|
+
* @param {TruncateOptions<AttachmentType, MessageType, UserType>} [options] Defines truncation options
|
|
466
|
+
* @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType, MessageType, ReactionType>>} The server response
|
|
613
467
|
*/
|
|
614
|
-
async truncate() {
|
|
468
|
+
async truncate(options: TruncateOptions<AttachmentType, MessageType, UserType> = {}) {
|
|
615
469
|
return await this.getClient().post<
|
|
616
|
-
TruncateChannelAPIResponse<ChannelType, CommandType, UserType>
|
|
617
|
-
>(this._channelURL() + '/truncate',
|
|
470
|
+
TruncateChannelAPIResponse<ChannelType, CommandType, UserType, MessageType, ReactionType>
|
|
471
|
+
>(this._channelURL() + '/truncate', options);
|
|
618
472
|
}
|
|
619
473
|
|
|
620
474
|
/**
|
|
@@ -625,19 +479,9 @@ export class Channel<
|
|
|
625
479
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
626
480
|
*/
|
|
627
481
|
async acceptInvite(
|
|
628
|
-
options: InviteOptions<
|
|
629
|
-
AttachmentType,
|
|
630
|
-
ChannelType,
|
|
631
|
-
CommandType,
|
|
632
|
-
MessageType,
|
|
633
|
-
ReactionType,
|
|
634
|
-
UserType
|
|
635
|
-
> = {},
|
|
482
|
+
options: InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {},
|
|
636
483
|
) {
|
|
637
|
-
return await this._update({
|
|
638
|
-
accept_invite: true,
|
|
639
|
-
...options,
|
|
640
|
-
});
|
|
484
|
+
return await this._update({ accept_invite: true, ...options });
|
|
641
485
|
}
|
|
642
486
|
|
|
643
487
|
/**
|
|
@@ -648,19 +492,9 @@ export class Channel<
|
|
|
648
492
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
649
493
|
*/
|
|
650
494
|
async rejectInvite(
|
|
651
|
-
options: InviteOptions<
|
|
652
|
-
AttachmentType,
|
|
653
|
-
ChannelType,
|
|
654
|
-
CommandType,
|
|
655
|
-
MessageType,
|
|
656
|
-
ReactionType,
|
|
657
|
-
UserType
|
|
658
|
-
> = {},
|
|
495
|
+
options: InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {},
|
|
659
496
|
) {
|
|
660
|
-
return await this._update({
|
|
661
|
-
reject_invite: true,
|
|
662
|
-
...options,
|
|
663
|
-
});
|
|
497
|
+
return await this._update({ reject_invite: true, ...options });
|
|
664
498
|
}
|
|
665
499
|
|
|
666
500
|
/**
|
|
@@ -668,16 +502,15 @@ export class Channel<
|
|
|
668
502
|
*
|
|
669
503
|
* @param {{user_id: string, channel_role?: Role}[]} members An array of members to add to the channel
|
|
670
504
|
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
|
|
505
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
671
506
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
672
507
|
*/
|
|
673
508
|
async addMembers(
|
|
674
509
|
members: string[] | { user_id: string; channel_role?: Role }[],
|
|
675
510
|
message?: Message<AttachmentType, MessageType, UserType>,
|
|
511
|
+
options: ChannelUpdateOptions = {},
|
|
676
512
|
) {
|
|
677
|
-
return await this._update({
|
|
678
|
-
add_members: members,
|
|
679
|
-
message,
|
|
680
|
-
});
|
|
513
|
+
return await this._update({ add_members: members, message, ...options });
|
|
681
514
|
}
|
|
682
515
|
|
|
683
516
|
/**
|
|
@@ -685,16 +518,15 @@ export class Channel<
|
|
|
685
518
|
*
|
|
686
519
|
* @param {string[]} members An array of member identifiers
|
|
687
520
|
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
|
|
521
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
688
522
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
689
523
|
*/
|
|
690
524
|
async addModerators(
|
|
691
525
|
members: string[],
|
|
692
526
|
message?: Message<AttachmentType, MessageType, UserType>,
|
|
527
|
+
options: ChannelUpdateOptions = {},
|
|
693
528
|
) {
|
|
694
|
-
return await this._update({
|
|
695
|
-
add_moderators: members,
|
|
696
|
-
message,
|
|
697
|
-
});
|
|
529
|
+
return await this._update({ add_moderators: members, message, ...options });
|
|
698
530
|
}
|
|
699
531
|
|
|
700
532
|
/**
|
|
@@ -702,16 +534,15 @@ export class Channel<
|
|
|
702
534
|
*
|
|
703
535
|
* @param {{channel_role: Role, user_id: string}[]} roles List of role assignments
|
|
704
536
|
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
|
|
537
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
705
538
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
706
539
|
*/
|
|
707
540
|
async assignRoles(
|
|
708
541
|
roles: { channel_role: Role; user_id: string }[],
|
|
709
542
|
message?: Message<AttachmentType, MessageType, UserType>,
|
|
543
|
+
options: ChannelUpdateOptions = {},
|
|
710
544
|
) {
|
|
711
|
-
return await this._update({
|
|
712
|
-
assign_roles: roles,
|
|
713
|
-
message,
|
|
714
|
-
});
|
|
545
|
+
return await this._update({ assign_roles: roles, message, ...options });
|
|
715
546
|
}
|
|
716
547
|
|
|
717
548
|
/**
|
|
@@ -719,16 +550,15 @@ export class Channel<
|
|
|
719
550
|
*
|
|
720
551
|
* @param {{user_id: string, channel_role?: Role}[]} members An array of members to invite to the channel
|
|
721
552
|
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
|
|
553
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
722
554
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
723
555
|
*/
|
|
724
556
|
async inviteMembers(
|
|
725
557
|
members: { user_id: string; channel_role?: Role }[] | string[],
|
|
726
558
|
message?: Message<AttachmentType, MessageType, UserType>,
|
|
559
|
+
options: ChannelUpdateOptions = {},
|
|
727
560
|
) {
|
|
728
|
-
return await this._update({
|
|
729
|
-
invites: members,
|
|
730
|
-
message,
|
|
731
|
-
});
|
|
561
|
+
return await this._update({ invites: members, message, ...options });
|
|
732
562
|
}
|
|
733
563
|
|
|
734
564
|
/**
|
|
@@ -736,16 +566,15 @@ export class Channel<
|
|
|
736
566
|
*
|
|
737
567
|
* @param {string[]} members An array of member identifiers
|
|
738
568
|
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
|
|
569
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
739
570
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
740
571
|
*/
|
|
741
572
|
async removeMembers(
|
|
742
573
|
members: string[],
|
|
743
574
|
message?: Message<AttachmentType, MessageType, UserType>,
|
|
575
|
+
options: ChannelUpdateOptions = {},
|
|
744
576
|
) {
|
|
745
|
-
return await this._update({
|
|
746
|
-
remove_members: members,
|
|
747
|
-
message,
|
|
748
|
-
});
|
|
577
|
+
return await this._update({ remove_members: members, message, ...options });
|
|
749
578
|
}
|
|
750
579
|
|
|
751
580
|
/**
|
|
@@ -753,16 +582,15 @@ export class Channel<
|
|
|
753
582
|
*
|
|
754
583
|
* @param {string[]} members An array of member identifiers
|
|
755
584
|
* @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
|
|
585
|
+
* @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
|
|
756
586
|
* @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
|
|
757
587
|
*/
|
|
758
588
|
async demoteModerators(
|
|
759
589
|
members: string[],
|
|
760
590
|
message?: Message<AttachmentType, MessageType, UserType>,
|
|
591
|
+
options: ChannelUpdateOptions = {},
|
|
761
592
|
) {
|
|
762
|
-
return await this._update({
|
|
763
|
-
demote_moderators: members,
|
|
764
|
-
message,
|
|
765
|
-
});
|
|
593
|
+
return await this._update({ demote_moderators: members, message, ...options });
|
|
766
594
|
}
|
|
767
595
|
|
|
768
596
|
/**
|
|
@@ -773,14 +601,7 @@ export class Channel<
|
|
|
773
601
|
*/
|
|
774
602
|
async _update(payload: Object) {
|
|
775
603
|
const data = await this.getClient().post<
|
|
776
|
-
UpdateChannelAPIResponse<
|
|
777
|
-
AttachmentType,
|
|
778
|
-
ChannelType,
|
|
779
|
-
CommandType,
|
|
780
|
-
MessageType,
|
|
781
|
-
ReactionType,
|
|
782
|
-
UserType
|
|
783
|
-
>
|
|
604
|
+
UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
784
605
|
>(this._channelURL(), payload);
|
|
785
606
|
this.data = data.channel;
|
|
786
607
|
return data;
|
|
@@ -799,12 +620,10 @@ export class Channel<
|
|
|
799
620
|
*
|
|
800
621
|
*/
|
|
801
622
|
async mute(opts: { expiration?: number; user_id?: string } = {}) {
|
|
802
|
-
return await this.getClient().post<
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
...opts,
|
|
807
|
-
});
|
|
623
|
+
return await this.getClient().post<MuteChannelAPIResponse<ChannelType, CommandType, UserType>>(
|
|
624
|
+
this.getClient().baseURL + '/moderation/mute/channel',
|
|
625
|
+
{ channel_cid: this.cid, ...opts },
|
|
626
|
+
);
|
|
808
627
|
}
|
|
809
628
|
|
|
810
629
|
/**
|
|
@@ -816,13 +635,10 @@ export class Channel<
|
|
|
816
635
|
* await channel.unmute({user_id: userId});
|
|
817
636
|
*/
|
|
818
637
|
async unmute(opts: { user_id?: string } = {}) {
|
|
819
|
-
return await this.getClient().post<APIResponse>(
|
|
820
|
-
this.
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
...opts,
|
|
824
|
-
},
|
|
825
|
-
);
|
|
638
|
+
return await this.getClient().post<APIResponse>(this.getClient().baseURL + '/moderation/unmute/channel', {
|
|
639
|
+
channel_cid: this.cid,
|
|
640
|
+
...opts,
|
|
641
|
+
});
|
|
826
642
|
}
|
|
827
643
|
|
|
828
644
|
/**
|
|
@@ -844,14 +660,7 @@ export class Channel<
|
|
|
844
660
|
throw Error(`Message id is missing`);
|
|
845
661
|
}
|
|
846
662
|
return this.getClient().post<
|
|
847
|
-
SendMessageAPIResponse<
|
|
848
|
-
AttachmentType,
|
|
849
|
-
ChannelType,
|
|
850
|
-
CommandType,
|
|
851
|
-
MessageType,
|
|
852
|
-
ReactionType,
|
|
853
|
-
UserType
|
|
854
|
-
>
|
|
663
|
+
SendMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
855
664
|
>(this.getClient().baseURL + `/messages/${messageID}/action`, {
|
|
856
665
|
message_id: messageID,
|
|
857
666
|
form_data: formData,
|
|
@@ -936,15 +745,7 @@ export class Channel<
|
|
|
936
745
|
}
|
|
937
746
|
|
|
938
747
|
return await this.getClient().post<
|
|
939
|
-
EventAPIResponse<
|
|
940
|
-
AttachmentType,
|
|
941
|
-
ChannelType,
|
|
942
|
-
CommandType,
|
|
943
|
-
EventType,
|
|
944
|
-
MessageType,
|
|
945
|
-
ReactionType,
|
|
946
|
-
UserType
|
|
947
|
-
>
|
|
748
|
+
EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
|
|
948
749
|
>(this._channelURL() + '/read', {
|
|
949
750
|
...data,
|
|
950
751
|
});
|
|
@@ -991,14 +792,10 @@ export class Channel<
|
|
|
991
792
|
this.initialized = true;
|
|
992
793
|
this.data = state.channel;
|
|
993
794
|
|
|
994
|
-
this._client.logger(
|
|
995
|
-
'
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
tags: ['channel'],
|
|
999
|
-
channel: this,
|
|
1000
|
-
},
|
|
1001
|
-
);
|
|
795
|
+
this._client.logger('info', `channel:watch() - started watching channel ${this.cid}`, {
|
|
796
|
+
tags: ['channel'],
|
|
797
|
+
channel: this,
|
|
798
|
+
});
|
|
1002
799
|
return state;
|
|
1003
800
|
}
|
|
1004
801
|
|
|
@@ -1008,19 +805,12 @@ export class Channel<
|
|
|
1008
805
|
* @return {Promise<APIResponse>} The server response
|
|
1009
806
|
*/
|
|
1010
807
|
async stopWatching() {
|
|
1011
|
-
const response = await this.getClient().post<APIResponse>(
|
|
1012
|
-
this._channelURL() + '/stop-watching',
|
|
1013
|
-
{},
|
|
1014
|
-
);
|
|
808
|
+
const response = await this.getClient().post<APIResponse>(this._channelURL() + '/stop-watching', {});
|
|
1015
809
|
|
|
1016
|
-
this._client.logger(
|
|
1017
|
-
'
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
tags: ['channel'],
|
|
1021
|
-
channel: this,
|
|
1022
|
-
},
|
|
1023
|
-
);
|
|
810
|
+
this._client.logger('info', `channel:watch() - stopped watching channel ${this.cid}`, {
|
|
811
|
+
tags: ['channel'],
|
|
812
|
+
channel: this,
|
|
813
|
+
});
|
|
1024
814
|
|
|
1025
815
|
return response;
|
|
1026
816
|
}
|
|
@@ -1038,14 +828,7 @@ export class Channel<
|
|
|
1038
828
|
options: PaginationOptions & { user?: UserResponse<UserType>; user_id?: string },
|
|
1039
829
|
) {
|
|
1040
830
|
const data = await this.getClient().get<
|
|
1041
|
-
GetRepliesAPIResponse<
|
|
1042
|
-
AttachmentType,
|
|
1043
|
-
ChannelType,
|
|
1044
|
-
CommandType,
|
|
1045
|
-
MessageType,
|
|
1046
|
-
ReactionType,
|
|
1047
|
-
UserType
|
|
1048
|
-
>
|
|
831
|
+
GetRepliesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
1049
832
|
>(this.getClient().baseURL + `/messages/${parent_id}/replies`, {
|
|
1050
833
|
...options,
|
|
1051
834
|
});
|
|
@@ -1084,14 +867,7 @@ export class Channel<
|
|
|
1084
867
|
*/
|
|
1085
868
|
getMessagesById(messageIds: string[]) {
|
|
1086
869
|
return this.getClient().get<
|
|
1087
|
-
GetMultipleMessagesAPIResponse<
|
|
1088
|
-
AttachmentType,
|
|
1089
|
-
ChannelType,
|
|
1090
|
-
CommandType,
|
|
1091
|
-
MessageType,
|
|
1092
|
-
ReactionType,
|
|
1093
|
-
UserType
|
|
1094
|
-
>
|
|
870
|
+
GetMultipleMessagesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
1095
871
|
>(this._channelURL() + '/messages', {
|
|
1096
872
|
ids: messageIds.join(','),
|
|
1097
873
|
});
|
|
@@ -1111,28 +887,13 @@ export class Channel<
|
|
|
1111
887
|
|
|
1112
888
|
_countMessageAsUnread(
|
|
1113
889
|
message:
|
|
1114
|
-
| FormatMessageResponse<
|
|
1115
|
-
|
|
1116
|
-
ChannelType,
|
|
1117
|
-
CommandType,
|
|
1118
|
-
MessageType,
|
|
1119
|
-
ReactionType,
|
|
1120
|
-
UserType
|
|
1121
|
-
>
|
|
1122
|
-
| MessageResponse<
|
|
1123
|
-
AttachmentType,
|
|
1124
|
-
ChannelType,
|
|
1125
|
-
CommandType,
|
|
1126
|
-
MessageType,
|
|
1127
|
-
ReactionType,
|
|
1128
|
-
UserType
|
|
1129
|
-
>,
|
|
890
|
+
| FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
891
|
+
| MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
|
|
1130
892
|
) {
|
|
1131
893
|
if (message.shadowed) return false;
|
|
1132
894
|
if (message.silent) return false;
|
|
1133
895
|
if (message.user?.id === this.getClient().userID) return false;
|
|
1134
|
-
if (message.user?.id && this.getClient().userMuteStatus(message.user.id))
|
|
1135
|
-
return false;
|
|
896
|
+
if (message.user?.id && this.getClient().userMuteStatus(message.user.id)) return false;
|
|
1136
897
|
if (message.type === 'system') return false;
|
|
1137
898
|
|
|
1138
899
|
if (this.muteStatus().muted) return false;
|
|
@@ -1214,14 +975,7 @@ export class Channel<
|
|
|
1214
975
|
}
|
|
1215
976
|
|
|
1216
977
|
const state = await this.getClient().post<
|
|
1217
|
-
ChannelAPIResponse<
|
|
1218
|
-
AttachmentType,
|
|
1219
|
-
ChannelType,
|
|
1220
|
-
CommandType,
|
|
1221
|
-
MessageType,
|
|
1222
|
-
ReactionType,
|
|
1223
|
-
UserType
|
|
1224
|
-
>
|
|
978
|
+
ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
|
|
1225
979
|
>(queryURL + '/query', {
|
|
1226
980
|
data: this._data,
|
|
1227
981
|
state: true,
|
|
@@ -1361,38 +1115,14 @@ export class Channel<
|
|
|
1361
1115
|
*/
|
|
1362
1116
|
on(
|
|
1363
1117
|
eventType: EventTypes,
|
|
1364
|
-
callback: EventHandler<
|
|
1365
|
-
AttachmentType,
|
|
1366
|
-
ChannelType,
|
|
1367
|
-
CommandType,
|
|
1368
|
-
EventType,
|
|
1369
|
-
MessageType,
|
|
1370
|
-
ReactionType,
|
|
1371
|
-
UserType
|
|
1372
|
-
>,
|
|
1118
|
+
callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
1373
1119
|
): { unsubscribe: () => void };
|
|
1374
1120
|
on(
|
|
1375
|
-
callback: EventHandler<
|
|
1376
|
-
AttachmentType,
|
|
1377
|
-
ChannelType,
|
|
1378
|
-
CommandType,
|
|
1379
|
-
EventType,
|
|
1380
|
-
MessageType,
|
|
1381
|
-
ReactionType,
|
|
1382
|
-
UserType
|
|
1383
|
-
>,
|
|
1121
|
+
callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
1384
1122
|
): { unsubscribe: () => void };
|
|
1385
1123
|
on(
|
|
1386
1124
|
callbackOrString:
|
|
1387
|
-
| EventHandler<
|
|
1388
|
-
AttachmentType,
|
|
1389
|
-
ChannelType,
|
|
1390
|
-
CommandType,
|
|
1391
|
-
EventType,
|
|
1392
|
-
MessageType,
|
|
1393
|
-
ReactionType,
|
|
1394
|
-
UserType
|
|
1395
|
-
>
|
|
1125
|
+
| EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
|
|
1396
1126
|
| EventTypes,
|
|
1397
1127
|
callbackOrNothing?: EventHandler<
|
|
1398
1128
|
AttachmentType,
|
|
@@ -1413,24 +1143,19 @@ export class Channel<
|
|
|
1413
1143
|
if (!(key in this.listeners)) {
|
|
1414
1144
|
this.listeners[key] = [];
|
|
1415
1145
|
}
|
|
1416
|
-
this._client.logger(
|
|
1417
|
-
'
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
tags: ['event', 'channel'],
|
|
1421
|
-
channel: this,
|
|
1422
|
-
},
|
|
1423
|
-
);
|
|
1146
|
+
this._client.logger('info', `Attaching listener for ${key} event on channel ${this.cid}`, {
|
|
1147
|
+
tags: ['event', 'channel'],
|
|
1148
|
+
channel: this,
|
|
1149
|
+
});
|
|
1424
1150
|
|
|
1425
1151
|
this.listeners[key].push(callback);
|
|
1426
1152
|
|
|
1427
1153
|
return {
|
|
1428
1154
|
unsubscribe: () => {
|
|
1429
|
-
this._client.logger(
|
|
1430
|
-
'
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
);
|
|
1155
|
+
this._client.logger('info', `Removing listener for ${key} event from channel ${this.cid}`, {
|
|
1156
|
+
tags: ['event', 'channel'],
|
|
1157
|
+
channel: this,
|
|
1158
|
+
});
|
|
1434
1159
|
|
|
1435
1160
|
this.listeners[key] = this.listeners[key].filter((el) => el !== callback);
|
|
1436
1161
|
},
|
|
@@ -1443,38 +1168,14 @@ export class Channel<
|
|
|
1443
1168
|
*/
|
|
1444
1169
|
off(
|
|
1445
1170
|
eventType: EventTypes,
|
|
1446
|
-
callback: EventHandler<
|
|
1447
|
-
AttachmentType,
|
|
1448
|
-
ChannelType,
|
|
1449
|
-
CommandType,
|
|
1450
|
-
EventType,
|
|
1451
|
-
MessageType,
|
|
1452
|
-
ReactionType,
|
|
1453
|
-
UserType
|
|
1454
|
-
>,
|
|
1171
|
+
callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
1455
1172
|
): void;
|
|
1456
1173
|
off(
|
|
1457
|
-
callback: EventHandler<
|
|
1458
|
-
AttachmentType,
|
|
1459
|
-
ChannelType,
|
|
1460
|
-
CommandType,
|
|
1461
|
-
EventType,
|
|
1462
|
-
MessageType,
|
|
1463
|
-
ReactionType,
|
|
1464
|
-
UserType
|
|
1465
|
-
>,
|
|
1174
|
+
callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
1466
1175
|
): void;
|
|
1467
1176
|
off(
|
|
1468
1177
|
callbackOrString:
|
|
1469
|
-
| EventHandler<
|
|
1470
|
-
AttachmentType,
|
|
1471
|
-
ChannelType,
|
|
1472
|
-
CommandType,
|
|
1473
|
-
EventType,
|
|
1474
|
-
MessageType,
|
|
1475
|
-
ReactionType,
|
|
1476
|
-
UserType
|
|
1477
|
-
>
|
|
1178
|
+
| EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
|
|
1478
1179
|
| EventTypes,
|
|
1479
1180
|
callbackOrNothing?: EventHandler<
|
|
1480
1181
|
AttachmentType,
|
|
@@ -1496,25 +1197,16 @@ export class Channel<
|
|
|
1496
1197
|
this.listeners[key] = [];
|
|
1497
1198
|
}
|
|
1498
1199
|
|
|
1499
|
-
this._client.logger(
|
|
1500
|
-
'
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
);
|
|
1200
|
+
this._client.logger('info', `Removing listener for ${key} event from channel ${this.cid}`, {
|
|
1201
|
+
tags: ['event', 'channel'],
|
|
1202
|
+
channel: this,
|
|
1203
|
+
});
|
|
1504
1204
|
this.listeners[key] = this.listeners[key].filter((value) => value !== callback);
|
|
1505
1205
|
}
|
|
1506
1206
|
|
|
1507
1207
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
1508
1208
|
_handleChannelEvent(
|
|
1509
|
-
event: Event<
|
|
1510
|
-
AttachmentType,
|
|
1511
|
-
ChannelType,
|
|
1512
|
-
CommandType,
|
|
1513
|
-
EventType,
|
|
1514
|
-
MessageType,
|
|
1515
|
-
ReactionType,
|
|
1516
|
-
UserType
|
|
1517
|
-
>,
|
|
1209
|
+
event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
1518
1210
|
) {
|
|
1519
1211
|
const channel = this;
|
|
1520
1212
|
this._client.logger(
|
|
@@ -1578,8 +1270,7 @@ export class Channel<
|
|
|
1578
1270
|
if (event.message) {
|
|
1579
1271
|
/* if message belongs to current user, always assume timestamp is changed to filter it out and add again to avoid duplication */
|
|
1580
1272
|
const ownMessage = event.user?.id === this.getClient().user?.id;
|
|
1581
|
-
const isThreadMessage =
|
|
1582
|
-
event.message.parent_id && !event.message.show_in_channel;
|
|
1273
|
+
const isThreadMessage = event.message.parent_id && !event.message.show_in_channel;
|
|
1583
1274
|
|
|
1584
1275
|
if (this.state.isUpToDate || isThreadMessage) {
|
|
1585
1276
|
channelState.addMessageSorted(event.message, ownMessage);
|
|
@@ -1660,15 +1351,7 @@ export class Channel<
|
|
|
1660
1351
|
}
|
|
1661
1352
|
|
|
1662
1353
|
_callChannelListeners = (
|
|
1663
|
-
event: Event<
|
|
1664
|
-
AttachmentType,
|
|
1665
|
-
ChannelType,
|
|
1666
|
-
CommandType,
|
|
1667
|
-
EventType,
|
|
1668
|
-
MessageType,
|
|
1669
|
-
ReactionType,
|
|
1670
|
-
UserType
|
|
1671
|
-
>,
|
|
1354
|
+
event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
|
|
1672
1355
|
) => {
|
|
1673
1356
|
const channel = this;
|
|
1674
1357
|
// gather and call the listeners
|
|
@@ -1710,14 +1393,7 @@ export class Channel<
|
|
|
1710
1393
|
|
|
1711
1394
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
1712
1395
|
_initializeState(
|
|
1713
|
-
state: ChannelAPIResponse<
|
|
1714
|
-
AttachmentType,
|
|
1715
|
-
ChannelType,
|
|
1716
|
-
CommandType,
|
|
1717
|
-
MessageType,
|
|
1718
|
-
ReactionType,
|
|
1719
|
-
UserType
|
|
1720
|
-
>,
|
|
1396
|
+
state: ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
|
|
1721
1397
|
) {
|
|
1722
1398
|
const { state: clientState, user, userID } = this.getClient();
|
|
1723
1399
|
|
|
@@ -1786,14 +1462,10 @@ export class Channel<
|
|
|
1786
1462
|
}
|
|
1787
1463
|
|
|
1788
1464
|
_disconnect() {
|
|
1789
|
-
this._client.logger(
|
|
1790
|
-
'
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
tags: ['connection', 'channel'],
|
|
1794
|
-
channel: this,
|
|
1795
|
-
},
|
|
1796
|
-
);
|
|
1465
|
+
this._client.logger('info', `channel:disconnect() - Disconnecting the channel ${this.cid}`, {
|
|
1466
|
+
tags: ['connection', 'channel'],
|
|
1467
|
+
channel: this,
|
|
1468
|
+
});
|
|
1797
1469
|
|
|
1798
1470
|
this.disconnected = true;
|
|
1799
1471
|
this.state.setIsUpToDate(false);
|