stream-chat 8.41.1 → 8.42.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.
package/dist/index.js CHANGED
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var base64Js = require('base64-js');
6
- var _extends = require('@babel/runtime/helpers/extends');
7
- var _typeof = require('@babel/runtime/helpers/typeof');
8
- var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
9
- var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
10
6
  var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
11
7
  var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
12
8
  var _createClass = require('@babel/runtime/helpers/createClass');
13
9
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
14
10
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
11
+ var _extends = require('@babel/runtime/helpers/extends');
12
+ var _typeof = require('@babel/runtime/helpers/typeof');
13
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
14
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
15
15
  var axios = require('axios');
16
16
  var https = require('https');
17
17
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
@@ -27,15 +27,15 @@ var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
27
27
 
28
28
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
29
29
 
30
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
31
- var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
32
- var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
33
- var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
34
30
  var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
35
31
  var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
36
32
  var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
37
33
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
38
34
  var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
35
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
36
+ var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
37
+ var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
38
+ var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
39
39
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
40
40
  var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
41
41
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
@@ -122,15 +122,220 @@ var decodeBase64 = function decodeBase64(s) {
122
122
  return r;
123
123
  };
124
124
 
125
- function ownKeys$b(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; }
125
+ var Campaign = /*#__PURE__*/function () {
126
+ function Campaign(client, id, data) {
127
+ _classCallCheck__default['default'](this, Campaign);
126
128
 
127
- function _objectSpread$b(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$b(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$b(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
129
+ _defineProperty__default['default'](this, "id", void 0);
128
130
 
129
- function _createForOfIteratorHelper$4(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$4(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; } } }; }
131
+ _defineProperty__default['default'](this, "data", void 0);
130
132
 
131
- function _unsupportedIterableToArray$4(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$4(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$4(o, minLen); }
133
+ _defineProperty__default['default'](this, "client", void 0);
132
134
 
133
- function _arrayLikeToArray$4(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
135
+ this.client = client;
136
+ this.id = id;
137
+ this.data = data;
138
+ }
139
+
140
+ _createClass__default['default'](Campaign, [{
141
+ key: "create",
142
+ value: function () {
143
+ var _create = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
144
+ var _this$data, _this$data2, _this$data3, _this$data4, _this$data5, _this$data6, _this$data7, _this$data8;
145
+
146
+ var body, result;
147
+ return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
148
+ while (1) {
149
+ switch (_context.prev = _context.next) {
150
+ case 0:
151
+ body = {
152
+ id: this.id,
153
+ message_template: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.message_template,
154
+ segment_ids: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.segment_ids,
155
+ sender_id: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.sender_id,
156
+ channel_template: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.channel_template,
157
+ create_channels: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.create_channels,
158
+ description: (_this$data6 = this.data) === null || _this$data6 === void 0 ? void 0 : _this$data6.description,
159
+ name: (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.name,
160
+ user_ids: (_this$data8 = this.data) === null || _this$data8 === void 0 ? void 0 : _this$data8.user_ids
161
+ };
162
+ _context.next = 3;
163
+ return this.client.createCampaign(body);
164
+
165
+ case 3:
166
+ result = _context.sent;
167
+ this.id = result.campaign.id;
168
+ this.data = result.campaign;
169
+ return _context.abrupt("return", result);
170
+
171
+ case 7:
172
+ case "end":
173
+ return _context.stop();
174
+ }
175
+ }
176
+ }, _callee, this);
177
+ }));
178
+
179
+ function create() {
180
+ return _create.apply(this, arguments);
181
+ }
182
+
183
+ return create;
184
+ }()
185
+ }, {
186
+ key: "verifyCampaignId",
187
+ value: function verifyCampaignId() {
188
+ if (!this.id) {
189
+ throw new Error('Campaign id is missing. Either create the campaign using campaign.create() or set the id during instantiation - const campaign = client.campaign(id)');
190
+ }
191
+ }
192
+ }, {
193
+ key: "start",
194
+ value: function () {
195
+ var _start = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(options) {
196
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
197
+ while (1) {
198
+ switch (_context2.prev = _context2.next) {
199
+ case 0:
200
+ this.verifyCampaignId();
201
+ _context2.next = 3;
202
+ return this.client.startCampaign(this.id, options);
203
+
204
+ case 3:
205
+ return _context2.abrupt("return", _context2.sent);
206
+
207
+ case 4:
208
+ case "end":
209
+ return _context2.stop();
210
+ }
211
+ }
212
+ }, _callee2, this);
213
+ }));
214
+
215
+ function start(_x) {
216
+ return _start.apply(this, arguments);
217
+ }
218
+
219
+ return start;
220
+ }()
221
+ }, {
222
+ key: "update",
223
+ value: function () {
224
+ var _update = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(data) {
225
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
226
+ while (1) {
227
+ switch (_context3.prev = _context3.next) {
228
+ case 0:
229
+ this.verifyCampaignId();
230
+ return _context3.abrupt("return", this.client.updateCampaign(this.id, data));
231
+
232
+ case 2:
233
+ case "end":
234
+ return _context3.stop();
235
+ }
236
+ }
237
+ }, _callee3, this);
238
+ }));
239
+
240
+ function update(_x2) {
241
+ return _update.apply(this, arguments);
242
+ }
243
+
244
+ return update;
245
+ }()
246
+ }, {
247
+ key: "delete",
248
+ value: function () {
249
+ var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
250
+ return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
251
+ while (1) {
252
+ switch (_context4.prev = _context4.next) {
253
+ case 0:
254
+ this.verifyCampaignId();
255
+ _context4.next = 3;
256
+ return this.client.deleteCampaign(this.id);
257
+
258
+ case 3:
259
+ return _context4.abrupt("return", _context4.sent);
260
+
261
+ case 4:
262
+ case "end":
263
+ return _context4.stop();
264
+ }
265
+ }
266
+ }, _callee4, this);
267
+ }));
268
+
269
+ function _delete() {
270
+ return _delete2.apply(this, arguments);
271
+ }
272
+
273
+ return _delete;
274
+ }()
275
+ }, {
276
+ key: "stop",
277
+ value: function () {
278
+ var _stop = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
279
+ return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
280
+ while (1) {
281
+ switch (_context5.prev = _context5.next) {
282
+ case 0:
283
+ this.verifyCampaignId();
284
+ return _context5.abrupt("return", this.client.stopCampaign(this.id));
285
+
286
+ case 2:
287
+ case "end":
288
+ return _context5.stop();
289
+ }
290
+ }
291
+ }, _callee5, this);
292
+ }));
293
+
294
+ function stop() {
295
+ return _stop.apply(this, arguments);
296
+ }
297
+
298
+ return stop;
299
+ }()
300
+ }, {
301
+ key: "get",
302
+ value: function () {
303
+ var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
304
+ return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
305
+ while (1) {
306
+ switch (_context6.prev = _context6.next) {
307
+ case 0:
308
+ this.verifyCampaignId();
309
+ return _context6.abrupt("return", this.client.getCampaign(this.id));
310
+
311
+ case 2:
312
+ case "end":
313
+ return _context6.stop();
314
+ }
315
+ }
316
+ }, _callee6, this);
317
+ }));
318
+
319
+ function get() {
320
+ return _get.apply(this, arguments);
321
+ }
322
+
323
+ return get;
324
+ }()
325
+ }]);
326
+
327
+ return Campaign;
328
+ }();
329
+
330
+ function ownKeys$c(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; }
331
+
332
+ function _objectSpread$c(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$c(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$c(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
333
+
334
+ function _createForOfIteratorHelper$5(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$5(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; } } }; }
335
+
336
+ function _unsupportedIterableToArray$5(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$5(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$5(o, minLen); }
337
+
338
+ function _arrayLikeToArray$5(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
134
339
 
135
340
  /**
136
341
  * logChatPromiseExecution - utility function for logging the execution of a promise..
@@ -215,7 +420,7 @@ function normalizeQuerySort(sort) {
215
420
  var sortFields = [];
216
421
  var sortArr = Array.isArray(sort) ? sort : [sort];
217
422
 
218
- var _iterator = _createForOfIteratorHelper$4(sortArr),
423
+ var _iterator = _createForOfIteratorHelper$5(sortArr),
219
424
  _step;
220
425
 
221
426
  try {
@@ -385,7 +590,7 @@ var axiosParamsSerializer = function axiosParamsSerializer(params) {
385
590
  */
386
591
 
387
592
  function formatMessage(message) {
388
- return _objectSpread$b(_objectSpread$b({}, message), {}, {
593
+ return _objectSpread$c(_objectSpread$c({}, message), {}, {
389
594
  /**
390
595
  * @deprecated please use `html`
391
596
  */
@@ -590,7 +795,7 @@ var messagePaginationCreatedAtAround = function messagePaginationCreatedAtAround
590
795
  returnedPage = _ref3.returnedPage,
591
796
  messagePaginationOptions = _ref3.messagePaginationOptions;
592
797
 
593
- var newPagination = _objectSpread$b({}, parentSet.pagination);
798
+ var newPagination = _objectSpread$c({}, parentSet.pagination);
594
799
 
595
800
  if (!(messagePaginationOptions !== null && messagePaginationOptions !== void 0 && messagePaginationOptions.created_at_around)) return newPagination;
596
801
  var hasPrev;
@@ -655,7 +860,7 @@ var messagePaginationIdAround = function messagePaginationIdAround(_ref5) {
655
860
  returnedPage = _ref5.returnedPage,
656
861
  messagePaginationOptions = _ref5.messagePaginationOptions;
657
862
 
658
- var newPagination = _objectSpread$b({}, parentSet.pagination);
863
+ var newPagination = _objectSpread$c({}, parentSet.pagination);
659
864
 
660
865
  var _ref6 = messagePaginationOptions || {},
661
866
  id_around = _ref6.id_around;
@@ -713,7 +918,7 @@ var messagePaginationLinear = function messagePaginationLinear(_ref8) {
713
918
  returnedPage = _ref8.returnedPage,
714
919
  messagePaginationOptions = _ref8.messagePaginationOptions;
715
920
 
716
- var newPagination = _objectSpread$b({}, parentSet.pagination);
921
+ var newPagination = _objectSpread$c({}, parentSet.pagination);
717
922
 
718
923
  var hasPrev;
719
924
  var hasNext;
@@ -767,9 +972,9 @@ var DEFAULT_MESSAGE_SET_PAGINATION = {
767
972
  hasPrev: true
768
973
  };
769
974
 
770
- function ownKeys$a(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; }
975
+ function ownKeys$b(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; }
771
976
 
772
- function _objectSpread$a(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$a(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$a(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
977
+ function _objectSpread$b(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$b(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$b(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
773
978
 
774
979
  /**
775
980
  * ChannelState - A container class for the channel state.
@@ -842,142 +1047,31 @@ var ChannelState = /*#__PURE__*/function () {
842
1047
  };
843
1048
  });
844
1049
 
845
- _defineProperty__default['default'](this, "updatePollVote", function (pollVote, poll, messageId) {
846
- var _message$poll;
847
-
848
- var message = _this.findMessage(messageId);
849
-
850
- if (!message) return;
851
- if (message.poll_id !== pollVote.poll_id) return;
852
-
853
- var updatedPoll = _objectSpread$a({}, poll);
1050
+ _defineProperty__default['default'](this, "updateUserMessages", function (user) {
1051
+ var _updateUserMessages = function _updateUserMessages(messages, user) {
1052
+ for (var i = 0; i < messages.length; i++) {
1053
+ var _m$user;
854
1054
 
855
- var ownVotes = _toConsumableArray__default['default'](((_message$poll = message.poll) === null || _message$poll === void 0 ? void 0 : _message$poll.own_votes) || []);
1055
+ var m = messages[i];
856
1056
 
857
- if (pollVote.user_id === _this._channel.getClient().userID) {
858
- if (pollVote.option_id && poll.enforce_unique_vote) {
859
- // remove all previous votes where option_id is not empty
860
- ownVotes = ownVotes.filter(function (vote) {
861
- return !vote.option_id;
862
- });
863
- } else if (pollVote.answer_text) {
864
- // remove all previous votes where option_id is empty
865
- ownVotes = ownVotes.filter(function (vote) {
866
- return vote.answer_text;
867
- });
1057
+ if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
1058
+ messages[i] = _objectSpread$b(_objectSpread$b({}, m), {}, {
1059
+ user: user
1060
+ });
1061
+ }
868
1062
  }
1063
+ };
869
1064
 
870
- ownVotes.push(pollVote);
871
- }
872
-
873
- updatedPoll.own_votes = ownVotes;
874
-
875
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
876
- poll: updatedPoll
1065
+ _this.messageSets.forEach(function (set) {
1066
+ return _updateUserMessages(set.messages, user);
877
1067
  });
878
1068
 
879
- _this.addMessageSorted(newMessage, false, false);
880
- });
1069
+ for (var parentId in _this.threads) {
1070
+ _updateUserMessages(_this.threads[parentId], user);
1071
+ }
881
1072
 
882
- _defineProperty__default['default'](this, "addPollVote", function (pollVote, poll, messageId) {
883
- var _message$poll2;
884
-
885
- var message = _this.findMessage(messageId);
886
-
887
- if (!message) return;
888
- if (message.poll_id !== pollVote.poll_id) return;
889
-
890
- var updatedPoll = _objectSpread$a({}, poll);
891
-
892
- var ownVotes = _toConsumableArray__default['default'](((_message$poll2 = message.poll) === null || _message$poll2 === void 0 ? void 0 : _message$poll2.own_votes) || []);
893
-
894
- if (pollVote.user_id === _this._channel.getClient().userID) {
895
- ownVotes.push(pollVote);
896
- }
897
-
898
- updatedPoll.own_votes = ownVotes;
899
-
900
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
901
- poll: updatedPoll
902
- });
903
-
904
- _this.addMessageSorted(newMessage, false, false);
905
- });
906
-
907
- _defineProperty__default['default'](this, "removePollVote", function (pollVote, poll, messageId) {
908
- var _message$poll3;
909
-
910
- var message = _this.findMessage(messageId);
911
-
912
- if (!message) return;
913
- if (message.poll_id !== pollVote.poll_id) return;
914
-
915
- var updatedPoll = _objectSpread$a({}, poll);
916
-
917
- var ownVotes = _toConsumableArray__default['default'](((_message$poll3 = message.poll) === null || _message$poll3 === void 0 ? void 0 : _message$poll3.own_votes) || []);
918
-
919
- if (pollVote.user_id === _this._channel.getClient().userID) {
920
- var index = ownVotes.findIndex(function (vote) {
921
- return vote.option_id === pollVote.option_id;
922
- });
923
-
924
- if (index > -1) {
925
- ownVotes.splice(index, 1);
926
- }
927
- }
928
-
929
- updatedPoll.own_votes = ownVotes;
930
-
931
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
932
- poll: updatedPoll
933
- });
934
-
935
- _this.addMessageSorted(newMessage, false, false);
936
- });
937
-
938
- _defineProperty__default['default'](this, "updatePoll", function (poll, messageId) {
939
- var _message$poll4;
940
-
941
- var message = _this.findMessage(messageId);
942
-
943
- if (!message) return;
944
-
945
- var updatedPoll = _objectSpread$a(_objectSpread$a({}, poll), {}, {
946
- own_votes: _toConsumableArray__default['default'](((_message$poll4 = message.poll) === null || _message$poll4 === void 0 ? void 0 : _message$poll4.own_votes) || [])
947
- });
948
-
949
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
950
- poll: updatedPoll
951
- });
952
-
953
- _this.addMessageSorted(newMessage, false, false);
954
- });
955
-
956
- _defineProperty__default['default'](this, "updateUserMessages", function (user) {
957
- var _updateUserMessages = function _updateUserMessages(messages, user) {
958
- for (var i = 0; i < messages.length; i++) {
959
- var _m$user;
960
-
961
- var m = messages[i];
962
-
963
- if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
964
- messages[i] = _objectSpread$a(_objectSpread$a({}, m), {}, {
965
- user: user
966
- });
967
- }
968
- }
969
- };
970
-
971
- _this.messageSets.forEach(function (set) {
972
- return _updateUserMessages(set.messages, user);
973
- });
974
-
975
- for (var parentId in _this.threads) {
976
- _updateUserMessages(_this.threads[parentId], user);
977
- }
978
-
979
- _updateUserMessages(_this.pinnedMessages, user);
980
- });
1073
+ _updateUserMessages(_this.pinnedMessages, user);
1074
+ });
981
1075
 
982
1076
  _defineProperty__default['default'](this, "deleteUserMessages", function (user) {
983
1077
  var hardDelete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1016,7 +1110,7 @@ var ChannelState = /*#__PURE__*/function () {
1016
1110
  user: m.user
1017
1111
  };
1018
1112
  } else {
1019
- messages[i] = _objectSpread$a(_objectSpread$a({}, m), {}, {
1113
+ messages[i] = _objectSpread$b(_objectSpread$b({}, m), {}, {
1020
1114
  type: 'deleted',
1021
1115
  deleted_at: user.deleted_at ? new Date(user.deleted_at) : null
1022
1116
  });
@@ -1334,7 +1428,7 @@ var ChannelState = /*#__PURE__*/function () {
1334
1428
  var parseMessage = function parseMessage(m) {
1335
1429
  var _m$pinned_at, _m$updated_at;
1336
1430
 
1337
- return _objectSpread$a(_objectSpread$a({}, m), {}, {
1431
+ return _objectSpread$b(_objectSpread$b({}, m), {}, {
1338
1432
  created_at: m.created_at.toISOString(),
1339
1433
  pinned_at: (_m$pinned_at = m.pinned_at) === null || _m$pinned_at === void 0 ? void 0 : _m$pinned_at.toISOString(),
1340
1434
  updated_at: (_m$updated_at = m.updated_at) === null || _m$updated_at === void 0 ? void 0 : _m$updated_at.toISOString()
@@ -1344,8 +1438,8 @@ var ChannelState = /*#__PURE__*/function () {
1344
1438
  var update = function update(messages) {
1345
1439
  var updatedMessages = messages.reduce(function (acc, msg) {
1346
1440
  if (msg.quoted_message_id === message.id) {
1347
- acc.push(_objectSpread$a(_objectSpread$a({}, parseMessage(msg)), {}, {
1348
- quoted_message: remove ? _objectSpread$a(_objectSpread$a({}, message), {}, {
1441
+ acc.push(_objectSpread$b(_objectSpread$b({}, parseMessage(msg)), {}, {
1442
+ quoted_message: remove ? _objectSpread$b(_objectSpread$b({}, message), {}, {
1349
1443
  attachments: []
1350
1444
  }) : message
1351
1445
  }));
@@ -1828,15 +1922,15 @@ var ChannelState = /*#__PURE__*/function () {
1828
1922
  return ChannelState;
1829
1923
  }();
1830
1924
 
1831
- 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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
1925
+ function _createForOfIteratorHelper$4(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$4(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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
1832
1926
 
1833
- 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); }
1927
+ function _unsupportedIterableToArray$4(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$4(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$4(o, minLen); }
1834
1928
 
1835
- function _arrayLikeToArray$3(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1929
+ function _arrayLikeToArray$4(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
1836
1930
 
1837
- function ownKeys$9(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; }
1931
+ function ownKeys$a(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; }
1838
1932
 
1839
- function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1933
+ function _objectSpread$a(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$a(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$a(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1840
1934
  /**
1841
1935
  * Channel - The Channel class manages it's own state.
1842
1936
  */
@@ -1909,7 +2003,7 @@ var Channel = /*#__PURE__*/function () {
1909
2003
  while (1) {
1910
2004
  switch (_context.prev = _context.next) {
1911
2005
  case 0:
1912
- defaultOptions = _objectSpread$9(_objectSpread$9({}, options), {}, {
2006
+ defaultOptions = _objectSpread$a(_objectSpread$a({}, options), {}, {
1913
2007
  watch: false,
1914
2008
  state: false,
1915
2009
  presence: false
@@ -1981,7 +2075,7 @@ var Channel = /*#__PURE__*/function () {
1981
2075
 
1982
2076
  this.data = data; // this._data is used for the requests...
1983
2077
 
1984
- this._data = _objectSpread$9({}, data);
2078
+ this._data = _objectSpread$a({}, data);
1985
2079
  this.cid = "".concat(type, ":").concat(id);
1986
2080
  this.listeners = {}; // perhaps the state variable should be private
1987
2081
 
@@ -2043,7 +2137,7 @@ var Channel = /*#__PURE__*/function () {
2043
2137
  switch (_context2.prev = _context2.next) {
2044
2138
  case 0:
2045
2139
  _context2.next = 2;
2046
- return this.getClient().post(this._channelURL() + '/message', _objectSpread$9({
2140
+ return this.getClient().post(this._channelURL() + '/message', _objectSpread$a({
2047
2141
  message: message
2048
2142
  }, options));
2049
2143
 
@@ -2159,7 +2253,7 @@ var Channel = /*#__PURE__*/function () {
2159
2253
 
2160
2254
  case 3:
2161
2255
  // Return a list of channels
2162
- payload = _objectSpread$9(_objectSpread$9({
2256
+ payload = _objectSpread$a(_objectSpread$a({
2163
2257
  filter_conditions: {
2164
2258
  cid: this.cid
2165
2259
  }
@@ -2256,7 +2350,7 @@ var Channel = /*#__PURE__*/function () {
2256
2350
 
2257
2351
  _context5.next = 6;
2258
2352
  return this.getClient().get(this.getClient().baseURL + '/members', {
2259
- payload: _objectSpread$9({
2353
+ payload: _objectSpread$a({
2260
2354
  type: type,
2261
2355
  id: id,
2262
2356
  members: members,
@@ -2362,7 +2456,7 @@ var Channel = /*#__PURE__*/function () {
2362
2456
 
2363
2457
  case 4:
2364
2458
  _context7.next = 6;
2365
- return this.getClient().post(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(messageID), "/reaction"), _objectSpread$9({
2459
+ return this.getClient().post(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(messageID), "/reaction"), _objectSpread$a({
2366
2460
  reaction: reaction
2367
2461
  }, options));
2368
2462
 
@@ -2443,7 +2537,7 @@ var Channel = /*#__PURE__*/function () {
2443
2537
  delete channelData[key];
2444
2538
  });
2445
2539
  _context8.next = 7;
2446
- return this._update(_objectSpread$9({
2540
+ return this._update(_objectSpread$a({
2447
2541
  message: updateMessage,
2448
2542
  data: channelData
2449
2543
  }, options));
@@ -2615,7 +2709,7 @@ var Channel = /*#__PURE__*/function () {
2615
2709
  case 0:
2616
2710
  options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
2617
2711
  _context12.next = 3;
2618
- return this.getClient().delete(this._channelURL(), _objectSpread$9({}, options));
2712
+ return this.getClient().delete(this._channelURL(), _objectSpread$a({}, options));
2619
2713
 
2620
2714
  case 3:
2621
2715
  return _context12.abrupt("return", _context12.sent);
@@ -2691,7 +2785,7 @@ var Channel = /*#__PURE__*/function () {
2691
2785
  case 0:
2692
2786
  options = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
2693
2787
  _context14.next = 3;
2694
- return this._update(_objectSpread$9({
2788
+ return this._update(_objectSpread$a({
2695
2789
  accept_invite: true
2696
2790
  }, options));
2697
2791
 
@@ -2732,7 +2826,7 @@ var Channel = /*#__PURE__*/function () {
2732
2826
  case 0:
2733
2827
  options = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
2734
2828
  _context15.next = 3;
2735
- return this._update(_objectSpread$9({
2829
+ return this._update(_objectSpread$a({
2736
2830
  reject_invite: true
2737
2831
  }, options));
2738
2832
 
@@ -2774,7 +2868,7 @@ var Channel = /*#__PURE__*/function () {
2774
2868
  case 0:
2775
2869
  options = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : {};
2776
2870
  _context16.next = 3;
2777
- return this._update(_objectSpread$9({
2871
+ return this._update(_objectSpread$a({
2778
2872
  add_members: members,
2779
2873
  message: message
2780
2874
  }, options));
@@ -2817,7 +2911,7 @@ var Channel = /*#__PURE__*/function () {
2817
2911
  case 0:
2818
2912
  options = _args17.length > 2 && _args17[2] !== undefined ? _args17[2] : {};
2819
2913
  _context17.next = 3;
2820
- return this._update(_objectSpread$9({
2914
+ return this._update(_objectSpread$a({
2821
2915
  add_moderators: members,
2822
2916
  message: message
2823
2917
  }, options));
@@ -2860,7 +2954,7 @@ var Channel = /*#__PURE__*/function () {
2860
2954
  case 0:
2861
2955
  options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
2862
2956
  _context18.next = 3;
2863
- return this._update(_objectSpread$9({
2957
+ return this._update(_objectSpread$a({
2864
2958
  assign_roles: roles,
2865
2959
  message: message
2866
2960
  }, options));
@@ -2903,7 +2997,7 @@ var Channel = /*#__PURE__*/function () {
2903
2997
  case 0:
2904
2998
  options = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {};
2905
2999
  _context19.next = 3;
2906
- return this._update(_objectSpread$9({
3000
+ return this._update(_objectSpread$a({
2907
3001
  invites: members,
2908
3002
  message: message
2909
3003
  }, options));
@@ -2946,7 +3040,7 @@ var Channel = /*#__PURE__*/function () {
2946
3040
  case 0:
2947
3041
  options = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2948
3042
  _context20.next = 3;
2949
- return this._update(_objectSpread$9({
3043
+ return this._update(_objectSpread$a({
2950
3044
  remove_members: members,
2951
3045
  message: message
2952
3046
  }, options));
@@ -2989,7 +3083,7 @@ var Channel = /*#__PURE__*/function () {
2989
3083
  case 0:
2990
3084
  options = _args21.length > 2 && _args21[2] !== undefined ? _args21[2] : {};
2991
3085
  _context21.next = 3;
2992
- return this._update(_objectSpread$9({
3086
+ return this._update(_objectSpread$a({
2993
3087
  demote_moderators: members,
2994
3088
  message: message
2995
3089
  }, options));
@@ -3074,7 +3168,7 @@ var Channel = /*#__PURE__*/function () {
3074
3168
  case 0:
3075
3169
  opts = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
3076
3170
  _context23.next = 3;
3077
- return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$9({
3171
+ return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$a({
3078
3172
  channel_cid: this.cid
3079
3173
  }, opts));
3080
3174
 
@@ -3116,7 +3210,7 @@ var Channel = /*#__PURE__*/function () {
3116
3210
  case 0:
3117
3211
  opts = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
3118
3212
  _context24.next = 3;
3119
- return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$9({
3213
+ return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$a({
3120
3214
  channel_cid: this.cid
3121
3215
  }, opts));
3122
3216
 
@@ -3201,7 +3295,7 @@ var Channel = /*#__PURE__*/function () {
3201
3295
 
3202
3296
  this.lastTypingEvent = new Date();
3203
3297
  _context25.next = 10;
3204
- return this.sendEvent(_objectSpread$9({
3298
+ return this.sendEvent(_objectSpread$a({
3205
3299
  type: 'typing.start',
3206
3300
  parent_id: parent_id
3207
3301
  }, options || {}));
@@ -3245,7 +3339,7 @@ var Channel = /*#__PURE__*/function () {
3245
3339
  this.lastTypingEvent = null;
3246
3340
  this.isTyping = false;
3247
3341
  _context26.next = 6;
3248
- return this.sendEvent(_objectSpread$9({
3342
+ return this.sendEvent(_objectSpread$a({
3249
3343
  type: 'typing.stop',
3250
3344
  parent_id: parent_id
3251
3345
  }, options || {}));
@@ -3332,7 +3426,7 @@ var Channel = /*#__PURE__*/function () {
3332
3426
 
3333
3427
  case 4:
3334
3428
  _context27.next = 6;
3335
- return this.getClient().post(this._channelURL() + '/read', _objectSpread$9({}, data));
3429
+ return this.getClient().post(this._channelURL() + '/read', _objectSpread$a({}, data));
3336
3430
 
3337
3431
  case 6:
3338
3432
  return _context27.abrupt("return", _context27.sent);
@@ -3379,7 +3473,7 @@ var Channel = /*#__PURE__*/function () {
3379
3473
 
3380
3474
  case 3:
3381
3475
  _context28.next = 5;
3382
- return this.getClient().post(this._channelURL() + '/unread', _objectSpread$9({}, data));
3476
+ return this.getClient().post(this._channelURL() + '/unread', _objectSpread$a({}, data));
3383
3477
 
3384
3478
  case 5:
3385
3479
  return _context28.abrupt("return", _context28.sent);
@@ -3447,7 +3541,7 @@ var Channel = /*#__PURE__*/function () {
3447
3541
  defaultOptions.watch = false;
3448
3542
  }
3449
3543
 
3450
- combined = _objectSpread$9(_objectSpread$9({}, defaultOptions), options);
3544
+ combined = _objectSpread$a(_objectSpread$a({}, defaultOptions), options);
3451
3545
  _context29.next = 7;
3452
3546
  return this.query(combined, 'latest');
3453
3547
 
@@ -3541,7 +3635,7 @@ var Channel = /*#__PURE__*/function () {
3541
3635
  case 0:
3542
3636
  normalizedSort = sort ? normalizeQuerySort(sort) : undefined;
3543
3637
  _context31.next = 3;
3544
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(parent_id), "/replies"), _objectSpread$9({
3638
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(parent_id), "/replies"), _objectSpread$a({
3545
3639
  sort: normalizedSort
3546
3640
  }, options));
3547
3641
 
@@ -3591,7 +3685,7 @@ var Channel = /*#__PURE__*/function () {
3591
3685
  sort = _args32.length > 1 && _args32[1] !== undefined ? _args32[1] : [];
3592
3686
  _context32.next = 3;
3593
3687
  return this.getClient().get(this._channelURL() + '/pinned_messages', {
3594
- payload: _objectSpread$9(_objectSpread$9({}, options), {}, {
3688
+ payload: _objectSpread$a(_objectSpread$a({}, options), {}, {
3595
3689
  sort: normalizeQuerySort(sort)
3596
3690
  })
3597
3691
  });
@@ -3625,7 +3719,7 @@ var Channel = /*#__PURE__*/function () {
3625
3719
  }, {
3626
3720
  key: "getReactions",
3627
3721
  value: function getReactions(message_id, options) {
3628
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(message_id), "/reactions"), _objectSpread$9({}, options));
3722
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(message_id), "/reactions"), _objectSpread$a({}, options));
3629
3723
  }
3630
3724
  /**
3631
3725
  * getMessagesById - Retrieves a list of messages by ID
@@ -3772,7 +3866,7 @@ var Channel = /*#__PURE__*/function () {
3772
3866
  }
3773
3867
 
3774
3868
  _context33.next = 7;
3775
- return this.getClient().post(queryURL + '/query', _objectSpread$9({
3869
+ return this.getClient().post(queryURL + '/query', _objectSpread$a({
3776
3870
  data: this._data,
3777
3871
  state: true
3778
3872
  }, options));
@@ -3807,13 +3901,14 @@ var Channel = /*#__PURE__*/function () {
3807
3901
 
3808
3902
 
3809
3903
  _this$_initializeStat = this._initializeState(state, messageSetToAddToIfDoesNotExist), messageSet = _this$_initializeStat.messageSet;
3810
- messageSet.pagination = _objectSpread$9(_objectSpread$9({}, messageSet.pagination), messageSetPagination({
3904
+ messageSet.pagination = _objectSpread$a(_objectSpread$a({}, messageSet.pagination), messageSetPagination({
3811
3905
  parentSet: messageSet,
3812
3906
  messagePaginationOptions: options === null || options === void 0 ? void 0 : options.messages,
3813
3907
  requestedPageSize: (_options$messages$lim = options === null || options === void 0 ? void 0 : (_options$messages = options.messages) === null || _options$messages === void 0 ? void 0 : _options$messages.limit) !== null && _options$messages$lim !== void 0 ? _options$messages$lim : DEFAULT_QUERY_CHANNEL_MESSAGE_LIST_PAGE_SIZE,
3814
3908
  returnedPage: state.messages,
3815
3909
  logger: this.getClient().logger
3816
3910
  }));
3911
+ this.getClient().polls.hydratePollCache(messageSet.messages, true);
3817
3912
  areCapabilitiesChanged = _toConsumableArray__default['default'](state.channel.own_capabilities || []).sort().join() !== _toConsumableArray__default['default'](Array.isArray((_this$data6 = this.data) === null || _this$data6 === void 0 ? void 0 : _this$data6.own_capabilities) ? (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.own_capabilities : []).sort().join();
3818
3913
  this.data = state.channel;
3819
3914
  this.offlineMode = false;
@@ -3835,7 +3930,7 @@ var Channel = /*#__PURE__*/function () {
3835
3930
  });
3836
3931
  return _context33.abrupt("return", state);
3837
3932
 
3838
- case 18:
3933
+ case 19:
3839
3934
  case "end":
3840
3935
  return _context33.stop();
3841
3936
  }
@@ -3868,7 +3963,7 @@ var Channel = /*#__PURE__*/function () {
3868
3963
  this._checkInitialized();
3869
3964
 
3870
3965
  _context34.next = 3;
3871
- return this.getClient().banUser(targetUserID, _objectSpread$9(_objectSpread$9({}, options), {}, {
3966
+ return this.getClient().banUser(targetUserID, _objectSpread$a(_objectSpread$a({}, options), {}, {
3872
3967
  type: this.type,
3873
3968
  id: this.id
3874
3969
  }));
@@ -4040,7 +4135,7 @@ var Channel = /*#__PURE__*/function () {
4040
4135
  this._checkInitialized();
4041
4136
 
4042
4137
  _context38.next = 3;
4043
- return this.getClient().shadowBan(targetUserID, _objectSpread$9(_objectSpread$9({}, options), {}, {
4138
+ return this.getClient().shadowBan(targetUserID, _objectSpread$a(_objectSpread$a({}, options), {}, {
4044
4139
  type: this.type,
4045
4140
  id: this.id
4046
4141
  }));
@@ -4494,7 +4589,7 @@ var Channel = /*#__PURE__*/function () {
4494
4589
  });
4495
4590
  }
4496
4591
 
4497
- channel.data = _objectSpread$9(_objectSpread$9({}, event.channel), {}, {
4592
+ channel.data = _objectSpread$a(_objectSpread$a({}, event.channel), {}, {
4498
4593
  hidden: (_event$channel$hidden = (_event$channel3 = event.channel) === null || _event$channel3 === void 0 ? void 0 : _event$channel3.hidden) !== null && _event$channel$hidden !== void 0 ? _event$channel$hidden : (_channel$data2 = channel.data) === null || _channel$data2 === void 0 ? void 0 : _channel$data2.hidden,
4499
4594
  own_capabilities: (_event$channel$own_ca = (_event$channel4 = event.channel) === null || _event$channel4 === void 0 ? void 0 : _event$channel4.own_capabilities) !== null && _event$channel$own_ca !== void 0 ? _event$channel$own_ca : (_channel$data3 = channel.data) === null || _channel$data3 === void 0 ? void 0 : _channel$data3.own_capabilities
4500
4595
  });
@@ -4502,49 +4597,6 @@ var Channel = /*#__PURE__*/function () {
4502
4597
 
4503
4598
  break;
4504
4599
 
4505
- case 'poll.updated':
4506
- if (event.poll) {
4507
- var _event$message;
4508
-
4509
- channelState.updatePoll(event.poll, ((_event$message = event.message) === null || _event$message === void 0 ? void 0 : _event$message.id) || '');
4510
- }
4511
-
4512
- break;
4513
-
4514
- case 'poll.vote_casted':
4515
- if (event.poll_vote && event.poll) {
4516
- var _event$message2;
4517
-
4518
- channelState.addPollVote(event.poll_vote, event.poll, ((_event$message2 = event.message) === null || _event$message2 === void 0 ? void 0 : _event$message2.id) || '');
4519
- }
4520
-
4521
- break;
4522
-
4523
- case 'poll.vote_changed':
4524
- if (event.poll_vote && event.poll) {
4525
- var _event$message3;
4526
-
4527
- channelState.updatePollVote(event.poll_vote, event.poll, ((_event$message3 = event.message) === null || _event$message3 === void 0 ? void 0 : _event$message3.id) || '');
4528
- }
4529
-
4530
- break;
4531
-
4532
- case 'poll.vote_removed':
4533
- if (event.poll_vote && event.poll) {
4534
- var _event$message4;
4535
-
4536
- channelState.removePollVote(event.poll_vote, event.poll, ((_event$message4 = event.message) === null || _event$message4 === void 0 ? void 0 : _event$message4.id) || '');
4537
- }
4538
-
4539
- break;
4540
-
4541
- case 'poll.closed':
4542
- if (event.message) {
4543
- channelState.addMessageSorted(event.message, false, false);
4544
- }
4545
-
4546
- break;
4547
-
4548
4600
  case 'reaction.new':
4549
4601
  if (event.message && event.reaction) {
4550
4602
  event.message = channelState.addReaction(event.reaction, event.message);
@@ -4568,7 +4620,7 @@ var Channel = /*#__PURE__*/function () {
4568
4620
  break;
4569
4621
 
4570
4622
  case 'channel.hidden':
4571
- channel.data = _objectSpread$9(_objectSpread$9({}, channel.data), {}, {
4623
+ channel.data = _objectSpread$a(_objectSpread$a({}, channel.data), {}, {
4572
4624
  hidden: true
4573
4625
  });
4574
4626
 
@@ -4579,26 +4631,26 @@ var Channel = /*#__PURE__*/function () {
4579
4631
  break;
4580
4632
 
4581
4633
  case 'channel.visible':
4582
- channel.data = _objectSpread$9(_objectSpread$9({}, channel.data), {}, {
4634
+ channel.data = _objectSpread$a(_objectSpread$a({}, channel.data), {}, {
4583
4635
  hidden: false
4584
4636
  });
4585
4637
  break;
4586
4638
 
4587
4639
  case 'user.banned':
4588
4640
  if (!((_event$user11 = event.user) !== null && _event$user11 !== void 0 && _event$user11.id)) break;
4589
- channelState.members[event.user.id] = _objectSpread$9(_objectSpread$9({}, channelState.members[event.user.id] || {}), {}, {
4641
+ channelState.members[event.user.id] = _objectSpread$a(_objectSpread$a({}, channelState.members[event.user.id] || {}), {}, {
4590
4642
  shadow_banned: !!event.shadow,
4591
4643
  banned: !event.shadow,
4592
- user: _objectSpread$9(_objectSpread$9({}, ((_channelState$members = channelState.members[event.user.id]) === null || _channelState$members === void 0 ? void 0 : _channelState$members.user) || {}), event.user)
4644
+ user: _objectSpread$a(_objectSpread$a({}, ((_channelState$members = channelState.members[event.user.id]) === null || _channelState$members === void 0 ? void 0 : _channelState$members.user) || {}), event.user)
4593
4645
  });
4594
4646
  break;
4595
4647
 
4596
4648
  case 'user.unbanned':
4597
4649
  if (!((_event$user12 = event.user) !== null && _event$user12 !== void 0 && _event$user12.id)) break;
4598
- channelState.members[event.user.id] = _objectSpread$9(_objectSpread$9({}, channelState.members[event.user.id] || {}), {}, {
4650
+ channelState.members[event.user.id] = _objectSpread$a(_objectSpread$a({}, channelState.members[event.user.id] || {}), {}, {
4599
4651
  shadow_banned: false,
4600
4652
  banned: false,
4601
- user: _objectSpread$9(_objectSpread$9({}, ((_channelState$members2 = channelState.members[event.user.id]) === null || _channelState$members2 === void 0 ? void 0 : _channelState$members2.user) || {}), event.user)
4653
+ user: _objectSpread$a(_objectSpread$a({}, ((_channelState$members2 = channelState.members[event.user.id]) === null || _channelState$members2 === void 0 ? void 0 : _channelState$members2.user) || {}), event.user)
4602
4654
  });
4603
4655
  break;
4604
4656
  } // any event can send over the online count
@@ -4628,7 +4680,7 @@ var Channel = /*#__PURE__*/function () {
4628
4680
 
4629
4681
 
4630
4682
  if (state.members) {
4631
- var _iterator = _createForOfIteratorHelper$3(state.members),
4683
+ var _iterator = _createForOfIteratorHelper$4(state.members),
4632
4684
  _step;
4633
4685
 
4634
4686
  try {
@@ -4672,7 +4724,7 @@ var Channel = /*#__PURE__*/function () {
4672
4724
 
4673
4725
 
4674
4726
  if (state.watchers) {
4675
- var _iterator2 = _createForOfIteratorHelper$3(state.watchers),
4727
+ var _iterator2 = _createForOfIteratorHelper$4(state.watchers),
4676
4728
  _step2;
4677
4729
 
4678
4730
  try {
@@ -4708,7 +4760,7 @@ var Channel = /*#__PURE__*/function () {
4708
4760
 
4709
4761
 
4710
4762
  if (state.read) {
4711
- var _iterator3 = _createForOfIteratorHelper$3(state.read),
4763
+ var _iterator3 = _createForOfIteratorHelper$4(state.read),
4712
4764
  _step3;
4713
4765
 
4714
4766
  try {
@@ -4782,11 +4834,11 @@ var Channel = /*#__PURE__*/function () {
4782
4834
  return Channel;
4783
4835
  }();
4784
4836
 
4785
- function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4837
+ 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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4786
4838
 
4787
- function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(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$2(o, minLen); }
4839
+ 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); }
4788
4840
 
4789
- function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
4841
+ function _arrayLikeToArray$3(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
4790
4842
 
4791
4843
  /**
4792
4844
  * ClientState - A container class for the client state.
@@ -4809,7 +4861,7 @@ var ClientState = /*#__PURE__*/function () {
4809
4861
  _createClass__default['default'](ClientState, [{
4810
4862
  key: "updateUsers",
4811
4863
  value: function updateUsers(users) {
4812
- var _iterator = _createForOfIteratorHelper$2(users),
4864
+ var _iterator = _createForOfIteratorHelper$3(users),
4813
4865
  _step;
4814
4866
 
4815
4867
  try {
@@ -4857,9 +4909,9 @@ var ClientState = /*#__PURE__*/function () {
4857
4909
  return ClientState;
4858
4910
  }();
4859
4911
 
4860
- function ownKeys$8(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; }
4912
+ function ownKeys$9(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; }
4861
4913
 
4862
- function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4914
+ function _objectSpread$9(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$9(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$9(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4863
4915
  var InsightMetrics = function InsightMetrics() {
4864
4916
  _classCallCheck__default['default'](this, InsightMetrics);
4865
4917
 
@@ -4938,7 +4990,7 @@ var postInsights = /*#__PURE__*/function () {
4938
4990
  };
4939
4991
  }();
4940
4992
  function buildWsFatalInsight(connection, event) {
4941
- return _objectSpread$8(_objectSpread$8({}, event), buildWsBaseInsight(connection));
4993
+ return _objectSpread$9(_objectSpread$9({}, event), buildWsBaseInsight(connection));
4942
4994
  }
4943
4995
 
4944
4996
  function buildWsBaseInsight(connection) {
@@ -4971,9 +5023,9 @@ function buildWsSuccessAfterFailureInsight(connection) {
4971
5023
  return buildWsBaseInsight(connection);
4972
5024
  }
4973
5025
 
4974
- 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; }
5026
+ function ownKeys$8(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; }
4975
5027
 
4976
- 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__default['default'](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; }
5028
+ function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$8(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4977
5029
 
4978
5030
  // Type guards to check WebSocket error type
4979
5031
  var isCloseEvent = function isCloseEvent(res) {
@@ -5337,7 +5389,7 @@ var StableWSConnection = /*#__PURE__*/function () {
5337
5389
  value: function _log(msg) {
5338
5390
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5339
5391
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
5340
- this.client.logger(level, 'connection:' + msg, _objectSpread$7({
5392
+ this.client.logger(level, 'connection:' + msg, _objectSpread$8({
5341
5393
  tags: ['connection']
5342
5394
  }, extra));
5343
5395
  }
@@ -5928,9 +5980,9 @@ var StableWSConnection = /*#__PURE__*/function () {
5928
5980
  return StableWSConnection;
5929
5981
  }();
5930
5982
 
5931
- 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; }
5983
+ 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; }
5932
5984
 
5933
- 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__default['default'](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; }
5985
+ 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__default['default'](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; }
5934
5986
 
5935
5987
  /**
5936
5988
  * Creates the JWT token that can be used for a UserSession
@@ -5951,7 +6003,7 @@ function JWTUserToken(apiSecret, userId) {
5951
6003
  throw new TypeError('userId should be a string');
5952
6004
  }
5953
6005
 
5954
- var payload = _objectSpread$6({
6006
+ var payload = _objectSpread$7({
5955
6007
  user_id: userId
5956
6008
  }, extraData); // make sure we return a clear error when jwt is shimmed (ie. browser build)
5957
6009
 
@@ -6361,9 +6413,9 @@ function isErrorResponse(res) {
6361
6413
  return !res.status || res.status < 200 || 300 <= res.status;
6362
6414
  }
6363
6415
 
6364
- function ownKeys$5(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; }
6416
+ 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; }
6365
6417
 
6366
- function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6418
+ 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__default['default'](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; }
6367
6419
  var ConnectionState;
6368
6420
 
6369
6421
  (function (ConnectionState) {
@@ -6426,7 +6478,7 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6426
6478
  _context.next = 4;
6427
6479
  return _this.client.doAxiosRequest('get', _this.client.baseURL.replace(':3030', ':8900') + '/longpoll', // replace port if present for testing with local API
6428
6480
  undefined, {
6429
- config: _objectSpread$5(_objectSpread$5({}, config), {}, {
6481
+ config: _objectSpread$6(_objectSpread$6({}, config), {}, {
6430
6482
  cancelToken: (_this$cancelToken2 = _this.cancelToken) === null || _this$cancelToken2 === void 0 ? void 0 : _this$cancelToken2.token
6431
6483
  }),
6432
6484
  params: params
@@ -6704,7 +6756,7 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6704
6756
  value: function _log(msg) {
6705
6757
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6706
6758
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
6707
- this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$5({
6759
+ this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$6({
6708
6760
  tags: ['connection_fallback', 'connection']
6709
6761
  }, extra));
6710
6762
  }
@@ -6737,53 +6789,45 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6737
6789
  return WSConnectionFallback;
6738
6790
  }();
6739
6791
 
6740
- var Campaign = /*#__PURE__*/function () {
6741
- function Campaign(client, id, data) {
6742
- _classCallCheck__default['default'](this, Campaign);
6792
+ var Segment = /*#__PURE__*/function () {
6793
+ function Segment(client, type, id, data) {
6794
+ _classCallCheck__default['default'](this, Segment);
6743
6795
 
6744
- _defineProperty__default['default'](this, "id", void 0);
6796
+ _defineProperty__default['default'](this, "type", void 0);
6745
6797
 
6746
- _defineProperty__default['default'](this, "data", void 0);
6798
+ _defineProperty__default['default'](this, "id", void 0);
6747
6799
 
6748
6800
  _defineProperty__default['default'](this, "client", void 0);
6749
6801
 
6802
+ _defineProperty__default['default'](this, "data", void 0);
6803
+
6750
6804
  this.client = client;
6805
+ this.type = type;
6751
6806
  this.id = id;
6752
6807
  this.data = data;
6753
6808
  }
6754
6809
 
6755
- _createClass__default['default'](Campaign, [{
6810
+ _createClass__default['default'](Segment, [{
6756
6811
  key: "create",
6757
6812
  value: function () {
6758
6813
  var _create = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
6759
- var _this$data, _this$data2, _this$data3, _this$data4, _this$data5, _this$data6, _this$data7, _this$data8;
6814
+ var _this$data, _this$data2, _this$data3, _this$data4, _this$data5;
6760
6815
 
6761
- var body, result;
6816
+ var body;
6762
6817
  return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
6763
6818
  while (1) {
6764
6819
  switch (_context.prev = _context.next) {
6765
6820
  case 0:
6766
6821
  body = {
6767
- id: this.id,
6768
- message_template: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.message_template,
6769
- segment_ids: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.segment_ids,
6770
- sender_id: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.sender_id,
6771
- channel_template: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.channel_template,
6772
- create_channels: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.create_channels,
6773
- description: (_this$data6 = this.data) === null || _this$data6 === void 0 ? void 0 : _this$data6.description,
6774
- name: (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.name,
6775
- user_ids: (_this$data8 = this.data) === null || _this$data8 === void 0 ? void 0 : _this$data8.user_ids
6822
+ name: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.name,
6823
+ filter: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.filter,
6824
+ description: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.description,
6825
+ all_sender_channels: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.all_sender_channels,
6826
+ all_users: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.all_users
6776
6827
  };
6777
- _context.next = 3;
6778
- return this.client.createCampaign(body);
6779
-
6780
- case 3:
6781
- result = _context.sent;
6782
- this.id = result.campaign.id;
6783
- this.data = result.campaign;
6784
- return _context.abrupt("return", result);
6828
+ return _context.abrupt("return", this.client.createSegment(this.type, this.id, body));
6785
6829
 
6786
- case 7:
6830
+ case 2:
6787
6831
  case "end":
6788
6832
  return _context.stop();
6789
6833
  }
@@ -6798,28 +6842,24 @@ var Campaign = /*#__PURE__*/function () {
6798
6842
  return create;
6799
6843
  }()
6800
6844
  }, {
6801
- key: "verifyCampaignId",
6802
- value: function verifyCampaignId() {
6845
+ key: "verifySegmentId",
6846
+ value: function verifySegmentId() {
6803
6847
  if (!this.id) {
6804
- throw new Error('Campaign id is missing. Either create the campaign using campaign.create() or set the id during instantiation - const campaign = client.campaign(id)');
6848
+ throw new Error('Segment id is missing. Either create the segment using segment.create() or set the id during instantiation - const segment = client.segment(id)');
6805
6849
  }
6806
6850
  }
6807
6851
  }, {
6808
- key: "start",
6852
+ key: "get",
6809
6853
  value: function () {
6810
- var _start = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(options) {
6854
+ var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
6811
6855
  return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
6812
6856
  while (1) {
6813
6857
  switch (_context2.prev = _context2.next) {
6814
6858
  case 0:
6815
- this.verifyCampaignId();
6816
- _context2.next = 3;
6817
- return this.client.startCampaign(this.id, options);
6818
-
6819
- case 3:
6820
- return _context2.abrupt("return", _context2.sent);
6859
+ this.verifySegmentId();
6860
+ return _context2.abrupt("return", this.client.getSegment(this.id));
6821
6861
 
6822
- case 4:
6862
+ case 2:
6823
6863
  case "end":
6824
6864
  return _context2.stop();
6825
6865
  }
@@ -6827,11 +6867,11 @@ var Campaign = /*#__PURE__*/function () {
6827
6867
  }, _callee2, this);
6828
6868
  }));
6829
6869
 
6830
- function start(_x) {
6831
- return _start.apply(this, arguments);
6870
+ function get() {
6871
+ return _get.apply(this, arguments);
6832
6872
  }
6833
6873
 
6834
- return start;
6874
+ return get;
6835
6875
  }()
6836
6876
  }, {
6837
6877
  key: "update",
@@ -6841,8 +6881,8 @@ var Campaign = /*#__PURE__*/function () {
6841
6881
  while (1) {
6842
6882
  switch (_context3.prev = _context3.next) {
6843
6883
  case 0:
6844
- this.verifyCampaignId();
6845
- return _context3.abrupt("return", this.client.updateCampaign(this.id, data));
6884
+ this.verifySegmentId();
6885
+ return _context3.abrupt("return", this.client.updateSegment(this.id, data));
6846
6886
 
6847
6887
  case 2:
6848
6888
  case "end":
@@ -6852,28 +6892,24 @@ var Campaign = /*#__PURE__*/function () {
6852
6892
  }, _callee3, this);
6853
6893
  }));
6854
6894
 
6855
- function update(_x2) {
6895
+ function update(_x) {
6856
6896
  return _update.apply(this, arguments);
6857
6897
  }
6858
6898
 
6859
6899
  return update;
6860
6900
  }()
6861
6901
  }, {
6862
- key: "delete",
6902
+ key: "addTargets",
6863
6903
  value: function () {
6864
- var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
6904
+ var _addTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(targets) {
6865
6905
  return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
6866
6906
  while (1) {
6867
6907
  switch (_context4.prev = _context4.next) {
6868
6908
  case 0:
6869
- this.verifyCampaignId();
6870
- _context4.next = 3;
6871
- return this.client.deleteCampaign(this.id);
6872
-
6873
- case 3:
6874
- return _context4.abrupt("return", _context4.sent);
6909
+ this.verifySegmentId();
6910
+ return _context4.abrupt("return", this.client.addSegmentTargets(this.id, targets));
6875
6911
 
6876
- case 4:
6912
+ case 2:
6877
6913
  case "end":
6878
6914
  return _context4.stop();
6879
6915
  }
@@ -6881,22 +6917,22 @@ var Campaign = /*#__PURE__*/function () {
6881
6917
  }, _callee4, this);
6882
6918
  }));
6883
6919
 
6884
- function _delete() {
6885
- return _delete2.apply(this, arguments);
6920
+ function addTargets(_x2) {
6921
+ return _addTargets.apply(this, arguments);
6886
6922
  }
6887
6923
 
6888
- return _delete;
6924
+ return addTargets;
6889
6925
  }()
6890
6926
  }, {
6891
- key: "stop",
6927
+ key: "removeTargets",
6892
6928
  value: function () {
6893
- var _stop = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
6929
+ var _removeTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(targets) {
6894
6930
  return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
6895
6931
  while (1) {
6896
6932
  switch (_context5.prev = _context5.next) {
6897
6933
  case 0:
6898
- this.verifyCampaignId();
6899
- return _context5.abrupt("return", this.client.stopCampaign(this.id));
6934
+ this.verifySegmentId();
6935
+ return _context5.abrupt("return", this.client.removeSegmentTargets(this.id, targets));
6900
6936
 
6901
6937
  case 2:
6902
6938
  case "end":
@@ -6906,22 +6942,22 @@ var Campaign = /*#__PURE__*/function () {
6906
6942
  }, _callee5, this);
6907
6943
  }));
6908
6944
 
6909
- function stop() {
6910
- return _stop.apply(this, arguments);
6945
+ function removeTargets(_x3) {
6946
+ return _removeTargets.apply(this, arguments);
6911
6947
  }
6912
6948
 
6913
- return stop;
6949
+ return removeTargets;
6914
6950
  }()
6915
6951
  }, {
6916
- key: "get",
6952
+ key: "delete",
6917
6953
  value: function () {
6918
- var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
6954
+ var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
6919
6955
  return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
6920
6956
  while (1) {
6921
6957
  switch (_context6.prev = _context6.next) {
6922
6958
  case 0:
6923
- this.verifyCampaignId();
6924
- return _context6.abrupt("return", this.client.getCampaign(this.id));
6959
+ this.verifySegmentId();
6960
+ return _context6.abrupt("return", this.client.deleteSegment(this.id));
6925
6961
 
6926
6962
  case 2:
6927
6963
  case "end":
@@ -6931,200 +6967,11 @@ var Campaign = /*#__PURE__*/function () {
6931
6967
  }, _callee6, this);
6932
6968
  }));
6933
6969
 
6934
- function get() {
6935
- return _get.apply(this, arguments);
6970
+ function _delete() {
6971
+ return _delete2.apply(this, arguments);
6936
6972
  }
6937
6973
 
6938
- return get;
6939
- }()
6940
- }]);
6941
-
6942
- return Campaign;
6943
- }();
6944
-
6945
- var Segment = /*#__PURE__*/function () {
6946
- function Segment(client, type, id, data) {
6947
- _classCallCheck__default['default'](this, Segment);
6948
-
6949
- _defineProperty__default['default'](this, "type", void 0);
6950
-
6951
- _defineProperty__default['default'](this, "id", void 0);
6952
-
6953
- _defineProperty__default['default'](this, "client", void 0);
6954
-
6955
- _defineProperty__default['default'](this, "data", void 0);
6956
-
6957
- this.client = client;
6958
- this.type = type;
6959
- this.id = id;
6960
- this.data = data;
6961
- }
6962
-
6963
- _createClass__default['default'](Segment, [{
6964
- key: "create",
6965
- value: function () {
6966
- var _create = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
6967
- var _this$data, _this$data2, _this$data3, _this$data4, _this$data5;
6968
-
6969
- var body;
6970
- return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
6971
- while (1) {
6972
- switch (_context.prev = _context.next) {
6973
- case 0:
6974
- body = {
6975
- name: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.name,
6976
- filter: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.filter,
6977
- description: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.description,
6978
- all_sender_channels: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.all_sender_channels,
6979
- all_users: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.all_users
6980
- };
6981
- return _context.abrupt("return", this.client.createSegment(this.type, this.id, body));
6982
-
6983
- case 2:
6984
- case "end":
6985
- return _context.stop();
6986
- }
6987
- }
6988
- }, _callee, this);
6989
- }));
6990
-
6991
- function create() {
6992
- return _create.apply(this, arguments);
6993
- }
6994
-
6995
- return create;
6996
- }()
6997
- }, {
6998
- key: "verifySegmentId",
6999
- value: function verifySegmentId() {
7000
- if (!this.id) {
7001
- throw new Error('Segment id is missing. Either create the segment using segment.create() or set the id during instantiation - const segment = client.segment(id)');
7002
- }
7003
- }
7004
- }, {
7005
- key: "get",
7006
- value: function () {
7007
- var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
7008
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
7009
- while (1) {
7010
- switch (_context2.prev = _context2.next) {
7011
- case 0:
7012
- this.verifySegmentId();
7013
- return _context2.abrupt("return", this.client.getSegment(this.id));
7014
-
7015
- case 2:
7016
- case "end":
7017
- return _context2.stop();
7018
- }
7019
- }
7020
- }, _callee2, this);
7021
- }));
7022
-
7023
- function get() {
7024
- return _get.apply(this, arguments);
7025
- }
7026
-
7027
- return get;
7028
- }()
7029
- }, {
7030
- key: "update",
7031
- value: function () {
7032
- var _update = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(data) {
7033
- return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
7034
- while (1) {
7035
- switch (_context3.prev = _context3.next) {
7036
- case 0:
7037
- this.verifySegmentId();
7038
- return _context3.abrupt("return", this.client.updateSegment(this.id, data));
7039
-
7040
- case 2:
7041
- case "end":
7042
- return _context3.stop();
7043
- }
7044
- }
7045
- }, _callee3, this);
7046
- }));
7047
-
7048
- function update(_x) {
7049
- return _update.apply(this, arguments);
7050
- }
7051
-
7052
- return update;
7053
- }()
7054
- }, {
7055
- key: "addTargets",
7056
- value: function () {
7057
- var _addTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(targets) {
7058
- return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
7059
- while (1) {
7060
- switch (_context4.prev = _context4.next) {
7061
- case 0:
7062
- this.verifySegmentId();
7063
- return _context4.abrupt("return", this.client.addSegmentTargets(this.id, targets));
7064
-
7065
- case 2:
7066
- case "end":
7067
- return _context4.stop();
7068
- }
7069
- }
7070
- }, _callee4, this);
7071
- }));
7072
-
7073
- function addTargets(_x2) {
7074
- return _addTargets.apply(this, arguments);
7075
- }
7076
-
7077
- return addTargets;
7078
- }()
7079
- }, {
7080
- key: "removeTargets",
7081
- value: function () {
7082
- var _removeTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(targets) {
7083
- return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
7084
- while (1) {
7085
- switch (_context5.prev = _context5.next) {
7086
- case 0:
7087
- this.verifySegmentId();
7088
- return _context5.abrupt("return", this.client.removeSegmentTargets(this.id, targets));
7089
-
7090
- case 2:
7091
- case "end":
7092
- return _context5.stop();
7093
- }
7094
- }
7095
- }, _callee5, this);
7096
- }));
7097
-
7098
- function removeTargets(_x3) {
7099
- return _removeTargets.apply(this, arguments);
7100
- }
7101
-
7102
- return removeTargets;
7103
- }()
7104
- }, {
7105
- key: "delete",
7106
- value: function () {
7107
- var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
7108
- return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
7109
- while (1) {
7110
- switch (_context6.prev = _context6.next) {
7111
- case 0:
7112
- this.verifySegmentId();
7113
- return _context6.abrupt("return", this.client.deleteSegment(this.id));
7114
-
7115
- case 2:
7116
- case "end":
7117
- return _context6.stop();
7118
- }
7119
- }
7120
- }, _callee6, this);
7121
- }));
7122
-
7123
- function _delete() {
7124
- return _delete2.apply(this, arguments);
7125
- }
7126
-
7127
- return _delete;
6974
+ return _delete;
7128
6975
  }()
7129
6976
  }, {
7130
6977
  key: "targetExists",
@@ -7284,9 +7131,9 @@ exports.VotingVisibility = void 0;
7284
7131
  VotingVisibility["public"] = "public";
7285
7132
  })(exports.VotingVisibility || (exports.VotingVisibility = {}));
7286
7133
 
7287
- function ownKeys$4(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; }
7134
+ function ownKeys$5(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; }
7288
7135
 
7289
- function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7136
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$5(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7290
7137
 
7291
7138
  function isPatch(value) {
7292
7139
  return typeof value === 'function';
@@ -7316,7 +7163,7 @@ var StateStore = function StateStore(value) {
7316
7163
 
7317
7164
  _defineProperty__default['default'](this, "partialNext", function (partial) {
7318
7165
  return _this.next(function (current) {
7319
- return _objectSpread$4(_objectSpread$4({}, current), partial);
7166
+ return _objectSpread$5(_objectSpread$5({}, current), partial);
7320
7167
  });
7321
7168
  });
7322
7169
 
@@ -7366,11 +7213,11 @@ var StateStore = function StateStore(value) {
7366
7213
 
7367
7214
  _defineProperty__default['default'](StateStore, "logCount", 5);
7368
7215
 
7369
- var _excluded$1 = ["limit", "sort"];
7216
+ var _excluded$2 = ["limit", "sort"];
7370
7217
 
7371
- function ownKeys$3(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; }
7218
+ function ownKeys$4(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; }
7372
7219
 
7373
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7220
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$4(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7374
7221
  var DEFAULT_PAGE_LIMIT = 50;
7375
7222
  var DEFAULT_SORT = [{
7376
7223
  created_at: -1
@@ -7599,14 +7446,14 @@ var Thread = /*#__PURE__*/function () {
7599
7446
  if (userId === ((_event$user2 = event.user) === null || _event$user2 === void 0 ? void 0 : _event$user2.id)) {
7600
7447
  // The user who just sent a message to the thread has no unread messages
7601
7448
  // in that thread
7602
- nextUserRead = _objectSpread$3(_objectSpread$3({}, nextUserRead), {}, {
7449
+ nextUserRead = _objectSpread$4(_objectSpread$4({}, nextUserRead), {}, {
7603
7450
  lastReadAt: event.created_at ? new Date(event.created_at) : new Date(),
7604
7451
  user: event.user,
7605
7452
  unreadMessageCount: 0
7606
7453
  });
7607
7454
  } else if (active && userId === _this.client.userID) ; else {
7608
7455
  // Increment unread count for all users except the author of the new message
7609
- nextUserRead = _objectSpread$3(_objectSpread$3({}, nextUserRead), {}, {
7456
+ nextUserRead = _objectSpread$4(_objectSpread$4({}, nextUserRead), {}, {
7610
7457
  unreadMessageCount: userRead.unreadMessageCount + 1
7611
7458
  });
7612
7459
  }
@@ -7630,8 +7477,8 @@ var Thread = /*#__PURE__*/function () {
7630
7477
  var user = event.user;
7631
7478
 
7632
7479
  _this.state.next(function (current) {
7633
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7634
- read: _objectSpread$3(_objectSpread$3({}, current.read), {}, _defineProperty__default['default']({}, userId, {
7480
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7481
+ read: _objectSpread$4(_objectSpread$4({}, current.read), {}, _defineProperty__default['default']({}, userId, {
7635
7482
  lastReadAt: new Date(createdAt),
7636
7483
  user: user,
7637
7484
  lastReadMessageId: event.last_read_message_id,
@@ -7742,7 +7589,7 @@ var Thread = /*#__PURE__*/function () {
7742
7589
  }
7743
7590
 
7744
7591
  _this.state.next(function (current) {
7745
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7592
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7746
7593
  replies: addToMessageList(current.replies, formattedMessage, timestampChanged)
7747
7594
  });
7748
7595
  });
@@ -7759,7 +7606,7 @@ var Thread = /*#__PURE__*/function () {
7759
7606
  var _message$reply_count;
7760
7607
 
7761
7608
  var formattedMessage = formatMessage(message);
7762
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7609
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7763
7610
  deletedAt: formattedMessage.deleted_at,
7764
7611
  parentMessage: formattedMessage,
7765
7612
  replyCount: (_message$reply_count = message.reply_count) !== null && _message$reply_count !== void 0 ? _message$reply_count : current.replyCount
@@ -7830,9 +7677,9 @@ var Thread = /*#__PURE__*/function () {
7830
7677
  limit = _ref10$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref10$limit,
7831
7678
  _ref10$sort = _ref10.sort,
7832
7679
  sort = _ref10$sort === void 0 ? DEFAULT_SORT : _ref10$sort,
7833
- otherOptions = _objectWithoutProperties__default['default'](_ref10, _excluded$1);
7680
+ otherOptions = _objectWithoutProperties__default['default'](_ref10, _excluded$2);
7834
7681
 
7835
- return _this.channel.getReplies(_this.id, _objectSpread$3({
7682
+ return _this.channel.getReplies(_this.id, _objectSpread$4({
7836
7683
  limit: limit
7837
7684
  }, otherOptions), sort);
7838
7685
  });
@@ -7876,12 +7723,12 @@ var Thread = /*#__PURE__*/function () {
7876
7723
  limit = Math.abs(count);
7877
7724
 
7878
7725
  _this.state.partialNext({
7879
- pagination: _objectSpread$3(_objectSpread$3({}, pagination), {}, _defineProperty__default['default']({}, loadingKey, true))
7726
+ pagination: _objectSpread$4(_objectSpread$4({}, pagination), {}, _defineProperty__default['default']({}, loadingKey, true))
7880
7727
  });
7881
7728
 
7882
7729
  _context3.prev = 7;
7883
7730
  _context3.next = 10;
7884
- return _this.queryReplies(_objectSpread$3(_objectSpread$3({}, queryOptions), {}, {
7731
+ return _this.queryReplies(_objectSpread$4(_objectSpread$4({}, queryOptions), {}, {
7885
7732
  limit: limit
7886
7733
  }));
7887
7734
 
@@ -7903,9 +7750,9 @@ var Thread = /*#__PURE__*/function () {
7903
7750
  (_nextReplies = nextReplies)[insertionMethodKey].apply(_nextReplies, _toConsumableArray__default['default'](replies));
7904
7751
  }
7905
7752
 
7906
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7753
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7907
7754
  replies: nextReplies,
7908
- pagination: _objectSpread$3(_objectSpread$3({}, current.pagination), {}, (_objectSpread4 = {}, _defineProperty__default['default'](_objectSpread4, cursorKey, data.messages.length < limit ? null : maybeNextCursor), _defineProperty__default['default'](_objectSpread4, loadingKey, false), _objectSpread4))
7755
+ pagination: _objectSpread$4(_objectSpread$4({}, current.pagination), {}, (_objectSpread4 = {}, _defineProperty__default['default'](_objectSpread4, cursorKey, data.messages.length < limit ? null : maybeNextCursor), _defineProperty__default['default'](_objectSpread4, loadingKey, false), _objectSpread4))
7909
7756
  });
7910
7757
  });
7911
7758
 
@@ -7919,8 +7766,8 @@ var Thread = /*#__PURE__*/function () {
7919
7766
  _this.client.logger('error', _context3.t0.message);
7920
7767
 
7921
7768
  _this.state.next(function (current) {
7922
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7923
- pagination: _objectSpread$3(_objectSpread$3({}, current.pagination), {}, _defineProperty__default['default']({}, loadingKey, false))
7769
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7770
+ pagination: _objectSpread$4(_objectSpread$4({}, current.pagination), {}, _defineProperty__default['default']({}, loadingKey, false))
7924
7771
  });
7925
7772
  });
7926
7773
 
@@ -8025,9 +7872,9 @@ var ownUnreadCountSelector = function ownUnreadCountSelector(currentUserId) {
8025
7872
  };
8026
7873
  };
8027
7874
 
8028
- function ownKeys$2(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; }
7875
+ function ownKeys$3(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; }
8029
7876
 
8030
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7877
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8031
7878
  var MODERATION_ENTITY_TYPES = {
8032
7879
  user: 'stream:user',
8033
7880
  message: 'stream:chat:v1:message'
@@ -8144,7 +7991,7 @@ var Moderation = /*#__PURE__*/function () {
8144
7991
  case 0:
8145
7992
  options = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : {};
8146
7993
  _context3.next = 3;
8147
- return this.client.post(this.client.baseURL + '/api/v2/moderation/flag', _objectSpread$2({
7994
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/flag', _objectSpread$3({
8148
7995
  entity_type: entityType,
8149
7996
  entity_id: entityId,
8150
7997
  entity_creator_id: entityCreatorID,
@@ -8189,7 +8036,7 @@ var Moderation = /*#__PURE__*/function () {
8189
8036
  case 0:
8190
8037
  options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
8191
8038
  _context4.next = 3;
8192
- return this.client.post(this.client.baseURL + '/api/v2/moderation/mute', _objectSpread$2({
8039
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/mute', _objectSpread$3({
8193
8040
  target_ids: [targetID]
8194
8041
  }, options));
8195
8042
 
@@ -8227,7 +8074,7 @@ var Moderation = /*#__PURE__*/function () {
8227
8074
  switch (_context5.prev = _context5.next) {
8228
8075
  case 0:
8229
8076
  _context5.next = 2;
8230
- return this.client.post(this.client.baseURL + '/api/v2/moderation/unmute', _objectSpread$2({
8077
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/unmute', _objectSpread$3({
8231
8078
  target_ids: [targetID]
8232
8079
  }, options));
8233
8080
 
@@ -8269,7 +8116,7 @@ var Moderation = /*#__PURE__*/function () {
8269
8116
  case 0:
8270
8117
  options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
8271
8118
  _context6.next = 3;
8272
- return this.client.get(this.client.baseURL + "/api/v2/moderation/user_report", _objectSpread$2({
8119
+ return this.client.get(this.client.baseURL + "/api/v2/moderation/user_report", _objectSpread$3({
8273
8120
  user_id: userID
8274
8121
  }, options));
8275
8122
 
@@ -8313,7 +8160,7 @@ var Moderation = /*#__PURE__*/function () {
8313
8160
  sort = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : [];
8314
8161
  options = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : {};
8315
8162
  _context7.next = 5;
8316
- return this.client.post(this.client.baseURL + '/api/v2/moderation/review_queue', _objectSpread$2({
8163
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/review_queue', _objectSpread$3({
8317
8164
  filter: filterConditions,
8318
8165
  sort: normalizeQuerySort(sort)
8319
8166
  }, options));
@@ -8416,7 +8263,7 @@ var Moderation = /*#__PURE__*/function () {
8416
8263
  case 0:
8417
8264
  options = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {};
8418
8265
  _context10.next = 3;
8419
- return this.client.post(this.client.baseURL + '/api/v2/moderation/submit_action', _objectSpread$2({
8266
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/submit_action', _objectSpread$3({
8420
8267
  action_type: actionType,
8421
8268
  item_id: itemID
8422
8269
  }, options));
@@ -8443,15 +8290,15 @@ var Moderation = /*#__PURE__*/function () {
8443
8290
  return Moderation;
8444
8291
  }();
8445
8292
 
8446
- function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8293
+ function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8447
8294
 
8448
- function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(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$1(o, minLen); }
8295
+ function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(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$2(o, minLen); }
8449
8296
 
8450
- function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8297
+ function _arrayLikeToArray$2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8451
8298
 
8452
- function ownKeys$1(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; }
8299
+ function ownKeys$2(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; }
8453
8300
 
8454
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8301
+ function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8455
8302
  var DEFAULT_CONNECTION_RECOVERY_THROTTLE_DURATION = 1000;
8456
8303
  var MAX_QUERY_THREADS_LIMIT = 25;
8457
8304
  var ThreadManager = /*#__PURE__*/function () {
@@ -8595,7 +8442,7 @@ var ThreadManager = /*#__PURE__*/function () {
8595
8442
  var unsubscribeConnectionDropped = _this.client.on('connection.changed', function (event) {
8596
8443
  if (event.online === false) {
8597
8444
  _this.state.next(function (current) {
8598
- return current.lastConnectionDropAt ? current : _objectSpread$1(_objectSpread$1({}, current), {}, {
8445
+ return current.lastConnectionDropAt ? current : _objectSpread$2(_objectSpread$2({}, current), {}, {
8599
8446
  lastConnectionDropAt: new Date()
8600
8447
  });
8601
8448
  });
@@ -8682,213 +8529,1219 @@ var ThreadManager = /*#__PURE__*/function () {
8682
8529
  _context.prev = 7;
8683
8530
 
8684
8531
  _this.state.next(function (current) {
8685
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8686
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8532
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8533
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8687
8534
  isLoading: true
8688
8535
  })
8689
8536
  });
8690
8537
  });
8691
8538
 
8692
- _context.next = 11;
8693
- return _this.queryThreads({
8694
- limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT) || MAX_QUERY_THREADS_LIMIT
8695
- });
8539
+ _context.next = 11;
8540
+ return _this.queryThreads({
8541
+ limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT) || MAX_QUERY_THREADS_LIMIT
8542
+ });
8543
+
8544
+ case 11:
8545
+ response = _context.sent;
8546
+ currentThreads = _this.threadsById;
8547
+ nextThreads = [];
8548
+ _iterator = _createForOfIteratorHelper$2(response.threads);
8549
+
8550
+ try {
8551
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
8552
+ incomingThread = _step.value;
8553
+ existingThread = currentThreads[incomingThread.id];
8554
+
8555
+ if (existingThread) {
8556
+ // Reuse thread instances if possible
8557
+ nextThreads.push(existingThread);
8558
+
8559
+ if (existingThread.hasStaleState) {
8560
+ existingThread.hydrateState(incomingThread);
8561
+ }
8562
+ } else {
8563
+ nextThreads.push(incomingThread);
8564
+ }
8565
+ }
8566
+ } catch (err) {
8567
+ _iterator.e(err);
8568
+ } finally {
8569
+ _iterator.f();
8570
+ }
8571
+
8572
+ _this.state.next(function (current) {
8573
+ var _response$next;
8574
+
8575
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8576
+ threads: nextThreads,
8577
+ unseenThreadIds: [],
8578
+ isThreadOrderStale: false,
8579
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8580
+ isLoading: false,
8581
+ nextCursor: (_response$next = response.next) !== null && _response$next !== void 0 ? _response$next : null
8582
+ }),
8583
+ ready: true
8584
+ });
8585
+ });
8586
+
8587
+ _context.next = 23;
8588
+ break;
8589
+
8590
+ case 19:
8591
+ _context.prev = 19;
8592
+ _context.t0 = _context["catch"](7);
8593
+
8594
+ _this.client.logger('error', _context.t0.message);
8595
+
8596
+ _this.state.next(function (current) {
8597
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8598
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8599
+ isLoading: false
8600
+ })
8601
+ });
8602
+ });
8603
+
8604
+ case 23:
8605
+ case "end":
8606
+ return _context.stop();
8607
+ }
8608
+ }
8609
+ }, _callee, null, [[7, 19]]);
8610
+ })));
8611
+
8612
+ _defineProperty__default['default'](this, "queryThreads", function () {
8613
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8614
+ return _this.client.queryThreads(_objectSpread$2({
8615
+ limit: 25,
8616
+ participant_limit: 10,
8617
+ reply_limit: 10,
8618
+ watch: true
8619
+ }, options));
8620
+ });
8621
+
8622
+ _defineProperty__default['default'](this, "loadNextPage", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
8623
+ var options,
8624
+ _this$state$getLatest4,
8625
+ pagination,
8626
+ response,
8627
+ _args2 = arguments;
8628
+
8629
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
8630
+ while (1) {
8631
+ switch (_context2.prev = _context2.next) {
8632
+ case 0:
8633
+ options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
8634
+ _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
8635
+
8636
+ if (!(pagination.isLoadingNext || !pagination.nextCursor)) {
8637
+ _context2.next = 4;
8638
+ break;
8639
+ }
8640
+
8641
+ return _context2.abrupt("return");
8642
+
8643
+ case 4:
8644
+ _context2.prev = 4;
8645
+
8646
+ _this.state.partialNext({
8647
+ pagination: _objectSpread$2(_objectSpread$2({}, pagination), {}, {
8648
+ isLoadingNext: true
8649
+ })
8650
+ });
8651
+
8652
+ _context2.next = 8;
8653
+ return _this.queryThreads(_objectSpread$2(_objectSpread$2({}, options), {}, {
8654
+ next: pagination.nextCursor
8655
+ }));
8656
+
8657
+ case 8:
8658
+ response = _context2.sent;
8659
+
8660
+ _this.state.next(function (current) {
8661
+ var _response$next2;
8662
+
8663
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8664
+ threads: response.threads.length ? current.threads.concat(response.threads) : current.threads,
8665
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8666
+ nextCursor: (_response$next2 = response.next) !== null && _response$next2 !== void 0 ? _response$next2 : null,
8667
+ isLoadingNext: false
8668
+ })
8669
+ });
8670
+ });
8671
+
8672
+ _context2.next = 16;
8673
+ break;
8674
+
8675
+ case 12:
8676
+ _context2.prev = 12;
8677
+ _context2.t0 = _context2["catch"](4);
8678
+
8679
+ _this.client.logger('error', _context2.t0.message);
8680
+
8681
+ _this.state.next(function (current) {
8682
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8683
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8684
+ isLoadingNext: false
8685
+ })
8686
+ });
8687
+ });
8688
+
8689
+ case 16:
8690
+ case "end":
8691
+ return _context2.stop();
8692
+ }
8693
+ }
8694
+ }, _callee2, null, [[4, 12]]);
8695
+ })));
8696
+
8697
+ this.client = client;
8698
+ this.state = new StateStore({
8699
+ active: false,
8700
+ isThreadOrderStale: false,
8701
+ threads: [],
8702
+ unreadThreadCount: 0,
8703
+ unseenThreadIds: [],
8704
+ lastConnectionDropAt: null,
8705
+ pagination: {
8706
+ isLoading: false,
8707
+ isLoadingNext: false,
8708
+ nextCursor: null
8709
+ },
8710
+ ready: false
8711
+ });
8712
+ this.threadsByIdGetterCache = {
8713
+ threads: [],
8714
+ threadsById: {}
8715
+ };
8716
+ }
8717
+
8718
+ _createClass__default['default'](ThreadManager, [{
8719
+ key: "threadsById",
8720
+ get: function get() {
8721
+ var _this$state$getLatest5 = this.state.getLatestValue(),
8722
+ threads = _this$state$getLatest5.threads;
8723
+
8724
+ if (threads === this.threadsByIdGetterCache.threads) {
8725
+ return this.threadsByIdGetterCache.threadsById;
8726
+ }
8727
+
8728
+ var threadsById = threads.reduce(function (newThreadsById, thread) {
8729
+ newThreadsById[thread.id] = thread;
8730
+ return newThreadsById;
8731
+ }, {});
8732
+ this.threadsByIdGetterCache.threads = threads;
8733
+ this.threadsByIdGetterCache.threadsById = threadsById;
8734
+ return threadsById;
8735
+ }
8736
+ }]);
8737
+
8738
+ return ThreadManager;
8739
+ }();
8740
+
8741
+ var _excluded$1 = ["own_votes", "id"],
8742
+ _excluded2$1 = ["id"];
8743
+
8744
+ function ownKeys$1(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; }
8745
+
8746
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8747
+
8748
+ var isPollUpdatedEvent = function isPollUpdatedEvent(e) {
8749
+ return e.type === 'poll.updated';
8750
+ };
8751
+
8752
+ var isPollClosedEventEvent = function isPollClosedEventEvent(e) {
8753
+ return e.type === 'poll.closed';
8754
+ };
8755
+
8756
+ var isPollVoteCastedEvent = function isPollVoteCastedEvent(e) {
8757
+ return e.type === 'poll.vote_casted';
8758
+ };
8759
+
8760
+ var isPollVoteChangedEvent = function isPollVoteChangedEvent(e) {
8761
+ return e.type === 'poll.vote_changed';
8762
+ };
8763
+
8764
+ var isPollVoteRemovedEvent = function isPollVoteRemovedEvent(e) {
8765
+ return e.type === 'poll.vote_removed';
8766
+ };
8767
+
8768
+ var isVoteAnswer = function isVoteAnswer(vote) {
8769
+ return !!(vote !== null && vote !== void 0 && vote.answer_text);
8770
+ };
8771
+ var Poll = /*#__PURE__*/function () {
8772
+ function Poll(_ref) {
8773
+ var _this = this;
8774
+
8775
+ var client = _ref.client,
8776
+ _poll = _ref.poll;
8777
+
8778
+ _classCallCheck__default['default'](this, Poll);
8779
+
8780
+ _defineProperty__default['default'](this, "state", void 0);
8781
+
8782
+ _defineProperty__default['default'](this, "id", void 0);
8783
+
8784
+ _defineProperty__default['default'](this, "client", void 0);
8785
+
8786
+ _defineProperty__default['default'](this, "unsubscribeFunctions", new Set());
8787
+
8788
+ _defineProperty__default['default'](this, "getInitialStateFromPollResponse", function (poll) {
8789
+ var _own_votes$reduce;
8790
+
8791
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8792
+ var own_votes = poll.own_votes;
8793
+ poll.id;
8794
+ var pollResponseForState = _objectWithoutProperties__default['default'](poll, _excluded$1);
8795
+
8796
+ var _ref2 = (_own_votes$reduce = own_votes === null || own_votes === void 0 ? void 0 : own_votes.reduce(function (acc, voteOrAnswer) {
8797
+ if (isVoteAnswer(voteOrAnswer)) {
8798
+ acc.ownAnswer = voteOrAnswer;
8799
+ } else {
8800
+ acc.ownVotes.push(voteOrAnswer);
8801
+ }
8802
+
8803
+ return acc;
8804
+ }, {
8805
+ ownVotes: []
8806
+ })) !== null && _own_votes$reduce !== void 0 ? _own_votes$reduce : {
8807
+ ownVotes: []
8808
+ },
8809
+ ownAnswer = _ref2.ownAnswer,
8810
+ ownVotes = _ref2.ownVotes;
8811
+
8812
+ return _objectSpread$1(_objectSpread$1({}, pollResponseForState), {}, {
8813
+ lastActivityAt: new Date(),
8814
+ maxVotedOptionIds: getMaxVotedOptionIds(pollResponseForState.vote_counts_by_option),
8815
+ ownAnswer: ownAnswer,
8816
+ ownVotesByOptionId: getOwnVotesByOptionId(ownVotes)
8817
+ });
8818
+ });
8819
+
8820
+ _defineProperty__default['default'](this, "reinitializeState", function (poll) {
8821
+ _this.state.partialNext(_this.getInitialStateFromPollResponse(poll));
8822
+ });
8823
+
8824
+ _defineProperty__default['default'](this, "handlePollUpdated", function (event) {
8825
+ var _event$poll;
8826
+
8827
+ if ((_event$poll = event.poll) !== null && _event$poll !== void 0 && _event$poll.id && event.poll.id !== _this.id) return;
8828
+ if (!isPollUpdatedEvent(event)) return; // eslint-disable-next-line @typescript-eslint/no-unused-vars
8829
+
8830
+ var _extractPollData = extractPollData(event.poll),
8831
+ pollData = _objectWithoutProperties__default['default'](_extractPollData, _excluded2$1); // @ts-ignore
8832
+
8833
+
8834
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollData), {}, {
8835
+ lastActivityAt: new Date(event.created_at)
8836
+ }));
8837
+ });
8838
+
8839
+ _defineProperty__default['default'](this, "handlePollClosed", function (event) {
8840
+ var _event$poll2;
8841
+
8842
+ if ((_event$poll2 = event.poll) !== null && _event$poll2 !== void 0 && _event$poll2.id && event.poll.id !== _this.id) return;
8843
+ if (!isPollClosedEventEvent(event)) return; // @ts-ignore
8844
+
8845
+ _this.state.partialNext({
8846
+ is_closed: true,
8847
+ lastActivityAt: new Date(event.created_at)
8848
+ });
8849
+ });
8850
+
8851
+ _defineProperty__default['default'](this, "handleVoteCasted", function (event) {
8852
+ var _event$poll3;
8853
+
8854
+ if ((_event$poll3 = event.poll) !== null && _event$poll3 !== void 0 && _event$poll3.id && event.poll.id !== _this.id) return;
8855
+ if (!isPollVoteCastedEvent(event)) return;
8856
+ var currentState = _this.data;
8857
+ var isOwnVote = event.poll_vote.user_id === _this.client.userID;
8858
+
8859
+ var latestAnswers = _toConsumableArray__default['default'](currentState.latest_answers);
8860
+
8861
+ var ownAnswer = currentState.ownAnswer;
8862
+ var ownVotesByOptionId = currentState.ownVotesByOptionId;
8863
+ var maxVotedOptionIds = currentState.maxVotedOptionIds;
8864
+
8865
+ if (isOwnVote) {
8866
+ if (isVoteAnswer(event.poll_vote)) {
8867
+ ownAnswer = event.poll_vote;
8868
+ } else if (event.poll_vote.option_id) {
8869
+ ownVotesByOptionId[event.poll_vote.option_id] = event.poll_vote;
8870
+ }
8871
+ }
8872
+
8873
+ if (isVoteAnswer(event.poll_vote)) {
8874
+ latestAnswers = [event.poll_vote].concat(_toConsumableArray__default['default'](latestAnswers));
8875
+ } else {
8876
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8877
+ }
8878
+
8879
+ var pollEnrichData = extractPollEnrichedData(event.poll); // @ts-ignore
8880
+
8881
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollEnrichData), {}, {
8882
+ latest_answers: latestAnswers,
8883
+ lastActivityAt: new Date(event.created_at),
8884
+ ownAnswer: ownAnswer,
8885
+ ownVotesByOptionId: ownVotesByOptionId,
8886
+ maxVotedOptionIds: maxVotedOptionIds
8887
+ }));
8888
+ });
8889
+
8890
+ _defineProperty__default['default'](this, "handleVoteChanged", function (event) {
8891
+ var _event$poll4;
8892
+
8893
+ // this event is triggered only when event.poll.enforce_unique_vote === true
8894
+ if ((_event$poll4 = event.poll) !== null && _event$poll4 !== void 0 && _event$poll4.id && event.poll.id !== _this.id) return;
8895
+ if (!isPollVoteChangedEvent(event)) return;
8896
+ var currentState = _this.data;
8897
+ var isOwnVote = event.poll_vote.user_id === _this.client.userID;
8898
+
8899
+ var latestAnswers = _toConsumableArray__default['default'](currentState.latest_answers);
8900
+
8901
+ var ownAnswer = currentState.ownAnswer;
8902
+ var ownVotesByOptionId = currentState.ownVotesByOptionId;
8903
+ var maxVotedOptionIds = currentState.maxVotedOptionIds;
8904
+
8905
+ if (isOwnVote) {
8906
+ if (isVoteAnswer(event.poll_vote)) {
8907
+ latestAnswers = [event.poll_vote].concat(_toConsumableArray__default['default'](latestAnswers.filter(function (answer) {
8908
+ return answer.id !== event.poll_vote.id;
8909
+ })));
8910
+ ownAnswer = event.poll_vote;
8911
+ } else if (event.poll_vote.option_id) {
8912
+ var _ownAnswer;
8913
+
8914
+ if (event.poll.enforce_unique_votes) {
8915
+ ownVotesByOptionId = _defineProperty__default['default']({}, event.poll_vote.option_id, event.poll_vote);
8916
+ } else {
8917
+ ownVotesByOptionId = Object.entries(ownVotesByOptionId).reduce(function (acc, _ref3) {
8918
+ var _ref4 = _slicedToArray__default['default'](_ref3, 2),
8919
+ optionId = _ref4[0],
8920
+ vote = _ref4[1];
8921
+
8922
+ if (optionId !== event.poll_vote.option_id && vote.id === event.poll_vote.id) {
8923
+ return acc;
8924
+ }
8925
+
8926
+ acc[optionId] = vote;
8927
+ return acc;
8928
+ }, {});
8929
+ ownVotesByOptionId[event.poll_vote.option_id] = event.poll_vote;
8930
+ }
8931
+
8932
+ if (((_ownAnswer = ownAnswer) === null || _ownAnswer === void 0 ? void 0 : _ownAnswer.id) === event.poll_vote.id) {
8933
+ ownAnswer = undefined;
8934
+ }
8935
+
8936
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8937
+ }
8938
+ } else if (isVoteAnswer(event.poll_vote)) {
8939
+ latestAnswers = [event.poll_vote].concat(_toConsumableArray__default['default'](latestAnswers));
8940
+ } else {
8941
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8942
+ }
8943
+
8944
+ var pollEnrichData = extractPollEnrichedData(event.poll); // @ts-ignore
8945
+
8946
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollEnrichData), {}, {
8947
+ latest_answers: latestAnswers,
8948
+ lastActivityAt: new Date(event.created_at),
8949
+ ownAnswer: ownAnswer,
8950
+ ownVotesByOptionId: ownVotesByOptionId,
8951
+ maxVotedOptionIds: maxVotedOptionIds
8952
+ }));
8953
+ });
8954
+
8955
+ _defineProperty__default['default'](this, "handleVoteRemoved", function (event) {
8956
+ var _event$poll5;
8957
+
8958
+ if ((_event$poll5 = event.poll) !== null && _event$poll5 !== void 0 && _event$poll5.id && event.poll.id !== _this.id) return;
8959
+ if (!isPollVoteRemovedEvent(event)) return;
8960
+ var currentState = _this.data;
8961
+ var isOwnVote = event.poll_vote.user_id === _this.client.userID;
8962
+
8963
+ var latestAnswers = _toConsumableArray__default['default'](currentState.latest_answers);
8964
+
8965
+ var ownAnswer = currentState.ownAnswer;
8966
+
8967
+ var ownVotesByOptionId = _objectSpread$1({}, currentState.ownVotesByOptionId);
8968
+
8969
+ var maxVotedOptionIds = currentState.maxVotedOptionIds;
8970
+
8971
+ if (isVoteAnswer(event.poll_vote)) {
8972
+ latestAnswers = latestAnswers.filter(function (answer) {
8973
+ return answer.id !== event.poll_vote.id;
8974
+ });
8975
+
8976
+ if (isOwnVote) {
8977
+ ownAnswer = undefined;
8978
+ }
8979
+ } else {
8980
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8981
+
8982
+ if (isOwnVote && event.poll_vote.option_id) {
8983
+ delete ownVotesByOptionId[event.poll_vote.option_id];
8984
+ }
8985
+ }
8986
+
8987
+ var pollEnrichData = extractPollEnrichedData(event.poll); // @ts-ignore
8988
+
8989
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollEnrichData), {}, {
8990
+ latest_answers: latestAnswers,
8991
+ lastActivityAt: new Date(event.created_at),
8992
+ ownAnswer: ownAnswer,
8993
+ ownVotesByOptionId: ownVotesByOptionId,
8994
+ maxVotedOptionIds: maxVotedOptionIds
8995
+ }));
8996
+ });
8997
+
8998
+ _defineProperty__default['default'](this, "query", /*#__PURE__*/function () {
8999
+ var _ref5 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(id) {
9000
+ var _yield$_this$client$g, poll;
9001
+
9002
+ return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
9003
+ while (1) {
9004
+ switch (_context.prev = _context.next) {
9005
+ case 0:
9006
+ _context.next = 2;
9007
+ return _this.client.getPoll(id);
9008
+
9009
+ case 2:
9010
+ _yield$_this$client$g = _context.sent;
9011
+ poll = _yield$_this$client$g.poll;
9012
+
9013
+ // @ts-ignore
9014
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, poll), {}, {
9015
+ lastActivityAt: new Date()
9016
+ }));
9017
+
9018
+ return _context.abrupt("return", poll);
9019
+
9020
+ case 6:
9021
+ case "end":
9022
+ return _context.stop();
9023
+ }
9024
+ }
9025
+ }, _callee);
9026
+ }));
9027
+
9028
+ return function (_x) {
9029
+ return _ref5.apply(this, arguments);
9030
+ };
9031
+ }());
9032
+
9033
+ _defineProperty__default['default'](this, "update", /*#__PURE__*/function () {
9034
+ var _ref6 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(data) {
9035
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
9036
+ while (1) {
9037
+ switch (_context2.prev = _context2.next) {
9038
+ case 0:
9039
+ _context2.next = 2;
9040
+ return _this.client.updatePoll(_objectSpread$1(_objectSpread$1({}, data), {}, {
9041
+ id: _this.id
9042
+ }));
9043
+
9044
+ case 2:
9045
+ return _context2.abrupt("return", _context2.sent);
9046
+
9047
+ case 3:
9048
+ case "end":
9049
+ return _context2.stop();
9050
+ }
9051
+ }
9052
+ }, _callee2);
9053
+ }));
9054
+
9055
+ return function (_x2) {
9056
+ return _ref6.apply(this, arguments);
9057
+ };
9058
+ }());
9059
+
9060
+ _defineProperty__default['default'](this, "partialUpdate", /*#__PURE__*/function () {
9061
+ var _ref7 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(partialPollObject) {
9062
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
9063
+ while (1) {
9064
+ switch (_context3.prev = _context3.next) {
9065
+ case 0:
9066
+ _context3.next = 2;
9067
+ return _this.client.partialUpdatePoll(_this.id, partialPollObject);
9068
+
9069
+ case 2:
9070
+ return _context3.abrupt("return", _context3.sent);
9071
+
9072
+ case 3:
9073
+ case "end":
9074
+ return _context3.stop();
9075
+ }
9076
+ }
9077
+ }, _callee3);
9078
+ }));
9079
+
9080
+ return function (_x3) {
9081
+ return _ref7.apply(this, arguments);
9082
+ };
9083
+ }());
9084
+
9085
+ _defineProperty__default['default'](this, "close", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
9086
+ return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
9087
+ while (1) {
9088
+ switch (_context4.prev = _context4.next) {
9089
+ case 0:
9090
+ _context4.next = 2;
9091
+ return _this.client.closePoll(_this.id);
9092
+
9093
+ case 2:
9094
+ return _context4.abrupt("return", _context4.sent);
9095
+
9096
+ case 3:
9097
+ case "end":
9098
+ return _context4.stop();
9099
+ }
9100
+ }
9101
+ }, _callee4);
9102
+ })));
9103
+
9104
+ _defineProperty__default['default'](this, "delete", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
9105
+ return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
9106
+ while (1) {
9107
+ switch (_context5.prev = _context5.next) {
9108
+ case 0:
9109
+ _context5.next = 2;
9110
+ return _this.client.deletePoll(_this.id);
9111
+
9112
+ case 2:
9113
+ return _context5.abrupt("return", _context5.sent);
9114
+
9115
+ case 3:
9116
+ case "end":
9117
+ return _context5.stop();
9118
+ }
9119
+ }
9120
+ }, _callee5);
9121
+ })));
9122
+
9123
+ _defineProperty__default['default'](this, "createOption", /*#__PURE__*/function () {
9124
+ var _ref10 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6(option) {
9125
+ return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
9126
+ while (1) {
9127
+ switch (_context6.prev = _context6.next) {
9128
+ case 0:
9129
+ _context6.next = 2;
9130
+ return _this.client.createPollOption(_this.id, option);
9131
+
9132
+ case 2:
9133
+ return _context6.abrupt("return", _context6.sent);
9134
+
9135
+ case 3:
9136
+ case "end":
9137
+ return _context6.stop();
9138
+ }
9139
+ }
9140
+ }, _callee6);
9141
+ }));
9142
+
9143
+ return function (_x4) {
9144
+ return _ref10.apply(this, arguments);
9145
+ };
9146
+ }());
9147
+
9148
+ _defineProperty__default['default'](this, "updateOption", /*#__PURE__*/function () {
9149
+ var _ref11 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee7(option) {
9150
+ return _regeneratorRuntime__default['default'].wrap(function _callee7$(_context7) {
9151
+ while (1) {
9152
+ switch (_context7.prev = _context7.next) {
9153
+ case 0:
9154
+ _context7.next = 2;
9155
+ return _this.client.updatePollOption(_this.id, option);
9156
+
9157
+ case 2:
9158
+ return _context7.abrupt("return", _context7.sent);
9159
+
9160
+ case 3:
9161
+ case "end":
9162
+ return _context7.stop();
9163
+ }
9164
+ }
9165
+ }, _callee7);
9166
+ }));
9167
+
9168
+ return function (_x5) {
9169
+ return _ref11.apply(this, arguments);
9170
+ };
9171
+ }());
9172
+
9173
+ _defineProperty__default['default'](this, "deleteOption", /*#__PURE__*/function () {
9174
+ var _ref12 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee8(optionId) {
9175
+ return _regeneratorRuntime__default['default'].wrap(function _callee8$(_context8) {
9176
+ while (1) {
9177
+ switch (_context8.prev = _context8.next) {
9178
+ case 0:
9179
+ _context8.next = 2;
9180
+ return _this.client.deletePollOption(_this.id, optionId);
9181
+
9182
+ case 2:
9183
+ return _context8.abrupt("return", _context8.sent);
9184
+
9185
+ case 3:
9186
+ case "end":
9187
+ return _context8.stop();
9188
+ }
9189
+ }
9190
+ }, _callee8);
9191
+ }));
9192
+
9193
+ return function (_x6) {
9194
+ return _ref12.apply(this, arguments);
9195
+ };
9196
+ }());
9197
+
9198
+ _defineProperty__default['default'](this, "castVote", /*#__PURE__*/function () {
9199
+ var _ref13 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee9(optionId, messageId) {
9200
+ var _this$data, max_votes_allowed, ownVotesByOptionId, reachedVoteLimit, _oldestVote2, oldestVote;
9201
+
9202
+ return _regeneratorRuntime__default['default'].wrap(function _callee9$(_context9) {
9203
+ while (1) {
9204
+ switch (_context9.prev = _context9.next) {
9205
+ case 0:
9206
+ _this$data = _this.data, max_votes_allowed = _this$data.max_votes_allowed, ownVotesByOptionId = _this$data.ownVotesByOptionId;
9207
+ reachedVoteLimit = max_votes_allowed && max_votes_allowed === Object.keys(ownVotesByOptionId).length;
9208
+
9209
+ if (!reachedVoteLimit) {
9210
+ _context9.next = 8;
9211
+ break;
9212
+ }
9213
+
9214
+ oldestVote = Object.values(ownVotesByOptionId)[0];
9215
+ Object.values(ownVotesByOptionId).slice(1).forEach(function (vote) {
9216
+ var _oldestVote;
9217
+
9218
+ if (!((_oldestVote = oldestVote) !== null && _oldestVote !== void 0 && _oldestVote.created_at) || new Date(vote.created_at) < new Date(oldestVote.created_at)) {
9219
+ oldestVote = vote;
9220
+ }
9221
+ });
9222
+
9223
+ if (!((_oldestVote2 = oldestVote) !== null && _oldestVote2 !== void 0 && _oldestVote2.id)) {
9224
+ _context9.next = 8;
9225
+ break;
9226
+ }
9227
+
9228
+ _context9.next = 8;
9229
+ return _this.removeVote(oldestVote.id, messageId);
9230
+
9231
+ case 8:
9232
+ _context9.next = 10;
9233
+ return _this.client.castPollVote(messageId, _this.id, {
9234
+ option_id: optionId
9235
+ });
9236
+
9237
+ case 10:
9238
+ return _context9.abrupt("return", _context9.sent);
9239
+
9240
+ case 11:
9241
+ case "end":
9242
+ return _context9.stop();
9243
+ }
9244
+ }
9245
+ }, _callee9);
9246
+ }));
9247
+
9248
+ return function (_x7, _x8) {
9249
+ return _ref13.apply(this, arguments);
9250
+ };
9251
+ }());
9252
+
9253
+ _defineProperty__default['default'](this, "removeVote", /*#__PURE__*/function () {
9254
+ var _ref14 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee10(voteId, messageId) {
9255
+ return _regeneratorRuntime__default['default'].wrap(function _callee10$(_context10) {
9256
+ while (1) {
9257
+ switch (_context10.prev = _context10.next) {
9258
+ case 0:
9259
+ _context10.next = 2;
9260
+ return _this.client.removePollVote(messageId, _this.id, voteId);
9261
+
9262
+ case 2:
9263
+ return _context10.abrupt("return", _context10.sent);
9264
+
9265
+ case 3:
9266
+ case "end":
9267
+ return _context10.stop();
9268
+ }
9269
+ }
9270
+ }, _callee10);
9271
+ }));
9272
+
9273
+ return function (_x9, _x10) {
9274
+ return _ref14.apply(this, arguments);
9275
+ };
9276
+ }());
9277
+
9278
+ _defineProperty__default['default'](this, "addAnswer", /*#__PURE__*/function () {
9279
+ var _ref15 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee11(answerText, messageId) {
9280
+ return _regeneratorRuntime__default['default'].wrap(function _callee11$(_context11) {
9281
+ while (1) {
9282
+ switch (_context11.prev = _context11.next) {
9283
+ case 0:
9284
+ _context11.next = 2;
9285
+ return _this.client.addPollAnswer(messageId, _this.id, answerText);
9286
+
9287
+ case 2:
9288
+ return _context11.abrupt("return", _context11.sent);
9289
+
9290
+ case 3:
9291
+ case "end":
9292
+ return _context11.stop();
9293
+ }
9294
+ }
9295
+ }, _callee11);
9296
+ }));
9297
+
9298
+ return function (_x11, _x12) {
9299
+ return _ref15.apply(this, arguments);
9300
+ };
9301
+ }());
9302
+
9303
+ _defineProperty__default['default'](this, "removeAnswer", /*#__PURE__*/function () {
9304
+ var _ref16 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee12(answerId, messageId) {
9305
+ return _regeneratorRuntime__default['default'].wrap(function _callee12$(_context12) {
9306
+ while (1) {
9307
+ switch (_context12.prev = _context12.next) {
9308
+ case 0:
9309
+ _context12.next = 2;
9310
+ return _this.client.removePollVote(messageId, _this.id, answerId);
9311
+
9312
+ case 2:
9313
+ return _context12.abrupt("return", _context12.sent);
9314
+
9315
+ case 3:
9316
+ case "end":
9317
+ return _context12.stop();
9318
+ }
9319
+ }
9320
+ }, _callee12);
9321
+ }));
9322
+
9323
+ return function (_x13, _x14) {
9324
+ return _ref16.apply(this, arguments);
9325
+ };
9326
+ }());
9327
+
9328
+ _defineProperty__default['default'](this, "queryAnswers", /*#__PURE__*/function () {
9329
+ var _ref17 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee13(params) {
9330
+ return _regeneratorRuntime__default['default'].wrap(function _callee13$(_context13) {
9331
+ while (1) {
9332
+ switch (_context13.prev = _context13.next) {
9333
+ case 0:
9334
+ _context13.next = 2;
9335
+ return _this.client.queryPollAnswers(_this.id, params.filter, params.sort, params.options);
9336
+
9337
+ case 2:
9338
+ return _context13.abrupt("return", _context13.sent);
9339
+
9340
+ case 3:
9341
+ case "end":
9342
+ return _context13.stop();
9343
+ }
9344
+ }
9345
+ }, _callee13);
9346
+ }));
9347
+
9348
+ return function (_x15) {
9349
+ return _ref17.apply(this, arguments);
9350
+ };
9351
+ }());
9352
+
9353
+ _defineProperty__default['default'](this, "queryOptionVotes", /*#__PURE__*/function () {
9354
+ var _ref18 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(params) {
9355
+ return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
9356
+ while (1) {
9357
+ switch (_context14.prev = _context14.next) {
9358
+ case 0:
9359
+ _context14.next = 2;
9360
+ return _this.client.queryPollVotes(_this.id, params.filter, params.sort, params.options);
9361
+
9362
+ case 2:
9363
+ return _context14.abrupt("return", _context14.sent);
9364
+
9365
+ case 3:
9366
+ case "end":
9367
+ return _context14.stop();
9368
+ }
9369
+ }
9370
+ }, _callee14);
9371
+ }));
9372
+
9373
+ return function (_x16) {
9374
+ return _ref18.apply(this, arguments);
9375
+ };
9376
+ }());
9377
+
9378
+ this.client = client;
9379
+ this.id = _poll.id;
9380
+ this.state = new StateStore(this.getInitialStateFromPollResponse(_poll));
9381
+ }
9382
+
9383
+ _createClass__default['default'](Poll, [{
9384
+ key: "data",
9385
+ get: function get() {
9386
+ return this.state.getLatestValue();
9387
+ }
9388
+ }]);
9389
+
9390
+ return Poll;
9391
+ }();
9392
+
9393
+ function getMaxVotedOptionIds(voteCountsByOption) {
9394
+ var maxVotes = 0;
9395
+ var winningOptions = [];
9396
+
9397
+ for (var _i = 0, _Object$entries = Object.entries(voteCountsByOption !== null && voteCountsByOption !== void 0 ? voteCountsByOption : {}); _i < _Object$entries.length; _i++) {
9398
+ var _Object$entries$_i = _slicedToArray__default['default'](_Object$entries[_i], 2),
9399
+ id = _Object$entries$_i[0],
9400
+ count = _Object$entries$_i[1];
9401
+
9402
+ if (count > maxVotes) {
9403
+ winningOptions = [id];
9404
+ maxVotes = count;
9405
+ } else if (count === maxVotes) {
9406
+ winningOptions.push(id);
9407
+ }
9408
+ }
9409
+
9410
+ return winningOptions;
9411
+ }
9412
+
9413
+ function getOwnVotesByOptionId(ownVotes) {
9414
+ return !ownVotes ? {} : ownVotes.reduce(function (acc, vote) {
9415
+ if (isVoteAnswer(vote) || !vote.option_id) return acc;
9416
+ acc[vote.option_id] = vote;
9417
+ return acc;
9418
+ }, {});
9419
+ }
9420
+
9421
+ function extractPollData(pollResponse) {
9422
+ return {
9423
+ allow_answers: pollResponse.allow_answers,
9424
+ allow_user_suggested_options: pollResponse.allow_user_suggested_options,
9425
+ description: pollResponse.description,
9426
+ enforce_unique_vote: pollResponse.enforce_unique_vote,
9427
+ id: pollResponse.id,
9428
+ is_closed: pollResponse.is_closed,
9429
+ max_votes_allowed: pollResponse.max_votes_allowed,
9430
+ name: pollResponse.name,
9431
+ options: pollResponse.options,
9432
+ voting_visibility: pollResponse.voting_visibility
9433
+ };
9434
+ }
9435
+ function extractPollEnrichedData(pollResponse) {
9436
+ return {
9437
+ answers_count: pollResponse.answers_count,
9438
+ latest_votes_by_option: pollResponse.latest_votes_by_option,
9439
+ vote_count: pollResponse.vote_count,
9440
+ vote_counts_by_option: pollResponse.vote_counts_by_option
9441
+ };
9442
+ }
9443
+
9444
+ function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(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(_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 e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
9445
+
9446
+ function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(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$1(o, minLen); }
9447
+
9448
+ function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
9449
+ var PollManager = /*#__PURE__*/function () {
9450
+ // The pollCache contains only polls that have been created and sent as messages
9451
+ // (i.e only polls that are coupled with a message, can be voted on and require a
9452
+ // reactive state). It shall work as a basic look-up table for our SDK to be able
9453
+ // to quickly consume poll state that will be reactive even without the polls being
9454
+ // rendered within the UI.
9455
+ function PollManager(_ref) {
9456
+ var _this = this;
9457
+
9458
+ var client = _ref.client;
9459
+
9460
+ _classCallCheck__default['default'](this, PollManager);
9461
+
9462
+ _defineProperty__default['default'](this, "client", void 0);
9463
+
9464
+ _defineProperty__default['default'](this, "pollCache", new Map());
9465
+
9466
+ _defineProperty__default['default'](this, "unsubscribeFunctions", new Set());
9467
+
9468
+ _defineProperty__default['default'](this, "fromState", function (id) {
9469
+ return _this.pollCache.get(id);
9470
+ });
9471
+
9472
+ _defineProperty__default['default'](this, "registerSubscriptions", function () {
9473
+ if (_this.unsubscribeFunctions.size) {
9474
+ // Already listening for events and changes
9475
+ return;
9476
+ }
9477
+
9478
+ _this.unsubscribeFunctions.add(_this.subscribeMessageNew());
9479
+
9480
+ _this.unsubscribeFunctions.add(_this.subscribePollUpdated());
9481
+
9482
+ _this.unsubscribeFunctions.add(_this.subscribePollClosed());
9483
+
9484
+ _this.unsubscribeFunctions.add(_this.subscribeVoteCasted());
9485
+
9486
+ _this.unsubscribeFunctions.add(_this.subscribeVoteChanged());
9487
+
9488
+ _this.unsubscribeFunctions.add(_this.subscribeVoteRemoved());
9489
+ });
9490
+
9491
+ _defineProperty__default['default'](this, "unregisterSubscriptions", function () {
9492
+ _this.unsubscribeFunctions.forEach(function (cleanupFunction) {
9493
+ return cleanupFunction();
9494
+ });
9495
+
9496
+ _this.unsubscribeFunctions.clear();
9497
+ });
9498
+
9499
+ _defineProperty__default['default'](this, "createPoll", /*#__PURE__*/function () {
9500
+ var _ref2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(poll) {
9501
+ var _yield$_this$client$c, createdPoll;
9502
+
9503
+ return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
9504
+ while (1) {
9505
+ switch (_context.prev = _context.next) {
9506
+ case 0:
9507
+ _context.next = 2;
9508
+ return _this.client.createPoll(poll);
9509
+
9510
+ case 2:
9511
+ _yield$_this$client$c = _context.sent;
9512
+ createdPoll = _yield$_this$client$c.poll;
9513
+ return _context.abrupt("return", new Poll({
9514
+ client: _this.client,
9515
+ poll: createdPoll
9516
+ }));
9517
+
9518
+ case 5:
9519
+ case "end":
9520
+ return _context.stop();
9521
+ }
9522
+ }
9523
+ }, _callee);
9524
+ }));
9525
+
9526
+ return function (_x) {
9527
+ return _ref2.apply(this, arguments);
9528
+ };
9529
+ }());
9530
+
9531
+ _defineProperty__default['default'](this, "getPoll", /*#__PURE__*/function () {
9532
+ var _ref3 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(id) {
9533
+ var cachedPoll, _yield$_this$client$g, poll;
9534
+
9535
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
9536
+ while (1) {
9537
+ switch (_context2.prev = _context2.next) {
9538
+ case 0:
9539
+ cachedPoll = _this.fromState(id); // optimistically return the cached poll if it exists and update in the background
9540
+
9541
+ if (!cachedPoll) {
9542
+ _context2.next = 4;
9543
+ break;
9544
+ }
9545
+
9546
+ _this.client.getPoll(id).then(function (_ref4) {
9547
+ var poll = _ref4.poll;
9548
+ return _this.setOrOverwriteInCache(poll, true);
9549
+ });
9550
+
9551
+ return _context2.abrupt("return", cachedPoll);
9552
+
9553
+ case 4:
9554
+ _context2.next = 6;
9555
+ return _this.client.getPoll(id);
9556
+
9557
+ case 6:
9558
+ _yield$_this$client$g = _context2.sent;
9559
+ poll = _yield$_this$client$g.poll;
9560
+
9561
+ _this.setOrOverwriteInCache(poll);
9562
+
9563
+ return _context2.abrupt("return", _this.fromState(id));
9564
+
9565
+ case 10:
9566
+ case "end":
9567
+ return _context2.stop();
9568
+ }
9569
+ }
9570
+ }, _callee2);
9571
+ }));
9572
+
9573
+ return function (_x2) {
9574
+ return _ref3.apply(this, arguments);
9575
+ };
9576
+ }());
9577
+
9578
+ _defineProperty__default['default'](this, "queryPolls", /*#__PURE__*/function () {
9579
+ var _ref5 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(filter) {
9580
+ var sort,
9581
+ options,
9582
+ _yield$_this$client$q,
9583
+ polls,
9584
+ next,
9585
+ pollInstances,
9586
+ _args3 = arguments;
9587
+
9588
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
9589
+ while (1) {
9590
+ switch (_context3.prev = _context3.next) {
9591
+ case 0:
9592
+ sort = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : [];
9593
+ options = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
9594
+ _context3.next = 4;
9595
+ return _this.client.queryPolls(filter, sort, options);
9596
+
9597
+ case 4:
9598
+ _yield$_this$client$q = _context3.sent;
9599
+ polls = _yield$_this$client$q.polls;
9600
+ next = _yield$_this$client$q.next;
9601
+ pollInstances = polls.map(function (poll) {
9602
+ _this.setOrOverwriteInCache(poll, true);
9603
+
9604
+ return _this.fromState(poll.id);
9605
+ });
9606
+ return _context3.abrupt("return", {
9607
+ polls: pollInstances,
9608
+ next: next
9609
+ });
9610
+
9611
+ case 9:
9612
+ case "end":
9613
+ return _context3.stop();
9614
+ }
9615
+ }
9616
+ }, _callee3);
9617
+ }));
9618
+
9619
+ return function (_x3) {
9620
+ return _ref5.apply(this, arguments);
9621
+ };
9622
+ }());
8696
9623
 
8697
- case 11:
8698
- response = _context.sent;
8699
- currentThreads = _this.threadsById;
8700
- nextThreads = [];
8701
- _iterator = _createForOfIteratorHelper$1(response.threads);
9624
+ _defineProperty__default['default'](this, "hydratePollCache", function (messages, overwriteState) {
9625
+ var _iterator = _createForOfIteratorHelper$1(messages),
9626
+ _step;
8702
9627
 
8703
- try {
8704
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
8705
- incomingThread = _step.value;
8706
- existingThread = currentThreads[incomingThread.id];
9628
+ try {
9629
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
9630
+ var message = _step.value;
8707
9631
 
8708
- if (existingThread) {
8709
- // Reuse thread instances if possible
8710
- nextThreads.push(existingThread);
9632
+ if (!message.poll) {
9633
+ continue;
9634
+ }
8711
9635
 
8712
- if (existingThread.hasStaleState) {
8713
- existingThread.hydrateState(incomingThread);
8714
- }
8715
- } else {
8716
- nextThreads.push(incomingThread);
8717
- }
8718
- }
8719
- } catch (err) {
8720
- _iterator.e(err);
8721
- } finally {
8722
- _iterator.f();
8723
- }
9636
+ var pollResponse = message.poll;
8724
9637
 
8725
- _this.state.next(function (current) {
8726
- var _response$next;
9638
+ _this.setOrOverwriteInCache(pollResponse, overwriteState);
9639
+ }
9640
+ } catch (err) {
9641
+ _iterator.e(err);
9642
+ } finally {
9643
+ _iterator.f();
9644
+ }
9645
+ });
8727
9646
 
8728
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8729
- threads: nextThreads,
8730
- unseenThreadIds: [],
8731
- isThreadOrderStale: false,
8732
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8733
- isLoading: false,
8734
- nextCursor: (_response$next = response.next) !== null && _response$next !== void 0 ? _response$next : null
8735
- }),
8736
- ready: true
8737
- });
8738
- });
9647
+ _defineProperty__default['default'](this, "setOrOverwriteInCache", function (pollResponse, overwriteState) {
9648
+ var pollFromCache = _this.fromState(pollResponse.id);
8739
9649
 
8740
- _context.next = 23;
8741
- break;
9650
+ if (!pollFromCache) {
9651
+ var poll = new Poll({
9652
+ client: _this.client,
9653
+ poll: pollResponse
9654
+ });
8742
9655
 
8743
- case 19:
8744
- _context.prev = 19;
8745
- _context.t0 = _context["catch"](7);
9656
+ _this.pollCache.set(poll.id, poll);
9657
+ } else if (overwriteState) {
9658
+ pollFromCache.reinitializeState(pollResponse);
9659
+ }
9660
+ });
8746
9661
 
8747
- _this.client.logger('error', _context.t0.message);
9662
+ _defineProperty__default['default'](this, "subscribePollUpdated", function () {
9663
+ return _this.client.on('poll.updated', function (event) {
9664
+ var _event$poll;
8748
9665
 
8749
- _this.state.next(function (current) {
8750
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8751
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8752
- isLoading: false
8753
- })
8754
- });
8755
- });
9666
+ if ((_event$poll = event.poll) !== null && _event$poll !== void 0 && _event$poll.id) {
9667
+ var _this$fromState;
8756
9668
 
8757
- case 23:
8758
- case "end":
8759
- return _context.stop();
8760
- }
9669
+ (_this$fromState = _this.fromState(event.poll.id)) === null || _this$fromState === void 0 ? void 0 : _this$fromState.handlePollUpdated(event);
8761
9670
  }
8762
- }, _callee, null, [[7, 19]]);
8763
- })));
8764
-
8765
- _defineProperty__default['default'](this, "queryThreads", function () {
8766
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8767
- return _this.client.queryThreads(_objectSpread$1({
8768
- limit: 25,
8769
- participant_limit: 10,
8770
- reply_limit: 10,
8771
- watch: true
8772
- }, options));
9671
+ }).unsubscribe;
8773
9672
  });
8774
9673
 
8775
- _defineProperty__default['default'](this, "loadNextPage", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
8776
- var options,
8777
- _this$state$getLatest4,
8778
- pagination,
8779
- response,
8780
- _args2 = arguments;
9674
+ _defineProperty__default['default'](this, "subscribePollClosed", function () {
9675
+ return _this.client.on('poll.closed', function (event) {
9676
+ var _event$poll2;
8781
9677
 
8782
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
8783
- while (1) {
8784
- switch (_context2.prev = _context2.next) {
8785
- case 0:
8786
- options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
8787
- _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
9678
+ if ((_event$poll2 = event.poll) !== null && _event$poll2 !== void 0 && _event$poll2.id) {
9679
+ var _this$fromState2;
8788
9680
 
8789
- if (!(pagination.isLoadingNext || !pagination.nextCursor)) {
8790
- _context2.next = 4;
8791
- break;
8792
- }
9681
+ (_this$fromState2 = _this.fromState(event.poll.id)) === null || _this$fromState2 === void 0 ? void 0 : _this$fromState2.handlePollClosed(event);
9682
+ }
9683
+ }).unsubscribe;
9684
+ });
8793
9685
 
8794
- return _context2.abrupt("return");
9686
+ _defineProperty__default['default'](this, "subscribeVoteCasted", function () {
9687
+ return _this.client.on('poll.vote_casted', function (event) {
9688
+ var _event$poll3;
8795
9689
 
8796
- case 4:
8797
- _context2.prev = 4;
9690
+ if ((_event$poll3 = event.poll) !== null && _event$poll3 !== void 0 && _event$poll3.id) {
9691
+ var _this$fromState3;
8798
9692
 
8799
- _this.state.partialNext({
8800
- pagination: _objectSpread$1(_objectSpread$1({}, pagination), {}, {
8801
- isLoadingNext: true
8802
- })
8803
- });
9693
+ (_this$fromState3 = _this.fromState(event.poll.id)) === null || _this$fromState3 === void 0 ? void 0 : _this$fromState3.handleVoteCasted(event);
9694
+ }
9695
+ }).unsubscribe;
9696
+ });
8804
9697
 
8805
- _context2.next = 8;
8806
- return _this.queryThreads(_objectSpread$1(_objectSpread$1({}, options), {}, {
8807
- next: pagination.nextCursor
8808
- }));
9698
+ _defineProperty__default['default'](this, "subscribeVoteChanged", function () {
9699
+ return _this.client.on('poll.vote_changed', function (event) {
9700
+ var _event$poll4;
8809
9701
 
8810
- case 8:
8811
- response = _context2.sent;
9702
+ if ((_event$poll4 = event.poll) !== null && _event$poll4 !== void 0 && _event$poll4.id) {
9703
+ var _this$fromState4;
8812
9704
 
8813
- _this.state.next(function (current) {
8814
- var _response$next2;
9705
+ (_this$fromState4 = _this.fromState(event.poll.id)) === null || _this$fromState4 === void 0 ? void 0 : _this$fromState4.handleVoteChanged(event);
9706
+ }
9707
+ }).unsubscribe;
9708
+ });
8815
9709
 
8816
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8817
- threads: response.threads.length ? current.threads.concat(response.threads) : current.threads,
8818
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8819
- nextCursor: (_response$next2 = response.next) !== null && _response$next2 !== void 0 ? _response$next2 : null,
8820
- isLoadingNext: false
8821
- })
8822
- });
8823
- });
9710
+ _defineProperty__default['default'](this, "subscribeVoteRemoved", function () {
9711
+ return _this.client.on('poll.vote_removed', function (event) {
9712
+ var _event$poll5;
8824
9713
 
8825
- _context2.next = 16;
8826
- break;
9714
+ if ((_event$poll5 = event.poll) !== null && _event$poll5 !== void 0 && _event$poll5.id) {
9715
+ var _this$fromState5;
8827
9716
 
8828
- case 12:
8829
- _context2.prev = 12;
8830
- _context2.t0 = _context2["catch"](4);
9717
+ (_this$fromState5 = _this.fromState(event.poll.id)) === null || _this$fromState5 === void 0 ? void 0 : _this$fromState5.handleVoteRemoved(event);
9718
+ }
9719
+ }).unsubscribe;
9720
+ });
8831
9721
 
8832
- _this.client.logger('error', _context2.t0.message);
9722
+ _defineProperty__default['default'](this, "subscribeMessageNew", function () {
9723
+ return _this.client.on('message.new', function (event) {
9724
+ var message = event.message;
8833
9725
 
8834
- _this.state.next(function (current) {
8835
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8836
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8837
- isLoadingNext: false
8838
- })
8839
- });
8840
- });
9726
+ if (message) {
9727
+ var formattedMessage = formatMessage(message);
8841
9728
 
8842
- case 16:
8843
- case "end":
8844
- return _context2.stop();
8845
- }
9729
+ _this.hydratePollCache([formattedMessage]);
8846
9730
  }
8847
- }, _callee2, null, [[4, 12]]);
8848
- })));
9731
+ }).unsubscribe;
9732
+ });
8849
9733
 
8850
9734
  this.client = client;
8851
- this.state = new StateStore({
8852
- active: false,
8853
- isThreadOrderStale: false,
8854
- threads: [],
8855
- unreadThreadCount: 0,
8856
- unseenThreadIds: [],
8857
- lastConnectionDropAt: null,
8858
- pagination: {
8859
- isLoading: false,
8860
- isLoadingNext: false,
8861
- nextCursor: null
8862
- },
8863
- ready: false
8864
- });
8865
- this.threadsByIdGetterCache = {
8866
- threads: [],
8867
- threadsById: {}
8868
- };
8869
9735
  }
8870
9736
 
8871
- _createClass__default['default'](ThreadManager, [{
8872
- key: "threadsById",
9737
+ _createClass__default['default'](PollManager, [{
9738
+ key: "data",
8873
9739
  get: function get() {
8874
- var _this$state$getLatest5 = this.state.getLatestValue(),
8875
- threads = _this$state$getLatest5.threads;
8876
-
8877
- if (threads === this.threadsByIdGetterCache.threads) {
8878
- return this.threadsByIdGetterCache.threadsById;
8879
- }
8880
-
8881
- var threadsById = threads.reduce(function (newThreadsById, thread) {
8882
- newThreadsById[thread.id] = thread;
8883
- return newThreadsById;
8884
- }, {});
8885
- this.threadsByIdGetterCache.threads = threads;
8886
- this.threadsByIdGetterCache.threadsById = threadsById;
8887
- return threadsById;
9740
+ return this.pollCache;
8888
9741
  }
8889
9742
  }]);
8890
9743
 
8891
- return ThreadManager;
9744
+ return PollManager;
8892
9745
  }();
8893
9746
 
8894
9747
  var _excluded = ["created_at", "updated_at", "last_active", "online"],
@@ -8921,6 +9774,8 @@ var StreamChat = /*#__PURE__*/function () {
8921
9774
 
8922
9775
  _defineProperty__default['default'](this, "threads", void 0);
8923
9776
 
9777
+ _defineProperty__default['default'](this, "polls", void 0);
9778
+
8924
9779
  _defineProperty__default['default'](this, "anonymous", void 0);
8925
9780
 
8926
9781
  _defineProperty__default['default'](this, "persistUserOnConnectionFailure", void 0);
@@ -9819,6 +10674,9 @@ var StreamChat = /*#__PURE__*/function () {
9819
10674
  this.threads = new ThreadManager({
9820
10675
  client: this
9821
10676
  });
10677
+ this.polls = new PollManager({
10678
+ client: this
10679
+ });
9822
10680
  }
9823
10681
  /**
9824
10682
  * Get a client instance
@@ -11085,6 +11943,7 @@ var StreamChat = /*#__PURE__*/function () {
11085
11943
  returnedPage: channelState.messages,
11086
11944
  logger: this.logger
11087
11945
  }));
11946
+ this.polls.hydratePollCache(updatedMessagesSet.messages, true);
11088
11947
  }
11089
11948
 
11090
11949
  channels.push(c);
@@ -13386,7 +14245,7 @@ var StreamChat = /*#__PURE__*/function () {
13386
14245
  }, {
13387
14246
  key: "getUserAgent",
13388
14247
  value: function getUserAgent() {
13389
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.41.1");
14248
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.42.0");
13390
14249
  }
13391
14250
  }, {
13392
14251
  key: "setUserAgent",
@@ -14830,7 +15689,7 @@ var StreamChat = /*#__PURE__*/function () {
14830
15689
  }()
14831
15690
  /**
14832
15691
  * Creates a poll
14833
- * @param params PollData The poll that will be created
15692
+ * @param poll PollData The poll that will be created
14834
15693
  * @param userId string The user id (only serverside)
14835
15694
  * @returns {APIResponse & CreatePollAPIResponse} The poll
14836
15695
  */
@@ -15030,13 +15889,11 @@ var StreamChat = /*#__PURE__*/function () {
15030
15889
  while (1) {
15031
15890
  switch (_context103.prev = _context103.next) {
15032
15891
  case 0:
15033
- return _context103.abrupt("return", this.partialUpdatePoll(id, _objectSpread({
15892
+ return _context103.abrupt("return", this.partialUpdatePoll(id, {
15034
15893
  set: {
15035
15894
  is_closed: true
15036
15895
  }
15037
- }, userId ? {
15038
- user_id: userId
15039
- } : {})));
15896
+ }, userId));
15040
15897
 
15041
15898
  case 1:
15042
15899
  case "end":
@@ -15412,6 +16269,60 @@ var StreamChat = /*#__PURE__*/function () {
15412
16269
 
15413
16270
  return queryPollVotes;
15414
16271
  }()
16272
+ /**
16273
+ * Queries poll answers
16274
+ * @param pollId
16275
+ * @param filter
16276
+ * @param sort
16277
+ * @param options Option object, {limit: 10, offset:0}
16278
+ * @param userId string The user id (only serverside)
16279
+ * @returns {APIResponse & PollAnswersAPIResponse} The poll votes
16280
+ */
16281
+
16282
+ }, {
16283
+ key: "queryPollAnswers",
16284
+ value: function () {
16285
+ var _queryPollAnswers = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee113(pollId) {
16286
+ var filter,
16287
+ sort,
16288
+ options,
16289
+ userId,
16290
+ q,
16291
+ _args113 = arguments;
16292
+ return _regeneratorRuntime__default['default'].wrap(function _callee113$(_context113) {
16293
+ while (1) {
16294
+ switch (_context113.prev = _context113.next) {
16295
+ case 0:
16296
+ filter = _args113.length > 1 && _args113[1] !== undefined ? _args113[1] : {};
16297
+ sort = _args113.length > 2 && _args113[2] !== undefined ? _args113[2] : [];
16298
+ options = _args113.length > 3 && _args113[3] !== undefined ? _args113[3] : {};
16299
+ userId = _args113.length > 4 ? _args113[4] : undefined;
16300
+ q = userId ? "?user_id=".concat(userId) : '';
16301
+ _context113.next = 7;
16302
+ return this.post(this.baseURL + "/polls/".concat(encodeURIComponent(pollId), "/votes").concat(q), _objectSpread({
16303
+ filter: _objectSpread(_objectSpread({}, filter), {}, {
16304
+ is_answer: true
16305
+ }),
16306
+ sort: normalizeQuerySort(sort)
16307
+ }, options));
16308
+
16309
+ case 7:
16310
+ return _context113.abrupt("return", _context113.sent);
16311
+
16312
+ case 8:
16313
+ case "end":
16314
+ return _context113.stop();
16315
+ }
16316
+ }
16317
+ }, _callee113, this);
16318
+ }));
16319
+
16320
+ function queryPollAnswers(_x174) {
16321
+ return _queryPollAnswers.apply(this, arguments);
16322
+ }
16323
+
16324
+ return queryPollAnswers;
16325
+ }()
15415
16326
  /**
15416
16327
  * Query message history
15417
16328
  * @param filter
@@ -15423,33 +16334,33 @@ var StreamChat = /*#__PURE__*/function () {
15423
16334
  }, {
15424
16335
  key: "queryMessageHistory",
15425
16336
  value: function () {
15426
- var _queryMessageHistory = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee113() {
16337
+ var _queryMessageHistory = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee114() {
15427
16338
  var filter,
15428
16339
  sort,
15429
16340
  options,
15430
- _args113 = arguments;
15431
- return _regeneratorRuntime__default['default'].wrap(function _callee113$(_context113) {
16341
+ _args114 = arguments;
16342
+ return _regeneratorRuntime__default['default'].wrap(function _callee114$(_context114) {
15432
16343
  while (1) {
15433
- switch (_context113.prev = _context113.next) {
16344
+ switch (_context114.prev = _context114.next) {
15434
16345
  case 0:
15435
- filter = _args113.length > 0 && _args113[0] !== undefined ? _args113[0] : {};
15436
- sort = _args113.length > 1 && _args113[1] !== undefined ? _args113[1] : [];
15437
- options = _args113.length > 2 && _args113[2] !== undefined ? _args113[2] : {};
15438
- _context113.next = 5;
16346
+ filter = _args114.length > 0 && _args114[0] !== undefined ? _args114[0] : {};
16347
+ sort = _args114.length > 1 && _args114[1] !== undefined ? _args114[1] : [];
16348
+ options = _args114.length > 2 && _args114[2] !== undefined ? _args114[2] : {};
16349
+ _context114.next = 5;
15439
16350
  return this.post(this.baseURL + '/messages/history', _objectSpread({
15440
16351
  filter: filter,
15441
16352
  sort: normalizeQuerySort(sort)
15442
16353
  }, options));
15443
16354
 
15444
16355
  case 5:
15445
- return _context113.abrupt("return", _context113.sent);
16356
+ return _context114.abrupt("return", _context114.sent);
15446
16357
 
15447
16358
  case 6:
15448
16359
  case "end":
15449
- return _context113.stop();
16360
+ return _context114.stop();
15450
16361
  }
15451
16362
  }
15452
- }, _callee113, this);
16363
+ }, _callee114, this);
15453
16364
  }));
15454
16365
 
15455
16366
  function queryMessageHistory() {
@@ -15470,32 +16381,32 @@ var StreamChat = /*#__PURE__*/function () {
15470
16381
  }, {
15471
16382
  key: "updateFlags",
15472
16383
  value: function () {
15473
- var _updateFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee114(message_ids, reviewed_by) {
16384
+ var _updateFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee115(message_ids, reviewed_by) {
15474
16385
  var options,
15475
- _args114 = arguments;
15476
- return _regeneratorRuntime__default['default'].wrap(function _callee114$(_context114) {
16386
+ _args115 = arguments;
16387
+ return _regeneratorRuntime__default['default'].wrap(function _callee115$(_context115) {
15477
16388
  while (1) {
15478
- switch (_context114.prev = _context114.next) {
16389
+ switch (_context115.prev = _context115.next) {
15479
16390
  case 0:
15480
- options = _args114.length > 2 && _args114[2] !== undefined ? _args114[2] : {};
15481
- _context114.next = 3;
16391
+ options = _args115.length > 2 && _args115[2] !== undefined ? _args115[2] : {};
16392
+ _context115.next = 3;
15482
16393
  return this.post(this.baseURL + '/automod/v1/moderation/update_flags', _objectSpread({
15483
16394
  message_ids: message_ids,
15484
16395
  reviewed_by: reviewed_by
15485
16396
  }, options));
15486
16397
 
15487
16398
  case 3:
15488
- return _context114.abrupt("return", _context114.sent);
16399
+ return _context115.abrupt("return", _context115.sent);
15489
16400
 
15490
16401
  case 4:
15491
16402
  case "end":
15492
- return _context114.stop();
16403
+ return _context115.stop();
15493
16404
  }
15494
16405
  }
15495
- }, _callee114, this);
16406
+ }, _callee115, this);
15496
16407
  }));
15497
16408
 
15498
- function updateFlags(_x174, _x175) {
16409
+ function updateFlags(_x175, _x176) {
15499
16410
  return _updateFlags.apply(this, arguments);
15500
16411
  }
15501
16412
 
@@ -15677,6 +16588,8 @@ exports.MaxPriority = MaxPriority;
15677
16588
  exports.MinPriority = MinPriority;
15678
16589
  exports.Moderation = Moderation;
15679
16590
  exports.Permission = Permission;
16591
+ exports.Poll = Poll;
16592
+ exports.PollManager = PollManager;
15680
16593
  exports.Segment = Segment;
15681
16594
  exports.StableWSConnection = StableWSConnection;
15682
16595
  exports.StateStore = StateStore;
@@ -15690,8 +16603,11 @@ exports.buildWsSuccessAfterFailureInsight = buildWsSuccessAfterFailureInsight;
15690
16603
  exports.chatCodes = chatCodes;
15691
16604
  exports.decodeBase64 = decodeBase64;
15692
16605
  exports.encodeBase64 = encodeBase64;
16606
+ exports.extractPollData = extractPollData;
16607
+ exports.extractPollEnrichedData = extractPollEnrichedData;
15693
16608
  exports.formatMessage = formatMessage;
15694
16609
  exports.isOwnUser = isOwnUser;
16610
+ exports.isVoteAnswer = isVoteAnswer;
15695
16611
  exports.logChatPromiseExecution = logChatPromiseExecution;
15696
16612
  exports.postInsights = postInsights;
15697
16613
  //# sourceMappingURL=index.js.map