stream-chat 6.7.3 → 6.8.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.
@@ -130,6 +130,8 @@ var ChannelState = /*#__PURE__*/function () {
130
130
 
131
131
  _defineProperty(this, "pinnedMessages", void 0);
132
132
 
133
+ _defineProperty(this, "pending_messages", void 0);
134
+
133
135
  _defineProperty(this, "threads", void 0);
134
136
 
135
137
  _defineProperty(this, "mutedUsers", void 0);
@@ -250,6 +252,7 @@ var ChannelState = /*#__PURE__*/function () {
250
252
  this.read = {};
251
253
  this.initMessages();
252
254
  this.pinnedMessages = [];
255
+ this.pending_messages = [];
253
256
  this.threads = {}; // a list of users to hide messages from
254
257
 
255
258
  this.mutedUsers = [];
@@ -905,6 +908,42 @@ var ChannelState = /*#__PURE__*/function () {
905
908
 
906
909
  return loadMessageIntoState;
907
910
  }()
911
+ /**
912
+ * findMessage - Finds a message inside the state
913
+ *
914
+ * @param {string} messageId The id of the message
915
+ * @param {string} parentMessageId The id of the parent message, if we want load a thread reply
916
+ *
917
+ * @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
918
+ */
919
+
920
+ }, {
921
+ key: "findMessage",
922
+ value: function findMessage(messageId, parentMessageId) {
923
+ if (parentMessageId) {
924
+ var messages = this.threads[parentMessageId];
925
+
926
+ if (!messages) {
927
+ return undefined;
928
+ }
929
+
930
+ return messages.find(function (m) {
931
+ return m.id === messageId;
932
+ });
933
+ }
934
+
935
+ var messageSetIndex = this.findMessageSetIndex({
936
+ id: messageId
937
+ });
938
+
939
+ if (messageSetIndex === -1) {
940
+ return undefined;
941
+ }
942
+
943
+ return this.messageSets[messageSetIndex].messages.find(function (m) {
944
+ return m.id === messageId;
945
+ });
946
+ }
908
947
  }, {
909
948
  key: "switchToMessageSet",
910
949
  value: function switchToMessageSet(index) {
@@ -1493,6 +1532,8 @@ var Channel = /*#__PURE__*/function () {
1493
1532
  * @param {Message<StreamChatGenerics>} message The Message object
1494
1533
  * @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
1495
1534
  * @param {boolean} [options.skip_push] Skip sending push notifications
1535
+ * @param {boolean} [options.is_pending_message] Make this message pending
1536
+ * @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
1496
1537
  *
1497
1538
  * @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
1498
1539
  */
@@ -3598,6 +3639,8 @@ var Channel = /*#__PURE__*/function () {
3598
3639
 
3599
3640
  case 'message.deleted':
3600
3641
  if (event.message) {
3642
+ this._extendEventWithOwnReactions(event);
3643
+
3601
3644
  if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
3602
3645
  channelState.removeQuotedMessageReferences(event.message);
3603
3646
 
@@ -3640,6 +3683,8 @@ var Channel = /*#__PURE__*/function () {
3640
3683
 
3641
3684
  case 'message.updated':
3642
3685
  if (event.message) {
3686
+ this._extendEventWithOwnReactions(event);
3687
+
3643
3688
  channelState.addMessageSorted(event.message, false, false);
3644
3689
 
3645
3690
  if (event.message.pinned) {
@@ -3801,6 +3846,11 @@ var Channel = /*#__PURE__*/function () {
3801
3846
  }
3802
3847
 
3803
3848
  this.state.addPinnedMessages(state.pinned_messages || []);
3849
+
3850
+ if (state.pending_messages) {
3851
+ this.state.pending_messages = state.pending_messages;
3852
+ }
3853
+
3804
3854
  this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
3805
3855
 
3806
3856
  if (state.watchers) {
@@ -3884,6 +3934,19 @@ var Channel = /*#__PURE__*/function () {
3884
3934
  }
3885
3935
  }
3886
3936
  }
3937
+ }, {
3938
+ key: "_extendEventWithOwnReactions",
3939
+ value: function _extendEventWithOwnReactions(event) {
3940
+ if (!event.message) {
3941
+ return;
3942
+ }
3943
+
3944
+ var message = this.state.findMessage(event.message.id, event.message.parent_id);
3945
+
3946
+ if (message) {
3947
+ event.message.own_reactions = message.own_reactions;
3948
+ }
3949
+ }
3887
3950
  }, {
3888
3951
  key: "_disconnect",
3889
3952
  value: function _disconnect() {
@@ -4459,6 +4522,11 @@ var StableWSConnection = /*#__PURE__*/function () {
4459
4522
  tags: ['connection']
4460
4523
  }, extra));
4461
4524
  }
4525
+ }, {
4526
+ key: "setClient",
4527
+ value: function setClient(client) {
4528
+ this.client = client;
4529
+ }
4462
4530
  /**
4463
4531
  * connect - Connect to the WS URL
4464
4532
  * the default 15s timeout allows between 2~3 tries
@@ -6121,7 +6189,7 @@ var StreamChat = /*#__PURE__*/function () {
6121
6189
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
6122
6190
 
6123
6191
  case 2:
6124
- if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
6192
+ if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
6125
6193
  _context3.next = 5;
6126
6194
  break;
6127
6195
  }
@@ -6130,7 +6198,7 @@ var StreamChat = /*#__PURE__*/function () {
6130
6198
  tags: ['connection', 'client']
6131
6199
  });
6132
6200
 
6133
- return _context3.abrupt("return", Promise.resolve());
6201
+ return _context3.abrupt("return", _this.wsPromise);
6134
6202
 
6135
6203
  case 5:
6136
6204
  if (!(((_this$wsConnection4 = _this.wsConnection) !== null && _this$wsConnection4 !== void 0 && _this$wsConnection4.isHealthy || (_this$wsFallback3 = _this.wsFallback) !== null && _this$wsFallback3 !== void 0 && _this$wsFallback3.isHealthy()) && _this._hasConnectionID())) {
@@ -7590,9 +7658,16 @@ var StreamChat = /*#__PURE__*/function () {
7590
7658
  } // The StableWSConnection handles all the reconnection logic.
7591
7659
 
7592
7660
 
7593
- this.wsConnection = new StableWSConnection({
7594
- client: this
7595
- });
7661
+ if (this.options.wsConnection && this.node) {
7662
+ // Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
7663
+ this.options.wsConnection.setClient(this);
7664
+ this.wsConnection = this.options.wsConnection;
7665
+ } else {
7666
+ this.wsConnection = new StableWSConnection({
7667
+ client: this
7668
+ });
7669
+ }
7670
+
7596
7671
  _context15.prev = 8;
7597
7672
 
7598
7673
  if (!this.wsFallback) {
@@ -7718,7 +7793,7 @@ var StreamChat = /*#__PURE__*/function () {
7718
7793
  }; // Make sure we wait for the connect promise if there is a pending one
7719
7794
 
7720
7795
  _context16.next = 5;
7721
- return this.setUserPromise;
7796
+ return this.wsPromise;
7722
7797
 
7723
7798
  case 5:
7724
7799
  if (!this._hasConnectionID()) {
@@ -7898,7 +7973,7 @@ var StreamChat = /*#__PURE__*/function () {
7898
7973
  }; // Make sure we wait for the connect promise if there is a pending one
7899
7974
 
7900
7975
  _context19.next = 7;
7901
- return this.setUserPromise;
7976
+ return this.wsPromise;
7902
7977
 
7903
7978
  case 7:
7904
7979
  if (!this._hasConnectionID()) {
@@ -8033,7 +8108,7 @@ var StreamChat = /*#__PURE__*/function () {
8033
8108
 
8034
8109
  case 13:
8035
8110
  _context20.next = 15;
8036
- return this.setUserPromise;
8111
+ return this.wsPromise;
8037
8112
 
8038
8113
  case 15:
8039
8114
  _context20.next = 17;
@@ -9722,7 +9797,7 @@ var StreamChat = /*#__PURE__*/function () {
9722
9797
  }, {
9723
9798
  key: "getUserAgent",
9724
9799
  value: function getUserAgent() {
9725
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.7.3");
9800
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.8.0");
9726
9801
  }
9727
9802
  }, {
9728
9803
  key: "setUserAgent",
@@ -9895,15 +9970,19 @@ var StreamChat = /*#__PURE__*/function () {
9895
9970
  /** sync - returns all events that happened for a list of channels since last sync
9896
9971
  * @param {string[]} channel_cids list of channel CIDs
9897
9972
  * @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
9973
+ * @param {SyncOptions} options See JSDoc in the type fields for more info
9974
+ *
9975
+ * @returns {Promise<SyncResponse>}
9898
9976
  */
9899
9977
 
9900
9978
  }, {
9901
9979
  key: "sync",
9902
9980
  value: function sync(channel_cids, last_sync_at) {
9903
- return this.post("".concat(this.baseURL, "/sync"), {
9981
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9982
+ return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
9904
9983
  channel_cids: channel_cids,
9905
9984
  last_sync_at: last_sync_at
9906
- });
9985
+ }, options));
9907
9986
  }
9908
9987
  /**
9909
9988
  * sendUserCustomEvent - Send a custom event to a user