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.
package/dist/index.js CHANGED
@@ -1385,6 +1385,12 @@ var Channel = /*#__PURE__*/function () {
1385
1385
  * Static state indicates that channel exists on backend, but is not being watched yet.
1386
1386
  */
1387
1387
 
1388
+ /**
1389
+ * Collects the incoming WS events before the channel is marked as initialized.
1390
+ * This prevents executing procedures that depend on channel being initialized.
1391
+ * Once the channel is marked as initialized the queue is flushed.
1392
+ */
1393
+
1388
1394
  /**
1389
1395
  * constructor - Create a channel
1390
1396
  *
@@ -1428,6 +1434,8 @@ var Channel = /*#__PURE__*/function () {
1428
1434
 
1429
1435
  _defineProperty__default['default'](this, "disconnected", void 0);
1430
1436
 
1437
+ _defineProperty__default['default'](this, "wsEventQueue", void 0);
1438
+
1431
1439
  _defineProperty__default['default'](this, "create", /*#__PURE__*/function () {
1432
1440
  var _ref = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(options) {
1433
1441
  var defaultOptions;
@@ -1517,6 +1525,7 @@ var Channel = /*#__PURE__*/function () {
1517
1525
  this.lastTypingEvent = null;
1518
1526
  this.isTyping = false;
1519
1527
  this.disconnected = false;
1528
+ this.wsEventQueue = [];
1520
1529
  }
1521
1530
  /**
1522
1531
  * getClient - Get the chat client for this channel. If client.disconnect() was called, this function will error
@@ -2920,6 +2929,9 @@ var Channel = /*#__PURE__*/function () {
2920
2929
  case 7:
2921
2930
  state = _context28.sent;
2922
2931
  this.initialized = true;
2932
+
2933
+ this._flushWsEventQueue();
2934
+
2923
2935
  this.data = state.channel;
2924
2936
 
2925
2937
  this._client.logger('info', "channel:watch() - started watching channel ".concat(this.cid), {
@@ -2929,7 +2941,7 @@ var Channel = /*#__PURE__*/function () {
2929
2941
 
2930
2942
  return _context28.abrupt("return", state);
2931
2943
 
2932
- case 12:
2944
+ case 13:
2933
2945
  case "end":
2934
2946
  return _context28.stop();
2935
2947
  }
@@ -3111,8 +3123,6 @@ var Channel = /*#__PURE__*/function () {
3111
3123
  }, {
3112
3124
  key: "lastRead",
3113
3125
  value: function lastRead() {
3114
- this._checkInitialized();
3115
-
3116
3126
  var _this$getClient = this.getClient(),
3117
3127
  userID = _this$getClient.userID;
3118
3128
 
@@ -3654,6 +3664,11 @@ var Channel = /*#__PURE__*/function () {
3654
3664
 
3655
3665
  var channel = this;
3656
3666
 
3667
+ if (!this._isInitialized()) {
3668
+ this.wsEventQueue.push(event);
3669
+ return;
3670
+ }
3671
+
3657
3672
  this._client.logger('info', "channel:_handleChannelEvent - Received event of type { ".concat(event.type, " } on ").concat(this.cid), {
3658
3673
  tags: ['event', 'channel'],
3659
3674
  channel: this
@@ -3904,6 +3919,11 @@ var Channel = /*#__PURE__*/function () {
3904
3919
  channel.state.watcher_count = event.watcher_count;
3905
3920
  }
3906
3921
  }
3922
+ }, {
3923
+ key: "_isInitialized",
3924
+ value: function _isInitialized() {
3925
+ return this.initialized || this.offlineMode || this.getClient()._isUsingServerAuth();
3926
+ }
3907
3927
  }, {
3908
3928
  key: "_checkInitialized",
3909
3929
  value: function _checkInitialized() {
@@ -4065,6 +4085,14 @@ var Channel = /*#__PURE__*/function () {
4065
4085
  this.disconnected = true;
4066
4086
  this.state.setIsUpToDate(false);
4067
4087
  }
4088
+ }, {
4089
+ key: "_flushWsEventQueue",
4090
+ value: function _flushWsEventQueue() {
4091
+ while (this.wsEventQueue.length) {
4092
+ var event = this.wsEventQueue.shift();
4093
+ if (event) this.getClient().dispatchEvent(event);
4094
+ }
4095
+ }
4068
4096
  }]);
4069
4097
 
4070
4098
  return Channel;
@@ -10118,7 +10146,7 @@ var StreamChat = /*#__PURE__*/function () {
10118
10146
  }, {
10119
10147
  key: "getUserAgent",
10120
10148
  value: function getUserAgent() {
10121
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.2");
10149
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.12.4");
10122
10150
  }
10123
10151
  }, {
10124
10152
  key: "setUserAgent",
@@ -11512,6 +11540,30 @@ var EVENT_MAP = {
11512
11540
  'connection.changed': true,
11513
11541
  'connection.recovered': true,
11514
11542
  'transport.changed': true
11543
+ }; // events handled by channel._handleChannelEvent
11544
+
11545
+ var CHANNEL_HANDLED_EVENTS = {
11546
+ 'typing.start': true,
11547
+ 'typing.stop': true,
11548
+ 'message.read': true,
11549
+ 'user.watching.start': true,
11550
+ 'user.updated': true,
11551
+ 'user.watching.stop': true,
11552
+ 'message.deleted': true,
11553
+ 'message.new': true,
11554
+ 'message.updated': true,
11555
+ 'channel.truncated': true,
11556
+ 'member.added': true,
11557
+ 'member.updated': true,
11558
+ 'member.removed': true,
11559
+ 'channel.updated': true,
11560
+ 'reaction.new': true,
11561
+ 'reaction.deleted': true,
11562
+ 'reaction.updated': true,
11563
+ 'channel.hidden': true,
11564
+ 'channel.visible': true,
11565
+ 'user.banned': true,
11566
+ 'user.unbanned': true
11515
11567
  };
11516
11568
 
11517
11569
  var Allow = 'Allow';
@@ -11594,6 +11646,7 @@ exports.AnyResource = AnyResource;
11594
11646
  exports.AnyRole = AnyRole;
11595
11647
  exports.BuiltinPermissions = BuiltinPermissions;
11596
11648
  exports.BuiltinRoles = BuiltinRoles;
11649
+ exports.CHANNEL_HANDLED_EVENTS = CHANNEL_HANDLED_EVENTS;
11597
11650
  exports.Channel = Channel;
11598
11651
  exports.ChannelState = ChannelState;
11599
11652
  exports.CheckSignature = CheckSignature;