stream-chat 8.12.2 → 8.12.4

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.
@@ -1356,6 +1356,12 @@ var Channel = /*#__PURE__*/function () {
1356
1356
  * Static state indicates that channel exists on backend, but is not being watched yet.
1357
1357
  */
1358
1358
 
1359
+ /**
1360
+ * Collects the incoming WS events before the channel is marked as initialized.
1361
+ * This prevents executing procedures that depend on channel being initialized.
1362
+ * Once the channel is marked as initialized the queue is flushed.
1363
+ */
1364
+
1359
1365
  /**
1360
1366
  * constructor - Create a channel
1361
1367
  *
@@ -1399,6 +1405,8 @@ var Channel = /*#__PURE__*/function () {
1399
1405
 
1400
1406
  _defineProperty(this, "disconnected", void 0);
1401
1407
 
1408
+ _defineProperty(this, "wsEventQueue", void 0);
1409
+
1402
1410
  _defineProperty(this, "create", /*#__PURE__*/function () {
1403
1411
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(options) {
1404
1412
  var defaultOptions;
@@ -1488,6 +1496,7 @@ var Channel = /*#__PURE__*/function () {
1488
1496
  this.lastTypingEvent = null;
1489
1497
  this.isTyping = false;
1490
1498
  this.disconnected = false;
1499
+ this.wsEventQueue = [];
1491
1500
  }
1492
1501
  /**
1493
1502
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2891,6 +2900,9 @@ var Channel = /*#__PURE__*/function () {
2891
2900
  case 7:
2892
2901
  state = _context28.sent;
2893
2902
  this.initialized = true;
2903
+
2904
+ this._flushWsEventQueue();
2905
+
2894
2906
  this.data = state.channel;
2895
2907
 
2896
2908
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2900,7 +2912,7 @@ var Channel = /*#__PURE__*/function () {
2900
2912
 
2901
2913
  return _context28.abrupt("return", state);
2902
2914
 
2903
- case 12:
2915
+ case 13:
2904
2916
  case "end":
2905
2917
  return _context28.stop();
2906
2918
  }
@@ -3082,8 +3094,6 @@ var Channel = /*#__PURE__*/function () {
3082
3094
  }, {
3083
3095
  key: "lastRead",
3084
3096
  value: function lastRead() {
3085
- this._checkInitialized();
3086
-
3087
3097
  var _this$getClient = this.getClient(),
3088
3098
  userID = _this$getClient.userID;
3089
3099
 
@@ -3625,6 +3635,11 @@ var Channel = /*#__PURE__*/function () {
3625
3635
 
3626
3636
  var channel = this;
3627
3637
 
3638
+ if (!this._isInitialized()) {
3639
+ this.wsEventQueue.push(event);
3640
+ return;
3641
+ }
3642
+
3628
3643
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3629
3644
  tags: ['event', 'channel'],
3630
3645
  channel: this
@@ -3875,6 +3890,11 @@ var Channel = /*#__PURE__*/function () {
3875
3890
  channel.state.watcher_count = event.watcher_count;
3876
3891
  }
3877
3892
  }
3893
+ }, {
3894
+ key: "_isInitialized",
3895
+ value: function _isInitialized() {
3896
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3897
+ }
3878
3898
  }, {
3879
3899
  key: "_checkInitialized",
3880
3900
  value: function _checkInitialized() {
@@ -4036,6 +4056,14 @@ var Channel = /*#__PURE__*/function () {
4036
4056
  this.disconnected = true;
4037
4057
  this.state.setIsUpToDate(false);
4038
4058
  }
4059
+ }, {
4060
+ key: "_flushWsEventQueue",
4061
+ value: function _flushWsEventQueue() {
4062
+ while (this.wsEventQueue.length) {
4063
+ var event = this.wsEventQueue.shift();
4064
+ if (event) this.getClient().dispatchEvent(event);
4065
+ }
4066
+ }
4039
4067
  }]);
4040
4068
 
4041
4069
  return Channel;
@@ -10087,7 +10115,7 @@ var StreamChat = /*#__PURE__*/function () {
10087
10115
  }, {
10088
10116
  key: "getUserAgent",
10089
10117
  value: function getUserAgent() {
10090
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.2");
10118
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.4");
10091
10119
  }
10092
10120
  }, {
10093
10121
  key: "setUserAgent",
@@ -11481,6 +11509,30 @@ var EVENT_MAP = {
11481
11509
  'connection.changed': true,
11482
11510
  'connection.recovered': true,
11483
11511
  'transport.changed': true
11512
+ }; // events handled by channel._handleChannelEvent
11513
+
11514
+ var CHANNEL_HANDLED_EVENTS = {
11515
+ 'typing.start': true,
11516
+ 'typing.stop': true,
11517
+ 'message.read': true,
11518
+ 'user.watching.start': true,
11519
+ 'user.updated': true,
11520
+ 'user.watching.stop': true,
11521
+ 'message.deleted': true,
11522
+ 'message.new': true,
11523
+ 'message.updated': true,
11524
+ 'channel.truncated': true,
11525
+ 'member.added': true,
11526
+ 'member.updated': true,
11527
+ 'member.removed': true,
11528
+ 'channel.updated': true,
11529
+ 'reaction.new': true,
11530
+ 'reaction.deleted': true,
11531
+ 'reaction.updated': true,
11532
+ 'channel.hidden': true,
11533
+ 'channel.visible': true,
11534
+ 'user.banned': true,
11535
+ 'user.unbanned': true
11484
11536
  };
11485
11537
 
11486
11538
  var Allow = 'Allow';
@@ -11557,5 +11609,5 @@ var BuiltinPermissions = {
11557
11609
  UseFrozenChannel: 'Send messages and reactions to frozen channels'
11558
11610
  };
11559
11611
 
11560
- 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 };
11612
+ export { Allow, AllowAll, AnyResource, AnyRole, BuiltinPermissions, BuiltinRoles, CHANNEL_HANDLED_EVENTS, 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 };
11561
11613
  //# sourceMappingURL=browser.es.js.map