stream-chat-angular 5.1.0 → 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.
@@ -19,7 +19,7 @@ import transliterate from '@stream-io/transliterate';
19
19
  import * as i8$1 from 'angular-mentions';
20
20
  import { MentionModule } from 'angular-mentions';
21
21
 
22
- const version = '5.1.0';
22
+ const version = '5.1.2';
23
23
 
24
24
  /**
25
25
  * The `NotificationService` can be used to add or remove notifications. By default the [`NotificationList`](../components/NotificationListComponent.mdx) component displays the currently active notifications.
@@ -241,9 +241,8 @@ class ChatClientService {
241
241
  { id: { $autocomplete: searchTerm } },
242
242
  { name: { $autocomplete: searchTerm } },
243
243
  ],
244
- id: { $ne: this.chatClient.userID },
245
244
  }); // TODO: find out why we need this typecast
246
- return result.users;
245
+ return result.users.filter((u) => u.id !== this.chatClient?.user?.id);
247
246
  }
248
247
  updatePendingInvites(e) {
249
248
  if (!this.trackPendingChannelInvites) {
@@ -507,6 +506,7 @@ class ChannelService {
507
506
  this.activeParentMessageIdSubject.next(message?.id);
508
507
  };
509
508
  this.areReadEventsPaused = false;
509
+ this.markReadThrottleTime = 1050;
510
510
  this.channels$ = this.channelsSubject.asObservable().pipe(shareReplay(1));
511
511
  this.activeChannel$ = this.activeChannelSubject
512
512
  .asObservable()
@@ -609,14 +609,16 @@ class ChannelService {
609
609
  return;
610
610
  }
611
611
  this.stopWatchForActiveChannelEvents(prevActiveChannel);
612
+ this.flushMarkReadQueue();
612
613
  this.areReadEventsPaused = false;
613
614
  const readState = channel.state.read[this.chatClientService.chatClient.user?.id || ''];
614
615
  this.activeChannelLastReadMessageId = readState?.last_read_message_id;
616
+ this.activeChannelUnreadCount = readState?.unread_messages || 0;
615
617
  if (channel.state.latestMessages[channel.state.latestMessages.length - 1]
616
- ?.id === this.activeChannelLastReadMessageId) {
618
+ ?.id === this.activeChannelLastReadMessageId ||
619
+ this.activeChannelUnreadCount === 0) {
617
620
  this.activeChannelLastReadMessageId = undefined;
618
621
  }
619
- this.activeChannelUnreadCount = readState?.unread_messages || 0;
620
622
  this.watchForActiveChannelEvents(channel);
621
623
  this.addChannel(channel);
622
624
  this.activeChannelSubject.next(channel);
@@ -635,6 +637,7 @@ class ChannelService {
635
637
  return;
636
638
  }
637
639
  this.stopWatchForActiveChannelEvents(activeChannel);
640
+ this.flushMarkReadQueue();
638
641
  this.activeChannelMessagesSubject.next([]);
639
642
  this.activeChannelSubject.next(undefined);
640
643
  this.activeParentMessageIdSubject.next(undefined);
@@ -1013,9 +1016,8 @@ class ChannelService {
1013
1016
  }
1014
1017
  const result = await activeChannel.queryMembers({
1015
1018
  name: { $autocomplete: searchTerm },
1016
- id: { $ne: this.chatClientService.chatClient.userID },
1017
1019
  }); // TODO: find out why we need typecast here
1018
- return Object.values(result.members);
1020
+ return result.members.filter((m) => m.user_id !== this.chatClientService.chatClient?.user?.id);
1019
1021
  }
1020
1022
  }
1021
1023
  /**
@@ -1409,6 +1411,9 @@ class ChannelService {
1409
1411
  this.ngZone.run(() => {
1410
1412
  this.activeChannelLastReadMessageId = e.last_read_message_id;
1411
1413
  this.activeChannelUnreadCount = e.unread_messages;
1414
+ if (this.activeChannelUnreadCount === 0) {
1415
+ this.activeChannelLastReadMessageId = undefined;
1416
+ }
1412
1417
  this.activeChannelSubject.next(this.activeChannel);
1413
1418
  });
1414
1419
  }));
@@ -1895,12 +1900,39 @@ class ChannelService {
1895
1900
  this.usersTypingInChannelSubject.next([]);
1896
1901
  this.usersTypingInThreadSubject.next([]);
1897
1902
  }
1898
- markRead(channel) {
1903
+ markRead(channel, isThrottled = true) {
1899
1904
  if (this.canSendReadEvents &&
1900
1905
  this.shouldMarkActiveChannelAsRead &&
1901
- !this.areReadEventsPaused) {
1902
- void channel.markRead();
1906
+ !this.areReadEventsPaused &&
1907
+ channel.countUnread() > 0) {
1908
+ if (isThrottled) {
1909
+ this.markReadThrottled(channel);
1910
+ }
1911
+ else {
1912
+ void channel.markRead();
1913
+ }
1914
+ }
1915
+ }
1916
+ markReadThrottled(channel) {
1917
+ if (!this.markReadTimeout) {
1918
+ this.markRead(channel, false);
1919
+ this.markReadTimeout = setTimeout(() => {
1920
+ this.flushMarkReadQueue();
1921
+ }, this.markReadThrottleTime);
1903
1922
  }
1923
+ else {
1924
+ clearTimeout(this.markReadTimeout);
1925
+ this.scheduledMarkReadRequest = () => this.markRead(channel, false);
1926
+ this.markReadTimeout = setTimeout(() => {
1927
+ this.flushMarkReadQueue();
1928
+ }, this.markReadThrottleTime);
1929
+ }
1930
+ }
1931
+ flushMarkReadQueue() {
1932
+ this.scheduledMarkReadRequest?.();
1933
+ this.scheduledMarkReadRequest = undefined;
1934
+ clearTimeout(this.markReadTimeout);
1935
+ this.markReadTimeout = undefined;
1904
1936
  }
1905
1937
  async _init(settings) {
1906
1938
  this.shouldSetActiveChannel = settings.shouldSetActiveChannel;