stream-chat-angular 3.1.0 → 3.2.2

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.2";
@@ -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.2';
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
@@ -3217,6 +3217,10 @@
3217
3217
  configurable: true
3218
3218
  });
3219
3219
  MessageInputComponent.prototype.initTextarea = function () {
3220
+ // cleanup previously built textarea
3221
+ if (!this.canSendMessages) {
3222
+ this.textareaRef = undefined;
3223
+ }
3220
3224
  if (!this.canSendMessages || this.textareaRef || !this.textareaAnchor) {
3221
3225
  return;
3222
3226
  }
@@ -3641,6 +3645,32 @@
3641
3645
  }]
3642
3646
  }], ctorParameters: function () { return [{ type: ChannelService }]; } });
3643
3647
 
3648
+ var listUsers = function (users) {
3649
+ var outStr = '';
3650
+ var slicedArr = users.map(function (item) { return item.name || item.id; }).slice(0, 5);
3651
+ var restLength = users.length - slicedArr.length;
3652
+ var commaSeparatedUsers = slicedArr.join(', ');
3653
+ outStr = commaSeparatedUsers;
3654
+ if (restLength > 0) {
3655
+ outStr += " +" + restLength;
3656
+ }
3657
+ return outStr;
3658
+ };
3659
+
3660
+ var getChannelDisplayText = function (channel, currentUser) {
3661
+ var _a;
3662
+ if ((_a = channel.data) === null || _a === void 0 ? void 0 : _a.name) {
3663
+ return channel.data.name;
3664
+ }
3665
+ if (channel.state.members && Object.keys(channel.state.members).length > 0) {
3666
+ var members = Object.values(channel.state.members)
3667
+ .map(function (m) { return m.user || { id: m.user_id }; })
3668
+ .filter(function (m) { return m.id !== currentUser.id; });
3669
+ return listUsers(members);
3670
+ }
3671
+ return channel.id;
3672
+ };
3673
+
3644
3674
  var getDeviceWidth = function () {
3645
3675
  var width = window.innerWidth;
3646
3676
  if (width < 768)
@@ -3728,12 +3758,13 @@
3728
3758
  * 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
3759
  */
3730
3760
  var ChannelHeaderComponent = /** @class */ (function () {
3731
- function ChannelHeaderComponent(channelService, channelListToggleService, customTemplatesService, cdRef) {
3761
+ function ChannelHeaderComponent(channelService, channelListToggleService, customTemplatesService, cdRef, chatClientService) {
3732
3762
  var _this = this;
3733
3763
  this.channelService = channelService;
3734
3764
  this.channelListToggleService = channelListToggleService;
3735
3765
  this.customTemplatesService = customTemplatesService;
3736
3766
  this.cdRef = cdRef;
3767
+ this.chatClientService = chatClientService;
3737
3768
  this.subscriptions = [];
3738
3769
  this.channelService.activeChannel$.subscribe(function (c) {
3739
3770
  var _a, _b;
@@ -3779,10 +3810,36 @@
3779
3810
  enumerable: false,
3780
3811
  configurable: true
3781
3812
  });
3813
+ Object.defineProperty(ChannelHeaderComponent.prototype, "displayText", {
3814
+ get: function () {
3815
+ if (!this.activeChannel) {
3816
+ return '';
3817
+ }
3818
+ return getChannelDisplayText(this.activeChannel, this.chatClientService.chatClient.user);
3819
+ },
3820
+ enumerable: false,
3821
+ configurable: true
3822
+ });
3823
+ Object.defineProperty(ChannelHeaderComponent.prototype, "avatarName", {
3824
+ get: function () {
3825
+ var _this = this;
3826
+ var _a, _b, _c, _d, _e, _f, _g;
3827
+ if ((_b = (_a = this.activeChannel) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name) {
3828
+ return (_d = (_c = this.activeChannel) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.name;
3829
+ }
3830
+ 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; });
3831
+ if (otherMembers.length === 1) {
3832
+ 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);
3833
+ }
3834
+ return '#';
3835
+ },
3836
+ enumerable: false,
3837
+ configurable: true
3838
+ });
3782
3839
  return ChannelHeaderComponent;
3783
3840
  }());
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 } });
3841
+ 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 });
3842
+ 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
3843
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelHeaderComponent, decorators: [{
3787
3844
  type: i0.Component,
3788
3845
  args: [{
@@ -3790,18 +3847,19 @@
3790
3847
  templateUrl: './channel-header.component.html',
3791
3848
  styles: [],
3792
3849
  }]
3793
- }], ctorParameters: function () { return [{ type: ChannelService }, { type: ChannelListToggleService }, { type: CustomTemplatesService }, { type: i0__namespace.ChangeDetectorRef }]; } });
3850
+ }], ctorParameters: function () { return [{ type: ChannelService }, { type: ChannelListToggleService }, { type: CustomTemplatesService }, { type: i0__namespace.ChangeDetectorRef }, { type: ChatClientService }]; } });
3794
3851
 
3795
3852
  /**
3796
3853
  * The `ChannelPreview` component displays a channel preview in the channel list, it consists of the image, name and latest message of the channel.
3797
3854
  */
3798
3855
  var ChannelPreviewComponent = /** @class */ (function () {
3799
- function ChannelPreviewComponent(channelService, ngZone) {
3856
+ function ChannelPreviewComponent(channelService, ngZone, chatClientService) {
3800
3857
  this.channelService = channelService;
3801
3858
  this.ngZone = ngZone;
3859
+ this.chatClientService = chatClientService;
3802
3860
  this.isActive = false;
3803
3861
  this.isUnread = false;
3804
- this.latestMessage = 'Nothing yet...';
3862
+ this.latestMessage = 'streamChat.Nothing yet...';
3805
3863
  this.subscriptions = [];
3806
3864
  this.canSendReadEvents = true;
3807
3865
  }
@@ -3838,16 +3896,26 @@
3838
3896
  });
3839
3897
  Object.defineProperty(ChannelPreviewComponent.prototype, "avatarName", {
3840
3898
  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;
3899
+ var _this = this;
3900
+ var _a, _b, _c, _d, _e, _f, _g;
3901
+ if ((_b = (_a = this.channel) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.name) {
3902
+ return (_d = (_c = this.channel) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.name;
3903
+ }
3904
+ 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; });
3905
+ if (otherMembers.length === 1) {
3906
+ 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);
3907
+ }
3908
+ return '#';
3843
3909
  },
3844
3910
  enumerable: false,
3845
3911
  configurable: true
3846
3912
  });
3847
3913
  Object.defineProperty(ChannelPreviewComponent.prototype, "title", {
3848
3914
  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;
3915
+ if (!this.channel) {
3916
+ return '';
3917
+ }
3918
+ return getChannelDisplayText(this.channel, this.chatClientService.chatClient.user);
3851
3919
  },
3852
3920
  enumerable: false,
3853
3921
  configurable: true
@@ -3860,7 +3928,7 @@
3860
3928
  this.ngZone.run(function () {
3861
3929
  var _a, _b, _c;
3862
3930
  if (((_a = _this.channel) === null || _a === void 0 ? void 0 : _a.state.messages.length) === 0) {
3863
- _this.latestMessage = 'Nothing yet...';
3931
+ _this.latestMessage = 'streamChat.Nothing yet...';
3864
3932
  return;
3865
3933
  }
3866
3934
  if (!event.message ||
@@ -3884,8 +3952,8 @@
3884
3952
  };
3885
3953
  return ChannelPreviewComponent;
3886
3954
  }());
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 } });
3955
+ 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 });
3956
+ 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
3957
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.5", ngImport: i0__namespace, type: ChannelPreviewComponent, decorators: [{
3890
3958
  type: i0.Component,
3891
3959
  args: [{
@@ -3893,7 +3961,7 @@
3893
3961
  templateUrl: './channel-preview.component.html',
3894
3962
  styles: [],
3895
3963
  }]
3896
- }], ctorParameters: function () { return [{ type: ChannelService }, { type: i0__namespace.NgZone }]; }, propDecorators: { channel: [{
3964
+ }], ctorParameters: function () { return [{ type: ChannelService }, { type: i0__namespace.NgZone }, { type: ChatClientService }]; }, propDecorators: { channel: [{
3897
3965
  type: i0.Input
3898
3966
  }] } });
3899
3967
 
@@ -3969,35 +4037,6 @@
3969
4037
  return parsedTime.calendar();
3970
4038
  };
3971
4039
 
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
4040
  var emojiReactionsMapping = {
4002
4041
  like: '👍',
4003
4042
  angry: '😠',
@@ -4217,7 +4256,7 @@
4217
4256
  });
4218
4257
  Object.defineProperty(MessageComponent.prototype, "readByText", {
4219
4258
  get: function () {
4220
- return getReadByText(this.message.readBy);
4259
+ return listUsers(this.message.readBy);
4221
4260
  },
4222
4261
  enumerable: false,
4223
4262
  configurable: true
@@ -5362,9 +5401,9 @@
5362
5401
  exports.getDeviceWidth = getDeviceWidth;
5363
5402
  exports.getGroupStyles = getGroupStyles;
5364
5403
  exports.getReadBy = getReadBy;
5365
- exports.getReadByText = getReadByText;
5366
5404
  exports.isImageAttachment = isImageAttachment;
5367
5405
  exports.isImageFile = isImageFile;
5406
+ exports.listUsers = listUsers;
5368
5407
  exports.parseDate = parseDate;
5369
5408
  exports.textareaInjectionToken = textareaInjectionToken;
5370
5409