stream-chat 5.6.0 → 6.2.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.
Files changed (40) hide show
  1. package/README.md +59 -114
  2. package/dist/browser.es.js +464 -366
  3. package/dist/browser.es.js.map +1 -1
  4. package/dist/browser.full-bundle.min.js +1 -1
  5. package/dist/browser.full-bundle.min.js.map +1 -1
  6. package/dist/browser.js +464 -366
  7. package/dist/browser.js.map +1 -1
  8. package/dist/index.es.js +464 -366
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.js +464 -366
  11. package/dist/index.js.map +1 -1
  12. package/dist/types/channel.d.ts +124 -124
  13. package/dist/types/channel.d.ts.map +1 -1
  14. package/dist/types/channel_state.d.ts +41 -41
  15. package/dist/types/channel_state.d.ts.map +1 -1
  16. package/dist/types/client.d.ts +190 -163
  17. package/dist/types/client.d.ts.map +1 -1
  18. package/dist/types/client_state.d.ts +6 -6
  19. package/dist/types/client_state.d.ts.map +1 -1
  20. package/dist/types/connection.d.ts +10 -10
  21. package/dist/types/connection.d.ts.map +1 -1
  22. package/dist/types/connection_fallback.d.ts +7 -7
  23. package/dist/types/connection_fallback.d.ts.map +1 -1
  24. package/dist/types/insights.d.ts +2 -2
  25. package/dist/types/token_manager.d.ts +6 -6
  26. package/dist/types/token_manager.d.ts.map +1 -1
  27. package/dist/types/types.d.ts +404 -236
  28. package/dist/types/types.d.ts.map +1 -1
  29. package/dist/types/utils.d.ts +2 -2
  30. package/dist/types/utils.d.ts.map +1 -1
  31. package/package.json +2 -2
  32. package/src/channel.ts +196 -290
  33. package/src/channel_state.ts +54 -219
  34. package/src/client.ts +297 -524
  35. package/src/client_state.ts +6 -6
  36. package/src/connection.ts +7 -22
  37. package/src/connection_fallback.ts +7 -21
  38. package/src/token_manager.ts +6 -6
  39. package/src/types.ts +540 -487
  40. package/src/utils.ts +7 -11
package/src/channel.ts CHANGED
@@ -23,14 +23,12 @@ import {
23
23
  GetReactionsAPIResponse,
24
24
  GetRepliesAPIResponse,
25
25
  InviteOptions,
26
- LiteralStringForUnion,
27
26
  MarkReadOptions,
28
27
  MemberSort,
29
28
  Message,
30
29
  MessageFilters,
31
30
  MessageResponse,
32
31
  MuteChannelAPIResponse,
33
- PaginationOptions,
34
32
  PartialUpdateChannel,
35
33
  PartialUpdateChannelAPIResponse,
36
34
  QueryMembersOptions,
@@ -43,40 +41,29 @@ import {
43
41
  SendMessageAPIResponse,
44
42
  TruncateChannelAPIResponse,
45
43
  TruncateOptions,
46
- UR,
47
44
  UpdateChannelAPIResponse,
48
45
  UserFilters,
49
46
  UserResponse,
47
+ ExtendableGenerics,
48
+ DefaultGenerics,
50
49
  PinnedMessagePaginationOptions,
51
50
  PinnedMessagesSort,
51
+ MessagePaginationOptions,
52
52
  } from './types';
53
53
  import { Role } from './permissions';
54
54
 
55
55
  /**
56
56
  * Channel - The Channel class manages it's own state.
57
57
  */
58
- export class Channel<
59
- AttachmentType extends UR = UR,
60
- ChannelType extends UR = UR,
61
- CommandType extends string = LiteralStringForUnion,
62
- EventType extends UR = UR,
63
- MessageType extends UR = UR,
64
- ReactionType extends UR = UR,
65
- UserType extends UR = UR
66
- > {
67
- _client: StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
58
+ export class Channel<StreamChatGenerics extends ExtendableGenerics = DefaultGenerics> {
59
+ _client: StreamChat<StreamChatGenerics>;
68
60
  type: string;
69
61
  id: string | undefined;
70
- data: ChannelData<ChannelType> | ChannelResponse<ChannelType, CommandType, UserType> | undefined;
71
- _data: ChannelData<ChannelType> | ChannelResponse<ChannelType, CommandType, UserType>;
62
+ data: ChannelData<StreamChatGenerics> | ChannelResponse<StreamChatGenerics> | undefined;
63
+ _data: ChannelData<StreamChatGenerics> | ChannelResponse<StreamChatGenerics>;
72
64
  cid: string;
73
- listeners: {
74
- [key: string]: (
75
- | string
76
- | EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
77
- )[];
78
- };
79
- state: ChannelState<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>;
65
+ listeners: { [key: string]: (string | EventHandler<StreamChatGenerics>)[] };
66
+ state: ChannelState<StreamChatGenerics>;
80
67
  initialized: boolean;
81
68
  lastKeyStroke?: Date;
82
69
  lastTypingEvent: Date | null;
@@ -86,18 +73,18 @@ export class Channel<
86
73
  /**
87
74
  * constructor - Create a channel
88
75
  *
89
- * @param {StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>} client the chat client
76
+ * @param {StreamChat<StreamChatGenerics>} client the chat client
90
77
  * @param {string} type the type of channel
91
78
  * @param {string} [id] the id of the chat
92
- * @param {ChannelData<ChannelType>} data any additional custom params
79
+ * @param {ChannelData<StreamChatGenerics>} data any additional custom params
93
80
  *
94
- * @return {Channel<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>} Returns a new uninitialized channel
81
+ * @return {Channel<StreamChatGenerics>} Returns a new uninitialized channel
95
82
  */
96
83
  constructor(
97
- client: StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
84
+ client: StreamChat<StreamChatGenerics>,
98
85
  type: string,
99
86
  id: string | undefined,
100
- data: ChannelData<ChannelType>,
87
+ data: ChannelData<StreamChatGenerics>,
101
88
  ) {
102
89
  const validTypeRe = /^[\w_-]+$/;
103
90
  const validIDRe = /^[\w!_-]+$/;
@@ -119,15 +106,7 @@ export class Channel<
119
106
  this.cid = `${type}:${id}`;
120
107
  this.listeners = {};
121
108
  // perhaps the state variable should be private
122
- this.state = new ChannelState<
123
- AttachmentType,
124
- ChannelType,
125
- CommandType,
126
- EventType,
127
- MessageType,
128
- ReactionType,
129
- UserType
130
- >(this);
109
+ this.state = new ChannelState<StreamChatGenerics>(this);
131
110
  this.initialized = false;
132
111
  this.lastTypingEvent = null;
133
112
  this.isTyping = false;
@@ -137,9 +116,9 @@ export class Channel<
137
116
  /**
138
117
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
139
118
  *
140
- * @return {StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>}
119
+ * @return {StreamChat<StreamChatGenerics>}
141
120
  */
142
- getClient(): StreamChat<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType> {
121
+ getClient(): StreamChat<StreamChatGenerics> {
143
122
  if (this.disconnected === true) {
144
123
  throw Error(`You can't use a channel after client.disconnect() was called`);
145
124
  }
@@ -159,22 +138,23 @@ export class Channel<
159
138
  /**
160
139
  * sendMessage - Send a message to this channel
161
140
  *
162
- * @param {Message<AttachmentType, MessageType, UserType>} message The Message object
141
+ * @param {Message<StreamChatGenerics>} message The Message object
163
142
  * @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
164
143
  * @param {boolean} [options.skip_push] Skip sending push notifications
165
144
  *
166
- * @return {Promise<SendMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The Server Response
145
+ * @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
167
146
  */
168
147
  async sendMessage(
169
- message: Message<AttachmentType, MessageType, UserType>,
148
+ message: Message<StreamChatGenerics>,
170
149
  options?: { skip_enrich_url?: boolean; skip_push?: boolean },
171
150
  ) {
172
- const sendMessageResponse = await this.getClient().post<
173
- SendMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
174
- >(this._channelURL() + '/message', {
175
- message,
176
- ...options,
177
- });
151
+ const sendMessageResponse = await this.getClient().post<SendMessageAPIResponse<StreamChatGenerics>>(
152
+ this._channelURL() + '/message',
153
+ {
154
+ message,
155
+ ...options,
156
+ },
157
+ );
178
158
 
179
159
  // Reset unreadCount to 0.
180
160
  this.state.unreadCount = 0;
@@ -186,7 +166,7 @@ export class Channel<
186
166
  uri: string | NodeJS.ReadableStream | Buffer | File,
187
167
  name?: string,
188
168
  contentType?: string,
189
- user?: UserResponse<UserType>,
169
+ user?: UserResponse<StreamChatGenerics>,
190
170
  ) {
191
171
  return this.getClient().sendFile(`${this._channelURL()}/file`, uri, name, contentType, user);
192
172
  }
@@ -195,7 +175,7 @@ export class Channel<
195
175
  uri: string | NodeJS.ReadableStream | File,
196
176
  name?: string,
197
177
  contentType?: string,
198
- user?: UserResponse<UserType>,
178
+ user?: UserResponse<StreamChatGenerics>,
199
179
  ) {
200
180
  return this.getClient().sendFile(`${this._channelURL()}/image`, uri, name, contentType, user);
201
181
  }
@@ -211,17 +191,13 @@ export class Channel<
211
191
  /**
212
192
  * sendEvent - Send an event on this channel
213
193
  *
214
- * @param {Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>} event for example {type: 'message.read'}
194
+ * @param {Event<StreamChatGenerics>} event for example {type: 'message.read'}
215
195
  *
216
- * @return {Promise<EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>>} The Server Response
196
+ * @return {Promise<EventAPIResponse<StreamChatGenerics>>} The Server Response
217
197
  */
218
- async sendEvent(
219
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
220
- ) {
198
+ async sendEvent(event: Event<StreamChatGenerics>) {
221
199
  this._checkInitialized();
222
- return await this.getClient().post<
223
- EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
224
- >(this._channelURL() + '/event', {
200
+ return await this.getClient().post<EventAPIResponse<StreamChatGenerics>>(this._channelURL() + '/event', {
225
201
  event,
226
202
  });
227
203
  }
@@ -229,24 +205,17 @@ export class Channel<
229
205
  /**
230
206
  * search - Query messages
231
207
  *
232
- * @param {MessageFilters<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> | string} query search query or object MongoDB style filters
233
- * @param {{client_id?: string; connection_id?: string; query?: string; message_filter_conditions?: MessageFilters<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>}} options Option object, {user_id: 'tommaso'}
208
+ * @param {MessageFilters<StreamChatGenerics> | string} query search query or object MongoDB style filters
209
+ * @param {{client_id?: string; connection_id?: string; query?: string; message_filter_conditions?: MessageFilters<StreamChatGenerics>}} options Option object, {user_id: 'tommaso'}
234
210
  *
235
- * @return {Promise<SearchAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} search messages response
211
+ * @return {Promise<SearchAPIResponse<StreamChatGenerics>>} search messages response
236
212
  */
237
213
  async search(
238
- query: MessageFilters<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> | string,
239
- options: SearchOptions<MessageType> & {
214
+ query: MessageFilters<StreamChatGenerics> | string,
215
+ options: SearchOptions<StreamChatGenerics> & {
240
216
  client_id?: string;
241
217
  connection_id?: string;
242
- message_filter_conditions?: MessageFilters<
243
- AttachmentType,
244
- ChannelType,
245
- CommandType,
246
- MessageType,
247
- ReactionType,
248
- UserType
249
- >;
218
+ message_filter_conditions?: MessageFilters<StreamChatGenerics>;
250
219
  query?: string;
251
220
  } = {},
252
221
  ) {
@@ -254,10 +223,10 @@ export class Channel<
254
223
  throw Error(`Cannot specify offset with sort or next parameters`);
255
224
  }
256
225
  // Return a list of channels
257
- const payload: SearchPayload<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {
258
- filter_conditions: { cid: this.cid } as ChannelFilters<ChannelType, CommandType, UserType>,
226
+ const payload: SearchPayload<StreamChatGenerics> = {
227
+ filter_conditions: { cid: this.cid } as ChannelFilters<StreamChatGenerics>,
259
228
  ...options,
260
- sort: options.sort ? normalizeQuerySort<SearchMessageSortBase<MessageType>>(options.sort) : undefined,
229
+ sort: options.sort ? normalizeQuerySort<SearchMessageSortBase<StreamChatGenerics>>(options.sort) : undefined,
261
230
  };
262
231
  if (typeof query === 'string') {
263
232
  payload.query = query;
@@ -269,9 +238,7 @@ export class Channel<
269
238
  // Make sure we wait for the connect promise if there is a pending one
270
239
  await this.getClient().wsPromise;
271
240
 
272
- return await this.getClient().get<
273
- SearchAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
274
- >(this.getClient().baseURL + '/search', {
241
+ return await this.getClient().get<SearchAPIResponse<StreamChatGenerics>>(this.getClient().baseURL + '/search', {
275
242
  payload,
276
243
  });
277
244
  }
@@ -279,51 +246,54 @@ export class Channel<
279
246
  /**
280
247
  * queryMembers - Query Members
281
248
  *
282
- * @param {UserFilters<UserType>} filterConditions object MongoDB style filters
283
- * @param {MemberSort<UserType>} [sort] Sort options, for instance [{created_at: -1}].
249
+ * @param {UserFilters<StreamChatGenerics>} filterConditions object MongoDB style filters
250
+ * @param {MemberSort<StreamChatGenerics>} [sort] Sort options, for instance [{created_at: -1}].
284
251
  * When using multiple fields, make sure you use array of objects to guarantee field order, for instance [{name: -1}, {created_at: 1}]
285
252
  * @param {{ limit?: number; offset?: number }} [options] Option object, {limit: 10, offset:10}
286
253
  *
287
- * @return {Promise<ChannelMemberAPIResponse<UserType>>} Query Members response
254
+ * @return {Promise<ChannelMemberAPIResponse<StreamChatGenerics>>} Query Members response
288
255
  */
289
256
  async queryMembers(
290
- filterConditions: UserFilters<UserType>,
291
- sort: MemberSort<UserType> = [],
257
+ filterConditions: UserFilters<StreamChatGenerics>,
258
+ sort: MemberSort<StreamChatGenerics> = [],
292
259
  options: QueryMembersOptions = {},
293
260
  ) {
294
261
  let id: string | undefined;
295
262
  const type = this.type;
296
- let members: string[] | ChannelMemberResponse<UserType>[] | undefined;
263
+ let members: string[] | ChannelMemberResponse<StreamChatGenerics>[] | undefined;
297
264
  if (this.id) {
298
265
  id = this.id;
299
266
  } else if (this.data?.members && Array.isArray(this.data.members)) {
300
267
  members = this.data.members;
301
268
  }
302
269
  // Return a list of members
303
- return await this.getClient().get<ChannelMemberAPIResponse<UserType>>(this.getClient().baseURL + '/members', {
304
- payload: {
305
- type,
306
- id,
307
- members,
308
- sort: normalizeQuerySort(sort),
309
- filter_conditions: filterConditions,
310
- ...options,
270
+ return await this.getClient().get<ChannelMemberAPIResponse<StreamChatGenerics>>(
271
+ this.getClient().baseURL + '/members',
272
+ {
273
+ payload: {
274
+ type,
275
+ id,
276
+ members,
277
+ sort: normalizeQuerySort(sort),
278
+ filter_conditions: filterConditions,
279
+ ...options,
280
+ },
311
281
  },
312
- });
282
+ );
313
283
  }
314
284
 
315
285
  /**
316
286
  * sendReaction - Send a reaction about a message
317
287
  *
318
288
  * @param {string} messageID the message id
319
- * @param {Reaction<ReactionType, UserType>} reaction the reaction object for instance {type: 'love'}
289
+ * @param {Reaction<StreamChatGenerics>} reaction the reaction object for instance {type: 'love'}
320
290
  * @param {{ enforce_unique?: boolean, skip_push?: boolean }} [options] Option object, {enforce_unique: true, skip_push: true} to override any existing reaction or skip sending push notifications
321
291
  *
322
- * @return {Promise<ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The Server Response
292
+ * @return {Promise<ReactionAPIResponse<StreamChatGenerics>>} The Server Response
323
293
  */
324
294
  async sendReaction(
325
295
  messageID: string,
326
- reaction: Reaction<ReactionType, UserType>,
296
+ reaction: Reaction<StreamChatGenerics>,
327
297
  options?: { enforce_unique?: boolean; skip_push?: boolean },
328
298
  ) {
329
299
  if (!messageID) {
@@ -332,12 +302,13 @@ export class Channel<
332
302
  if (!reaction || Object.keys(reaction).length === 0) {
333
303
  throw Error(`Reaction object is missing`);
334
304
  }
335
- return await this.getClient().post<
336
- ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
337
- >(this.getClient().baseURL + `/messages/${messageID}/reaction`, {
338
- reaction,
339
- ...options,
340
- });
305
+ return await this.getClient().post<ReactionAPIResponse<StreamChatGenerics>>(
306
+ this.getClient().baseURL + `/messages/${messageID}/reaction`,
307
+ {
308
+ reaction,
309
+ ...options,
310
+ },
311
+ );
341
312
  }
342
313
 
343
314
  /**
@@ -347,7 +318,7 @@ export class Channel<
347
318
  * @param {string} reactionType the type of reaction that should be removed
348
319
  * @param {string} [user_id] the id of the user (used only for server side request) default null
349
320
  *
350
- * @return {Promise<ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The Server Response
321
+ * @return {Promise<ReactionAPIResponse<StreamChatGenerics>>} The Server Response
351
322
  */
352
323
  deleteReaction(messageID: string, reactionType: string, user_id?: string) {
353
324
  this._checkInitialized();
@@ -358,27 +329,23 @@ export class Channel<
358
329
  const url = this.getClient().baseURL + `/messages/${messageID}/reaction/${reactionType}`;
359
330
  //provided when server side request
360
331
  if (user_id) {
361
- return this.getClient().delete<
362
- ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
363
- >(url, { user_id });
332
+ return this.getClient().delete<ReactionAPIResponse<StreamChatGenerics>>(url, { user_id });
364
333
  }
365
334
 
366
- return this.getClient().delete<
367
- ReactionAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
368
- >(url, {});
335
+ return this.getClient().delete<ReactionAPIResponse<StreamChatGenerics>>(url, {});
369
336
  }
370
337
 
371
338
  /**
372
339
  * update - Edit the channel's custom properties
373
340
  *
374
- * @param {ChannelData<ChannelType>} channelData The object to update the custom properties of this channel with
375
- * @param {Message<AttachmentType, MessageType, UserType>} [updateMessage] Optional message object for channel members notification
341
+ * @param {ChannelData<StreamChatGenerics>} channelData The object to update the custom properties of this channel with
342
+ * @param {Message<StreamChatGenerics>} [updateMessage] Optional message object for channel members notification
376
343
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
377
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
344
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
378
345
  */
379
346
  async update(
380
- channelData: Partial<ChannelData<ChannelType>> | Partial<ChannelResponse<ChannelType, CommandType, UserType>> = {},
381
- updateMessage?: Message<AttachmentType, MessageType, UserType>,
347
+ channelData: Partial<ChannelData<StreamChatGenerics>> | Partial<ChannelResponse<StreamChatGenerics>> = {},
348
+ updateMessage?: Message<StreamChatGenerics>,
382
349
  options?: ChannelUpdateOptions,
383
350
  ) {
384
351
  // Strip out reserved names that will result in API errors.
@@ -408,12 +375,12 @@ export class Channel<
408
375
  /**
409
376
  * updatePartial - partial update channel properties
410
377
  *
411
- * @param {PartialUpdateChannel<ChannelType>} partial update request
378
+ * @param {PartialUpdateChannel<StreamChatGenerics>} partial update request
412
379
  *
413
- * @return {Promise<PartialUpdateChannelAPIResponse<ChannelType,CommandType, UserType>>}
380
+ * @return {Promise<PartialUpdateChannelAPIResponse<StreamChatGenerics>>}
414
381
  */
415
- async updatePartial(update: PartialUpdateChannel<ChannelType>) {
416
- return await this.getClient().patch<PartialUpdateChannelAPIResponse<ChannelType, CommandType, UserType>>(
382
+ async updatePartial(update: PartialUpdateChannel<StreamChatGenerics>) {
383
+ return await this.getClient().patch<PartialUpdateChannelAPIResponse<StreamChatGenerics>>(
417
384
  this._channelURL(),
418
385
  update,
419
386
  );
@@ -423,12 +390,10 @@ export class Channel<
423
390
  * enableSlowMode - enable slow mode
424
391
  *
425
392
  * @param {number} coolDownInterval the cooldown interval in seconds
426
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
393
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
427
394
  */
428
395
  async enableSlowMode(coolDownInterval: number) {
429
- const data = await this.getClient().post<
430
- UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
431
- >(this._channelURL(), {
396
+ const data = await this.getClient().post<UpdateChannelAPIResponse<StreamChatGenerics>>(this._channelURL(), {
432
397
  cooldown: coolDownInterval,
433
398
  });
434
399
  this.data = data.channel;
@@ -438,12 +403,10 @@ export class Channel<
438
403
  /**
439
404
  * disableSlowMode - disable slow mode
440
405
  *
441
- * @return {Promise<UpdateChannelAPIResponse<ChannelType, AttachmentType, MessageType, ReactionType, UserType>>} The server response
406
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
442
407
  */
443
408
  async disableSlowMode() {
444
- const data = await this.getClient().post<
445
- UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
446
- >(this._channelURL(), {
409
+ const data = await this.getClient().post<UpdateChannelAPIResponse<StreamChatGenerics>>(this._channelURL(), {
447
410
  cooldown: 0,
448
411
  });
449
412
  this.data = data.channel;
@@ -455,49 +418,45 @@ export class Channel<
455
418
  *
456
419
  * @param {boolean} [options.hard_delete] Defines if the channel is hard deleted or not
457
420
  *
458
- * @return {Promise<DeleteChannelAPIResponse<ChannelType, CommandType, UserType>>} The server response
421
+ * @return {Promise<DeleteChannelAPIResponse<StreamChatGenerics>>} The server response
459
422
  */
460
423
  async delete(options: { hard_delete?: boolean } = {}) {
461
- return await this.getClient().delete<DeleteChannelAPIResponse<ChannelType, CommandType, UserType>>(
462
- this._channelURL(),
463
- { ...options },
464
- );
424
+ return await this.getClient().delete<DeleteChannelAPIResponse<StreamChatGenerics>>(this._channelURL(), {
425
+ ...options,
426
+ });
465
427
  }
466
428
 
467
429
  /**
468
430
  * truncate - Removes all messages from the channel
469
- * @param {TruncateOptions<AttachmentType, MessageType, UserType>} [options] Defines truncation options
470
- * @return {Promise<TruncateChannelAPIResponse<ChannelType, CommandType, UserType, MessageType, ReactionType>>} The server response
431
+ * @param {TruncateOptions<StreamChatGenerics>} [options] Defines truncation options
432
+ * @return {Promise<TruncateChannelAPIResponse<StreamChatGenerics>>} The server response
471
433
  */
472
- async truncate(options: TruncateOptions<AttachmentType, MessageType, UserType> = {}) {
473
- return await this.getClient().post<
474
- TruncateChannelAPIResponse<ChannelType, CommandType, UserType, MessageType, ReactionType>
475
- >(this._channelURL() + '/truncate', options);
434
+ async truncate(options: TruncateOptions<StreamChatGenerics> = {}) {
435
+ return await this.getClient().post<TruncateChannelAPIResponse<StreamChatGenerics>>(
436
+ this._channelURL() + '/truncate',
437
+ options,
438
+ );
476
439
  }
477
440
 
478
441
  /**
479
442
  * acceptInvite - accept invitation to the channel
480
443
  *
481
- * @param {InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>} [options] The object to update the custom properties of this channel with
444
+ * @param {InviteOptions<StreamChatGenerics>} [options] The object to update the custom properties of this channel with
482
445
  *
483
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
446
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
484
447
  */
485
- async acceptInvite(
486
- options: InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {},
487
- ) {
448
+ async acceptInvite(options: InviteOptions<StreamChatGenerics> = {}) {
488
449
  return await this._update({ accept_invite: true, ...options });
489
450
  }
490
451
 
491
452
  /**
492
453
  * rejectInvite - reject invitation to the channel
493
454
  *
494
- * @param {InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>} [options] The object to update the custom properties of this channel with
455
+ * @param {InviteOptions<StreamChatGenerics>} [options] The object to update the custom properties of this channel with
495
456
  *
496
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
457
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
497
458
  */
498
- async rejectInvite(
499
- options: InviteOptions<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType> = {},
500
- ) {
459
+ async rejectInvite(options: InviteOptions<StreamChatGenerics> = {}) {
501
460
  return await this._update({ reject_invite: true, ...options });
502
461
  }
503
462
 
@@ -505,13 +464,13 @@ export class Channel<
505
464
  * addMembers - add members to the channel
506
465
  *
507
466
  * @param {{user_id: string, channel_role?: Role}[]} members An array of members to add to the channel
508
- * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
467
+ * @param {Message<StreamChatGenerics>} [message] Optional message object for channel members notification
509
468
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
510
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
469
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
511
470
  */
512
471
  async addMembers(
513
472
  members: string[] | { user_id: string; channel_role?: Role }[],
514
- message?: Message<AttachmentType, MessageType, UserType>,
473
+ message?: Message<StreamChatGenerics>,
515
474
  options: ChannelUpdateOptions = {},
516
475
  ) {
517
476
  return await this._update({ add_members: members, message, ...options });
@@ -521,15 +480,11 @@ export class Channel<
521
480
  * addModerators - add moderators to the channel
522
481
  *
523
482
  * @param {string[]} members An array of member identifiers
524
- * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
483
+ * @param {Message<StreamChatGenerics>} [message] Optional message object for channel members notification
525
484
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
526
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
485
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
527
486
  */
528
- async addModerators(
529
- members: string[],
530
- message?: Message<AttachmentType, MessageType, UserType>,
531
- options: ChannelUpdateOptions = {},
532
- ) {
487
+ async addModerators(members: string[], message?: Message<StreamChatGenerics>, options: ChannelUpdateOptions = {}) {
533
488
  return await this._update({ add_moderators: members, message, ...options });
534
489
  }
535
490
 
@@ -537,13 +492,13 @@ export class Channel<
537
492
  * assignRoles - sets member roles in a channel
538
493
  *
539
494
  * @param {{channel_role: Role, user_id: string}[]} roles List of role assignments
540
- * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
495
+ * @param {Message<StreamChatGenerics>} [message] Optional message object for channel members notification
541
496
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
542
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
497
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
543
498
  */
544
499
  async assignRoles(
545
500
  roles: { channel_role: Role; user_id: string }[],
546
- message?: Message<AttachmentType, MessageType, UserType>,
501
+ message?: Message<StreamChatGenerics>,
547
502
  options: ChannelUpdateOptions = {},
548
503
  ) {
549
504
  return await this._update({ assign_roles: roles, message, ...options });
@@ -553,13 +508,13 @@ export class Channel<
553
508
  * inviteMembers - invite members to the channel
554
509
  *
555
510
  * @param {{user_id: string, channel_role?: Role}[]} members An array of members to invite to the channel
556
- * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
511
+ * @param {Message<StreamChatGenerics>} [message] Optional message object for channel members notification
557
512
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
558
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
513
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
559
514
  */
560
515
  async inviteMembers(
561
516
  members: { user_id: string; channel_role?: Role }[] | string[],
562
- message?: Message<AttachmentType, MessageType, UserType>,
517
+ message?: Message<StreamChatGenerics>,
563
518
  options: ChannelUpdateOptions = {},
564
519
  ) {
565
520
  return await this._update({ invites: members, message, ...options });
@@ -569,15 +524,11 @@ export class Channel<
569
524
  * removeMembers - remove members from channel
570
525
  *
571
526
  * @param {string[]} members An array of member identifiers
572
- * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
527
+ * @param {Message<StreamChatGenerics>} [message] Optional message object for channel members notification
573
528
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
574
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
529
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
575
530
  */
576
- async removeMembers(
577
- members: string[],
578
- message?: Message<AttachmentType, MessageType, UserType>,
579
- options: ChannelUpdateOptions = {},
580
- ) {
531
+ async removeMembers(members: string[], message?: Message<StreamChatGenerics>, options: ChannelUpdateOptions = {}) {
581
532
  return await this._update({ remove_members: members, message, ...options });
582
533
  }
583
534
 
@@ -585,28 +536,22 @@ export class Channel<
585
536
  * demoteModerators - remove moderator role from channel members
586
537
  *
587
538
  * @param {string[]} members An array of member identifiers
588
- * @param {Message<AttachmentType, MessageType, UserType>} [message] Optional message object for channel members notification
539
+ * @param {Message<StreamChatGenerics>} [message] Optional message object for channel members notification
589
540
  * @param {ChannelUpdateOptions} [options] Option object, configuration to control the behavior while updating
590
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
541
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
591
542
  */
592
- async demoteModerators(
593
- members: string[],
594
- message?: Message<AttachmentType, MessageType, UserType>,
595
- options: ChannelUpdateOptions = {},
596
- ) {
543
+ async demoteModerators(members: string[], message?: Message<StreamChatGenerics>, options: ChannelUpdateOptions = {}) {
597
544
  return await this._update({ demote_moderators: members, message, ...options });
598
545
  }
599
546
 
600
547
  /**
601
548
  * _update - executes channel update request
602
549
  * @param payload Object Update Channel payload
603
- * @return {Promise<UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
550
+ * @return {Promise<UpdateChannelAPIResponse<StreamChatGenerics>>} The server response
604
551
  * TODO: introduce new type instead of Object in the next major update
605
552
  */
606
553
  async _update(payload: Object) {
607
- const data = await this.getClient().post<
608
- UpdateChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
609
- >(this._channelURL(), payload);
554
+ const data = await this.getClient().post<UpdateChannelAPIResponse<StreamChatGenerics>>(this._channelURL(), payload);
610
555
  this.data = data.channel;
611
556
  return data;
612
557
  }
@@ -614,7 +559,7 @@ export class Channel<
614
559
  /**
615
560
  * mute - mutes the current channel
616
561
  * @param {{ user_id?: string, expiration?: string }} opts expiration in minutes or user_id
617
- * @return {Promise<MuteChannelAPIResponse<ChannelType, CommandType, UserType>>} The server response
562
+ * @return {Promise<MuteChannelAPIResponse<StreamChatGenerics>>} The server response
618
563
  *
619
564
  * example with expiration:
620
565
  * await channel.mute({expiration: moment.duration(2, 'weeks')});
@@ -624,7 +569,7 @@ export class Channel<
624
569
  *
625
570
  */
626
571
  async mute(opts: { expiration?: number; user_id?: string } = {}) {
627
- return await this.getClient().post<MuteChannelAPIResponse<ChannelType, CommandType, UserType>>(
572
+ return await this.getClient().post<MuteChannelAPIResponse<StreamChatGenerics>>(
628
573
  this.getClient().baseURL + '/moderation/mute/channel',
629
574
  { channel_cid: this.cid, ...opts },
630
575
  );
@@ -663,14 +608,15 @@ export class Channel<
663
608
  if (!messageID) {
664
609
  throw Error(`Message id is missing`);
665
610
  }
666
- return this.getClient().post<
667
- SendMessageAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
668
- >(this.getClient().baseURL + `/messages/${messageID}/action`, {
669
- message_id: messageID,
670
- form_data: formData,
671
- id: this.id,
672
- type: this.type,
673
- });
611
+ return this.getClient().post<SendMessageAPIResponse<StreamChatGenerics>>(
612
+ this.getClient().baseURL + `/messages/${messageID}/action`,
613
+ {
614
+ message_id: messageID,
615
+ form_data: formData,
616
+ id: this.id,
617
+ type: this.type,
618
+ },
619
+ );
674
620
  }
675
621
 
676
622
  /**
@@ -693,7 +639,7 @@ export class Channel<
693
639
  await this.sendEvent({
694
640
  type: 'typing.start',
695
641
  parent_id,
696
- } as Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>);
642
+ } as Event<StreamChatGenerics>);
697
643
  }
698
644
  }
699
645
 
@@ -711,13 +657,13 @@ export class Channel<
711
657
  await this.sendEvent({
712
658
  type: 'typing.stop',
713
659
  parent_id,
714
- } as Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>);
660
+ } as Event<StreamChatGenerics>);
715
661
  }
716
662
 
717
663
  /**
718
664
  * lastMessage - return the last message, takes into account that last few messages might not be perfectly sorted
719
665
  *
720
- * @return {ReturnType<ChannelState<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>['formatMessage']> | undefined} Description
666
+ * @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']> | undefined} Description
721
667
  */
722
668
  lastMessage() {
723
669
  // get last 5 messages, sort, return the latest
@@ -738,19 +684,17 @@ export class Channel<
738
684
  /**
739
685
  * markRead - Send the mark read event for this user, only works if the `read_events` setting is enabled
740
686
  *
741
- * @param {MarkReadOptions<UserType>} data
742
- * @return {Promise<EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType> | null>} Description
687
+ * @param {MarkReadOptions<StreamChatGenerics>} data
688
+ * @return {Promise<EventAPIResponse<StreamChatGenerics> | null>} Description
743
689
  */
744
- async markRead(data: MarkReadOptions<UserType> = {}) {
690
+ async markRead(data: MarkReadOptions<StreamChatGenerics> = {}) {
745
691
  this._checkInitialized();
746
692
 
747
693
  if (!this.getConfig()?.read_events) {
748
694
  return Promise.resolve(null);
749
695
  }
750
696
 
751
- return await this.getClient().post<
752
- EventAPIResponse<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
753
- >(this._channelURL() + '/read', {
697
+ return await this.getClient().post<EventAPIResponse<StreamChatGenerics>>(this._channelURL() + '/read', {
754
698
  ...data,
755
699
  });
756
700
  }
@@ -773,11 +717,11 @@ export class Channel<
773
717
  /**
774
718
  * watch - Loads the initial channel state and watches for changes
775
719
  *
776
- * @param {ChannelQueryOptions<ChannelType, CommandType, UserType>} options additional options for the query endpoint
720
+ * @param {ChannelQueryOptions<StreamChatGenerics>} options additional options for the query endpoint
777
721
  *
778
- * @return {Promise<ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The server response
722
+ * @return {Promise<ChannelAPIResponse<StreamChatGenerics>>} The server response
779
723
  */
780
- async watch(options?: ChannelQueryOptions<ChannelType, CommandType, UserType>) {
724
+ async watch(options?: ChannelQueryOptions<StreamChatGenerics>) {
781
725
  const defaultOptions = {
782
726
  state: true,
783
727
  watch: true,
@@ -823,19 +767,20 @@ export class Channel<
823
767
  * getReplies - List the message replies for a parent message
824
768
  *
825
769
  * @param {string} parent_id The message parent id, ie the top of the thread
826
- * @param {PaginationOptions & { user?: UserResponse<UserType>; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
770
+ * @param {PaginationOptions & { user?: UserResponse<StreamChatGenerics>; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
827
771
  *
828
- * @return {Promise<GetRepliesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} A response with a list of messages
772
+ * @return {Promise<GetRepliesAPIResponse<StreamChatGenerics>>} A response with a list of messages
829
773
  */
830
774
  async getReplies(
831
775
  parent_id: string,
832
- options: PaginationOptions & { user?: UserResponse<UserType>; user_id?: string },
776
+ options: MessagePaginationOptions & { user?: UserResponse<StreamChatGenerics>; user_id?: string },
833
777
  ) {
834
- const data = await this.getClient().get<
835
- GetRepliesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
836
- >(this.getClient().baseURL + `/messages/${parent_id}/replies`, {
837
- ...options,
838
- });
778
+ const data = await this.getClient().get<GetRepliesAPIResponse<StreamChatGenerics>>(
779
+ this.getClient().baseURL + `/messages/${parent_id}/replies`,
780
+ {
781
+ ...options,
782
+ },
783
+ );
839
784
 
840
785
  // add any messages to our thread state
841
786
  if (data.messages) {
@@ -848,23 +793,24 @@ export class Channel<
848
793
  /**
849
794
  * getPinnedMessages - List list pinned messages of the channel
850
795
  *
851
- * @param {PinnedMessagePaginationOptions & { user?: UserResponse<UserType>; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
796
+ * @param {PinnedMessagePaginationOptions & { user?: UserResponse<StreamChatGenerics>; user_id?: string }} options Pagination params, ie {limit:10, id_lte: 10}
852
797
  * @param {PinnedMessagesSort} sort defines sorting direction of pinned messages
853
798
  *
854
- * @return {Promise<GetRepliesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} A response with a list of messages
799
+ * @return {Promise<GetRepliesAPIResponse<StreamChatGenerics>>} A response with a list of messages
855
800
  */
856
801
  async getPinnedMessages(
857
- options: PinnedMessagePaginationOptions & { user?: UserResponse<UserType>; user_id?: string },
802
+ options: PinnedMessagePaginationOptions & { user?: UserResponse<StreamChatGenerics>; user_id?: string },
858
803
  sort: PinnedMessagesSort = [],
859
804
  ) {
860
- return await this.getClient().get<
861
- GetRepliesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
862
- >(this.getClient().baseURL + `/channels/${this.type}/${this.id}/pinned_messages`, {
863
- payload: {
864
- ...options,
865
- sort: normalizeQuerySort(sort),
805
+ return await this.getClient().get<GetRepliesAPIResponse<StreamChatGenerics>>(
806
+ this.getClient().baseURL + `/channels/${this.type}/${this.id}/pinned_messages`,
807
+ {
808
+ payload: {
809
+ ...options,
810
+ sort: normalizeQuerySort(sort),
811
+ },
866
812
  },
867
- });
813
+ );
868
814
  }
869
815
 
870
816
  /**
@@ -873,10 +819,10 @@ export class Channel<
873
819
  * @param {string} message_id The message id
874
820
  * @param {{ limit?: number; offset?: number }} options The pagination options
875
821
  *
876
- * @return {Promise<GetReactionsAPIResponse<ReactionType, UserType>>} Server response
822
+ * @return {Promise<GetReactionsAPIResponse<StreamChatGenerics>>} Server response
877
823
  */
878
824
  getReactions(message_id: string, options: { limit?: number; offset?: number }) {
879
- return this.getClient().get<GetReactionsAPIResponse<ReactionType, UserType>>(
825
+ return this.getClient().get<GetReactionsAPIResponse<StreamChatGenerics>>(
880
826
  this.getClient().baseURL + `/messages/${message_id}/reactions`,
881
827
  {
882
828
  ...options,
@@ -889,12 +835,10 @@ export class Channel<
889
835
  *
890
836
  * @param {string[]} messageIds The ids of the messages to retrieve from this channel
891
837
  *
892
- * @return {Promise<GetMultipleMessagesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} Server response
838
+ * @return {Promise<GetMultipleMessagesAPIResponse<StreamChatGenerics>>} Server response
893
839
  */
894
840
  getMessagesById(messageIds: string[]) {
895
- return this.getClient().get<
896
- GetMultipleMessagesAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
897
- >(this._channelURL() + '/messages', {
841
+ return this.getClient().get<GetMultipleMessagesAPIResponse<StreamChatGenerics>>(this._channelURL() + '/messages', {
898
842
  ids: messageIds.join(','),
899
843
  });
900
844
  }
@@ -911,11 +855,7 @@ export class Channel<
911
855
  }
912
856
  }
913
857
 
914
- _countMessageAsUnread(
915
- message:
916
- | FormatMessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
917
- | MessageResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
918
- ) {
858
+ _countMessageAsUnread(message: FormatMessageResponse<StreamChatGenerics> | MessageResponse<StreamChatGenerics>) {
919
859
  if (message.shadowed) return false;
920
860
  if (message.silent) return false;
921
861
  if (message.parent_id && !message.show_in_channel) return false;
@@ -923,6 +863,10 @@ export class Channel<
923
863
  if (message.user?.id && this.getClient().userMuteStatus(message.user.id)) return false;
924
864
  if (message.type === 'system') return false;
925
865
 
866
+ // Return false if channel doesn't allow read events.
867
+ if (Array.isArray(this.data?.own_capabilities) && !this.data?.own_capabilities.includes('read-events'))
868
+ return false;
869
+
926
870
  if (this.muteStatus().muted) return false;
927
871
 
928
872
  return true;
@@ -974,7 +918,7 @@ export class Channel<
974
918
  /**
975
919
  * create - Creates a new channel
976
920
  *
977
- * @return {Promise<ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} The Server Response
921
+ * @return {Promise<ChannelAPIResponse<StreamChatGenerics>>} The Server Response
978
922
  */
979
923
  create = async () => {
980
924
  const options = {
@@ -988,11 +932,11 @@ export class Channel<
988
932
  /**
989
933
  * query - Query the API, get messages, members or other channel fields
990
934
  *
991
- * @param {ChannelQueryOptions<ChannelType, CommandType, UserType>} options The query options
935
+ * @param {ChannelQueryOptions<StreamChatGenerics>} options The query options
992
936
  *
993
- * @return {Promise<ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>>} Returns a query response
937
+ * @return {Promise<ChannelAPIResponse<StreamChatGenerics>>} Returns a query response
994
938
  */
995
- async query(options: ChannelQueryOptions<ChannelType, CommandType, UserType>) {
939
+ async query(options: ChannelQueryOptions<StreamChatGenerics>) {
996
940
  // Make sure we wait for the connect promise if there is a pending one
997
941
  await this.getClient().wsPromise;
998
942
 
@@ -1001,9 +945,7 @@ export class Channel<
1001
945
  queryURL += `/${this.id}`;
1002
946
  }
1003
947
 
1004
- const state = await this.getClient().post<
1005
- ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>
1006
- >(queryURL + '/query', {
948
+ const state = await this.getClient().post<ChannelAPIResponse<StreamChatGenerics>>(queryURL + '/query', {
1007
949
  data: this._data,
1008
950
  state: true,
1009
951
  ...options,
@@ -1044,10 +986,10 @@ export class Channel<
1044
986
  * banUser - Bans a user from a channel
1045
987
  *
1046
988
  * @param {string} targetUserID
1047
- * @param {BanUserOptions<UserType>} options
989
+ * @param {BanUserOptions<StreamChatGenerics>} options
1048
990
  * @returns {Promise<APIResponse>}
1049
991
  */
1050
- async banUser(targetUserID: string, options: BanUserOptions<UserType>) {
992
+ async banUser(targetUserID: string, options: BanUserOptions<StreamChatGenerics>) {
1051
993
  this._checkInitialized();
1052
994
  return await this.getClient().banUser(targetUserID, {
1053
995
  ...options,
@@ -1104,10 +1046,10 @@ export class Channel<
1104
1046
  * shadowBan - Shadow bans a user from a channel
1105
1047
  *
1106
1048
  * @param {string} targetUserID
1107
- * @param {BanUserOptions<UserType>} options
1049
+ * @param {BanUserOptions<StreamChatGenerics>} options
1108
1050
  * @returns {Promise<APIResponse>}
1109
1051
  */
1110
- async shadowBan(targetUserID: string, options: BanUserOptions<UserType>) {
1052
+ async shadowBan(targetUserID: string, options: BanUserOptions<StreamChatGenerics>) {
1111
1053
  this._checkInitialized();
1112
1054
  return await this.getClient().shadowBan(targetUserID, {
1113
1055
  ...options,
@@ -1137,29 +1079,14 @@ export class Channel<
1137
1079
  * or
1138
1080
  * channel.on(event => {console.log(event.type)})
1139
1081
  *
1140
- * @param {EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType> | EventTypes} callbackOrString The event type to listen for (optional)
1141
- * @param {EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>} [callbackOrNothing] The callback to call
1082
+ * @param {EventHandler<StreamChatGenerics> | EventTypes} callbackOrString The event type to listen for (optional)
1083
+ * @param {EventHandler<StreamChatGenerics>} [callbackOrNothing] The callback to call
1142
1084
  */
1085
+ on(eventType: EventTypes, callback: EventHandler<StreamChatGenerics>): { unsubscribe: () => void };
1086
+ on(callback: EventHandler<StreamChatGenerics>): { unsubscribe: () => void };
1143
1087
  on(
1144
- eventType: EventTypes,
1145
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1146
- ): { unsubscribe: () => void };
1147
- on(
1148
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1149
- ): { unsubscribe: () => void };
1150
- on(
1151
- callbackOrString:
1152
- | EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
1153
- | EventTypes,
1154
- callbackOrNothing?: EventHandler<
1155
- AttachmentType,
1156
- ChannelType,
1157
- CommandType,
1158
- EventType,
1159
- MessageType,
1160
- ReactionType,
1161
- UserType
1162
- >,
1088
+ callbackOrString: EventHandler<StreamChatGenerics> | EventTypes,
1089
+ callbackOrNothing?: EventHandler<StreamChatGenerics>,
1163
1090
  ): { unsubscribe: () => void } {
1164
1091
  const key = callbackOrNothing ? (callbackOrString as string) : 'all';
1165
1092
  const valid = isValidEventType(key);
@@ -1193,26 +1120,11 @@ export class Channel<
1193
1120
  * off - Remove the event handler
1194
1121
  *
1195
1122
  */
1123
+ off(eventType: EventTypes, callback: EventHandler<StreamChatGenerics>): void;
1124
+ off(callback: EventHandler<StreamChatGenerics>): void;
1196
1125
  off(
1197
- eventType: EventTypes,
1198
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1199
- ): void;
1200
- off(
1201
- callback: EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1202
- ): void;
1203
- off(
1204
- callbackOrString:
1205
- | EventHandler<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>
1206
- | EventTypes,
1207
- callbackOrNothing?: EventHandler<
1208
- AttachmentType,
1209
- ChannelType,
1210
- CommandType,
1211
- EventType,
1212
- MessageType,
1213
- ReactionType,
1214
- UserType
1215
- >,
1126
+ callbackOrString: EventHandler<StreamChatGenerics> | EventTypes,
1127
+ callbackOrNothing?: EventHandler<StreamChatGenerics>,
1216
1128
  ): void {
1217
1129
  const key = callbackOrNothing ? (callbackOrString as string) : 'all';
1218
1130
  const valid = isValidEventType(key);
@@ -1232,9 +1144,7 @@ export class Channel<
1232
1144
  }
1233
1145
 
1234
1146
  // eslint-disable-next-line sonarjs/cognitive-complexity
1235
- _handleChannelEvent(
1236
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1237
- ) {
1147
+ _handleChannelEvent(event: Event<StreamChatGenerics>) {
1238
1148
  const channel = this;
1239
1149
  this._client.logger(
1240
1150
  'info',
@@ -1390,9 +1300,7 @@ export class Channel<
1390
1300
  }
1391
1301
  }
1392
1302
 
1393
- _callChannelListeners = (
1394
- event: Event<AttachmentType, ChannelType, CommandType, EventType, MessageType, ReactionType, UserType>,
1395
- ) => {
1303
+ _callChannelListeners = (event: Event<StreamChatGenerics>) => {
1396
1304
  const channel = this;
1397
1305
  // gather and call the listeners
1398
1306
  const listeners = [];
@@ -1432,9 +1340,7 @@ export class Channel<
1432
1340
  }
1433
1341
 
1434
1342
  // eslint-disable-next-line sonarjs/cognitive-complexity
1435
- _initializeState(
1436
- state: ChannelAPIResponse<AttachmentType, ChannelType, CommandType, MessageType, ReactionType, UserType>,
1437
- ) {
1343
+ _initializeState(state: ChannelAPIResponse<StreamChatGenerics>) {
1438
1344
  const { state: clientState, user, userID } = this.getClient();
1439
1345
 
1440
1346
  // add the Users