stream-chat-angular 3.1.0 → 3.2.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 = "3.1.0";
1
+ export declare const version = "3.2.0";
@@ -354,7 +354,7 @@
354
354
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
355
355
  }
356
356
 
357
- var version = '3.1.0';
357
+ var version = '3.2.0';
358
358
 
359
359
  /**
360
360
  * The `NotificationService` can be used to add or remove notifications. By default the [`NotificationList`](../components/NotificationListComponent.mdx) component displays the currently active notifications.
@@ -728,7 +728,7 @@
728
728
  this.latestMessageDateByUserByChannelsSubject.asObservable();
729
729
  }
730
730
  /**
731
- * Sets the given `channel` as active.
731
+ * Sets the given `channel` as active and marks it as read.
732
732
  * @param channel
733
733
  */
734
734
  ChannelService.prototype.setAsActiveChannel = function (channel) {
@@ -853,7 +853,7 @@
853
853
  });
854
854
  };
855
855
  /**
856
- * Queries the channels with the given filters, sorts and options. More info about [channel querying](https://getstream.io/chat/docs/javascript/query_channels/?language=javascript) can be found in the platform documentation.
856
+ * Queries the channels with the given filters, sorts and options. More info about [channel querying](https://getstream.io/chat/docs/javascript/query_channels/?language=javascript) can be found in the platform documentation. By default the first channel in the list will be set as active channel and will be marked as read.
857
857
  * @param filters
858
858
  * @param sort
859
859
  * @param options
@@ -3641,6 +3641,32 @@
3641
3641
  }]
3642
3642
  }], ctorParameters: function () { return [{ type: ChannelService }]; } });
3643
3643
 
3644
+ var listUsers = function (users) {
3645
+ var outStr = '';
3646
+ var slicedArr = users.map(function (item) { return item.name || item.id; }).slice(0, 5);
3647
+ var restLength = users.length - slicedArr.length;
3648
+ var commaSeparatedUsers = slicedArr.join(', ');
3649
+ outStr = commaSeparatedUsers;
3650
+ if (restLength > 0) {
3651
+ outStr += " +" + restLength;
3652
+ }
3653
+ return outStr;
3654
+ };
3655
+
3656
+ var getChannelDisplayText = function (channel, currentUser) {
3657
+ var _a;
3658
+ if ((_a = channel.data) === null || _a === void 0 ? void 0 : _a.name) {
3659
+ return channel.data.name;
3660
+ }
3661
+ if (channel.state.members && Object.keys(channel.state.members).length > 0) {
3662
+ var members = Object.values(channel.state.members)
3663
+ .map(function (m) { return m.user || { id: m.user_id }; })
3664
+ .filter(function (m) { return m.id !== currentUser.id; });
3665
+ return listUsers(members);
3666
+ }
3667
+ return channel.id;
3668
+ };
3669
+
3644
3670
  var getDeviceWidth = function () {
3645
3671
  var width = window.innerWidth;
3646
3672
  if (width < 768)
@@ -3728,12 +3754,13 @@
3728
3754
  * The `ChannelHeader` component displays the avatar and name of the currently active channel along with member and watcher information. You can read about [the difference between members and watchers](https://getstream.io/chat/docs/javascript/watch_channel/?language=javascript#watchers-vs-members) in the platform documentation. Please note that number of watchers is only displayed if the user has [`connect-events` capability](https://getstream.io/chat/docs/javascript/channel_capabilities/?language=javascript)
3729
3755
  */
3730
3756
  var ChannelHeaderComponent = /** @class */ (function () {
3731
- function ChannelHeaderComponent(channelService, channelListToggleService, customTemplatesService, cdRef) {
3757
+ function ChannelHeaderComponent(channelService, channelListToggleService, customTemplatesService, cdRef, chatClientService) {
3732
3758
  var _this = this;
3733
3759
  this.channelService = channelService;
3734
3760
  this.channelListToggleService = channelListToggleService;
3735
3761
  this.customTemplatesService = customTemplatesService;
3736
3762
  this.cdRef = cdRef;
3763
+ this.chatClientService = chatClientService;
3737
3764
  this.subscriptions = [];
3738
3765
  this.channelService.activeChannel$.subscribe(function (c) {
3739
3766
  var _a, _b;
@@ -3779,10 +3806,36 @@
3779
3806
  enumerable: false,
3780
3807
  configurable: true
3781
3808
  });
3809
+ Object.defineProperty(ChannelHeaderComponent.prototype, "displayText", {
3810
+ get: function () {
3811
+ if (!this.activeChannel) {
3812
+ return '';
3813
+ }
3814
+ return getChannelDisplayText(this.activeChannel, this.chatClientService.chatClient.user);
3815
+ },
3816
+ enumerable: false,
3817
+ configurable: true
3818
+ });
3819
+ Object.defineProperty(ChannelHeaderComponent.prototype, "avatarName", {
3820
+ get: function () {
3821
+ var _this = this;
3822
+ var _a, _b, _c, _d, _e, _f, _g;
3823
+ if ((_b = (_a = this.activeChannel) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name) {
3824
+ return (_d = (_c = this.activeChannel) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.name;
3825
+ }
3826
+ var otherMembers = Object.values(((_e = this.activeChannel) === null || _e === void 0 ? void 0 : _e.state.members) || {}).filter(function (m) { return m.user_id !== _this.chatClientService.chatClient.user.id; });
3827
+ if (otherMembers.length === 1) {
3828
+ return ((_f = otherMembers[0].user) === null || _f === void 0 ? void 0 : _f.name) || ((_g = otherMembers[0].user) === null || _g === void 0 ? void 0 : _g.name);
3829
+ }
3830
+ return '#';
3831
+ },
3832
+ enumerable: false,
3833
+ configurable: true
3834
+ });
3782
3835
  return ChannelHeaderComponent;
3783
3836
  }());
3784
- ChannelHeaderComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelHeaderComponent, deps: [{ token: ChannelService }, { token: ChannelListToggleService }, { token: CustomTemplatesService }, { token: i0__namespace.ChangeDetectorRef }], target: i0__namespace.ɵɵFactoryTarget.Component });
3785
- ChannelHeaderComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.5", type: ChannelHeaderComponent, selector: "stream-channel-header", ngImport: i0__namespace, template: "<div class=\"str-chat__header-livestream\">\n <div\n class=\"str-chat__header-hamburger\"\n (click)=\"toggleMenu($event)\"\n (keyup.enter)=\"toggleMenu($event)\"\n >\n <stream-icon-placeholder icon=\"menu\"></stream-icon-placeholder>\n </div>\n <stream-avatar-placeholder\n imageUrl=\"{{ activeChannel?.data?.image }}\"\n name=\"{{ activeChannel?.data?.name }}\"\n ></stream-avatar-placeholder>\n <div class=\"str-chat__header-livestream-left\">\n <p data-testid=\"name\" class=\"str-chat__header-livestream-left--title\">\n {{ activeChannel?.data?.name }}\n </p>\n <p data-testid=\"info\" class=\"str-chat__header-livestream-left--members\">\n {{'streamChat.{{ memberCount }} members' | translate:memberCountParam}}\n {{canReceiveConnectEvents ? ('streamChat.{{ watcherCount }} online' |\n translate:watcherCountParam) : ''}}\n </p>\n </div>\n <ng-container *ngIf=\"channelActionsTemplate\">\n <ng-container\n *ngTemplateOutlet=\"\n channelActionsTemplate;\n context: getChannelActionsContext()\n \"\n ></ng-container>\n </ng-container>\n</div>\n", components: [{ type: IconPlaceholderComponent, selector: "stream-icon-placeholder", inputs: ["icon", "size"] }, { type: AvatarPlaceholderComponent, selector: "stream-avatar-placeholder", inputs: ["name", "imageUrl", "size"] }], directives: [{ type: i3__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3__namespace.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], pipes: { "translate": i9__namespace.TranslatePipe } });
3837
+ ChannelHeaderComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelHeaderComponent, deps: [{ token: ChannelService }, { token: ChannelListToggleService }, { token: CustomTemplatesService }, { token: i0__namespace.ChangeDetectorRef }, { token: ChatClientService }], target: i0__namespace.ɵɵFactoryTarget.Component });
3838
+ ChannelHeaderComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.5", type: ChannelHeaderComponent, selector: "stream-channel-header", ngImport: i0__namespace, template: "<div class=\"str-chat__header-livestream\">\n <div\n class=\"str-chat__header-hamburger\"\n (click)=\"toggleMenu($event)\"\n (keyup.enter)=\"toggleMenu($event)\"\n >\n <stream-icon-placeholder icon=\"menu\"></stream-icon-placeholder>\n </div>\n <stream-avatar-placeholder\n imageUrl=\"{{ activeChannel?.data?.image }}\"\n name=\"{{ avatarName }}\"\n ></stream-avatar-placeholder>\n <div class=\"str-chat__header-livestream-left\">\n <p data-testid=\"name\" class=\"str-chat__header-livestream-left--title\">\n {{ displayText }}\n </p>\n <p data-testid=\"info\" class=\"str-chat__header-livestream-left--members\">\n {{'streamChat.{{ memberCount }} members' | translate:memberCountParam}}\n {{canReceiveConnectEvents ? ('streamChat.{{ watcherCount }} online' |\n translate:watcherCountParam) : ''}}\n </p>\n </div>\n <ng-container *ngIf=\"channelActionsTemplate\">\n <ng-container\n *ngTemplateOutlet=\"\n channelActionsTemplate;\n context: getChannelActionsContext()\n \"\n ></ng-container>\n </ng-container>\n</div>\n", components: [{ type: IconPlaceholderComponent, selector: "stream-icon-placeholder", inputs: ["icon", "size"] }, { type: AvatarPlaceholderComponent, selector: "stream-avatar-placeholder", inputs: ["name", "imageUrl", "size"] }], directives: [{ type: i3__namespace.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3__namespace.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], pipes: { "translate": i9__namespace.TranslatePipe } });
3786
3839
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelHeaderComponent, decorators: [{
3787
3840
  type: i0.Component,
3788
3841
  args: [{
@@ -3790,15 +3843,16 @@
3790
3843
  templateUrl: './channel-header.component.html',
3791
3844
  styles: [],
3792
3845
  }]
3793
- }], ctorParameters: function () { return [{ type: ChannelService }, { type: ChannelListToggleService }, { type: CustomTemplatesService }, { type: i0__namespace.ChangeDetectorRef }]; } });
3846
+ }], ctorParameters: function () { return [{ type: ChannelService }, { type: ChannelListToggleService }, { type: CustomTemplatesService }, { type: i0__namespace.ChangeDetectorRef }, { type: ChatClientService }]; } });
3794
3847
 
3795
3848
  /**
3796
3849
  * The `ChannelPreview` component displays a channel preview in the channel list, it consists of the image, name and latest message of the channel.
3797
3850
  */
3798
3851
  var ChannelPreviewComponent = /** @class */ (function () {
3799
- function ChannelPreviewComponent(channelService, ngZone) {
3852
+ function ChannelPreviewComponent(channelService, ngZone, chatClientService) {
3800
3853
  this.channelService = channelService;
3801
3854
  this.ngZone = ngZone;
3855
+ this.chatClientService = chatClientService;
3802
3856
  this.isActive = false;
3803
3857
  this.isUnread = false;
3804
3858
  this.latestMessage = 'Nothing yet...';
@@ -3838,16 +3892,26 @@
3838
3892
  });
3839
3893
  Object.defineProperty(ChannelPreviewComponent.prototype, "avatarName", {
3840
3894
  get: function () {
3841
- var _a, _b;
3842
- return (_b = (_a = this.channel) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name;
3895
+ var _this = this;
3896
+ var _a, _b, _c, _d, _e, _f, _g;
3897
+ if ((_b = (_a = this.channel) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name) {
3898
+ return (_d = (_c = this.channel) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.name;
3899
+ }
3900
+ var otherMembers = Object.values(((_e = this.channel) === null || _e === void 0 ? void 0 : _e.state.members) || {}).filter(function (m) { return m.user_id !== _this.chatClientService.chatClient.user.id; });
3901
+ if (otherMembers.length === 1) {
3902
+ return ((_f = otherMembers[0].user) === null || _f === void 0 ? void 0 : _f.name) || ((_g = otherMembers[0].user) === null || _g === void 0 ? void 0 : _g.name);
3903
+ }
3904
+ return '#';
3843
3905
  },
3844
3906
  enumerable: false,
3845
3907
  configurable: true
3846
3908
  });
3847
3909
  Object.defineProperty(ChannelPreviewComponent.prototype, "title", {
3848
3910
  get: function () {
3849
- var _a, _b;
3850
- return (_b = (_a = this.channel) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name;
3911
+ if (!this.channel) {
3912
+ return '';
3913
+ }
3914
+ return getChannelDisplayText(this.channel, this.chatClientService.chatClient.user);
3851
3915
  },
3852
3916
  enumerable: false,
3853
3917
  configurable: true
@@ -3884,8 +3948,8 @@
3884
3948
  };
3885
3949
  return ChannelPreviewComponent;
3886
3950
  }());
3887
- ChannelPreviewComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelPreviewComponent, deps: [{ token: ChannelService }, { token: i0__namespace.NgZone }], target: i0__namespace.ɵɵFactoryTarget.Component });
3888
- ChannelPreviewComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.5", type: ChannelPreviewComponent, selector: "stream-channel-preview", inputs: { channel: "channel" }, ngImport: i0__namespace, template: "<button\n class=\"str-chat__channel-preview-messenger\"\n [class.str-chat__channel-preview-messenger--active]=\"isActive\"\n [class.str-chat__channel-preview-messenger--unread]=\"isUnread\"\n (click)=\"setAsActiveChannel()\"\n data-testid=\"channel-preview-container\"\n>\n <div class=\"str-chat__channel-preview-messenger--left\">\n <stream-avatar-placeholder\n imageUrl=\"{{ avatarImage }}\"\n name=\"{{ avatarName }}\"\n [size]=\"40\"\n ></stream-avatar-placeholder>\n </div>\n <div class=\"str-chat__channel-preview-messenger--right\">\n <div class=\"str-chat__channel-preview-messenger--name\">\n <span data-testid=\"channel-preview-title\">{{ title }}</span>\n </div>\n <div\n data-testid=\"latest-message\"\n class=\"str-chat__channel-preview-messenger--last-message\"\n >\n {{ latestMessage | translate }}\n </div>\n </div>\n</button>\n", components: [{ type: AvatarPlaceholderComponent, selector: "stream-avatar-placeholder", inputs: ["name", "imageUrl", "size"] }], pipes: { "translate": i9__namespace.TranslatePipe } });
3951
+ ChannelPreviewComponent.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelPreviewComponent, deps: [{ token: ChannelService }, { token: i0__namespace.NgZone }, { token: ChatClientService }], target: i0__namespace.ɵɵFactoryTarget.Component });
3952
+ ChannelPreviewComponent.ɵcmp = i0__namespace.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "12.2.5", type: ChannelPreviewComponent, selector: "stream-channel-preview", inputs: { channel: "channel" }, ngImport: i0__namespace, template: "<button\n class=\"str-chat__channel-preview-messenger\"\n [class.str-chat__channel-preview-messenger--active]=\"isActive\"\n [class.str-chat__channel-preview-messenger--unread]=\"isUnread\"\n (click)=\"setAsActiveChannel()\"\n data-testid=\"channel-preview-container\"\n>\n <div class=\"str-chat__channel-preview-messenger--left\">\n <stream-avatar-placeholder\n imageUrl=\"{{ avatarImage }}\"\n name=\"{{ avatarName }}\"\n [size]=\"40\"\n ></stream-avatar-placeholder>\n </div>\n <div class=\"str-chat__channel-preview-messenger--right\">\n <div\n style=\"position: relative\"\n class=\"str-chat__channel-preview-messenger--name\"\n >\n <span data-testid=\"channel-preview-title\">{{ title }}</span>\n </div>\n <div\n data-testid=\"latest-message\"\n class=\"str-chat__channel-preview-messenger--last-message\"\n >\n {{ latestMessage | translate }}\n </div>\n </div>\n</button>\n", components: [{ type: AvatarPlaceholderComponent, selector: "stream-avatar-placeholder", inputs: ["name", "imageUrl", "size"] }], pipes: { "translate": i9__namespace.TranslatePipe } });
3889
3953
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelPreviewComponent, decorators: [{
3890
3954
  type: i0.Component,
3891
3955
  args: [{
@@ -3893,7 +3957,7 @@
3893
3957
  templateUrl: './channel-preview.component.html',
3894
3958
  styles: [],
3895
3959
  }]
3896
- }], ctorParameters: function () { return [{ type: ChannelService }, { type: i0__namespace.NgZone }]; }, propDecorators: { channel: [{
3960
+ }], ctorParameters: function () { return [{ type: ChannelService }, { type: i0__namespace.NgZone }, { type: ChatClientService }]; }, propDecorators: { channel: [{
3897
3961
  type: i0.Input
3898
3962
  }] } });
3899
3963
 
@@ -3969,35 +4033,6 @@
3969
4033
  return parsedTime.calendar();
3970
4034
  };
3971
4035
 
3972
- var getReadByText = function (users) {
3973
- var outStr = '';
3974
- var slicedArr = users.map(function (item) { return item.name || item.id; }).slice(0, 5);
3975
- var restLength = users.length - slicedArr.length;
3976
- if (slicedArr.length === 1) {
3977
- outStr = slicedArr[0] + " ";
3978
- }
3979
- else if (slicedArr.length === 2) {
3980
- // joins all with "and" but =no commas
3981
- // example: "bob and sam"
3982
- outStr = slicedArr[0] + " and " + slicedArr[1];
3983
- }
3984
- else if (slicedArr.length > 2) {
3985
- // joins all with commas, but last one gets ", and" (oxford comma!)
3986
- // example: "bob, joe, sam and 4 more"
3987
- if (restLength === 0) {
3988
- // mutate slicedArr to remove last user to display it separately
3989
- var lastUser = slicedArr.splice(slicedArr.length - 2, 1)[0];
3990
- var commaSeparatedUsers = slicedArr.join(', ');
3991
- outStr = commaSeparatedUsers + ", and " + lastUser;
3992
- }
3993
- else {
3994
- var commaSeparatedUsers = slicedArr.join(', ');
3995
- outStr = commaSeparatedUsers + " and " + restLength + " more";
3996
- }
3997
- }
3998
- return outStr;
3999
- };
4000
-
4001
4036
  var emojiReactionsMapping = {
4002
4037
  like: '👍',
4003
4038
  angry: '😠',
@@ -4217,7 +4252,7 @@
4217
4252
  });
4218
4253
  Object.defineProperty(MessageComponent.prototype, "readByText", {
4219
4254
  get: function () {
4220
- return getReadByText(this.message.readBy);
4255
+ return listUsers(this.message.readBy);
4221
4256
  },
4222
4257
  enumerable: false,
4223
4258
  configurable: true
@@ -5362,9 +5397,9 @@
5362
5397
  exports.getDeviceWidth = getDeviceWidth;
5363
5398
  exports.getGroupStyles = getGroupStyles;
5364
5399
  exports.getReadBy = getReadBy;
5365
- exports.getReadByText = getReadByText;
5366
5400
  exports.isImageAttachment = isImageAttachment;
5367
5401
  exports.isImageFile = isImageFile;
5402
+ exports.listUsers = listUsers;
5368
5403
  exports.parseDate = parseDate;
5369
5404
  exports.textareaInjectionToken = textareaInjectionToken;
5370
5405