stream-chat-angular 5.11.0 → 5.11.1

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 from 'angular-mentions';
21
21
  import { MentionModule } from 'angular-mentions';
22
22
 
23
- const version = '5.11.0';
23
+ const version = '5.11.1';
24
24
 
25
25
  /**
26
26
  * The `NotificationService` can be used to add or remove notifications. By default the [`NotificationList`](/chat/docs/sdk/angular/components/NotificationListComponent/) component displays the currently active notifications.
@@ -447,6 +447,10 @@ class ChannelService {
447
447
  this.chatClientService = chatClientService;
448
448
  this.ngZone = ngZone;
449
449
  this.notificationService = notificationService;
450
+ /**
451
+ * @internal
452
+ */
453
+ this.isMessageLoadingInProgress = false;
450
454
  this.messagePageSize = 25;
451
455
  this.channelsSubject = new BehaviorSubject(undefined);
452
456
  this.activeChannelSubject = new BehaviorSubject(undefined);
@@ -612,6 +616,7 @@ class ChannelService {
612
616
  this.stopWatchForActiveChannelEvents(prevActiveChannel);
613
617
  this.flushMarkReadQueue();
614
618
  this.areReadEventsPaused = false;
619
+ this.isMessageLoadingInProgress = false;
615
620
  const readState = channel.state.read[this.chatClientService.chatClient.user?.id || ''];
616
621
  this.activeChannelLastReadMessageId = readState?.last_read_message_id;
617
622
  if (channel.state.latestMessages[channel.state.latestMessages.length - 1]
@@ -651,6 +656,7 @@ class ChannelService {
651
656
  this.activeChannelLastReadMessageId = undefined;
652
657
  this.activeChannelUnreadCount = undefined;
653
658
  this.areReadEventsPaused = false;
659
+ this.isMessageLoadingInProgress = false;
654
660
  }
655
661
  /**
656
662
  * Sets the given `message` as an active parent message. If `undefined` is provided, it will deleselect the current parent message.
@@ -1177,6 +1183,7 @@ class ChannelService {
1177
1183
  * @param parentMessageId The ID of the parent message if we want to load a thread message
1178
1184
  */
1179
1185
  async jumpToMessage(messageId, parentMessageId) {
1186
+ this.isMessageLoadingInProgress = true;
1180
1187
  const activeChannel = this.activeChannelSubject.getValue();
1181
1188
  try {
1182
1189
  await activeChannel?.state.loadMessageIntoState(messageId, parentMessageId);
@@ -1195,6 +1202,9 @@ class ChannelService {
1195
1202
  this.notificationService.addTemporaryNotification('streamChat.Message not found');
1196
1203
  throw error;
1197
1204
  }
1205
+ finally {
1206
+ this.isMessageLoadingInProgress = false;
1207
+ }
1198
1208
  }
1199
1209
  /**
1200
1210
  * Clears the currently selected message to jump
@@ -7780,9 +7790,9 @@ class MessageListComponent {
7780
7790
  this.forceRepaint();
7781
7791
  }));
7782
7792
  this.subscriptions.push(this.channelService.activeChannel$.subscribe((channel) => {
7783
- let isNewChannel = false;
7793
+ let wasChannelSwitch = false;
7784
7794
  if (this.channelId !== channel?.id) {
7785
- isNewChannel = true;
7795
+ wasChannelSwitch = true;
7786
7796
  if (this.checkIfUnreadNotificationIsVisibleTimeout) {
7787
7797
  clearTimeout(this.checkIfUnreadNotificationIsVisibleTimeout);
7788
7798
  }
@@ -7805,9 +7815,16 @@ class MessageListComponent {
7805
7815
  unreadCount !== this.unreadCount) {
7806
7816
  this.lastReadMessageId = lastReadMessageId;
7807
7817
  this.unreadCount = unreadCount || 0;
7808
- if (isNewChannel && this.lastReadMessageId) {
7818
+ if (wasChannelSwitch && this.lastReadMessageId) {
7819
+ // Delay jumping to last read message in case we need to give precedence to channelService.jumpToMessage
7809
7820
  if (this.openMessageListAt === 'last-read-message') {
7810
- this.jumpToFirstUnreadMessage();
7821
+ setTimeout(() => {
7822
+ // Don't jump if a jump to a message was already started (using channelService.jumpToMessage)
7823
+ if (!this.isJumpingToMessage &&
7824
+ !this.channelService.isMessageLoadingInProgress) {
7825
+ this.jumpToFirstUnreadMessage();
7826
+ }
7827
+ }, 0);
7811
7828
  }
7812
7829
  else {
7813
7830
  // Wait till messages and the unread banner is rendered
@@ -8193,8 +8210,9 @@ class MessageListComponent {
8193
8210
  !this.firstUnreadMessageId &&
8194
8211
  this.lastReadMessageId) {
8195
8212
  const lastReadIndex = messages.findIndex((m) => m.id === this.lastReadMessageId);
8196
- this.firstUnreadMessageId =
8197
- messages[lastReadIndex + 1]?.id || this.lastReadMessageId;
8213
+ if (lastReadIndex !== -1) {
8214
+ this.firstUnreadMessageId = messages[lastReadIndex + 1]?.id;
8215
+ }
8198
8216
  }
8199
8217
  }), tap((messages) => (this.lastSentMessageId = [...messages]
8200
8218
  .reverse()