stream-chat-angular 2.20.2 → 2.21.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 i6$1 from 'angular-mentions';
18
18
  import { MentionModule } from 'angular-mentions';
19
19
 
20
- const version = '2.20.2';
20
+ const version = '2.21.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.
@@ -358,6 +358,21 @@ class ChannelService {
358
358
  this.activeThreadMessagesSubject.next([]);
359
359
  this.messageToQuoteSubject.next(undefined);
360
360
  }
361
+ /**
362
+ * Deselects the currently active (if any) channel
363
+ */
364
+ deselectActiveChannel() {
365
+ const activeChannel = this.activeChannelSubject.getValue();
366
+ if (!activeChannel) {
367
+ return;
368
+ }
369
+ this.activeChannelMessagesSubject.next([]);
370
+ this.activeChannelSubject.next(undefined);
371
+ this.activeParentMessageIdSubject.next(undefined);
372
+ this.activeThreadMessagesSubject.next([]);
373
+ this.latestMessageDateByUserByChannelsSubject.next({});
374
+ this.selectMessageToQuote(undefined);
375
+ }
361
376
  /**
362
377
  * Sets the given `message` as an active parent message. If `undefined` is provided, it will deleselect the current parent message.
363
378
  * @param message
@@ -428,8 +443,10 @@ class ChannelService {
428
443
  * @param filters
429
444
  * @param sort
430
445
  * @param options
446
+ * @param shouldSetActiveChannel Decides if the first channel in the result should be made as an active channel, or no channel should be marked as active
447
+ * @returns the list of channels found by the query
431
448
  */
432
- init(filters, sort, options) {
449
+ init(filters, sort, options, shouldSetActiveChannel = true) {
433
450
  return __awaiter(this, void 0, void 0, function* () {
434
451
  this.filters = filters;
435
452
  this.options = options || {
@@ -441,21 +458,17 @@ class ChannelService {
441
458
  message_limit: this.messagePageSize,
442
459
  };
443
460
  this.sort = sort || { last_message_at: -1, updated_at: -1 };
444
- yield this.queryChannels();
461
+ const result = yield this.queryChannels(shouldSetActiveChannel);
445
462
  this.chatClientService.notification$.subscribe((notification) => void this.handleNotification(notification));
463
+ return result;
446
464
  });
447
465
  }
448
466
  /**
449
467
  * Resets the `activeChannel$`, `channels$` and `activeChannelMessages$` Observables. Useful when disconnecting a chat user, use in combination with [`disconnectUser`](./ChatClientService.mdx/#disconnectuser).
450
468
  */
451
469
  reset() {
452
- this.activeChannelMessagesSubject.next([]);
453
- this.activeChannelSubject.next(undefined);
454
- this.activeParentMessageIdSubject.next(undefined);
455
- this.activeThreadMessagesSubject.next([]);
470
+ this.deselectActiveChannel();
456
471
  this.channelsSubject.next(undefined);
457
- this.latestMessageDateByUserByChannelsSubject.next({});
458
- this.selectMessageToQuote(undefined);
459
472
  }
460
473
  /**
461
474
  * 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.
@@ -463,7 +476,7 @@ class ChannelService {
463
476
  loadMoreChannels() {
464
477
  return __awaiter(this, void 0, void 0, function* () {
465
478
  this.options.offset = this.channels.length;
466
- yield this.queryChannels();
479
+ yield this.queryChannels(false);
467
480
  });
468
481
  }
469
482
  /**
@@ -884,20 +897,24 @@ class ChannelService {
884
897
  this.activeChannelSubscriptions.forEach((s) => s.unsubscribe());
885
898
  this.activeChannelSubscriptions = [];
886
899
  }
887
- queryChannels() {
900
+ queryChannels(shouldSetActiveChannel) {
888
901
  return __awaiter(this, void 0, void 0, function* () {
889
902
  try {
890
903
  const channels = yield this.chatClientService.chatClient.queryChannels(this.filters, this.sort, this.options);
891
904
  channels.forEach((c) => this.watchForChannelEvents(c));
892
905
  const prevChannels = this.channelsSubject.getValue() || [];
893
906
  this.channelsSubject.next([...prevChannels, ...channels]);
894
- if (channels.length > 0 && !this.activeChannelSubject.getValue()) {
907
+ if (channels.length > 0 &&
908
+ !this.activeChannelSubject.getValue() &&
909
+ shouldSetActiveChannel) {
895
910
  this.setAsActiveChannel(channels[0]);
896
911
  }
897
912
  this.hasMoreChannelsSubject.next(channels.length >= this.options.limit);
913
+ return channels;
898
914
  }
899
915
  catch (error) {
900
916
  this.channelsSubject.error(error);
917
+ throw error;
901
918
  }
902
919
  });
903
920
  }