stream-chat-angular 3.2.2 → 3.4.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.
@@ -17,7 +17,7 @@ import transliterate from '@stream-io/transliterate';
17
17
  import * as i7 from 'angular-mentions';
18
18
  import { MentionModule } from 'angular-mentions';
19
19
 
20
- const version = '3.2.2';
20
+ const version = '3.4.0';
21
21
 
22
22
  /**
23
23
  * The `NotificationService` can be used to add or remove notifications. By default the [`NotificationList`](../components/NotificationListComponent.mdx) component displays the currently active notifications.
@@ -271,6 +271,7 @@ class ChannelService {
271
271
  this.messageToQuoteSubject = new BehaviorSubject(undefined);
272
272
  this.usersTypingInChannelSubject = new BehaviorSubject([]);
273
273
  this.usersTypingInThreadSubject = new BehaviorSubject([]);
274
+ this._shouldMarkActiveChannelAsRead = true;
274
275
  this.channelListSetter = (channels) => {
275
276
  const currentChannels = this.channelsSubject.getValue() || [];
276
277
  const newChannels = channels.filter((c) => !currentChannels.find((channel) => channel.cid === c.cid));
@@ -326,6 +327,22 @@ class ChannelService {
326
327
  this.latestMessageDateByUserByChannels$ =
327
328
  this.latestMessageDateByUserByChannelsSubject.asObservable();
328
329
  }
330
+ /**
331
+ * If set to false, read events won't be sent as new messages are received. If set to true active channel (if any) will immediately be marked as read.
332
+ */
333
+ get shouldMarkActiveChannelAsRead() {
334
+ return this._shouldMarkActiveChannelAsRead;
335
+ }
336
+ /**
337
+ * If set to false, read events won't be sent as new messages are received. If set to true active channel (if any) will immediately be marked as read.
338
+ */
339
+ set shouldMarkActiveChannelAsRead(shouldMarkActiveChannelAsRead) {
340
+ var _a;
341
+ if (!this._shouldMarkActiveChannelAsRead && shouldMarkActiveChannelAsRead) {
342
+ (_a = this.activeChannelSubject.getValue()) === null || _a === void 0 ? void 0 : _a.markRead();
343
+ }
344
+ this._shouldMarkActiveChannelAsRead = shouldMarkActiveChannelAsRead;
345
+ }
329
346
  /**
330
347
  * Sets the given `channel` as active and marks it as read.
331
348
  * @param channel
@@ -338,7 +355,7 @@ class ChannelService {
338
355
  channel.state.messages.forEach((m) => {
339
356
  m.readBy = getReadBy(m, channel);
340
357
  });
341
- if (this.canSendReadEvents) {
358
+ if (this.canSendReadEvents && this.shouldMarkActiveChannelAsRead) {
342
359
  void channel.markRead();
343
360
  }
344
361
  this.activeChannelMessagesSubject.next([...channel.state.messages]);
@@ -354,6 +371,7 @@ class ChannelService {
354
371
  if (!activeChannel) {
355
372
  return;
356
373
  }
374
+ this.stopWatchForActiveChannelEvents(activeChannel);
357
375
  this.activeChannelMessagesSubject.next([]);
358
376
  this.activeChannelSubject.next(undefined);
359
377
  this.activeParentMessageIdSubject.next(undefined);
@@ -446,8 +464,9 @@ class ChannelService {
446
464
  message_limit: this.messagePageSize,
447
465
  };
448
466
  this.sort = sort || { last_message_at: -1, updated_at: -1 };
449
- const result = yield this.queryChannels(shouldSetActiveChannel);
450
- this.chatClientService.events$.subscribe((notification) => void this.handleNotification(notification));
467
+ this.shouldSetActiveChannel = shouldSetActiveChannel;
468
+ const result = yield this.queryChannels(this.shouldSetActiveChannel);
469
+ this.clientEventsSubscription = this.chatClientService.events$.subscribe((notification) => void this.handleNotification(notification));
451
470
  return result;
452
471
  });
453
472
  }
@@ -455,8 +474,10 @@ class ChannelService {
455
474
  * Resets the `activeChannel$`, `channels$` and `activeChannelMessages$` Observables. Useful when disconnecting a chat user, use in combination with [`disconnectUser`](./ChatClientService.mdx/#disconnectuser).
456
475
  */
457
476
  reset() {
477
+ var _a;
458
478
  this.deselectActiveChannel();
459
479
  this.channelsSubject.next(undefined);
480
+ (_a = this.clientEventsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
460
481
  }
461
482
  /**
462
483
  * Loads the next page of channels. The page size can be set in the [query option](https://getstream.io/chat/docs/javascript/query_channels/?language=javascript#query-options) object.
@@ -691,6 +712,13 @@ class ChannelService {
691
712
  }
692
713
  handleNotification(clientEvent) {
693
714
  switch (clientEvent.eventType) {
715
+ case 'connection.recovered': {
716
+ this.ngZone.run(() => {
717
+ this.reset();
718
+ void this.init(this.filters, this.sort, this.options, this.shouldSetActiveChannel);
719
+ });
720
+ break;
721
+ }
694
722
  case 'notification.message_new': {
695
723
  this.ngZone.run(() => {
696
724
  if (this.customNewMessageNotificationHandler) {
@@ -778,7 +806,7 @@ class ChannelService {
778
806
  ...channel.state.messages,
779
807
  ]);
780
808
  this.activeChannel$.pipe(first()).subscribe((c) => {
781
- if (this.canSendReadEvents) {
809
+ if (this.canSendReadEvents && this.shouldMarkActiveChannelAsRead) {
782
810
  void (c === null || c === void 0 ? void 0 : c.markRead());
783
811
  }
784
812
  });