stream-chat-angular 4.31.1 → 4.32.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.
@@ -1 +1 @@
1
- export declare const version = "4.31.1";
1
+ export declare const version = "4.32.0";
@@ -356,7 +356,7 @@
356
356
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
357
357
  }
358
358
 
359
- var version = '4.31.1';
359
+ var version = '4.32.0';
360
360
 
361
361
  /**
362
362
  * The `NotificationService` can be used to add or remove notifications. By default the [`NotificationList`](../components/NotificationListComponent.mdx) component displays the currently active notifications.
@@ -462,8 +462,12 @@
462
462
  /**
463
463
  * Creates a [`StreamChat`](https://github.com/GetStream/stream-chat-js/blob/668b3e5521339f4e14fc657834531b4c8bf8176b/src/client.ts#L124) instance using the provided `apiKey`, and connects a user with the given meta data and token. More info about [connecting users](https://getstream.io/chat/docs/javascript/init_and_users/?language=javascript) can be found in the platform documentation.
464
464
  * @param apiKey
465
- * @param userOrId
466
- * @param userTokenOrProvider You can provide a token, or the keyword 'guest' to connect as [guest user](https://getstream.io/chat/docs/javascript/authless_users/?language=javascript#guest-users)
465
+ * @param userOrId you can emit this for anonymous logins
466
+ * @param userTokenOrProvider You can provide:<ul>
467
+ * <li> a token, </li>
468
+ * <li> the keyword 'guest' to connect as [guest user](https://getstream.io/chat/docs/javascript/authless_users/?language=javascript#guest-users) </li>
469
+ * <li> the keyword 'anonymous' to connect as [anonymous user](https://getstream.io/chat/docs/javascript/authless_users/?language=javascript#anonymous-users) </li>
470
+ * </ul>
467
471
  * @param clientOptions Setting to provide to the Stream client instance
468
472
  */
469
473
  ChatClientService.prototype.init = function (apiKey, userOrId, userTokenOrProvider, clientOptions) {
@@ -477,31 +481,28 @@
477
481
  this.chatClient = streamChat.StreamChat.getInstance(apiKey, clientOptions);
478
482
  this.chatClient.devToken;
479
483
  return [4 /*yield*/, this.ngZone.runOutsideAngular(function () { return __awaiter(_this, void 0, void 0, function () {
480
- var user, _d, error_1, sdkPrefix;
481
- return __generator(this, function (_e) {
482
- switch (_e.label) {
484
+ var _b, user, error_1, sdkPrefix;
485
+ var _this = this;
486
+ return __generator(this, function (_d) {
487
+ switch (_d.label) {
483
488
  case 0:
484
489
  user = typeof userOrId === 'string' ? { id: userOrId } : userOrId;
485
- _e.label = 1;
490
+ _d.label = 1;
486
491
  case 1:
487
- _e.trys.push([1, 6, , 7]);
488
- if (!(userTokenOrProvider === 'guest')) return [3 /*break*/, 3];
489
- return [4 /*yield*/, this.chatClient.setGuestUser(user)];
492
+ _d.trys.push([1, 3, , 4]);
493
+ return [4 /*yield*/, ((_b = {
494
+ guest: function () { return _this.chatClient.setGuestUser(user); },
495
+ anonymous: function () { return _this.chatClient.connectAnonymousUser(); },
496
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
497
+ }["" + userTokenOrProvider]) !== null && _b !== void 0 ? _b : (function () { return _this.chatClient.connectUser(user, userTokenOrProvider); }))()];
490
498
  case 2:
491
- _d = _e.sent();
492
- return [3 /*break*/, 5];
493
- case 3: return [4 /*yield*/, this.chatClient.connectUser(user, userTokenOrProvider)];
494
- case 4:
495
- _d = _e.sent();
496
- _e.label = 5;
497
- case 5:
498
- result = _d;
499
- return [3 /*break*/, 7];
500
- case 6:
501
- error_1 = _e.sent();
499
+ result = _d.sent();
500
+ return [3 /*break*/, 4];
501
+ case 3:
502
+ error_1 = _d.sent();
502
503
  this.notificationService.addPermanentNotification('streamChat.Error connecting to chat, refresh the page to try again.', 'error');
503
504
  throw error_1;
504
- case 7:
505
+ case 4:
505
506
  this.userSubject.next(this.chatClient.user);
506
507
  sdkPrefix = 'stream-chat-angular';
507
508
  if (!this.chatClient.getUserAgent().includes(sdkPrefix)) {
@@ -718,6 +719,7 @@
718
719
  this.usersTypingInThreadSubject = new rxjs.BehaviorSubject([]);
719
720
  this._shouldMarkActiveChannelAsRead = true;
720
721
  this.isStateRecoveryInProgress = false;
722
+ this.channelQueryStateSubject = new rxjs.BehaviorSubject(undefined);
721
723
  this.channelListSetter = function (channels) {
722
724
  var currentChannels = _this.channelsSubject.getValue() || [];
723
725
  var newChannels = channels.filter(function (c) { return !currentChannels.find(function (channel) { return channel.cid === c.cid; }); });
@@ -775,6 +777,7 @@
775
777
  this.latestMessageDateByUserByChannelsSubject.asObservable();
776
778
  this.activeChannelPinnedMessages$ =
777
779
  this.activeChannelPinnedMessagesSubject.asObservable();
780
+ this.channelQueryState$ = this.channelQueryStateSubject.asObservable();
778
781
  }
779
782
  Object.defineProperty(ChannelService.prototype, "shouldMarkActiveChannelAsRead", {
780
783
  /**
@@ -986,27 +989,21 @@
986
989
  switch (_h.label) {
987
990
  case 0:
988
991
  this.filters = filters;
989
- this.options = options || {
990
- offset: 0,
991
- limit: 25,
992
- state: true,
993
- presence: true,
994
- watch: true,
995
- message_limit: this.messagePageSize,
996
- };
992
+ this.options = Object.assign({ offset: 0, limit: 25, state: true, presence: true, watch: true, message_limit: this.messagePageSize }, options);
997
993
  this.sort = sort || { last_message_at: -1, updated_at: -1 };
998
994
  this.shouldSetActiveChannel = shouldSetActiveChannel;
995
+ this.clientEventsSubscription = this.chatClientService.events$.subscribe(function (notification) { return void _this.handleNotification(notification); });
999
996
  _h.label = 1;
1000
997
  case 1:
1001
998
  _h.trys.push([1, 3, , 4]);
1002
999
  return [4 /*yield*/, this.queryChannels(this.shouldSetActiveChannel)];
1003
1000
  case 2:
1004
1001
  result = _h.sent();
1005
- this.clientEventsSubscription = this.chatClientService.events$.subscribe(function (notification) { return void _this.handleNotification(notification); });
1006
1002
  return [2 /*return*/, result];
1007
1003
  case 3:
1008
1004
  error_1 = _h.sent();
1009
- this.notificationService.addPermanentNotification('streamChat.Error loading channels', 'error');
1005
+ this.dismissErrorNotification =
1006
+ this.notificationService.addPermanentNotification('streamChat.Error loading channels', 'error');
1010
1007
  throw error_1;
1011
1008
  case 4: return [2 /*return*/];
1012
1009
  }
@@ -1017,10 +1014,13 @@
1017
1014
  * Resets the `activeChannel$`, `channels$` and `activeChannelMessages$` Observables. Useful when disconnecting a chat user, use in combination with [`disconnectUser`](./ChatClientService.mdx/#disconnectuser).
1018
1015
  */
1019
1016
  ChannelService.prototype.reset = function () {
1020
- var _a;
1017
+ var _a, _b;
1021
1018
  this.deselectActiveChannel();
1022
1019
  this.channelsSubject.next(undefined);
1020
+ this.channelQueryStateSubject.next(undefined);
1023
1021
  (_a = this.clientEventsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1022
+ (_b = this.dismissErrorNotification) === null || _b === void 0 ? void 0 : _b.call(this);
1023
+ this.dismissErrorNotification = undefined;
1024
1024
  };
1025
1025
  /**
1026
1026
  * 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.
@@ -1462,7 +1462,7 @@
1462
1462
  switch (clientEvent.eventType) {
1463
1463
  case 'connection.recovered': {
1464
1464
  void this.ngZone.run(function () { return __awaiter(_this, void 0, void 0, function () {
1465
- var _a_1;
1465
+ var shoulSetActiveChannel, _a_1;
1466
1466
  return __generator(this, function (_h) {
1467
1467
  switch (_h.label) {
1468
1468
  case 0:
@@ -1476,7 +1476,9 @@
1476
1476
  if (this.options) {
1477
1477
  this.options.offset = 0;
1478
1478
  }
1479
- return [4 /*yield*/, this.queryChannels(false, true)];
1479
+ shoulSetActiveChannel = this.shouldSetActiveChannel &&
1480
+ !this.activeChannelSubject.getValue();
1481
+ return [4 /*yield*/, this.queryChannels(shoulSetActiveChannel || false, true)];
1480
1482
  case 2:
1481
1483
  _h.sent();
1482
1484
  // Thread messages are not refetched so active thread gets deselected to avoid displaying stale messages
@@ -1737,6 +1739,7 @@
1737
1739
  };
1738
1740
  ChannelService.prototype.queryChannels = function (shouldSetActiveChannel, recoverState) {
1739
1741
  if (recoverState === void 0) { recoverState = false; }
1742
+ var _a, _b;
1740
1743
  return __awaiter(this, void 0, void 0, function () {
1741
1744
  var channels, prevChannels, currentActiveChannel_1, error_6;
1742
1745
  var _this = this;
@@ -1744,6 +1747,7 @@
1744
1747
  switch (_h.label) {
1745
1748
  case 0:
1746
1749
  _h.trys.push([0, 2, , 3]);
1750
+ this.channelQueryStateSubject.next({ state: 'in-progress' });
1747
1751
  return [4 /*yield*/, this.chatClientService.chatClient.queryChannels(this.filters, this.sort || {}, this.options)];
1748
1752
  case 1:
1749
1753
  channels = _h.sent();
@@ -1757,16 +1761,29 @@
1757
1761
  !currentActiveChannel_1 &&
1758
1762
  shouldSetActiveChannel) {
1759
1763
  this.setAsActiveChannel(channels[0]);
1764
+ currentActiveChannel_1 = this.activeChannelSubject.getValue();
1760
1765
  }
1761
1766
  if (recoverState &&
1762
1767
  !channels.find(function (c) { return c.cid === (currentActiveChannel_1 === null || currentActiveChannel_1 === void 0 ? void 0 : currentActiveChannel_1.cid); })) {
1763
1768
  this.deselectActiveChannel();
1764
1769
  }
1765
1770
  this.hasMoreChannelsSubject.next(channels.length >= this.options.limit);
1771
+ this.channelQueryStateSubject.next({ state: 'success' });
1772
+ if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.keepAliveChannels$OnError) &&
1773
+ this.dismissErrorNotification) {
1774
+ this.dismissErrorNotification();
1775
+ }
1766
1776
  return [2 /*return*/, channels];
1767
1777
  case 2:
1768
1778
  error_6 = _h.sent();
1769
- this.channelsSubject.error(error_6);
1779
+ if (!((_b = this.options) === null || _b === void 0 ? void 0 : _b.keepAliveChannels$OnError)) {
1780
+ this.channelsSubject.error(error_6);
1781
+ }
1782
+ this.channelQueryStateSubject.next({
1783
+ state: 'error',
1784
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
1785
+ error: error_6,
1786
+ });
1770
1787
  throw error_6;
1771
1788
  case 3: return [2 /*return*/];
1772
1789
  }
@@ -4511,8 +4528,20 @@
4511
4528
  this.channelService = channelService;
4512
4529
  this.themeService = themeService;
4513
4530
  this.subscriptions = [];
4514
- this.isError$ = this.channelService.channels$.pipe(operators.map(function () { return false; }), operators.catchError(function () { return rxjs.of(true); }), operators.startWith(false));
4515
- this.isInitializing$ = this.channelService.channels$.pipe(operators.map(function (channels) { return !channels; }), operators.catchError(function () { return rxjs.of(false); }));
4531
+ this.isError$ = rxjs.combineLatest([
4532
+ this.channelService.channelQueryState$,
4533
+ this.channelService.activeChannel$,
4534
+ ]).pipe(operators.map(function (_a) {
4535
+ var _b = __read(_a, 2), state = _b[0], activeChannel = _b[1];
4536
+ return !activeChannel && (state === null || state === void 0 ? void 0 : state.state) === 'error';
4537
+ }));
4538
+ this.isInitializing$ = rxjs.combineLatest([
4539
+ this.channelService.channelQueryState$,
4540
+ this.channelService.activeChannel$,
4541
+ ]).pipe(operators.map(function (_a) {
4542
+ var _b = __read(_a, 2), state = _b[0], activeChannel = _b[1];
4543
+ return !activeChannel && (state === null || state === void 0 ? void 0 : state.state) === 'in-progress';
4544
+ }));
4516
4545
  this.isActiveThread$ = this.channelService.activeParentMessageId$.pipe(operators.map(function (id) { return !!id; }));
4517
4546
  this.theme$ = this.themeService.theme$;
4518
4547
  this.isActiveChannel$ = this.channelService.activeChannel$.pipe(operators.map(function (c) { return !!c; }));
@@ -4855,8 +4884,8 @@
4855
4884
  this.isOpen$ = this.channelListToggleService.isOpen$;
4856
4885
  this.channels$ = this.channelService.channels$;
4857
4886
  this.hasMoreChannels$ = this.channelService.hasMoreChannels$;
4858
- this.isError$ = this.channels$.pipe(operators.map(function () { return false; }), operators.catchError(function () { return rxjs.of(true); }), operators.startWith(false));
4859
- this.isInitializing$ = this.channels$.pipe(operators.map(function (channels) { return !channels; }), operators.catchError(function () { return rxjs.of(false); }));
4887
+ this.isError$ = this.channelService.channelQueryState$.pipe(operators.map(function (s) { return !_this.isLoadingMoreChannels && (s === null || s === void 0 ? void 0 : s.state) === 'error'; }));
4888
+ this.isInitializing$ = this.channelService.channelQueryState$.pipe(operators.map(function (s) { return !_this.isLoadingMoreChannels && (s === null || s === void 0 ? void 0 : s.state) === 'in-progress'; }));
4860
4889
  this.subscriptions.push(this.customTemplatesService.channelPreviewTemplate$.subscribe(function (template) { return (_this.customChannelPreviewTemplate = template); }));
4861
4890
  }
4862
4891
  ChannelListComponent.prototype.ngAfterViewInit = function () {