stream-chat-angular 5.1.1 → 5.1.2

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.
@@ -20,7 +20,7 @@ import transliterate from '@stream-io/transliterate';
20
20
  import * as i8$1 from 'angular-mentions';
21
21
  import { MentionModule } from 'angular-mentions';
22
22
 
23
- const version = '5.1.1';
23
+ const version = '5.1.2';
24
24
 
25
25
  /**
26
26
  * The `NotificationService` can be used to add or remove notifications. By default the [`NotificationList`](../components/NotificationListComponent.mdx) component displays the currently active notifications.
@@ -495,6 +495,7 @@ class ChannelService {
495
495
  this.activeParentMessageIdSubject.next(message === null || message === void 0 ? void 0 : message.id);
496
496
  };
497
497
  this.areReadEventsPaused = false;
498
+ this.markReadThrottleTime = 1050;
498
499
  this.channels$ = this.channelsSubject.asObservable().pipe(shareReplay(1));
499
500
  this.activeChannel$ = this.activeChannelSubject
500
501
  .asObservable()
@@ -598,13 +599,15 @@ class ChannelService {
598
599
  return;
599
600
  }
600
601
  this.stopWatchForActiveChannelEvents(prevActiveChannel);
602
+ this.flushMarkReadQueue();
601
603
  this.areReadEventsPaused = false;
602
604
  const readState = channel.state.read[((_a = this.chatClientService.chatClient.user) === null || _a === void 0 ? void 0 : _a.id) || ''];
603
605
  this.activeChannelLastReadMessageId = readState === null || readState === void 0 ? void 0 : readState.last_read_message_id;
604
- if (((_b = channel.state.latestMessages[channel.state.latestMessages.length - 1]) === null || _b === void 0 ? void 0 : _b.id) === this.activeChannelLastReadMessageId) {
606
+ this.activeChannelUnreadCount = (readState === null || readState === void 0 ? void 0 : readState.unread_messages) || 0;
607
+ if (((_b = channel.state.latestMessages[channel.state.latestMessages.length - 1]) === null || _b === void 0 ? void 0 : _b.id) === this.activeChannelLastReadMessageId ||
608
+ this.activeChannelUnreadCount === 0) {
605
609
  this.activeChannelLastReadMessageId = undefined;
606
610
  }
607
- this.activeChannelUnreadCount = (readState === null || readState === void 0 ? void 0 : readState.unread_messages) || 0;
608
611
  this.watchForActiveChannelEvents(channel);
609
612
  this.addChannel(channel);
610
613
  this.activeChannelSubject.next(channel);
@@ -623,6 +626,7 @@ class ChannelService {
623
626
  return;
624
627
  }
625
628
  this.stopWatchForActiveChannelEvents(activeChannel);
629
+ this.flushMarkReadQueue();
626
630
  this.activeChannelMessagesSubject.next([]);
627
631
  this.activeChannelSubject.next(undefined);
628
632
  this.activeParentMessageIdSubject.next(undefined);
@@ -1406,6 +1410,9 @@ class ChannelService {
1406
1410
  this.ngZone.run(() => {
1407
1411
  this.activeChannelLastReadMessageId = e.last_read_message_id;
1408
1412
  this.activeChannelUnreadCount = e.unread_messages;
1413
+ if (this.activeChannelUnreadCount === 0) {
1414
+ this.activeChannelLastReadMessageId = undefined;
1415
+ }
1409
1416
  this.activeChannelSubject.next(this.activeChannel);
1410
1417
  });
1411
1418
  }));
@@ -1907,13 +1914,41 @@ class ChannelService {
1907
1914
  this.usersTypingInChannelSubject.next([]);
1908
1915
  this.usersTypingInThreadSubject.next([]);
1909
1916
  }
1910
- markRead(channel) {
1917
+ markRead(channel, isThrottled = true) {
1911
1918
  if (this.canSendReadEvents &&
1912
1919
  this.shouldMarkActiveChannelAsRead &&
1913
- !this.areReadEventsPaused) {
1914
- void channel.markRead();
1920
+ !this.areReadEventsPaused &&
1921
+ channel.countUnread() > 0) {
1922
+ if (isThrottled) {
1923
+ this.markReadThrottled(channel);
1924
+ }
1925
+ else {
1926
+ void channel.markRead();
1927
+ }
1915
1928
  }
1916
1929
  }
1930
+ markReadThrottled(channel) {
1931
+ if (!this.markReadTimeout) {
1932
+ this.markRead(channel, false);
1933
+ this.markReadTimeout = setTimeout(() => {
1934
+ this.flushMarkReadQueue();
1935
+ }, this.markReadThrottleTime);
1936
+ }
1937
+ else {
1938
+ clearTimeout(this.markReadTimeout);
1939
+ this.scheduledMarkReadRequest = () => this.markRead(channel, false);
1940
+ this.markReadTimeout = setTimeout(() => {
1941
+ this.flushMarkReadQueue();
1942
+ }, this.markReadThrottleTime);
1943
+ }
1944
+ }
1945
+ flushMarkReadQueue() {
1946
+ var _a;
1947
+ (_a = this.scheduledMarkReadRequest) === null || _a === void 0 ? void 0 : _a.call(this);
1948
+ this.scheduledMarkReadRequest = undefined;
1949
+ clearTimeout(this.markReadTimeout);
1950
+ this.markReadTimeout = undefined;
1951
+ }
1917
1952
  _init(settings) {
1918
1953
  return __awaiter(this, void 0, void 0, function* () {
1919
1954
  this.shouldSetActiveChannel = settings.shouldSetActiveChannel;