stream-chat 6.7.2 → 6.9.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 = [];
@@ -806,40 +809,46 @@ var ChannelState = /*#__PURE__*/function () {
806
809
  var _loadMessageIntoState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(messageId, parentMessageId) {
807
810
  var _this$threads$parentM;
808
811
 
809
- var messageSetIndex, switchedToMessageSet, loadedMessageThread, messageIdToFind;
812
+ var limit,
813
+ messageSetIndex,
814
+ switchedToMessageSet,
815
+ loadedMessageThread,
816
+ messageIdToFind,
817
+ _args = arguments;
810
818
  return _regeneratorRuntime.wrap(function _callee$(_context) {
811
819
  while (1) {
812
820
  switch (_context.prev = _context.next) {
813
821
  case 0:
822
+ limit = _args.length > 2 && _args[2] !== undefined ? _args[2] : 25;
814
823
  switchedToMessageSet = false;
815
824
  loadedMessageThread = false;
816
825
  messageIdToFind = parentMessageId || messageId;
817
826
 
818
827
  if (!(messageId === 'latest')) {
819
- _context.next = 9;
828
+ _context.next = 10;
820
829
  break;
821
830
  }
822
831
 
823
832
  if (!(this.messages === this.latestMessages)) {
824
- _context.next = 6;
833
+ _context.next = 7;
825
834
  break;
826
835
  }
827
836
 
828
837
  return _context.abrupt("return");
829
838
 
830
- case 6:
839
+ case 7:
831
840
  messageSetIndex = this.messageSets.findIndex(function (s) {
832
841
  return s.isLatest;
833
842
  });
834
- _context.next = 10;
843
+ _context.next = 11;
835
844
  break;
836
845
 
837
- case 9:
846
+ case 10:
838
847
  messageSetIndex = this.findMessageSetIndex({
839
848
  id: messageIdToFind
840
849
  });
841
850
 
842
- case 10:
851
+ case 11:
843
852
  if (messageSetIndex !== -1) {
844
853
  this.switchToMessageSet(messageSetIndex);
845
854
  switchedToMessageSet = true;
@@ -850,39 +859,39 @@ var ChannelState = /*#__PURE__*/function () {
850
859
  }));
851
860
 
852
861
  if (!(switchedToMessageSet && loadedMessageThread)) {
853
- _context.next = 14;
862
+ _context.next = 15;
854
863
  break;
855
864
  }
856
865
 
857
866
  return _context.abrupt("return");
858
867
 
859
- case 14:
868
+ case 15:
860
869
  if (switchedToMessageSet) {
861
- _context.next = 17;
870
+ _context.next = 18;
862
871
  break;
863
872
  }
864
873
 
865
- _context.next = 17;
874
+ _context.next = 18;
866
875
  return this._channel.query({
867
876
  messages: {
868
877
  id_around: messageIdToFind,
869
- limit: 25
878
+ limit: limit
870
879
  }
871
880
  }, 'new');
872
881
 
873
- case 17:
882
+ case 18:
874
883
  if (!(!loadedMessageThread && parentMessageId)) {
875
- _context.next = 20;
884
+ _context.next = 21;
876
885
  break;
877
886
  }
878
887
 
879
- _context.next = 20;
888
+ _context.next = 21;
880
889
  return this._channel.getReplies(parentMessageId, {
881
890
  id_around: messageId,
882
- limit: 25
891
+ limit: limit
883
892
  });
884
893
 
885
- case 20:
894
+ case 21:
886
895
  messageSetIndex = this.findMessageSetIndex({
887
896
  id: messageIdToFind
888
897
  });
@@ -891,7 +900,7 @@ var ChannelState = /*#__PURE__*/function () {
891
900
  this.switchToMessageSet(messageSetIndex);
892
901
  }
893
902
 
894
- case 22:
903
+ case 23:
895
904
  case "end":
896
905
  return _context.stop();
897
906
  }
@@ -905,6 +914,42 @@ var ChannelState = /*#__PURE__*/function () {
905
914
 
906
915
  return loadMessageIntoState;
907
916
  }()
917
+ /**
918
+ * findMessage - Finds a message inside the state
919
+ *
920
+ * @param {string} messageId The id of the message
921
+ * @param {string} parentMessageId The id of the parent message, if we want load a thread reply
922
+ *
923
+ * @return {ReturnType<ChannelState<StreamChatGenerics>['formatMessage']>} Returns the message, or undefined if the message wasn't found
924
+ */
925
+
926
+ }, {
927
+ key: "findMessage",
928
+ value: function findMessage(messageId, parentMessageId) {
929
+ if (parentMessageId) {
930
+ var messages = this.threads[parentMessageId];
931
+
932
+ if (!messages) {
933
+ return undefined;
934
+ }
935
+
936
+ return messages.find(function (m) {
937
+ return m.id === messageId;
938
+ });
939
+ }
940
+
941
+ var messageSetIndex = this.findMessageSetIndex({
942
+ id: messageId
943
+ });
944
+
945
+ if (messageSetIndex === -1) {
946
+ return undefined;
947
+ }
948
+
949
+ return this.messageSets[messageSetIndex].messages.find(function (m) {
950
+ return m.id === messageId;
951
+ });
952
+ }
908
953
  }, {
909
954
  key: "switchToMessageSet",
910
955
  value: function switchToMessageSet(index) {
@@ -1493,6 +1538,8 @@ var Channel = /*#__PURE__*/function () {
1493
1538
  * @param {Message<StreamChatGenerics>} message The Message object
1494
1539
  * @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
1495
1540
  * @param {boolean} [options.skip_push] Skip sending push notifications
1541
+ * @param {boolean} [options.is_pending_message] Make this message pending
1542
+ * @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
1496
1543
  *
1497
1544
  * @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
1498
1545
  */
@@ -1899,6 +1946,7 @@ var Channel = /*#__PURE__*/function () {
1899
1946
  key: "updatePartial",
1900
1947
  value: function () {
1901
1948
  var _updatePartial = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(update) {
1949
+ var data;
1902
1950
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
1903
1951
  while (1) {
1904
1952
  switch (_context8.prev = _context8.next) {
@@ -1907,9 +1955,11 @@ var Channel = /*#__PURE__*/function () {
1907
1955
  return this.getClient().patch(this._channelURL(), update);
1908
1956
 
1909
1957
  case 2:
1910
- return _context8.abrupt("return", _context8.sent);
1958
+ data = _context8.sent;
1959
+ this.data = data.channel;
1960
+ return _context8.abrupt("return", data);
1911
1961
 
1912
- case 3:
1962
+ case 5:
1913
1963
  case "end":
1914
1964
  return _context8.stop();
1915
1965
  }
@@ -3151,9 +3201,10 @@ var Channel = /*#__PURE__*/function () {
3151
3201
 
3152
3202
  this._initializeState(state, messageSetToAddToIfDoesNotExist);
3153
3203
 
3204
+ this.data = state.channel;
3154
3205
  return _context31.abrupt("return", state);
3155
3206
 
3156
- case 12:
3207
+ case 13:
3157
3208
  case "end":
3158
3209
  return _context31.stop();
3159
3210
  }
@@ -3598,6 +3649,8 @@ var Channel = /*#__PURE__*/function () {
3598
3649
 
3599
3650
  case 'message.deleted':
3600
3651
  if (event.message) {
3652
+ this._extendEventWithOwnReactions(event);
3653
+
3601
3654
  if (event.hard_delete) channelState.removeMessage(event.message);else channelState.addMessageSorted(event.message, false, false);
3602
3655
  channelState.removeQuotedMessageReferences(event.message);
3603
3656
 
@@ -3640,6 +3693,8 @@ var Channel = /*#__PURE__*/function () {
3640
3693
 
3641
3694
  case 'message.updated':
3642
3695
  if (event.message) {
3696
+ this._extendEventWithOwnReactions(event);
3697
+
3643
3698
  channelState.addMessageSorted(event.message, false, false);
3644
3699
 
3645
3700
  if (event.message.pinned) {
@@ -3801,6 +3856,11 @@ var Channel = /*#__PURE__*/function () {
3801
3856
  }
3802
3857
 
3803
3858
  this.state.addPinnedMessages(state.pinned_messages || []);
3859
+
3860
+ if (state.pending_messages) {
3861
+ this.state.pending_messages = state.pending_messages;
3862
+ }
3863
+
3804
3864
  this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
3805
3865
 
3806
3866
  if (state.watchers) {
@@ -3884,6 +3944,19 @@ var Channel = /*#__PURE__*/function () {
3884
3944
  }
3885
3945
  }
3886
3946
  }
3947
+ }, {
3948
+ key: "_extendEventWithOwnReactions",
3949
+ value: function _extendEventWithOwnReactions(event) {
3950
+ if (!event.message) {
3951
+ return;
3952
+ }
3953
+
3954
+ var message = this.state.findMessage(event.message.id, event.message.parent_id);
3955
+
3956
+ if (message) {
3957
+ event.message.own_reactions = message.own_reactions;
3958
+ }
3959
+ }
3887
3960
  }, {
3888
3961
  key: "_disconnect",
3889
3962
  value: function _disconnect() {
@@ -4459,6 +4532,11 @@ var StableWSConnection = /*#__PURE__*/function () {
4459
4532
  tags: ['connection']
4460
4533
  }, extra));
4461
4534
  }
4535
+ }, {
4536
+ key: "setClient",
4537
+ value: function setClient(client) {
4538
+ this.client = client;
4539
+ }
4462
4540
  /**
4463
4541
  * connect - Connect to the WS URL
4464
4542
  * the default 15s timeout allows between 2~3 tries
@@ -6121,7 +6199,7 @@ var StreamChat = /*#__PURE__*/function () {
6121
6199
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
6122
6200
 
6123
6201
  case 2:
6124
- if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
6202
+ if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
6125
6203
  _context3.next = 5;
6126
6204
  break;
6127
6205
  }
@@ -6130,7 +6208,7 @@ var StreamChat = /*#__PURE__*/function () {
6130
6208
  tags: ['connection', 'client']
6131
6209
  });
6132
6210
 
6133
- return _context3.abrupt("return", Promise.resolve());
6211
+ return _context3.abrupt("return", _this.wsPromise);
6134
6212
 
6135
6213
  case 5:
6136
6214
  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())) {
@@ -6886,23 +6964,28 @@ var StreamChat = /*#__PURE__*/function () {
6886
6964
  */
6887
6965
  function () {
6888
6966
  var _updateAppSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(options) {
6889
- var _options$apn_config;
6890
-
6967
+ var apn_config;
6891
6968
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
6892
6969
  while (1) {
6893
6970
  switch (_context7.prev = _context7.next) {
6894
6971
  case 0:
6895
- if ((_options$apn_config = options.apn_config) !== null && _options$apn_config !== void 0 && _options$apn_config.p12_cert) {
6896
- options.apn_config.p12_cert = Buffer.from(options.apn_config.p12_cert).toString('base64');
6972
+ apn_config = options.apn_config;
6973
+
6974
+ if (apn_config !== null && apn_config !== void 0 && apn_config.p12_cert) {
6975
+ options = _objectSpread(_objectSpread({}, options), {}, {
6976
+ apn_config: _objectSpread(_objectSpread({}, apn_config), {}, {
6977
+ p12_cert: Buffer.from(apn_config.p12_cert).toString('base64')
6978
+ })
6979
+ });
6897
6980
  }
6898
6981
 
6899
- _context7.next = 3;
6982
+ _context7.next = 4;
6900
6983
  return this.patch(this.baseURL + '/app', options);
6901
6984
 
6902
- case 3:
6985
+ case 4:
6903
6986
  return _context7.abrupt("return", _context7.sent);
6904
6987
 
6905
- case 4:
6988
+ case 5:
6906
6989
  case "end":
6907
6990
  return _context7.stop();
6908
6991
  }
@@ -7590,9 +7673,16 @@ var StreamChat = /*#__PURE__*/function () {
7590
7673
  } // The StableWSConnection handles all the reconnection logic.
7591
7674
 
7592
7675
 
7593
- this.wsConnection = new StableWSConnection({
7594
- client: this
7595
- });
7676
+ if (this.options.wsConnection && this.node) {
7677
+ // Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
7678
+ this.options.wsConnection.setClient(this);
7679
+ this.wsConnection = this.options.wsConnection;
7680
+ } else {
7681
+ this.wsConnection = new StableWSConnection({
7682
+ client: this
7683
+ });
7684
+ }
7685
+
7596
7686
  _context15.prev = 8;
7597
7687
 
7598
7688
  if (!this.wsFallback) {
@@ -7718,7 +7808,7 @@ var StreamChat = /*#__PURE__*/function () {
7718
7808
  }; // Make sure we wait for the connect promise if there is a pending one
7719
7809
 
7720
7810
  _context16.next = 5;
7721
- return this.setUserPromise;
7811
+ return this.wsPromise;
7722
7812
 
7723
7813
  case 5:
7724
7814
  if (!this._hasConnectionID()) {
@@ -7898,7 +7988,7 @@ var StreamChat = /*#__PURE__*/function () {
7898
7988
  }; // Make sure we wait for the connect promise if there is a pending one
7899
7989
 
7900
7990
  _context19.next = 7;
7901
- return this.setUserPromise;
7991
+ return this.wsPromise;
7902
7992
 
7903
7993
  case 7:
7904
7994
  if (!this._hasConnectionID()) {
@@ -8033,7 +8123,7 @@ var StreamChat = /*#__PURE__*/function () {
8033
8123
 
8034
8124
  case 13:
8035
8125
  _context20.next = 15;
8036
- return this.setUserPromise;
8126
+ return this.wsPromise;
8037
8127
 
8038
8128
  case 15:
8039
8129
  _context20.next = 17;
@@ -9722,7 +9812,7 @@ var StreamChat = /*#__PURE__*/function () {
9722
9812
  }, {
9723
9813
  key: "getUserAgent",
9724
9814
  value: function getUserAgent() {
9725
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.7.2");
9815
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "6.9.0");
9726
9816
  }
9727
9817
  }, {
9728
9818
  key: "setUserAgent",
@@ -9895,15 +9985,19 @@ var StreamChat = /*#__PURE__*/function () {
9895
9985
  /** sync - returns all events that happened for a list of channels since last sync
9896
9986
  * @param {string[]} channel_cids list of channel CIDs
9897
9987
  * @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
9988
+ * @param {SyncOptions} options See JSDoc in the type fields for more info
9989
+ *
9990
+ * @returns {Promise<SyncResponse>}
9898
9991
  */
9899
9992
 
9900
9993
  }, {
9901
9994
  key: "sync",
9902
9995
  value: function sync(channel_cids, last_sync_at) {
9903
- return this.post("".concat(this.baseURL, "/sync"), {
9996
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9997
+ return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
9904
9998
  channel_cids: channel_cids,
9905
9999
  last_sync_at: last_sync_at
9906
- });
10000
+ }, options));
9907
10001
  }
9908
10002
  /**
9909
10003
  * sendUserCustomEvent - Send a custom event to a user