stream-chat 7.0.0-offline-support.2 → 7.0.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.
@@ -93,9 +93,9 @@ var decodeBase64 = function decodeBase64(s) {
93
93
 
94
94
  var https = null;
95
95
 
96
- function ownKeys$7(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
96
+ function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
97
97
 
98
- function _objectSpread$7(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$7(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$7(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
98
+ function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
99
99
 
100
100
  /**
101
101
  * ChannelState - A container class for the channel state.
@@ -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);
@@ -170,7 +172,7 @@ var ChannelState = /*#__PURE__*/function () {
170
172
  var m = messages[i];
171
173
 
172
174
  if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
173
- messages[i] = _objectSpread$7(_objectSpread$7({}, m), {}, {
175
+ messages[i] = _objectSpread$6(_objectSpread$6({}, m), {}, {
174
176
  user: user
175
177
  });
176
178
  }
@@ -225,7 +227,7 @@ var ChannelState = /*#__PURE__*/function () {
225
227
  user: m.user
226
228
  };
227
229
  } else {
228
- messages[i] = _objectSpread$7(_objectSpread$7({}, m), {}, {
230
+ messages[i] = _objectSpread$6(_objectSpread$6({}, m), {}, {
229
231
  type: 'deleted',
230
232
  deleted_at: user.deleted_at
231
233
  });
@@ -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 = [];
@@ -331,7 +334,7 @@ var ChannelState = /*#__PURE__*/function () {
331
334
  }, {
332
335
  key: "formatMessage",
333
336
  value: function formatMessage(message) {
334
- return _objectSpread$7(_objectSpread$7({}, message), {}, {
337
+ return _objectSpread$6(_objectSpread$6({}, message), {}, {
335
338
  /**
336
339
  * @deprecated please use `html`
337
340
  */
@@ -549,7 +552,7 @@ var ChannelState = /*#__PURE__*/function () {
549
552
  var parseMessage = function parseMessage(m) {
550
553
  var _m$pinned_at, _m$updated_at;
551
554
 
552
- return _objectSpread$7(_objectSpread$7({}, m), {}, {
555
+ return _objectSpread$6(_objectSpread$6({}, m), {}, {
553
556
  created_at: m.created_at.toString(),
554
557
  pinned_at: (_m$pinned_at = m.pinned_at) === null || _m$pinned_at === void 0 ? void 0 : _m$pinned_at.toString(),
555
558
  updated_at: (_m$updated_at = m.updated_at) === null || _m$updated_at === void 0 ? void 0 : _m$updated_at.toString()
@@ -560,8 +563,8 @@ var ChannelState = /*#__PURE__*/function () {
560
563
  var updatedMessages = set.messages.filter(function (msg) {
561
564
  return msg.quoted_message_id === message.id;
562
565
  }).map(parseMessage).map(function (msg) {
563
- return _objectSpread$7(_objectSpread$7({}, msg), {}, {
564
- quoted_message: _objectSpread$7(_objectSpread$7({}, message), {}, {
566
+ return _objectSpread$6(_objectSpread$6({}, msg), {}, {
567
+ quoted_message: _objectSpread$6(_objectSpread$6({}, message), {}, {
565
568
  attachments: []
566
569
  })
567
570
  });
@@ -810,40 +813,46 @@ var ChannelState = /*#__PURE__*/function () {
810
813
  var _loadMessageIntoState = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(messageId, parentMessageId) {
811
814
  var _this$threads$parentM;
812
815
 
813
- var messageSetIndex, switchedToMessageSet, loadedMessageThread, messageIdToFind;
816
+ var limit,
817
+ messageSetIndex,
818
+ switchedToMessageSet,
819
+ loadedMessageThread,
820
+ messageIdToFind,
821
+ _args = arguments;
814
822
  return _regeneratorRuntime.wrap(function _callee$(_context) {
815
823
  while (1) {
816
824
  switch (_context.prev = _context.next) {
817
825
  case 0:
826
+ limit = _args.length > 2 && _args[2] !== undefined ? _args[2] : 25;
818
827
  switchedToMessageSet = false;
819
828
  loadedMessageThread = false;
820
829
  messageIdToFind = parentMessageId || messageId;
821
830
 
822
831
  if (!(messageId === 'latest')) {
823
- _context.next = 9;
832
+ _context.next = 10;
824
833
  break;
825
834
  }
826
835
 
827
836
  if (!(this.messages === this.latestMessages)) {
828
- _context.next = 6;
837
+ _context.next = 7;
829
838
  break;
830
839
  }
831
840
 
832
841
  return _context.abrupt("return");
833
842
 
834
- case 6:
843
+ case 7:
835
844
  messageSetIndex = this.messageSets.findIndex(function (s) {
836
845
  return s.isLatest;
837
846
  });
838
- _context.next = 10;
847
+ _context.next = 11;
839
848
  break;
840
849
 
841
- case 9:
850
+ case 10:
842
851
  messageSetIndex = this.findMessageSetIndex({
843
852
  id: messageIdToFind
844
853
  });
845
854
 
846
- case 10:
855
+ case 11:
847
856
  if (messageSetIndex !== -1) {
848
857
  this.switchToMessageSet(messageSetIndex);
849
858
  switchedToMessageSet = true;
@@ -854,39 +863,39 @@ var ChannelState = /*#__PURE__*/function () {
854
863
  }));
855
864
 
856
865
  if (!(switchedToMessageSet && loadedMessageThread)) {
857
- _context.next = 14;
866
+ _context.next = 15;
858
867
  break;
859
868
  }
860
869
 
861
870
  return _context.abrupt("return");
862
871
 
863
- case 14:
872
+ case 15:
864
873
  if (switchedToMessageSet) {
865
- _context.next = 17;
874
+ _context.next = 18;
866
875
  break;
867
876
  }
868
877
 
869
- _context.next = 17;
878
+ _context.next = 18;
870
879
  return this._channel.query({
871
880
  messages: {
872
881
  id_around: messageIdToFind,
873
- limit: 25
882
+ limit: limit
874
883
  }
875
884
  }, 'new');
876
885
 
877
- case 17:
886
+ case 18:
878
887
  if (!(!loadedMessageThread && parentMessageId)) {
879
- _context.next = 20;
888
+ _context.next = 21;
880
889
  break;
881
890
  }
882
891
 
883
- _context.next = 20;
892
+ _context.next = 21;
884
893
  return this._channel.getReplies(parentMessageId, {
885
894
  id_around: messageId,
886
- limit: 25
895
+ limit: limit
887
896
  });
888
897
 
889
- case 20:
898
+ case 21:
890
899
  messageSetIndex = this.findMessageSetIndex({
891
900
  id: messageIdToFind
892
901
  });
@@ -895,7 +904,7 @@ var ChannelState = /*#__PURE__*/function () {
895
904
  this.switchToMessageSet(messageSetIndex);
896
905
  }
897
906
 
898
- case 22:
907
+ case 23:
899
908
  case "end":
900
909
  return _context.stop();
901
910
  }
@@ -1070,67 +1079,6 @@ var ChannelState = /*#__PURE__*/function () {
1070
1079
  return ChannelState;
1071
1080
  }();
1072
1081
 
1073
- function ownKeys$6(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
1074
-
1075
- function _objectSpread$6(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$6(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$6(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1076
-
1077
- var EVENT_MAP = {
1078
- 'channel.created': true,
1079
- 'channel.deleted': true,
1080
- 'channel.hidden': true,
1081
- 'channel.kicked': true,
1082
- 'channel.muted': true,
1083
- 'channel.truncated': true,
1084
- 'channel.unmuted': true,
1085
- 'channel.updated': true,
1086
- 'channel.visible': true,
1087
- 'health.check': true,
1088
- 'member.added': true,
1089
- 'member.removed': true,
1090
- 'member.updated': true,
1091
- 'message.deleted': true,
1092
- 'message.new': true,
1093
- 'message.read': true,
1094
- 'message.updated': true,
1095
- 'notification.added_to_channel': true,
1096
- 'notification.channel_deleted': true,
1097
- 'notification.channel_mutes_updated': true,
1098
- 'notification.channel_truncated': true,
1099
- 'notification.invite_accepted': true,
1100
- 'notification.invite_rejected': true,
1101
- 'notification.invited': true,
1102
- 'notification.mark_read': true,
1103
- 'notification.message_new': true,
1104
- 'notification.mutes_updated': true,
1105
- 'notification.removed_from_channel': true,
1106
- 'reaction.deleted': true,
1107
- 'reaction.new': true,
1108
- 'reaction.updated': true,
1109
- 'typing.start': true,
1110
- 'typing.stop': true,
1111
- 'user.banned': true,
1112
- 'user.deleted': true,
1113
- 'user.presence.changed': true,
1114
- 'user.unbanned': true,
1115
- 'user.unread_message_reminder': true,
1116
- 'user.updated': true,
1117
- 'user.watching.start': true,
1118
- 'user.watching.stop': true,
1119
- // local events
1120
- 'channels.queried': true,
1121
- 'connection.changed': true,
1122
- 'connection.recovered': true,
1123
- 'transport.changed': true
1124
- };
1125
-
1126
- var IS_VALID_EVENT_MAP_TYPE = _objectSpread$6(_objectSpread$6({}, EVENT_MAP), {}, {
1127
- all: true
1128
- });
1129
-
1130
- var isValidEventType = function isValidEventType(eventType) {
1131
- return IS_VALID_EVENT_MAP_TYPE[eventType] || false;
1132
- };
1133
-
1134
1082
  function _createForOfIteratorHelper$3(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$3(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function (_e) { function e(_x) { return _e.apply(this, arguments); } e.toString = function () { return _e.toString(); }; return e; }(function (e) { throw e; }), f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function (_e2) { function e(_x2) { return _e2.apply(this, arguments); } e.toString = function () { return _e2.toString(); }; return e; }(function (e) { didErr = true; err = e; }), f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
1135
1083
 
1136
1084
  function _unsupportedIterableToArray$3(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$3(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$3(o, minLen); }
@@ -1376,6 +1324,23 @@ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) {
1376
1324
  * Channel - The Channel class manages it's own state.
1377
1325
  */
1378
1326
  var Channel = /*#__PURE__*/function () {
1327
+ /** */
1328
+
1329
+ /**
1330
+ * This boolean is a vague indication of weather the channel exists on chat backend.
1331
+ *
1332
+ * If the value is true, then that means the channel has been initialized by either calling
1333
+ * channel.create() or channel.query() or channel.watch().
1334
+ *
1335
+ * If the value is false, then channel may or may not exist on the backend. The only way to ensure
1336
+ * is by calling channel.create() or channel.query() or channel.watch().
1337
+ */
1338
+
1339
+ /**
1340
+ * Indicates weather channel has been initialized by manually populating the state with some messages, members etc.
1341
+ * Static state indicates that channel exists on backend, but is not being watched yet.
1342
+ */
1343
+
1379
1344
  /**
1380
1345
  * constructor - Create a channel
1381
1346
  *
@@ -1409,7 +1374,7 @@ var Channel = /*#__PURE__*/function () {
1409
1374
 
1410
1375
  _defineProperty(this, "initialized", void 0);
1411
1376
 
1412
- _defineProperty(this, "staticState", void 0);
1377
+ _defineProperty(this, "offlineMode", void 0);
1413
1378
 
1414
1379
  _defineProperty(this, "lastKeyStroke", void 0);
1415
1380
 
@@ -1498,7 +1463,7 @@ var Channel = /*#__PURE__*/function () {
1498
1463
 
1499
1464
  this.state = new ChannelState(this);
1500
1465
  this.initialized = false;
1501
- this.staticState = true;
1466
+ this.offlineMode = false;
1502
1467
  this.lastTypingEvent = null;
1503
1468
  this.isTyping = false;
1504
1469
  this.disconnected = false;
@@ -1537,6 +1502,8 @@ var Channel = /*#__PURE__*/function () {
1537
1502
  * @param {Message<StreamChatGenerics>} message The Message object
1538
1503
  * @param {boolean} [options.skip_enrich_url] Do not try to enrich the URLs within message
1539
1504
  * @param {boolean} [options.skip_push] Skip sending push notifications
1505
+ * @param {boolean} [options.is_pending_message] Make this message pending
1506
+ * @param {Record<string,string>} [options.pending_message_metadata] Metadata for the pending message
1540
1507
  *
1541
1508
  * @return {Promise<SendMessageAPIResponse<StreamChatGenerics>>} The Server Response
1542
1509
  */
@@ -1943,6 +1910,7 @@ var Channel = /*#__PURE__*/function () {
1943
1910
  key: "updatePartial",
1944
1911
  value: function () {
1945
1912
  var _updatePartial = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(update) {
1913
+ var data;
1946
1914
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
1947
1915
  while (1) {
1948
1916
  switch (_context8.prev = _context8.next) {
@@ -1951,9 +1919,11 @@ var Channel = /*#__PURE__*/function () {
1951
1919
  return this.getClient().patch(this._channelURL(), update);
1952
1920
 
1953
1921
  case 2:
1954
- return _context8.abrupt("return", _context8.sent);
1922
+ data = _context8.sent;
1923
+ this.data = data.channel;
1924
+ return _context8.abrupt("return", data);
1955
1925
 
1956
- case 3:
1926
+ case 5:
1957
1927
  case "end":
1958
1928
  return _context8.stop();
1959
1929
  }
@@ -3197,6 +3167,7 @@ var Channel = /*#__PURE__*/function () {
3197
3167
 
3198
3168
 
3199
3169
  _this$_initializeStat = this._initializeState(state, messageSetToAddToIfDoesNotExist), messageSet = _this$_initializeStat.messageSet;
3170
+ this.data = state.channel;
3200
3171
  this.getClient().dispatchEvent({
3201
3172
  type: 'channels.queried',
3202
3173
  queriedChannels: {
@@ -3206,7 +3177,7 @@ var Channel = /*#__PURE__*/function () {
3206
3177
  });
3207
3178
  return _context31.abrupt("return", state);
3208
3179
 
3209
- case 13:
3180
+ case 14:
3210
3181
  case "end":
3211
3182
  return _context31.stop();
3212
3183
  }
@@ -3525,12 +3496,6 @@ var Channel = /*#__PURE__*/function () {
3525
3496
  var _this2 = this;
3526
3497
 
3527
3498
  var key = callbackOrNothing ? callbackOrString : 'all';
3528
- var valid = isValidEventType(key);
3529
-
3530
- if (!valid) {
3531
- throw Error("Invalid event type ".concat(key));
3532
- }
3533
-
3534
3499
  var callback = callbackOrNothing ? callbackOrNothing : callbackOrString;
3535
3500
 
3536
3501
  if (!(key in this.listeners)) {
@@ -3565,12 +3530,6 @@ var Channel = /*#__PURE__*/function () {
3565
3530
  key: "off",
3566
3531
  value: function off(callbackOrString, callbackOrNothing) {
3567
3532
  var key = callbackOrNothing ? callbackOrString : 'all';
3568
- var valid = isValidEventType(key);
3569
-
3570
- if (!valid) {
3571
- throw Error("Invalid event type ".concat(key));
3572
- }
3573
-
3574
3533
  var callback = callbackOrNothing ? callbackOrNothing : callbackOrString;
3575
3534
 
3576
3535
  if (!(key in this.listeners)) {
@@ -3809,7 +3768,7 @@ var Channel = /*#__PURE__*/function () {
3809
3768
  }, {
3810
3769
  key: "_checkInitialized",
3811
3770
  value: function _checkInitialized() {
3812
- if (!this.initialized && !this.staticState && !this.getClient()._isUsingServerAuth()) {
3771
+ if (!this.initialized && !this.offlineMode && !this.getClient()._isUsingServerAuth()) {
3813
3772
  throw Error("Channel ".concat(this.cid, " hasn't been initialized yet. Make sure to call .watch() and wait for it to resolve"));
3814
3773
  }
3815
3774
  } // eslint-disable-next-line sonarjs/cognitive-complexity
@@ -3859,6 +3818,11 @@ var Channel = /*#__PURE__*/function () {
3859
3818
  }
3860
3819
 
3861
3820
  this.state.addPinnedMessages(state.pinned_messages || []);
3821
+
3822
+ if (state.pending_messages) {
3823
+ this.state.pending_messages = state.pending_messages;
3824
+ }
3825
+
3862
3826
  this.state.watcher_count = state.watcher_count || 0; // convert the arrays into objects for easier syncing...
3863
3827
 
3864
3828
  if (state.watchers) {
@@ -4534,6 +4498,11 @@ var StableWSConnection = /*#__PURE__*/function () {
4534
4498
  tags: ['connection']
4535
4499
  }, extra));
4536
4500
  }
4501
+ }, {
4502
+ key: "setClient",
4503
+ value: function setClient(client) {
4504
+ this.client = client;
4505
+ }
4537
4506
  /**
4538
4507
  * connect - Connect to the WS URL
4539
4508
  * the default 15s timeout allows between 2~3 tries
@@ -6228,7 +6197,7 @@ var StreamChat = /*#__PURE__*/function () {
6228
6197
  throw Error('User is not set on client, use client.connectUser or client.connectAnonymousUser instead');
6229
6198
 
6230
6199
  case 2:
6231
- if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting)) {
6200
+ if (!((_this$wsConnection3 = _this.wsConnection) !== null && _this$wsConnection3 !== void 0 && _this$wsConnection3.isConnecting && _this.wsPromise)) {
6232
6201
  _context3.next = 5;
6233
6202
  break;
6234
6203
  }
@@ -6237,7 +6206,7 @@ var StreamChat = /*#__PURE__*/function () {
6237
6206
  tags: ['connection', 'client']
6238
6207
  });
6239
6208
 
6240
- return _context3.abrupt("return", Promise.resolve());
6209
+ return _context3.abrupt("return", _this.wsPromise);
6241
6210
 
6242
6211
  case 5:
6243
6212
  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())) {
@@ -6995,23 +6964,28 @@ var StreamChat = /*#__PURE__*/function () {
6995
6964
  */
6996
6965
  function () {
6997
6966
  var _updateAppSettings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(options) {
6998
- var _options$apn_config;
6999
-
6967
+ var apn_config;
7000
6968
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
7001
6969
  while (1) {
7002
6970
  switch (_context7.prev = _context7.next) {
7003
6971
  case 0:
7004
- if ((_options$apn_config = options.apn_config) !== null && _options$apn_config !== void 0 && _options$apn_config.p12_cert) {
7005
- 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
+ });
7006
6980
  }
7007
6981
 
7008
- _context7.next = 3;
6982
+ _context7.next = 4;
7009
6983
  return this.patch(this.baseURL + '/app', options);
7010
6984
 
7011
- case 3:
6985
+ case 4:
7012
6986
  return _context7.abrupt("return", _context7.sent);
7013
6987
 
7014
- case 4:
6988
+ case 5:
7015
6989
  case "end":
7016
6990
  return _context7.stop();
7017
6991
  }
@@ -7402,12 +7376,6 @@ var StreamChat = /*#__PURE__*/function () {
7402
7376
  var _this2 = this;
7403
7377
 
7404
7378
  var key = callbackOrNothing ? callbackOrString : 'all';
7405
- var valid = isValidEventType(key);
7406
-
7407
- if (!valid) {
7408
- throw Error("Invalid event type ".concat(key));
7409
- }
7410
-
7411
7379
  var callback = callbackOrNothing ? callbackOrNothing : callbackOrString;
7412
7380
 
7413
7381
  if (!(key in this.listeners)) {
@@ -7439,12 +7407,6 @@ var StreamChat = /*#__PURE__*/function () {
7439
7407
  key: "off",
7440
7408
  value: function off(callbackOrString, callbackOrNothing) {
7441
7409
  var key = callbackOrNothing ? callbackOrString : 'all';
7442
- var valid = isValidEventType(key);
7443
-
7444
- if (!valid) {
7445
- throw Error("Invalid event type ".concat(key));
7446
- }
7447
-
7448
7410
  var callback = callbackOrNothing ? callbackOrNothing : callbackOrString;
7449
7411
 
7450
7412
  if (!(key in this.listeners)) {
@@ -7699,9 +7661,16 @@ var StreamChat = /*#__PURE__*/function () {
7699
7661
  } // The StableWSConnection handles all the reconnection logic.
7700
7662
 
7701
7663
 
7702
- this.wsConnection = new StableWSConnection({
7703
- client: this
7704
- });
7664
+ if (this.options.wsConnection && this.node) {
7665
+ // Intentionally avoiding adding ts generics on wsConnection in options since its only useful for unit test purpose.
7666
+ this.options.wsConnection.setClient(this);
7667
+ this.wsConnection = this.options.wsConnection;
7668
+ } else {
7669
+ this.wsConnection = new StableWSConnection({
7670
+ client: this
7671
+ });
7672
+ }
7673
+
7705
7674
  _context15.prev = 8;
7706
7675
 
7707
7676
  if (!this.wsFallback) {
@@ -7827,7 +7796,7 @@ var StreamChat = /*#__PURE__*/function () {
7827
7796
  }; // Make sure we wait for the connect promise if there is a pending one
7828
7797
 
7829
7798
  _context16.next = 5;
7830
- return this.setUserPromise;
7799
+ return this.wsPromise;
7831
7800
 
7832
7801
  case 5:
7833
7802
  if (!this._hasConnectionID()) {
@@ -7996,7 +7965,7 @@ var StreamChat = /*#__PURE__*/function () {
7996
7965
  }; // Make sure we wait for the connect promise if there is a pending one
7997
7966
 
7998
7967
  _context19.next = 6;
7999
- return this.setUserPromise;
7968
+ return this.wsPromise;
8000
7969
 
8001
7970
  case 6:
8002
7971
  if (!this._hasConnectionID()) {
@@ -8042,8 +8011,8 @@ var StreamChat = /*#__PURE__*/function () {
8042
8011
  var channelsFromApi = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
8043
8012
  var stateOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8044
8013
  var skipInitialization = stateOptions.skipInitialization,
8045
- _stateOptions$staticS = stateOptions.staticState,
8046
- staticState = _stateOptions$staticS === void 0 ? false : _stateOptions$staticS;
8014
+ _stateOptions$offline = stateOptions.offlineMode,
8015
+ offlineMode = _stateOptions$offline === void 0 ? false : _stateOptions$offline;
8047
8016
 
8048
8017
  var _iterator2 = _createForOfIteratorHelper(channelsFromApi),
8049
8018
  _step2;
@@ -8070,8 +8039,8 @@ var StreamChat = /*#__PURE__*/function () {
8070
8039
  var _channelState = _step3.value;
8071
8040
  var c = this.channel(_channelState.channel.type, _channelState.channel.id);
8072
8041
  c.data = _channelState.channel;
8073
- c.staticState = staticState;
8074
- c.initialized = !staticState;
8042
+ c.offlineMode = offlineMode;
8043
+ c.initialized = !offlineMode;
8075
8044
 
8076
8045
  if (skipInitialization === undefined) {
8077
8046
  c._initializeState(_channelState, 'latest');
@@ -8089,13 +8058,13 @@ var StreamChat = /*#__PURE__*/function () {
8089
8058
  _iterator3.f();
8090
8059
  }
8091
8060
 
8092
- if (!staticState) {
8061
+ if (!offlineMode) {
8093
8062
  // If the channels are coming from server, then clear out the
8094
8063
  // previously help offline channels.
8095
8064
  for (var _key5 in this.activeChannels) {
8096
8065
  var _channel7 = this.activeChannels[_key5];
8097
8066
 
8098
- if (_channel7.staticState) {
8067
+ if (_channel7.offlineMode) {
8099
8068
  delete this.activeChannels[_key5];
8100
8069
  }
8101
8070
  }
@@ -8164,7 +8133,7 @@ var StreamChat = /*#__PURE__*/function () {
8164
8133
 
8165
8134
  case 13:
8166
8135
  _context20.next = 15;
8167
- return this.setUserPromise;
8136
+ return this.wsPromise;
8168
8137
 
8169
8138
  case 15:
8170
8139
  _context20.next = 17;
@@ -9853,7 +9822,7 @@ var StreamChat = /*#__PURE__*/function () {
9853
9822
  }, {
9854
9823
  key: "getUserAgent",
9855
9824
  value: function getUserAgent() {
9856
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "7.0.0-offline-support.2");
9825
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "7.0.0");
9857
9826
  }
9858
9827
  }, {
9859
9828
  key: "setUserAgent",
@@ -10026,15 +9995,19 @@ var StreamChat = /*#__PURE__*/function () {
10026
9995
  /** sync - returns all events that happened for a list of channels since last sync
10027
9996
  * @param {string[]} channel_cids list of channel CIDs
10028
9997
  * @param {string} last_sync_at last time the user was online and in sync. RFC3339 ie. "2020-05-06T15:05:01.207Z"
9998
+ * @param {SyncOptions} options See JSDoc in the type fields for more info
9999
+ *
10000
+ * @returns {Promise<SyncResponse>}
10029
10001
  */
10030
10002
 
10031
10003
  }, {
10032
10004
  key: "sync",
10033
10005
  value: function sync(channel_cids, last_sync_at) {
10034
- return this.post("".concat(this.baseURL, "/sync"), {
10006
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10007
+ return this.post("".concat(this.baseURL, "/sync"), _objectSpread({
10035
10008
  channel_cids: channel_cids,
10036
10009
  last_sync_at: last_sync_at
10037
- });
10010
+ }, options));
10038
10011
  }
10039
10012
  /**
10040
10013
  * sendUserCustomEvent - Send a custom event to a user
@@ -11161,6 +11134,55 @@ var StreamChat = /*#__PURE__*/function () {
11161
11134
 
11162
11135
  _defineProperty(StreamChat, "_instance", void 0);
11163
11136
 
11137
+ var EVENT_MAP = {
11138
+ 'channel.created': true,
11139
+ 'channel.deleted': true,
11140
+ 'channel.hidden': true,
11141
+ 'channel.kicked': true,
11142
+ 'channel.muted': true,
11143
+ 'channel.truncated': true,
11144
+ 'channel.unmuted': true,
11145
+ 'channel.updated': true,
11146
+ 'channel.visible': true,
11147
+ 'health.check': true,
11148
+ 'member.added': true,
11149
+ 'member.removed': true,
11150
+ 'member.updated': true,
11151
+ 'message.deleted': true,
11152
+ 'message.new': true,
11153
+ 'message.read': true,
11154
+ 'message.updated': true,
11155
+ 'notification.added_to_channel': true,
11156
+ 'notification.channel_deleted': true,
11157
+ 'notification.channel_mutes_updated': true,
11158
+ 'notification.channel_truncated': true,
11159
+ 'notification.invite_accepted': true,
11160
+ 'notification.invite_rejected': true,
11161
+ 'notification.invited': true,
11162
+ 'notification.mark_read': true,
11163
+ 'notification.message_new': true,
11164
+ 'notification.mutes_updated': true,
11165
+ 'notification.removed_from_channel': true,
11166
+ 'reaction.deleted': true,
11167
+ 'reaction.new': true,
11168
+ 'reaction.updated': true,
11169
+ 'typing.start': true,
11170
+ 'typing.stop': true,
11171
+ 'user.banned': true,
11172
+ 'user.deleted': true,
11173
+ 'user.presence.changed': true,
11174
+ 'user.unbanned': true,
11175
+ 'user.unread_message_reminder': true,
11176
+ 'user.updated': true,
11177
+ 'user.watching.start': true,
11178
+ 'user.watching.stop': true,
11179
+ // local events
11180
+ 'channels.queried': true,
11181
+ 'connection.changed': true,
11182
+ 'connection.recovered': true,
11183
+ 'transport.changed': true
11184
+ };
11185
+
11164
11186
  var Allow = 'Allow';
11165
11187
  var Deny = 'Deny';
11166
11188
  var AnyResource = ['*'];
@@ -11235,5 +11257,5 @@ var BuiltinPermissions = {
11235
11257
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
11236
11258
  };
11237
11259
 
11238
- export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, isValidEventType, logChatPromiseExecution, postInsights };
11260
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, Channel, ChannelState, CheckSignature, ClientState, Deny, DenyAll, DevToken, EVENT_MAP, ErrorFromResponse, InsightMetrics, JWTServerToken, JWTUserToken, MaxPriority, MinPriority, Permission, StableWSConnection, StreamChat, TokenManager, UserFromToken, buildWsFatalInsight, buildWsSuccessAfterFailureInsight, chatCodes, decodeBase64, encodeBase64, isOwnUser, logChatPromiseExecution, postInsights };
11239
11261
  //# sourceMappingURL=browser.es.js.map