stream-chat-angular 4.39.5 → 4.39.6

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 = '4.39.5';
23
+ const version = '4.39.6';
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.
@@ -309,6 +309,7 @@ class ChannelService {
309
309
  this.activeChannelPinnedMessagesSubject = new BehaviorSubject([]);
310
310
  this.hasMoreChannelsSubject = new ReplaySubject(1);
311
311
  this.activeChannelSubscriptions = [];
312
+ this.channelSubscriptions = {};
312
313
  this.activeParentMessageIdSubject = new BehaviorSubject(undefined);
313
314
  this.activeThreadMessagesSubject = new BehaviorSubject([]);
314
315
  this.jumpToMessageSubject = new BehaviorSubject({ id: undefined, parentId: undefined });
@@ -320,12 +321,12 @@ class ChannelService {
320
321
  this._shouldMarkActiveChannelAsRead = true;
321
322
  this.isStateRecoveryInProgress = false;
322
323
  this.channelQueryStateSubject = new BehaviorSubject(undefined);
323
- this.channelListSetter = (channels) => {
324
+ this.channelListSetter = (channels, shouldStopWatchingRemovedChannels = true) => {
324
325
  const currentChannels = this.channelsSubject.getValue() || [];
325
326
  const newChannels = channels.filter((c) => !currentChannels.find((channel) => channel.cid === c.cid));
326
327
  const deletedChannels = currentChannels.filter((c) => !(channels === null || channels === void 0 ? void 0 : channels.find((channel) => channel.cid === c.cid)));
327
328
  void this.addChannelsFromNotification(newChannels);
328
- this.removeChannelsFromChannelList(deletedChannels.map((c) => c.cid));
329
+ this.removeChannelsFromChannelList(deletedChannels.map((c) => c.cid), shouldStopWatchingRemovedChannels);
329
330
  };
330
331
  this.messageListSetter = (messages) => {
331
332
  this.activeChannelMessagesSubject.next(messages);
@@ -568,6 +569,10 @@ class ChannelService {
568
569
  (_a = this.clientEventsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
569
570
  (_b = this.dismissErrorNotification) === null || _b === void 0 ? void 0 : _b.call(this);
570
571
  this.dismissErrorNotification = undefined;
572
+ Object.keys(this.channelSubscriptions).forEach((cid) => {
573
+ this.channelSubscriptions[cid]();
574
+ });
575
+ this.channelSubscriptions = {};
571
576
  }
572
577
  /**
573
578
  * 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.
@@ -966,7 +971,7 @@ class ChannelService {
966
971
  }
967
972
  handleRemovedFromChannelNotification(clientEvent) {
968
973
  const channelIdToBeRemoved = clientEvent.event.channel.cid;
969
- this.removeChannelsFromChannelList([channelIdToBeRemoved]);
974
+ this.removeChannelsFromChannelList([channelIdToBeRemoved], true);
970
975
  }
971
976
  handleNewMessageNotification(clientEvent) {
972
977
  if (clientEvent.event.channel) {
@@ -996,13 +1001,19 @@ class ChannelService {
996
1001
  }
997
1002
  });
998
1003
  }
999
- removeChannelsFromChannelList(cids) {
1004
+ removeChannelsFromChannelList(cids, shouldStopWatching) {
1000
1005
  var _a;
1001
1006
  const channels = this.channels.filter((c) => !cids.includes(c.cid || ''));
1002
- cids.forEach((cid) => {
1003
- var _a;
1004
- return void ((_a = this.chatClientService.chatClient.activeChannels[cid]) === null || _a === void 0 ? void 0 : _a.stopWatching());
1005
- });
1007
+ if (shouldStopWatching) {
1008
+ cids.forEach((cid) => {
1009
+ var _a;
1010
+ if (this.channelSubscriptions[cid]) {
1011
+ this.channelSubscriptions[cid]();
1012
+ delete this.channelSubscriptions.cid;
1013
+ }
1014
+ void ((_a = this.chatClientService.chatClient.activeChannels[cid]) === null || _a === void 0 ? void 0 : _a.stopWatching());
1015
+ });
1016
+ }
1006
1017
  if (channels.length < this.channels.length) {
1007
1018
  this.channelsSubject.next(channels);
1008
1019
  if (cids.includes(((_a = this.activeChannelSubject.getValue()) === null || _a === void 0 ? void 0 : _a.cid) || '')) {
@@ -1197,7 +1208,7 @@ class ChannelService {
1197
1208
  });
1198
1209
  }
1199
1210
  watchForChannelEvents(channel) {
1200
- channel.on((event) => {
1211
+ const unsubscribe = channel.on((event) => {
1201
1212
  switch (event.type) {
1202
1213
  case 'message.new': {
1203
1214
  this.ngZone.run(() => {
@@ -1267,6 +1278,7 @@ class ChannelService {
1267
1278
  }
1268
1279
  }
1269
1280
  });
1281
+ this.channelSubscriptions[channel.cid] = unsubscribe.unsubscribe;
1270
1282
  }
1271
1283
  handleNewMessage(_, channel) {
1272
1284
  const channelIndex = this.channels.findIndex((c) => c.cid === channel.cid);
@@ -1274,10 +1286,10 @@ class ChannelService {
1274
1286
  this.channelsSubject.next([channel, ...this.channels]);
1275
1287
  }
1276
1288
  handleChannelHidden(event) {
1277
- this.removeChannelsFromChannelList([event.channel.cid]);
1289
+ this.removeChannelsFromChannelList([event.channel.cid], false);
1278
1290
  }
1279
1291
  handleChannelDeleted(event) {
1280
- this.removeChannelsFromChannelList([event.channel.cid]);
1292
+ this.removeChannelsFromChannelList([event.channel.cid], true);
1281
1293
  }
1282
1294
  handleChannelVisible(event, channel) {
1283
1295
  if (!this.channels.find((c) => c.cid === event.cid)) {