stream-chat 8.41.0 → 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/browser.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 _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
17
17
  var FormData = require('form-data');
@@ -24,15 +24,15 @@ var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
24
24
 
25
25
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
26
26
 
27
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
28
- var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
29
- var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
30
- var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
31
27
  var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
32
28
  var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
33
29
  var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
34
30
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
35
31
  var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
32
+ var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
33
+ var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
34
+ var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
35
+ var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray);
36
36
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
37
37
  var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
38
38
  var FormData__default = /*#__PURE__*/_interopDefaultLegacy(FormData);
@@ -116,17 +116,222 @@ var decodeBase64 = function decodeBase64(s) {
116
116
  return r;
117
117
  };
118
118
 
119
+ var Campaign = /*#__PURE__*/function () {
120
+ function Campaign(client, id, data) {
121
+ _classCallCheck__default['default'](this, Campaign);
122
+
123
+ _defineProperty__default['default'](this, "id", void 0);
124
+
125
+ _defineProperty__default['default'](this, "data", void 0);
126
+
127
+ _defineProperty__default['default'](this, "client", void 0);
128
+
129
+ this.client = client;
130
+ this.id = id;
131
+ this.data = data;
132
+ }
133
+
134
+ _createClass__default['default'](Campaign, [{
135
+ key: "create",
136
+ value: function () {
137
+ var _create = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
138
+ var _this$data, _this$data2, _this$data3, _this$data4, _this$data5, _this$data6, _this$data7, _this$data8;
139
+
140
+ var body, result;
141
+ return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
142
+ while (1) {
143
+ switch (_context.prev = _context.next) {
144
+ case 0:
145
+ body = {
146
+ id: this.id,
147
+ message_template: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.message_template,
148
+ segment_ids: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.segment_ids,
149
+ sender_id: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.sender_id,
150
+ channel_template: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.channel_template,
151
+ create_channels: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.create_channels,
152
+ description: (_this$data6 = this.data) === null || _this$data6 === void 0 ? void 0 : _this$data6.description,
153
+ name: (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.name,
154
+ user_ids: (_this$data8 = this.data) === null || _this$data8 === void 0 ? void 0 : _this$data8.user_ids
155
+ };
156
+ _context.next = 3;
157
+ return this.client.createCampaign(body);
158
+
159
+ case 3:
160
+ result = _context.sent;
161
+ this.id = result.campaign.id;
162
+ this.data = result.campaign;
163
+ return _context.abrupt("return", result);
164
+
165
+ case 7:
166
+ case "end":
167
+ return _context.stop();
168
+ }
169
+ }
170
+ }, _callee, this);
171
+ }));
172
+
173
+ function create() {
174
+ return _create.apply(this, arguments);
175
+ }
176
+
177
+ return create;
178
+ }()
179
+ }, {
180
+ key: "verifyCampaignId",
181
+ value: function verifyCampaignId() {
182
+ if (!this.id) {
183
+ 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)');
184
+ }
185
+ }
186
+ }, {
187
+ key: "start",
188
+ value: function () {
189
+ var _start = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(options) {
190
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
191
+ while (1) {
192
+ switch (_context2.prev = _context2.next) {
193
+ case 0:
194
+ this.verifyCampaignId();
195
+ _context2.next = 3;
196
+ return this.client.startCampaign(this.id, options);
197
+
198
+ case 3:
199
+ return _context2.abrupt("return", _context2.sent);
200
+
201
+ case 4:
202
+ case "end":
203
+ return _context2.stop();
204
+ }
205
+ }
206
+ }, _callee2, this);
207
+ }));
208
+
209
+ function start(_x) {
210
+ return _start.apply(this, arguments);
211
+ }
212
+
213
+ return start;
214
+ }()
215
+ }, {
216
+ key: "update",
217
+ value: function () {
218
+ var _update = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(data) {
219
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
220
+ while (1) {
221
+ switch (_context3.prev = _context3.next) {
222
+ case 0:
223
+ this.verifyCampaignId();
224
+ return _context3.abrupt("return", this.client.updateCampaign(this.id, data));
225
+
226
+ case 2:
227
+ case "end":
228
+ return _context3.stop();
229
+ }
230
+ }
231
+ }, _callee3, this);
232
+ }));
233
+
234
+ function update(_x2) {
235
+ return _update.apply(this, arguments);
236
+ }
237
+
238
+ return update;
239
+ }()
240
+ }, {
241
+ key: "delete",
242
+ value: function () {
243
+ var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
244
+ return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
245
+ while (1) {
246
+ switch (_context4.prev = _context4.next) {
247
+ case 0:
248
+ this.verifyCampaignId();
249
+ _context4.next = 3;
250
+ return this.client.deleteCampaign(this.id);
251
+
252
+ case 3:
253
+ return _context4.abrupt("return", _context4.sent);
254
+
255
+ case 4:
256
+ case "end":
257
+ return _context4.stop();
258
+ }
259
+ }
260
+ }, _callee4, this);
261
+ }));
262
+
263
+ function _delete() {
264
+ return _delete2.apply(this, arguments);
265
+ }
266
+
267
+ return _delete;
268
+ }()
269
+ }, {
270
+ key: "stop",
271
+ value: function () {
272
+ var _stop = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
273
+ return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
274
+ while (1) {
275
+ switch (_context5.prev = _context5.next) {
276
+ case 0:
277
+ this.verifyCampaignId();
278
+ return _context5.abrupt("return", this.client.stopCampaign(this.id));
279
+
280
+ case 2:
281
+ case "end":
282
+ return _context5.stop();
283
+ }
284
+ }
285
+ }, _callee5, this);
286
+ }));
287
+
288
+ function stop() {
289
+ return _stop.apply(this, arguments);
290
+ }
291
+
292
+ return stop;
293
+ }()
294
+ }, {
295
+ key: "get",
296
+ value: function () {
297
+ var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
298
+ return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
299
+ while (1) {
300
+ switch (_context6.prev = _context6.next) {
301
+ case 0:
302
+ this.verifyCampaignId();
303
+ return _context6.abrupt("return", this.client.getCampaign(this.id));
304
+
305
+ case 2:
306
+ case "end":
307
+ return _context6.stop();
308
+ }
309
+ }
310
+ }, _callee6, this);
311
+ }));
312
+
313
+ function get() {
314
+ return _get.apply(this, arguments);
315
+ }
316
+
317
+ return get;
318
+ }()
319
+ }]);
320
+
321
+ return Campaign;
322
+ }();
323
+
119
324
  var https = null;
120
325
 
121
- 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; }
326
+ 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; }
122
327
 
123
- 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; }
328
+ 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; }
124
329
 
125
- 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; } } }; }
330
+ 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; } } }; }
126
331
 
127
- 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); }
332
+ 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); }
128
333
 
129
- 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; }
334
+ 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; }
130
335
 
131
336
  /**
132
337
  * logChatPromiseExecution - utility function for logging the execution of a promise..
@@ -211,7 +416,7 @@ function normalizeQuerySort(sort) {
211
416
  var sortFields = [];
212
417
  var sortArr = Array.isArray(sort) ? sort : [sort];
213
418
 
214
- var _iterator = _createForOfIteratorHelper$4(sortArr),
419
+ var _iterator = _createForOfIteratorHelper$5(sortArr),
215
420
  _step;
216
421
 
217
422
  try {
@@ -381,7 +586,7 @@ var axiosParamsSerializer = function axiosParamsSerializer(params) {
381
586
  */
382
587
 
383
588
  function formatMessage(message) {
384
- return _objectSpread$b(_objectSpread$b({}, message), {}, {
589
+ return _objectSpread$c(_objectSpread$c({}, message), {}, {
385
590
  /**
386
591
  * @deprecated please use `html`
387
592
  */
@@ -586,7 +791,7 @@ var messagePaginationCreatedAtAround = function messagePaginationCreatedAtAround
586
791
  returnedPage = _ref3.returnedPage,
587
792
  messagePaginationOptions = _ref3.messagePaginationOptions;
588
793
 
589
- var newPagination = _objectSpread$b({}, parentSet.pagination);
794
+ var newPagination = _objectSpread$c({}, parentSet.pagination);
590
795
 
591
796
  if (!(messagePaginationOptions !== null && messagePaginationOptions !== void 0 && messagePaginationOptions.created_at_around)) return newPagination;
592
797
  var hasPrev;
@@ -651,7 +856,7 @@ var messagePaginationIdAround = function messagePaginationIdAround(_ref5) {
651
856
  returnedPage = _ref5.returnedPage,
652
857
  messagePaginationOptions = _ref5.messagePaginationOptions;
653
858
 
654
- var newPagination = _objectSpread$b({}, parentSet.pagination);
859
+ var newPagination = _objectSpread$c({}, parentSet.pagination);
655
860
 
656
861
  var _ref6 = messagePaginationOptions || {},
657
862
  id_around = _ref6.id_around;
@@ -709,7 +914,7 @@ var messagePaginationLinear = function messagePaginationLinear(_ref8) {
709
914
  returnedPage = _ref8.returnedPage,
710
915
  messagePaginationOptions = _ref8.messagePaginationOptions;
711
916
 
712
- var newPagination = _objectSpread$b({}, parentSet.pagination);
917
+ var newPagination = _objectSpread$c({}, parentSet.pagination);
713
918
 
714
919
  var hasPrev;
715
920
  var hasNext;
@@ -763,9 +968,9 @@ var DEFAULT_MESSAGE_SET_PAGINATION = {
763
968
  hasPrev: true
764
969
  };
765
970
 
766
- 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; }
971
+ 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; }
767
972
 
768
- 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; }
973
+ 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; }
769
974
 
770
975
  /**
771
976
  * ChannelState - A container class for the channel state.
@@ -838,142 +1043,31 @@ var ChannelState = /*#__PURE__*/function () {
838
1043
  };
839
1044
  });
840
1045
 
841
- _defineProperty__default['default'](this, "updatePollVote", function (pollVote, poll, messageId) {
842
- var _message$poll;
843
-
844
- var message = _this.findMessage(messageId);
845
-
846
- if (!message) return;
847
- if (message.poll_id !== pollVote.poll_id) return;
848
-
849
- var updatedPoll = _objectSpread$a({}, poll);
1046
+ _defineProperty__default['default'](this, "updateUserMessages", function (user) {
1047
+ var _updateUserMessages = function _updateUserMessages(messages, user) {
1048
+ for (var i = 0; i < messages.length; i++) {
1049
+ var _m$user;
850
1050
 
851
- var ownVotes = _toConsumableArray__default['default'](((_message$poll = message.poll) === null || _message$poll === void 0 ? void 0 : _message$poll.own_votes) || []);
1051
+ var m = messages[i];
852
1052
 
853
- if (pollVote.user_id === _this._channel.getClient().userID) {
854
- if (pollVote.option_id && poll.enforce_unique_vote) {
855
- // remove all previous votes where option_id is not empty
856
- ownVotes = ownVotes.filter(function (vote) {
857
- return !vote.option_id;
858
- });
859
- } else if (pollVote.answer_text) {
860
- // remove all previous votes where option_id is empty
861
- ownVotes = ownVotes.filter(function (vote) {
862
- return vote.answer_text;
863
- });
1053
+ if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
1054
+ messages[i] = _objectSpread$b(_objectSpread$b({}, m), {}, {
1055
+ user: user
1056
+ });
1057
+ }
864
1058
  }
1059
+ };
865
1060
 
866
- ownVotes.push(pollVote);
867
- }
868
-
869
- updatedPoll.own_votes = ownVotes;
870
-
871
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
872
- poll: updatedPoll
1061
+ _this.messageSets.forEach(function (set) {
1062
+ return _updateUserMessages(set.messages, user);
873
1063
  });
874
1064
 
875
- _this.addMessageSorted(newMessage, false, false);
876
- });
1065
+ for (var parentId in _this.threads) {
1066
+ _updateUserMessages(_this.threads[parentId], user);
1067
+ }
877
1068
 
878
- _defineProperty__default['default'](this, "addPollVote", function (pollVote, poll, messageId) {
879
- var _message$poll2;
880
-
881
- var message = _this.findMessage(messageId);
882
-
883
- if (!message) return;
884
- if (message.poll_id !== pollVote.poll_id) return;
885
-
886
- var updatedPoll = _objectSpread$a({}, poll);
887
-
888
- var ownVotes = _toConsumableArray__default['default'](((_message$poll2 = message.poll) === null || _message$poll2 === void 0 ? void 0 : _message$poll2.own_votes) || []);
889
-
890
- if (pollVote.user_id === _this._channel.getClient().userID) {
891
- ownVotes.push(pollVote);
892
- }
893
-
894
- updatedPoll.own_votes = ownVotes;
895
-
896
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
897
- poll: updatedPoll
898
- });
899
-
900
- _this.addMessageSorted(newMessage, false, false);
901
- });
902
-
903
- _defineProperty__default['default'](this, "removePollVote", function (pollVote, poll, messageId) {
904
- var _message$poll3;
905
-
906
- var message = _this.findMessage(messageId);
907
-
908
- if (!message) return;
909
- if (message.poll_id !== pollVote.poll_id) return;
910
-
911
- var updatedPoll = _objectSpread$a({}, poll);
912
-
913
- var ownVotes = _toConsumableArray__default['default'](((_message$poll3 = message.poll) === null || _message$poll3 === void 0 ? void 0 : _message$poll3.own_votes) || []);
914
-
915
- if (pollVote.user_id === _this._channel.getClient().userID) {
916
- var index = ownVotes.findIndex(function (vote) {
917
- return vote.option_id === pollVote.option_id;
918
- });
919
-
920
- if (index > -1) {
921
- ownVotes.splice(index, 1);
922
- }
923
- }
924
-
925
- updatedPoll.own_votes = ownVotes;
926
-
927
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
928
- poll: updatedPoll
929
- });
930
-
931
- _this.addMessageSorted(newMessage, false, false);
932
- });
933
-
934
- _defineProperty__default['default'](this, "updatePoll", function (poll, messageId) {
935
- var _message$poll4;
936
-
937
- var message = _this.findMessage(messageId);
938
-
939
- if (!message) return;
940
-
941
- var updatedPoll = _objectSpread$a(_objectSpread$a({}, poll), {}, {
942
- own_votes: _toConsumableArray__default['default'](((_message$poll4 = message.poll) === null || _message$poll4 === void 0 ? void 0 : _message$poll4.own_votes) || [])
943
- });
944
-
945
- var newMessage = _objectSpread$a(_objectSpread$a({}, message), {}, {
946
- poll: updatedPoll
947
- });
948
-
949
- _this.addMessageSorted(newMessage, false, false);
950
- });
951
-
952
- _defineProperty__default['default'](this, "updateUserMessages", function (user) {
953
- var _updateUserMessages = function _updateUserMessages(messages, user) {
954
- for (var i = 0; i < messages.length; i++) {
955
- var _m$user;
956
-
957
- var m = messages[i];
958
-
959
- if (((_m$user = m.user) === null || _m$user === void 0 ? void 0 : _m$user.id) === user.id) {
960
- messages[i] = _objectSpread$a(_objectSpread$a({}, m), {}, {
961
- user: user
962
- });
963
- }
964
- }
965
- };
966
-
967
- _this.messageSets.forEach(function (set) {
968
- return _updateUserMessages(set.messages, user);
969
- });
970
-
971
- for (var parentId in _this.threads) {
972
- _updateUserMessages(_this.threads[parentId], user);
973
- }
974
-
975
- _updateUserMessages(_this.pinnedMessages, user);
976
- });
1069
+ _updateUserMessages(_this.pinnedMessages, user);
1070
+ });
977
1071
 
978
1072
  _defineProperty__default['default'](this, "deleteUserMessages", function (user) {
979
1073
  var hardDelete = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
@@ -1012,7 +1106,7 @@ var ChannelState = /*#__PURE__*/function () {
1012
1106
  user: m.user
1013
1107
  };
1014
1108
  } else {
1015
- messages[i] = _objectSpread$a(_objectSpread$a({}, m), {}, {
1109
+ messages[i] = _objectSpread$b(_objectSpread$b({}, m), {}, {
1016
1110
  type: 'deleted',
1017
1111
  deleted_at: user.deleted_at ? new Date(user.deleted_at) : null
1018
1112
  });
@@ -1330,7 +1424,7 @@ var ChannelState = /*#__PURE__*/function () {
1330
1424
  var parseMessage = function parseMessage(m) {
1331
1425
  var _m$pinned_at, _m$updated_at;
1332
1426
 
1333
- return _objectSpread$a(_objectSpread$a({}, m), {}, {
1427
+ return _objectSpread$b(_objectSpread$b({}, m), {}, {
1334
1428
  created_at: m.created_at.toISOString(),
1335
1429
  pinned_at: (_m$pinned_at = m.pinned_at) === null || _m$pinned_at === void 0 ? void 0 : _m$pinned_at.toISOString(),
1336
1430
  updated_at: (_m$updated_at = m.updated_at) === null || _m$updated_at === void 0 ? void 0 : _m$updated_at.toISOString()
@@ -1340,8 +1434,8 @@ var ChannelState = /*#__PURE__*/function () {
1340
1434
  var update = function update(messages) {
1341
1435
  var updatedMessages = messages.reduce(function (acc, msg) {
1342
1436
  if (msg.quoted_message_id === message.id) {
1343
- acc.push(_objectSpread$a(_objectSpread$a({}, parseMessage(msg)), {}, {
1344
- quoted_message: remove ? _objectSpread$a(_objectSpread$a({}, message), {}, {
1437
+ acc.push(_objectSpread$b(_objectSpread$b({}, parseMessage(msg)), {}, {
1438
+ quoted_message: remove ? _objectSpread$b(_objectSpread$b({}, message), {}, {
1345
1439
  attachments: []
1346
1440
  }) : message
1347
1441
  }));
@@ -1824,15 +1918,15 @@ var ChannelState = /*#__PURE__*/function () {
1824
1918
  return ChannelState;
1825
1919
  }();
1826
1920
 
1827
- 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; } } }; }
1921
+ 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; } } }; }
1828
1922
 
1829
- 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); }
1923
+ 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); }
1830
1924
 
1831
- 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; }
1925
+ 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; }
1832
1926
 
1833
- 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; }
1927
+ 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; }
1834
1928
 
1835
- 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; }
1929
+ 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; }
1836
1930
  /**
1837
1931
  * Channel - The Channel class manages it's own state.
1838
1932
  */
@@ -1905,7 +1999,7 @@ var Channel = /*#__PURE__*/function () {
1905
1999
  while (1) {
1906
2000
  switch (_context.prev = _context.next) {
1907
2001
  case 0:
1908
- defaultOptions = _objectSpread$9(_objectSpread$9({}, options), {}, {
2002
+ defaultOptions = _objectSpread$a(_objectSpread$a({}, options), {}, {
1909
2003
  watch: false,
1910
2004
  state: false,
1911
2005
  presence: false
@@ -1977,7 +2071,7 @@ var Channel = /*#__PURE__*/function () {
1977
2071
 
1978
2072
  this.data = data; // this._data is used for the requests...
1979
2073
 
1980
- this._data = _objectSpread$9({}, data);
2074
+ this._data = _objectSpread$a({}, data);
1981
2075
  this.cid = "".concat(type, ":").concat(id);
1982
2076
  this.listeners = {}; // perhaps the state variable should be private
1983
2077
 
@@ -2039,7 +2133,7 @@ var Channel = /*#__PURE__*/function () {
2039
2133
  switch (_context2.prev = _context2.next) {
2040
2134
  case 0:
2041
2135
  _context2.next = 2;
2042
- return this.getClient().post(this._channelURL() + '/message', _objectSpread$9({
2136
+ return this.getClient().post(this._channelURL() + '/message', _objectSpread$a({
2043
2137
  message: message
2044
2138
  }, options));
2045
2139
 
@@ -2155,7 +2249,7 @@ var Channel = /*#__PURE__*/function () {
2155
2249
 
2156
2250
  case 3:
2157
2251
  // Return a list of channels
2158
- payload = _objectSpread$9(_objectSpread$9({
2252
+ payload = _objectSpread$a(_objectSpread$a({
2159
2253
  filter_conditions: {
2160
2254
  cid: this.cid
2161
2255
  }
@@ -2252,7 +2346,7 @@ var Channel = /*#__PURE__*/function () {
2252
2346
 
2253
2347
  _context5.next = 6;
2254
2348
  return this.getClient().get(this.getClient().baseURL + '/members', {
2255
- payload: _objectSpread$9({
2349
+ payload: _objectSpread$a({
2256
2350
  type: type,
2257
2351
  id: id,
2258
2352
  members: members,
@@ -2358,7 +2452,7 @@ var Channel = /*#__PURE__*/function () {
2358
2452
 
2359
2453
  case 4:
2360
2454
  _context7.next = 6;
2361
- return this.getClient().post(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(messageID), "/reaction"), _objectSpread$9({
2455
+ return this.getClient().post(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(messageID), "/reaction"), _objectSpread$a({
2362
2456
  reaction: reaction
2363
2457
  }, options));
2364
2458
 
@@ -2439,7 +2533,7 @@ var Channel = /*#__PURE__*/function () {
2439
2533
  delete channelData[key];
2440
2534
  });
2441
2535
  _context8.next = 7;
2442
- return this._update(_objectSpread$9({
2536
+ return this._update(_objectSpread$a({
2443
2537
  message: updateMessage,
2444
2538
  data: channelData
2445
2539
  }, options));
@@ -2611,7 +2705,7 @@ var Channel = /*#__PURE__*/function () {
2611
2705
  case 0:
2612
2706
  options = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
2613
2707
  _context12.next = 3;
2614
- return this.getClient().delete(this._channelURL(), _objectSpread$9({}, options));
2708
+ return this.getClient().delete(this._channelURL(), _objectSpread$a({}, options));
2615
2709
 
2616
2710
  case 3:
2617
2711
  return _context12.abrupt("return", _context12.sent);
@@ -2687,7 +2781,7 @@ var Channel = /*#__PURE__*/function () {
2687
2781
  case 0:
2688
2782
  options = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
2689
2783
  _context14.next = 3;
2690
- return this._update(_objectSpread$9({
2784
+ return this._update(_objectSpread$a({
2691
2785
  accept_invite: true
2692
2786
  }, options));
2693
2787
 
@@ -2728,7 +2822,7 @@ var Channel = /*#__PURE__*/function () {
2728
2822
  case 0:
2729
2823
  options = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : {};
2730
2824
  _context15.next = 3;
2731
- return this._update(_objectSpread$9({
2825
+ return this._update(_objectSpread$a({
2732
2826
  reject_invite: true
2733
2827
  }, options));
2734
2828
 
@@ -2770,7 +2864,7 @@ var Channel = /*#__PURE__*/function () {
2770
2864
  case 0:
2771
2865
  options = _args16.length > 2 && _args16[2] !== undefined ? _args16[2] : {};
2772
2866
  _context16.next = 3;
2773
- return this._update(_objectSpread$9({
2867
+ return this._update(_objectSpread$a({
2774
2868
  add_members: members,
2775
2869
  message: message
2776
2870
  }, options));
@@ -2813,7 +2907,7 @@ var Channel = /*#__PURE__*/function () {
2813
2907
  case 0:
2814
2908
  options = _args17.length > 2 && _args17[2] !== undefined ? _args17[2] : {};
2815
2909
  _context17.next = 3;
2816
- return this._update(_objectSpread$9({
2910
+ return this._update(_objectSpread$a({
2817
2911
  add_moderators: members,
2818
2912
  message: message
2819
2913
  }, options));
@@ -2856,7 +2950,7 @@ var Channel = /*#__PURE__*/function () {
2856
2950
  case 0:
2857
2951
  options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
2858
2952
  _context18.next = 3;
2859
- return this._update(_objectSpread$9({
2953
+ return this._update(_objectSpread$a({
2860
2954
  assign_roles: roles,
2861
2955
  message: message
2862
2956
  }, options));
@@ -2899,7 +2993,7 @@ var Channel = /*#__PURE__*/function () {
2899
2993
  case 0:
2900
2994
  options = _args19.length > 2 && _args19[2] !== undefined ? _args19[2] : {};
2901
2995
  _context19.next = 3;
2902
- return this._update(_objectSpread$9({
2996
+ return this._update(_objectSpread$a({
2903
2997
  invites: members,
2904
2998
  message: message
2905
2999
  }, options));
@@ -2942,7 +3036,7 @@ var Channel = /*#__PURE__*/function () {
2942
3036
  case 0:
2943
3037
  options = _args20.length > 2 && _args20[2] !== undefined ? _args20[2] : {};
2944
3038
  _context20.next = 3;
2945
- return this._update(_objectSpread$9({
3039
+ return this._update(_objectSpread$a({
2946
3040
  remove_members: members,
2947
3041
  message: message
2948
3042
  }, options));
@@ -2985,7 +3079,7 @@ var Channel = /*#__PURE__*/function () {
2985
3079
  case 0:
2986
3080
  options = _args21.length > 2 && _args21[2] !== undefined ? _args21[2] : {};
2987
3081
  _context21.next = 3;
2988
- return this._update(_objectSpread$9({
3082
+ return this._update(_objectSpread$a({
2989
3083
  demote_moderators: members,
2990
3084
  message: message
2991
3085
  }, options));
@@ -3070,7 +3164,7 @@ var Channel = /*#__PURE__*/function () {
3070
3164
  case 0:
3071
3165
  opts = _args23.length > 0 && _args23[0] !== undefined ? _args23[0] : {};
3072
3166
  _context23.next = 3;
3073
- return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$9({
3167
+ return this.getClient().post(this.getClient().baseURL + '/moderation/mute/channel', _objectSpread$a({
3074
3168
  channel_cid: this.cid
3075
3169
  }, opts));
3076
3170
 
@@ -3112,7 +3206,7 @@ var Channel = /*#__PURE__*/function () {
3112
3206
  case 0:
3113
3207
  opts = _args24.length > 0 && _args24[0] !== undefined ? _args24[0] : {};
3114
3208
  _context24.next = 3;
3115
- return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$9({
3209
+ return this.getClient().post(this.getClient().baseURL + '/moderation/unmute/channel', _objectSpread$a({
3116
3210
  channel_cid: this.cid
3117
3211
  }, opts));
3118
3212
 
@@ -3197,7 +3291,7 @@ var Channel = /*#__PURE__*/function () {
3197
3291
 
3198
3292
  this.lastTypingEvent = new Date();
3199
3293
  _context25.next = 10;
3200
- return this.sendEvent(_objectSpread$9({
3294
+ return this.sendEvent(_objectSpread$a({
3201
3295
  type: 'typing.start',
3202
3296
  parent_id: parent_id
3203
3297
  }, options || {}));
@@ -3241,7 +3335,7 @@ var Channel = /*#__PURE__*/function () {
3241
3335
  this.lastTypingEvent = null;
3242
3336
  this.isTyping = false;
3243
3337
  _context26.next = 6;
3244
- return this.sendEvent(_objectSpread$9({
3338
+ return this.sendEvent(_objectSpread$a({
3245
3339
  type: 'typing.stop',
3246
3340
  parent_id: parent_id
3247
3341
  }, options || {}));
@@ -3328,7 +3422,7 @@ var Channel = /*#__PURE__*/function () {
3328
3422
 
3329
3423
  case 4:
3330
3424
  _context27.next = 6;
3331
- return this.getClient().post(this._channelURL() + '/read', _objectSpread$9({}, data));
3425
+ return this.getClient().post(this._channelURL() + '/read', _objectSpread$a({}, data));
3332
3426
 
3333
3427
  case 6:
3334
3428
  return _context27.abrupt("return", _context27.sent);
@@ -3375,7 +3469,7 @@ var Channel = /*#__PURE__*/function () {
3375
3469
 
3376
3470
  case 3:
3377
3471
  _context28.next = 5;
3378
- return this.getClient().post(this._channelURL() + '/unread', _objectSpread$9({}, data));
3472
+ return this.getClient().post(this._channelURL() + '/unread', _objectSpread$a({}, data));
3379
3473
 
3380
3474
  case 5:
3381
3475
  return _context28.abrupt("return", _context28.sent);
@@ -3443,7 +3537,7 @@ var Channel = /*#__PURE__*/function () {
3443
3537
  defaultOptions.watch = false;
3444
3538
  }
3445
3539
 
3446
- combined = _objectSpread$9(_objectSpread$9({}, defaultOptions), options);
3540
+ combined = _objectSpread$a(_objectSpread$a({}, defaultOptions), options);
3447
3541
  _context29.next = 7;
3448
3542
  return this.query(combined, 'latest');
3449
3543
 
@@ -3537,7 +3631,7 @@ var Channel = /*#__PURE__*/function () {
3537
3631
  case 0:
3538
3632
  normalizedSort = sort ? normalizeQuerySort(sort) : undefined;
3539
3633
  _context31.next = 3;
3540
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(parent_id), "/replies"), _objectSpread$9({
3634
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(parent_id), "/replies"), _objectSpread$a({
3541
3635
  sort: normalizedSort
3542
3636
  }, options));
3543
3637
 
@@ -3587,7 +3681,7 @@ var Channel = /*#__PURE__*/function () {
3587
3681
  sort = _args32.length > 1 && _args32[1] !== undefined ? _args32[1] : [];
3588
3682
  _context32.next = 3;
3589
3683
  return this.getClient().get(this._channelURL() + '/pinned_messages', {
3590
- payload: _objectSpread$9(_objectSpread$9({}, options), {}, {
3684
+ payload: _objectSpread$a(_objectSpread$a({}, options), {}, {
3591
3685
  sort: normalizeQuerySort(sort)
3592
3686
  })
3593
3687
  });
@@ -3621,7 +3715,7 @@ var Channel = /*#__PURE__*/function () {
3621
3715
  }, {
3622
3716
  key: "getReactions",
3623
3717
  value: function getReactions(message_id, options) {
3624
- return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(message_id), "/reactions"), _objectSpread$9({}, options));
3718
+ return this.getClient().get(this.getClient().baseURL + "/messages/".concat(encodeURIComponent(message_id), "/reactions"), _objectSpread$a({}, options));
3625
3719
  }
3626
3720
  /**
3627
3721
  * getMessagesById - Retrieves a list of messages by ID
@@ -3768,7 +3862,7 @@ var Channel = /*#__PURE__*/function () {
3768
3862
  }
3769
3863
 
3770
3864
  _context33.next = 7;
3771
- return this.getClient().post(queryURL + '/query', _objectSpread$9({
3865
+ return this.getClient().post(queryURL + '/query', _objectSpread$a({
3772
3866
  data: this._data,
3773
3867
  state: true
3774
3868
  }, options));
@@ -3803,13 +3897,14 @@ var Channel = /*#__PURE__*/function () {
3803
3897
 
3804
3898
 
3805
3899
  _this$_initializeStat = this._initializeState(state, messageSetToAddToIfDoesNotExist), messageSet = _this$_initializeStat.messageSet;
3806
- messageSet.pagination = _objectSpread$9(_objectSpread$9({}, messageSet.pagination), messageSetPagination({
3900
+ messageSet.pagination = _objectSpread$a(_objectSpread$a({}, messageSet.pagination), messageSetPagination({
3807
3901
  parentSet: messageSet,
3808
3902
  messagePaginationOptions: options === null || options === void 0 ? void 0 : options.messages,
3809
3903
  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,
3810
3904
  returnedPage: state.messages,
3811
3905
  logger: this.getClient().logger
3812
3906
  }));
3907
+ this.getClient().polls.hydratePollCache(messageSet.messages, true);
3813
3908
  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();
3814
3909
  this.data = state.channel;
3815
3910
  this.offlineMode = false;
@@ -3831,7 +3926,7 @@ var Channel = /*#__PURE__*/function () {
3831
3926
  });
3832
3927
  return _context33.abrupt("return", state);
3833
3928
 
3834
- case 18:
3929
+ case 19:
3835
3930
  case "end":
3836
3931
  return _context33.stop();
3837
3932
  }
@@ -3864,7 +3959,7 @@ var Channel = /*#__PURE__*/function () {
3864
3959
  this._checkInitialized();
3865
3960
 
3866
3961
  _context34.next = 3;
3867
- return this.getClient().banUser(targetUserID, _objectSpread$9(_objectSpread$9({}, options), {}, {
3962
+ return this.getClient().banUser(targetUserID, _objectSpread$a(_objectSpread$a({}, options), {}, {
3868
3963
  type: this.type,
3869
3964
  id: this.id
3870
3965
  }));
@@ -4036,7 +4131,7 @@ var Channel = /*#__PURE__*/function () {
4036
4131
  this._checkInitialized();
4037
4132
 
4038
4133
  _context38.next = 3;
4039
- return this.getClient().shadowBan(targetUserID, _objectSpread$9(_objectSpread$9({}, options), {}, {
4134
+ return this.getClient().shadowBan(targetUserID, _objectSpread$a(_objectSpread$a({}, options), {}, {
4040
4135
  type: this.type,
4041
4136
  id: this.id
4042
4137
  }));
@@ -4490,7 +4585,7 @@ var Channel = /*#__PURE__*/function () {
4490
4585
  });
4491
4586
  }
4492
4587
 
4493
- channel.data = _objectSpread$9(_objectSpread$9({}, event.channel), {}, {
4588
+ channel.data = _objectSpread$a(_objectSpread$a({}, event.channel), {}, {
4494
4589
  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,
4495
4590
  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
4496
4591
  });
@@ -4498,49 +4593,6 @@ var Channel = /*#__PURE__*/function () {
4498
4593
 
4499
4594
  break;
4500
4595
 
4501
- case 'poll.updated':
4502
- if (event.poll) {
4503
- var _event$message;
4504
-
4505
- channelState.updatePoll(event.poll, ((_event$message = event.message) === null || _event$message === void 0 ? void 0 : _event$message.id) || '');
4506
- }
4507
-
4508
- break;
4509
-
4510
- case 'poll.vote_casted':
4511
- if (event.poll_vote && event.poll) {
4512
- var _event$message2;
4513
-
4514
- channelState.addPollVote(event.poll_vote, event.poll, ((_event$message2 = event.message) === null || _event$message2 === void 0 ? void 0 : _event$message2.id) || '');
4515
- }
4516
-
4517
- break;
4518
-
4519
- case 'poll.vote_changed':
4520
- if (event.poll_vote && event.poll) {
4521
- var _event$message3;
4522
-
4523
- channelState.updatePollVote(event.poll_vote, event.poll, ((_event$message3 = event.message) === null || _event$message3 === void 0 ? void 0 : _event$message3.id) || '');
4524
- }
4525
-
4526
- break;
4527
-
4528
- case 'poll.vote_removed':
4529
- if (event.poll_vote && event.poll) {
4530
- var _event$message4;
4531
-
4532
- channelState.removePollVote(event.poll_vote, event.poll, ((_event$message4 = event.message) === null || _event$message4 === void 0 ? void 0 : _event$message4.id) || '');
4533
- }
4534
-
4535
- break;
4536
-
4537
- case 'poll.closed':
4538
- if (event.message) {
4539
- channelState.addMessageSorted(event.message, false, false);
4540
- }
4541
-
4542
- break;
4543
-
4544
4596
  case 'reaction.new':
4545
4597
  if (event.message && event.reaction) {
4546
4598
  event.message = channelState.addReaction(event.reaction, event.message);
@@ -4564,7 +4616,7 @@ var Channel = /*#__PURE__*/function () {
4564
4616
  break;
4565
4617
 
4566
4618
  case 'channel.hidden':
4567
- channel.data = _objectSpread$9(_objectSpread$9({}, channel.data), {}, {
4619
+ channel.data = _objectSpread$a(_objectSpread$a({}, channel.data), {}, {
4568
4620
  hidden: true
4569
4621
  });
4570
4622
 
@@ -4575,26 +4627,26 @@ var Channel = /*#__PURE__*/function () {
4575
4627
  break;
4576
4628
 
4577
4629
  case 'channel.visible':
4578
- channel.data = _objectSpread$9(_objectSpread$9({}, channel.data), {}, {
4630
+ channel.data = _objectSpread$a(_objectSpread$a({}, channel.data), {}, {
4579
4631
  hidden: false
4580
4632
  });
4581
4633
  break;
4582
4634
 
4583
4635
  case 'user.banned':
4584
4636
  if (!((_event$user11 = event.user) !== null && _event$user11 !== void 0 && _event$user11.id)) break;
4585
- channelState.members[event.user.id] = _objectSpread$9(_objectSpread$9({}, channelState.members[event.user.id] || {}), {}, {
4637
+ channelState.members[event.user.id] = _objectSpread$a(_objectSpread$a({}, channelState.members[event.user.id] || {}), {}, {
4586
4638
  shadow_banned: !!event.shadow,
4587
4639
  banned: !event.shadow,
4588
- user: _objectSpread$9(_objectSpread$9({}, ((_channelState$members = channelState.members[event.user.id]) === null || _channelState$members === void 0 ? void 0 : _channelState$members.user) || {}), event.user)
4640
+ user: _objectSpread$a(_objectSpread$a({}, ((_channelState$members = channelState.members[event.user.id]) === null || _channelState$members === void 0 ? void 0 : _channelState$members.user) || {}), event.user)
4589
4641
  });
4590
4642
  break;
4591
4643
 
4592
4644
  case 'user.unbanned':
4593
4645
  if (!((_event$user12 = event.user) !== null && _event$user12 !== void 0 && _event$user12.id)) break;
4594
- channelState.members[event.user.id] = _objectSpread$9(_objectSpread$9({}, channelState.members[event.user.id] || {}), {}, {
4646
+ channelState.members[event.user.id] = _objectSpread$a(_objectSpread$a({}, channelState.members[event.user.id] || {}), {}, {
4595
4647
  shadow_banned: false,
4596
4648
  banned: false,
4597
- user: _objectSpread$9(_objectSpread$9({}, ((_channelState$members2 = channelState.members[event.user.id]) === null || _channelState$members2 === void 0 ? void 0 : _channelState$members2.user) || {}), event.user)
4649
+ user: _objectSpread$a(_objectSpread$a({}, ((_channelState$members2 = channelState.members[event.user.id]) === null || _channelState$members2 === void 0 ? void 0 : _channelState$members2.user) || {}), event.user)
4598
4650
  });
4599
4651
  break;
4600
4652
  } // any event can send over the online count
@@ -4624,7 +4676,7 @@ var Channel = /*#__PURE__*/function () {
4624
4676
 
4625
4677
 
4626
4678
  if (state.members) {
4627
- var _iterator = _createForOfIteratorHelper$3(state.members),
4679
+ var _iterator = _createForOfIteratorHelper$4(state.members),
4628
4680
  _step;
4629
4681
 
4630
4682
  try {
@@ -4668,7 +4720,7 @@ var Channel = /*#__PURE__*/function () {
4668
4720
 
4669
4721
 
4670
4722
  if (state.watchers) {
4671
- var _iterator2 = _createForOfIteratorHelper$3(state.watchers),
4723
+ var _iterator2 = _createForOfIteratorHelper$4(state.watchers),
4672
4724
  _step2;
4673
4725
 
4674
4726
  try {
@@ -4704,7 +4756,7 @@ var Channel = /*#__PURE__*/function () {
4704
4756
 
4705
4757
 
4706
4758
  if (state.read) {
4707
- var _iterator3 = _createForOfIteratorHelper$3(state.read),
4759
+ var _iterator3 = _createForOfIteratorHelper$4(state.read),
4708
4760
  _step3;
4709
4761
 
4710
4762
  try {
@@ -4778,11 +4830,11 @@ var Channel = /*#__PURE__*/function () {
4778
4830
  return Channel;
4779
4831
  }();
4780
4832
 
4781
- 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; } } }; }
4833
+ 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; } } }; }
4782
4834
 
4783
- 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); }
4835
+ 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); }
4784
4836
 
4785
- 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; }
4837
+ 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; }
4786
4838
 
4787
4839
  /**
4788
4840
  * ClientState - A container class for the client state.
@@ -4805,7 +4857,7 @@ var ClientState = /*#__PURE__*/function () {
4805
4857
  _createClass__default['default'](ClientState, [{
4806
4858
  key: "updateUsers",
4807
4859
  value: function updateUsers(users) {
4808
- var _iterator = _createForOfIteratorHelper$2(users),
4860
+ var _iterator = _createForOfIteratorHelper$3(users),
4809
4861
  _step;
4810
4862
 
4811
4863
  try {
@@ -4853,9 +4905,9 @@ var ClientState = /*#__PURE__*/function () {
4853
4905
  return ClientState;
4854
4906
  }();
4855
4907
 
4856
- 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; }
4908
+ 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; }
4857
4909
 
4858
- 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; }
4910
+ 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; }
4859
4911
  var InsightMetrics = function InsightMetrics() {
4860
4912
  _classCallCheck__default['default'](this, InsightMetrics);
4861
4913
 
@@ -4934,7 +4986,7 @@ var postInsights = /*#__PURE__*/function () {
4934
4986
  };
4935
4987
  }();
4936
4988
  function buildWsFatalInsight(connection, event) {
4937
- return _objectSpread$8(_objectSpread$8({}, event), buildWsBaseInsight(connection));
4989
+ return _objectSpread$9(_objectSpread$9({}, event), buildWsBaseInsight(connection));
4938
4990
  }
4939
4991
 
4940
4992
  function buildWsBaseInsight(connection) {
@@ -4967,9 +5019,9 @@ function buildWsSuccessAfterFailureInsight(connection) {
4967
5019
  return buildWsBaseInsight(connection);
4968
5020
  }
4969
5021
 
4970
- 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; }
5022
+ 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; }
4971
5023
 
4972
- 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; }
5024
+ 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; }
4973
5025
 
4974
5026
  // Type guards to check WebSocket error type
4975
5027
  var isCloseEvent = function isCloseEvent(res) {
@@ -5333,7 +5385,7 @@ var StableWSConnection = /*#__PURE__*/function () {
5333
5385
  value: function _log(msg) {
5334
5386
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5335
5387
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
5336
- this.client.logger(level, 'connection:' + msg, _objectSpread$7({
5388
+ this.client.logger(level, 'connection:' + msg, _objectSpread$8({
5337
5389
  tags: ['connection']
5338
5390
  }, extra));
5339
5391
  }
@@ -5928,9 +5980,9 @@ var jwt = null;
5928
5980
 
5929
5981
  var crypto$1 = null;
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
 
@@ -6355,9 +6407,9 @@ function isErrorResponse(res) {
6355
6407
  return !res.status || res.status < 200 || 300 <= res.status;
6356
6408
  }
6357
6409
 
6358
- 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; }
6410
+ 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; }
6359
6411
 
6360
- 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; }
6412
+ 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; }
6361
6413
  var ConnectionState;
6362
6414
 
6363
6415
  (function (ConnectionState) {
@@ -6420,7 +6472,7 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6420
6472
  _context.next = 4;
6421
6473
  return _this.client.doAxiosRequest('get', _this.client.baseURL.replace(':3030', ':8900') + '/longpoll', // replace port if present for testing with local API
6422
6474
  undefined, {
6423
- config: _objectSpread$5(_objectSpread$5({}, config), {}, {
6475
+ config: _objectSpread$6(_objectSpread$6({}, config), {}, {
6424
6476
  cancelToken: (_this$cancelToken2 = _this.cancelToken) === null || _this$cancelToken2 === void 0 ? void 0 : _this$cancelToken2.token
6425
6477
  }),
6426
6478
  params: params
@@ -6698,7 +6750,7 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6698
6750
  value: function _log(msg) {
6699
6751
  var extra = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
6700
6752
  var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'info';
6701
- this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$5({
6753
+ this.client.logger(level, 'WSConnectionFallback:' + msg, _objectSpread$6({
6702
6754
  tags: ['connection_fallback', 'connection']
6703
6755
  }, extra));
6704
6756
  }
@@ -6731,53 +6783,45 @@ var WSConnectionFallback = /*#__PURE__*/function () {
6731
6783
  return WSConnectionFallback;
6732
6784
  }();
6733
6785
 
6734
- var Campaign = /*#__PURE__*/function () {
6735
- function Campaign(client, id, data) {
6736
- _classCallCheck__default['default'](this, Campaign);
6786
+ var Segment = /*#__PURE__*/function () {
6787
+ function Segment(client, type, id, data) {
6788
+ _classCallCheck__default['default'](this, Segment);
6737
6789
 
6738
- _defineProperty__default['default'](this, "id", void 0);
6790
+ _defineProperty__default['default'](this, "type", void 0);
6739
6791
 
6740
- _defineProperty__default['default'](this, "data", void 0);
6792
+ _defineProperty__default['default'](this, "id", void 0);
6741
6793
 
6742
6794
  _defineProperty__default['default'](this, "client", void 0);
6743
6795
 
6796
+ _defineProperty__default['default'](this, "data", void 0);
6797
+
6744
6798
  this.client = client;
6799
+ this.type = type;
6745
6800
  this.id = id;
6746
6801
  this.data = data;
6747
6802
  }
6748
6803
 
6749
- _createClass__default['default'](Campaign, [{
6804
+ _createClass__default['default'](Segment, [{
6750
6805
  key: "create",
6751
6806
  value: function () {
6752
6807
  var _create = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
6753
- var _this$data, _this$data2, _this$data3, _this$data4, _this$data5, _this$data6, _this$data7, _this$data8;
6808
+ var _this$data, _this$data2, _this$data3, _this$data4, _this$data5;
6754
6809
 
6755
- var body, result;
6810
+ var body;
6756
6811
  return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
6757
6812
  while (1) {
6758
6813
  switch (_context.prev = _context.next) {
6759
6814
  case 0:
6760
6815
  body = {
6761
- id: this.id,
6762
- message_template: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.message_template,
6763
- segment_ids: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.segment_ids,
6764
- sender_id: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.sender_id,
6765
- channel_template: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.channel_template,
6766
- create_channels: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.create_channels,
6767
- description: (_this$data6 = this.data) === null || _this$data6 === void 0 ? void 0 : _this$data6.description,
6768
- name: (_this$data7 = this.data) === null || _this$data7 === void 0 ? void 0 : _this$data7.name,
6769
- user_ids: (_this$data8 = this.data) === null || _this$data8 === void 0 ? void 0 : _this$data8.user_ids
6816
+ name: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.name,
6817
+ filter: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.filter,
6818
+ description: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.description,
6819
+ all_sender_channels: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.all_sender_channels,
6820
+ all_users: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.all_users
6770
6821
  };
6771
- _context.next = 3;
6772
- return this.client.createCampaign(body);
6773
-
6774
- case 3:
6775
- result = _context.sent;
6776
- this.id = result.campaign.id;
6777
- this.data = result.campaign;
6778
- return _context.abrupt("return", result);
6822
+ return _context.abrupt("return", this.client.createSegment(this.type, this.id, body));
6779
6823
 
6780
- case 7:
6824
+ case 2:
6781
6825
  case "end":
6782
6826
  return _context.stop();
6783
6827
  }
@@ -6792,28 +6836,24 @@ var Campaign = /*#__PURE__*/function () {
6792
6836
  return create;
6793
6837
  }()
6794
6838
  }, {
6795
- key: "verifyCampaignId",
6796
- value: function verifyCampaignId() {
6839
+ key: "verifySegmentId",
6840
+ value: function verifySegmentId() {
6797
6841
  if (!this.id) {
6798
- 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)');
6842
+ 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)');
6799
6843
  }
6800
6844
  }
6801
6845
  }, {
6802
- key: "start",
6846
+ key: "get",
6803
6847
  value: function () {
6804
- var _start = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(options) {
6848
+ var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
6805
6849
  return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
6806
6850
  while (1) {
6807
6851
  switch (_context2.prev = _context2.next) {
6808
6852
  case 0:
6809
- this.verifyCampaignId();
6810
- _context2.next = 3;
6811
- return this.client.startCampaign(this.id, options);
6812
-
6813
- case 3:
6814
- return _context2.abrupt("return", _context2.sent);
6853
+ this.verifySegmentId();
6854
+ return _context2.abrupt("return", this.client.getSegment(this.id));
6815
6855
 
6816
- case 4:
6856
+ case 2:
6817
6857
  case "end":
6818
6858
  return _context2.stop();
6819
6859
  }
@@ -6821,11 +6861,11 @@ var Campaign = /*#__PURE__*/function () {
6821
6861
  }, _callee2, this);
6822
6862
  }));
6823
6863
 
6824
- function start(_x) {
6825
- return _start.apply(this, arguments);
6864
+ function get() {
6865
+ return _get.apply(this, arguments);
6826
6866
  }
6827
6867
 
6828
- return start;
6868
+ return get;
6829
6869
  }()
6830
6870
  }, {
6831
6871
  key: "update",
@@ -6835,8 +6875,8 @@ var Campaign = /*#__PURE__*/function () {
6835
6875
  while (1) {
6836
6876
  switch (_context3.prev = _context3.next) {
6837
6877
  case 0:
6838
- this.verifyCampaignId();
6839
- return _context3.abrupt("return", this.client.updateCampaign(this.id, data));
6878
+ this.verifySegmentId();
6879
+ return _context3.abrupt("return", this.client.updateSegment(this.id, data));
6840
6880
 
6841
6881
  case 2:
6842
6882
  case "end":
@@ -6846,28 +6886,24 @@ var Campaign = /*#__PURE__*/function () {
6846
6886
  }, _callee3, this);
6847
6887
  }));
6848
6888
 
6849
- function update(_x2) {
6889
+ function update(_x) {
6850
6890
  return _update.apply(this, arguments);
6851
6891
  }
6852
6892
 
6853
6893
  return update;
6854
6894
  }()
6855
6895
  }, {
6856
- key: "delete",
6896
+ key: "addTargets",
6857
6897
  value: function () {
6858
- var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
6898
+ var _addTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(targets) {
6859
6899
  return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
6860
6900
  while (1) {
6861
6901
  switch (_context4.prev = _context4.next) {
6862
6902
  case 0:
6863
- this.verifyCampaignId();
6864
- _context4.next = 3;
6865
- return this.client.deleteCampaign(this.id);
6866
-
6867
- case 3:
6868
- return _context4.abrupt("return", _context4.sent);
6903
+ this.verifySegmentId();
6904
+ return _context4.abrupt("return", this.client.addSegmentTargets(this.id, targets));
6869
6905
 
6870
- case 4:
6906
+ case 2:
6871
6907
  case "end":
6872
6908
  return _context4.stop();
6873
6909
  }
@@ -6875,22 +6911,22 @@ var Campaign = /*#__PURE__*/function () {
6875
6911
  }, _callee4, this);
6876
6912
  }));
6877
6913
 
6878
- function _delete() {
6879
- return _delete2.apply(this, arguments);
6914
+ function addTargets(_x2) {
6915
+ return _addTargets.apply(this, arguments);
6880
6916
  }
6881
6917
 
6882
- return _delete;
6918
+ return addTargets;
6883
6919
  }()
6884
6920
  }, {
6885
- key: "stop",
6921
+ key: "removeTargets",
6886
6922
  value: function () {
6887
- var _stop = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
6923
+ var _removeTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(targets) {
6888
6924
  return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
6889
6925
  while (1) {
6890
6926
  switch (_context5.prev = _context5.next) {
6891
6927
  case 0:
6892
- this.verifyCampaignId();
6893
- return _context5.abrupt("return", this.client.stopCampaign(this.id));
6928
+ this.verifySegmentId();
6929
+ return _context5.abrupt("return", this.client.removeSegmentTargets(this.id, targets));
6894
6930
 
6895
6931
  case 2:
6896
6932
  case "end":
@@ -6900,22 +6936,22 @@ var Campaign = /*#__PURE__*/function () {
6900
6936
  }, _callee5, this);
6901
6937
  }));
6902
6938
 
6903
- function stop() {
6904
- return _stop.apply(this, arguments);
6939
+ function removeTargets(_x3) {
6940
+ return _removeTargets.apply(this, arguments);
6905
6941
  }
6906
6942
 
6907
- return stop;
6943
+ return removeTargets;
6908
6944
  }()
6909
6945
  }, {
6910
- key: "get",
6946
+ key: "delete",
6911
6947
  value: function () {
6912
- var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
6948
+ var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
6913
6949
  return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
6914
6950
  while (1) {
6915
6951
  switch (_context6.prev = _context6.next) {
6916
6952
  case 0:
6917
- this.verifyCampaignId();
6918
- return _context6.abrupt("return", this.client.getCampaign(this.id));
6953
+ this.verifySegmentId();
6954
+ return _context6.abrupt("return", this.client.deleteSegment(this.id));
6919
6955
 
6920
6956
  case 2:
6921
6957
  case "end":
@@ -6925,200 +6961,11 @@ var Campaign = /*#__PURE__*/function () {
6925
6961
  }, _callee6, this);
6926
6962
  }));
6927
6963
 
6928
- function get() {
6929
- return _get.apply(this, arguments);
6964
+ function _delete() {
6965
+ return _delete2.apply(this, arguments);
6930
6966
  }
6931
6967
 
6932
- return get;
6933
- }()
6934
- }]);
6935
-
6936
- return Campaign;
6937
- }();
6938
-
6939
- var Segment = /*#__PURE__*/function () {
6940
- function Segment(client, type, id, data) {
6941
- _classCallCheck__default['default'](this, Segment);
6942
-
6943
- _defineProperty__default['default'](this, "type", void 0);
6944
-
6945
- _defineProperty__default['default'](this, "id", void 0);
6946
-
6947
- _defineProperty__default['default'](this, "client", void 0);
6948
-
6949
- _defineProperty__default['default'](this, "data", void 0);
6950
-
6951
- this.client = client;
6952
- this.type = type;
6953
- this.id = id;
6954
- this.data = data;
6955
- }
6956
-
6957
- _createClass__default['default'](Segment, [{
6958
- key: "create",
6959
- value: function () {
6960
- var _create = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
6961
- var _this$data, _this$data2, _this$data3, _this$data4, _this$data5;
6962
-
6963
- var body;
6964
- return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
6965
- while (1) {
6966
- switch (_context.prev = _context.next) {
6967
- case 0:
6968
- body = {
6969
- name: (_this$data = this.data) === null || _this$data === void 0 ? void 0 : _this$data.name,
6970
- filter: (_this$data2 = this.data) === null || _this$data2 === void 0 ? void 0 : _this$data2.filter,
6971
- description: (_this$data3 = this.data) === null || _this$data3 === void 0 ? void 0 : _this$data3.description,
6972
- all_sender_channels: (_this$data4 = this.data) === null || _this$data4 === void 0 ? void 0 : _this$data4.all_sender_channels,
6973
- all_users: (_this$data5 = this.data) === null || _this$data5 === void 0 ? void 0 : _this$data5.all_users
6974
- };
6975
- return _context.abrupt("return", this.client.createSegment(this.type, this.id, body));
6976
-
6977
- case 2:
6978
- case "end":
6979
- return _context.stop();
6980
- }
6981
- }
6982
- }, _callee, this);
6983
- }));
6984
-
6985
- function create() {
6986
- return _create.apply(this, arguments);
6987
- }
6988
-
6989
- return create;
6990
- }()
6991
- }, {
6992
- key: "verifySegmentId",
6993
- value: function verifySegmentId() {
6994
- if (!this.id) {
6995
- 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)');
6996
- }
6997
- }
6998
- }, {
6999
- key: "get",
7000
- value: function () {
7001
- var _get = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
7002
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
7003
- while (1) {
7004
- switch (_context2.prev = _context2.next) {
7005
- case 0:
7006
- this.verifySegmentId();
7007
- return _context2.abrupt("return", this.client.getSegment(this.id));
7008
-
7009
- case 2:
7010
- case "end":
7011
- return _context2.stop();
7012
- }
7013
- }
7014
- }, _callee2, this);
7015
- }));
7016
-
7017
- function get() {
7018
- return _get.apply(this, arguments);
7019
- }
7020
-
7021
- return get;
7022
- }()
7023
- }, {
7024
- key: "update",
7025
- value: function () {
7026
- var _update = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(data) {
7027
- return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
7028
- while (1) {
7029
- switch (_context3.prev = _context3.next) {
7030
- case 0:
7031
- this.verifySegmentId();
7032
- return _context3.abrupt("return", this.client.updateSegment(this.id, data));
7033
-
7034
- case 2:
7035
- case "end":
7036
- return _context3.stop();
7037
- }
7038
- }
7039
- }, _callee3, this);
7040
- }));
7041
-
7042
- function update(_x) {
7043
- return _update.apply(this, arguments);
7044
- }
7045
-
7046
- return update;
7047
- }()
7048
- }, {
7049
- key: "addTargets",
7050
- value: function () {
7051
- var _addTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4(targets) {
7052
- return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
7053
- while (1) {
7054
- switch (_context4.prev = _context4.next) {
7055
- case 0:
7056
- this.verifySegmentId();
7057
- return _context4.abrupt("return", this.client.addSegmentTargets(this.id, targets));
7058
-
7059
- case 2:
7060
- case "end":
7061
- return _context4.stop();
7062
- }
7063
- }
7064
- }, _callee4, this);
7065
- }));
7066
-
7067
- function addTargets(_x2) {
7068
- return _addTargets.apply(this, arguments);
7069
- }
7070
-
7071
- return addTargets;
7072
- }()
7073
- }, {
7074
- key: "removeTargets",
7075
- value: function () {
7076
- var _removeTargets = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5(targets) {
7077
- return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
7078
- while (1) {
7079
- switch (_context5.prev = _context5.next) {
7080
- case 0:
7081
- this.verifySegmentId();
7082
- return _context5.abrupt("return", this.client.removeSegmentTargets(this.id, targets));
7083
-
7084
- case 2:
7085
- case "end":
7086
- return _context5.stop();
7087
- }
7088
- }
7089
- }, _callee5, this);
7090
- }));
7091
-
7092
- function removeTargets(_x3) {
7093
- return _removeTargets.apply(this, arguments);
7094
- }
7095
-
7096
- return removeTargets;
7097
- }()
7098
- }, {
7099
- key: "delete",
7100
- value: function () {
7101
- var _delete2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6() {
7102
- return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
7103
- while (1) {
7104
- switch (_context6.prev = _context6.next) {
7105
- case 0:
7106
- this.verifySegmentId();
7107
- return _context6.abrupt("return", this.client.deleteSegment(this.id));
7108
-
7109
- case 2:
7110
- case "end":
7111
- return _context6.stop();
7112
- }
7113
- }
7114
- }, _callee6, this);
7115
- }));
7116
-
7117
- function _delete() {
7118
- return _delete2.apply(this, arguments);
7119
- }
7120
-
7121
- return _delete;
6968
+ return _delete;
7122
6969
  }()
7123
6970
  }, {
7124
6971
  key: "targetExists",
@@ -7278,9 +7125,9 @@ exports.VotingVisibility = void 0;
7278
7125
  VotingVisibility["public"] = "public";
7279
7126
  })(exports.VotingVisibility || (exports.VotingVisibility = {}));
7280
7127
 
7281
- 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; }
7128
+ 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; }
7282
7129
 
7283
- 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; }
7130
+ 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; }
7284
7131
 
7285
7132
  function isPatch(value) {
7286
7133
  return typeof value === 'function';
@@ -7310,7 +7157,7 @@ var StateStore = function StateStore(value) {
7310
7157
 
7311
7158
  _defineProperty__default['default'](this, "partialNext", function (partial) {
7312
7159
  return _this.next(function (current) {
7313
- return _objectSpread$4(_objectSpread$4({}, current), partial);
7160
+ return _objectSpread$5(_objectSpread$5({}, current), partial);
7314
7161
  });
7315
7162
  });
7316
7163
 
@@ -7333,12 +7180,21 @@ var StateStore = function StateStore(value) {
7333
7180
  var selectedValues;
7334
7181
 
7335
7182
  var wrappedHandler = function wrappedHandler(nextValue) {
7336
- var _selectedValues$some, _selectedValues;
7337
-
7338
7183
  var newlySelectedValues = selector(nextValue);
7339
- var hasUpdatedValues = (_selectedValues$some = (_selectedValues = selectedValues) === null || _selectedValues === void 0 ? void 0 : _selectedValues.some(function (value, index) {
7340
- return value !== newlySelectedValues[index];
7341
- })) !== null && _selectedValues$some !== void 0 ? _selectedValues$some : true;
7184
+ var hasUpdatedValues = !selectedValues;
7185
+
7186
+ if (Array.isArray(newlySelectedValues) && StateStore.logCount > 0) {
7187
+ console.warn('[StreamChat]: The API of our StateStore has changed. Instead of returning an array in the selector, please return a named object of properties.');
7188
+ StateStore.logCount--;
7189
+ }
7190
+
7191
+ for (var key in selectedValues) {
7192
+ // @ts-ignore TODO: remove array support (Readonly<unknown[]>)
7193
+ if (selectedValues[key] === newlySelectedValues[key]) continue;
7194
+ hasUpdatedValues = true;
7195
+ break;
7196
+ }
7197
+
7342
7198
  if (!hasUpdatedValues) return;
7343
7199
  var oldSelectedValues = selectedValues;
7344
7200
  selectedValues = newlySelectedValues;
@@ -7349,11 +7205,13 @@ var StateStore = function StateStore(value) {
7349
7205
  });
7350
7206
  };
7351
7207
 
7352
- var _excluded$1 = ["limit", "sort"];
7208
+ _defineProperty__default['default'](StateStore, "logCount", 5);
7353
7209
 
7354
- 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; }
7210
+ var _excluded$2 = ["limit", "sort"];
7355
7211
 
7356
- 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; }
7212
+ 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; }
7213
+
7214
+ 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; }
7357
7215
  var DEFAULT_PAGE_LIMIT = 50;
7358
7216
  var DEFAULT_SORT = [{
7359
7217
  created_at: -1
@@ -7497,12 +7355,13 @@ var Thread = /*#__PURE__*/function () {
7497
7355
 
7498
7356
  _defineProperty__default['default'](this, "subscribeMarkActiveThreadRead", function () {
7499
7357
  return _this.state.subscribeWithSelector(function (nextValue) {
7500
- return [nextValue.active, ownUnreadCountSelector(_this.client.userID)(nextValue)];
7358
+ return {
7359
+ active: nextValue.active,
7360
+ unreadMessageCount: ownUnreadCountSelector(_this.client.userID)(nextValue)
7361
+ };
7501
7362
  }, function (_ref3) {
7502
- var _ref4 = _slicedToArray__default['default'](_ref3, 2),
7503
- active = _ref4[0],
7504
- unreadMessageCount = _ref4[1];
7505
-
7363
+ var active = _ref3.active,
7364
+ unreadMessageCount = _ref3.unreadMessageCount;
7506
7365
  if (!active || !unreadMessageCount) return;
7507
7366
 
7508
7367
  _this.throttledMarkAsRead();
@@ -7511,11 +7370,13 @@ var Thread = /*#__PURE__*/function () {
7511
7370
 
7512
7371
  _defineProperty__default['default'](this, "subscribeReloadActiveStaleThread", function () {
7513
7372
  return _this.state.subscribeWithSelector(function (nextValue) {
7514
- return [nextValue.active, nextValue.isStateStale];
7515
- }, function (_ref5) {
7516
- var _ref6 = _slicedToArray__default['default'](_ref5, 2),
7517
- active = _ref6[0],
7518
- isStateStale = _ref6[1];
7373
+ return {
7374
+ active: nextValue.active,
7375
+ isStateStale: nextValue.isStateStale
7376
+ };
7377
+ }, function (_ref4) {
7378
+ var active = _ref4.active,
7379
+ isStateStale = _ref4.isStateStale;
7519
7380
 
7520
7381
  if (active && isStateStale) {
7521
7382
  _this.reload();
@@ -7579,14 +7440,14 @@ var Thread = /*#__PURE__*/function () {
7579
7440
  if (userId === ((_event$user2 = event.user) === null || _event$user2 === void 0 ? void 0 : _event$user2.id)) {
7580
7441
  // The user who just sent a message to the thread has no unread messages
7581
7442
  // in that thread
7582
- nextUserRead = _objectSpread$3(_objectSpread$3({}, nextUserRead), {}, {
7443
+ nextUserRead = _objectSpread$4(_objectSpread$4({}, nextUserRead), {}, {
7583
7444
  lastReadAt: event.created_at ? new Date(event.created_at) : new Date(),
7584
7445
  user: event.user,
7585
7446
  unreadMessageCount: 0
7586
7447
  });
7587
7448
  } else if (active && userId === _this.client.userID) ; else {
7588
7449
  // Increment unread count for all users except the author of the new message
7589
- nextUserRead = _objectSpread$3(_objectSpread$3({}, nextUserRead), {}, {
7450
+ nextUserRead = _objectSpread$4(_objectSpread$4({}, nextUserRead), {}, {
7590
7451
  unreadMessageCount: userRead.unreadMessageCount + 1
7591
7452
  });
7592
7453
  }
@@ -7610,8 +7471,8 @@ var Thread = /*#__PURE__*/function () {
7610
7471
  var user = event.user;
7611
7472
 
7612
7473
  _this.state.next(function (current) {
7613
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7614
- read: _objectSpread$3(_objectSpread$3({}, current.read), {}, _defineProperty__default['default']({}, userId, {
7474
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7475
+ read: _objectSpread$4(_objectSpread$4({}, current.read), {}, _defineProperty__default['default']({}, userId, {
7615
7476
  lastReadAt: new Date(createdAt),
7616
7477
  user: user,
7617
7478
  lastReadMessageId: event.last_read_message_id,
@@ -7672,10 +7533,10 @@ var Thread = /*#__PURE__*/function () {
7672
7533
  _this.unsubscribeFunctions.clear();
7673
7534
  });
7674
7535
 
7675
- _defineProperty__default['default'](this, "deleteReplyLocally", function (_ref7) {
7536
+ _defineProperty__default['default'](this, "deleteReplyLocally", function (_ref5) {
7676
7537
  var _replies$index, _replies;
7677
7538
 
7678
- var message = _ref7.message;
7539
+ var message = _ref5.message;
7679
7540
 
7680
7541
  var _this$state$getLatest3 = _this.state.getLatestValue(),
7681
7542
  replies = _this$state$getLatest3.replies;
@@ -7703,10 +7564,10 @@ var Thread = /*#__PURE__*/function () {
7703
7564
  });
7704
7565
  });
7705
7566
 
7706
- _defineProperty__default['default'](this, "upsertReplyLocally", function (_ref8) {
7707
- var message = _ref8.message,
7708
- _ref8$timestampChange = _ref8.timestampChanged,
7709
- timestampChanged = _ref8$timestampChange === void 0 ? false : _ref8$timestampChange;
7567
+ _defineProperty__default['default'](this, "upsertReplyLocally", function (_ref6) {
7568
+ var message = _ref6.message,
7569
+ _ref6$timestampChange = _ref6.timestampChanged,
7570
+ timestampChanged = _ref6$timestampChange === void 0 ? false : _ref6$timestampChange;
7710
7571
 
7711
7572
  if (message.parent_id !== _this.id) {
7712
7573
  throw new Error('Reply does not belong to this thread');
@@ -7722,14 +7583,14 @@ var Thread = /*#__PURE__*/function () {
7722
7583
  }
7723
7584
 
7724
7585
  _this.state.next(function (current) {
7725
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7586
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7726
7587
  replies: addToMessageList(current.replies, formattedMessage, timestampChanged)
7727
7588
  });
7728
7589
  });
7729
7590
  });
7730
7591
 
7731
- _defineProperty__default['default'](this, "updateParentMessageLocally", function (_ref9) {
7732
- var message = _ref9.message;
7592
+ _defineProperty__default['default'](this, "updateParentMessageLocally", function (_ref7) {
7593
+ var message = _ref7.message;
7733
7594
 
7734
7595
  if (message.id !== _this.id) {
7735
7596
  throw new Error('Message does not belong to this thread');
@@ -7739,7 +7600,7 @@ var Thread = /*#__PURE__*/function () {
7739
7600
  var _message$reply_count;
7740
7601
 
7741
7602
  var formattedMessage = formatMessage(message);
7742
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7603
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7743
7604
  deletedAt: formattedMessage.deleted_at,
7744
7605
  parentMessage: formattedMessage,
7745
7606
  replyCount: (_message$reply_count = message.reply_count) !== null && _message$reply_count !== void 0 ? _message$reply_count : current.replyCount
@@ -7762,8 +7623,8 @@ var Thread = /*#__PURE__*/function () {
7762
7623
  });
7763
7624
 
7764
7625
  _defineProperty__default['default'](this, "markAsRead", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
7765
- var _ref11,
7766
- _ref11$force,
7626
+ var _ref9,
7627
+ _ref9$force,
7767
7628
  force,
7768
7629
  _args2 = arguments;
7769
7630
 
@@ -7771,7 +7632,7 @@ var Thread = /*#__PURE__*/function () {
7771
7632
  while (1) {
7772
7633
  switch (_context2.prev = _context2.next) {
7773
7634
  case 0:
7774
- _ref11 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref11$force = _ref11.force, force = _ref11$force === void 0 ? false : _ref11$force;
7635
+ _ref9 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref9$force = _ref9.force, force = _ref9$force === void 0 ? false : _ref9$force;
7775
7636
 
7776
7637
  if (!(_this.ownUnreadCount === 0 && !force)) {
7777
7638
  _context2.next = 3;
@@ -7804,45 +7665,45 @@ var Thread = /*#__PURE__*/function () {
7804
7665
  }));
7805
7666
 
7806
7667
  _defineProperty__default['default'](this, "queryReplies", function () {
7807
- var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7668
+ var _ref10 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7808
7669
 
7809
- var _ref12$limit = _ref12.limit,
7810
- limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit,
7811
- _ref12$sort = _ref12.sort,
7812
- sort = _ref12$sort === void 0 ? DEFAULT_SORT : _ref12$sort,
7813
- otherOptions = _objectWithoutProperties__default['default'](_ref12, _excluded$1);
7670
+ var _ref10$limit = _ref10.limit,
7671
+ limit = _ref10$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref10$limit,
7672
+ _ref10$sort = _ref10.sort,
7673
+ sort = _ref10$sort === void 0 ? DEFAULT_SORT : _ref10$sort,
7674
+ otherOptions = _objectWithoutProperties__default['default'](_ref10, _excluded$2);
7814
7675
 
7815
- return _this.channel.getReplies(_this.id, _objectSpread$3({
7676
+ return _this.channel.getReplies(_this.id, _objectSpread$4({
7816
7677
  limit: limit
7817
7678
  }, otherOptions), sort);
7818
7679
  });
7819
7680
 
7820
7681
  _defineProperty__default['default'](this, "loadNextPage", function () {
7821
- var _ref13 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7822
- _ref13$limit = _ref13.limit,
7823
- limit = _ref13$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref13$limit;
7682
+ var _ref11 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7683
+ _ref11$limit = _ref11.limit,
7684
+ limit = _ref11$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref11$limit;
7824
7685
 
7825
7686
  return _this.loadPage(limit);
7826
7687
  });
7827
7688
 
7828
7689
  _defineProperty__default['default'](this, "loadPrevPage", function () {
7829
- var _ref14 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7830
- _ref14$limit = _ref14.limit,
7831
- limit = _ref14$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref14$limit;
7690
+ var _ref12 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
7691
+ _ref12$limit = _ref12.limit,
7692
+ limit = _ref12$limit === void 0 ? DEFAULT_PAGE_LIMIT : _ref12$limit;
7832
7693
 
7833
7694
  return _this.loadPage(-limit);
7834
7695
  });
7835
7696
 
7836
7697
  _defineProperty__default['default'](this, "loadPage", /*#__PURE__*/function () {
7837
- var _ref15 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(count) {
7838
- var _this$state$getLatest4, pagination, _ref16, _ref17, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7698
+ var _ref13 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(count) {
7699
+ var _this$state$getLatest4, pagination, _ref14, _ref15, loadingKey, cursorKey, insertionMethodKey, queryOptions, limit, _replies$at$id, _replies$at, data, replies, maybeNextCursor;
7839
7700
 
7840
7701
  return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
7841
7702
  while (1) {
7842
7703
  switch (_context3.prev = _context3.next) {
7843
7704
  case 0:
7844
7705
  _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
7845
- _ref16 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref17 = _slicedToArray__default['default'](_ref16, 3), loadingKey = _ref17[0], cursorKey = _ref17[1], insertionMethodKey = _ref17[2];
7706
+ _ref14 = count > 0 ? ['isLoadingNext', 'nextCursor', 'push'] : ['isLoadingPrev', 'prevCursor', 'unshift'], _ref15 = _slicedToArray__default['default'](_ref14, 3), loadingKey = _ref15[0], cursorKey = _ref15[1], insertionMethodKey = _ref15[2];
7846
7707
 
7847
7708
  if (!(pagination[loadingKey] || pagination[cursorKey] === null)) {
7848
7709
  _context3.next = 4;
@@ -7856,12 +7717,12 @@ var Thread = /*#__PURE__*/function () {
7856
7717
  limit = Math.abs(count);
7857
7718
 
7858
7719
  _this.state.partialNext({
7859
- pagination: _objectSpread$3(_objectSpread$3({}, pagination), {}, _defineProperty__default['default']({}, loadingKey, true))
7720
+ pagination: _objectSpread$4(_objectSpread$4({}, pagination), {}, _defineProperty__default['default']({}, loadingKey, true))
7860
7721
  });
7861
7722
 
7862
7723
  _context3.prev = 7;
7863
7724
  _context3.next = 10;
7864
- return _this.queryReplies(_objectSpread$3(_objectSpread$3({}, queryOptions), {}, {
7725
+ return _this.queryReplies(_objectSpread$4(_objectSpread$4({}, queryOptions), {}, {
7865
7726
  limit: limit
7866
7727
  }));
7867
7728
 
@@ -7883,9 +7744,9 @@ var Thread = /*#__PURE__*/function () {
7883
7744
  (_nextReplies = nextReplies)[insertionMethodKey].apply(_nextReplies, _toConsumableArray__default['default'](replies));
7884
7745
  }
7885
7746
 
7886
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7747
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7887
7748
  replies: nextReplies,
7888
- 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))
7749
+ 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))
7889
7750
  });
7890
7751
  });
7891
7752
 
@@ -7899,8 +7760,8 @@ var Thread = /*#__PURE__*/function () {
7899
7760
  _this.client.logger('error', _context3.t0.message);
7900
7761
 
7901
7762
  _this.state.next(function (current) {
7902
- return _objectSpread$3(_objectSpread$3({}, current), {}, {
7903
- pagination: _objectSpread$3(_objectSpread$3({}, current.pagination), {}, _defineProperty__default['default']({}, loadingKey, false))
7763
+ return _objectSpread$4(_objectSpread$4({}, current), {}, {
7764
+ pagination: _objectSpread$4(_objectSpread$4({}, current.pagination), {}, _defineProperty__default['default']({}, loadingKey, false))
7904
7765
  });
7905
7766
  });
7906
7767
 
@@ -7913,7 +7774,7 @@ var Thread = /*#__PURE__*/function () {
7913
7774
  }));
7914
7775
 
7915
7776
  return function (_x) {
7916
- return _ref15.apply(this, arguments);
7777
+ return _ref13.apply(this, arguments);
7917
7778
  };
7918
7779
  }());
7919
7780
 
@@ -8005,9 +7866,9 @@ var ownUnreadCountSelector = function ownUnreadCountSelector(currentUserId) {
8005
7866
  };
8006
7867
  };
8007
7868
 
8008
- 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; }
7869
+ 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; }
8009
7870
 
8010
- 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; }
7871
+ 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; }
8011
7872
  var MODERATION_ENTITY_TYPES = {
8012
7873
  user: 'stream:user',
8013
7874
  message: 'stream:chat:v1:message'
@@ -8124,7 +7985,7 @@ var Moderation = /*#__PURE__*/function () {
8124
7985
  case 0:
8125
7986
  options = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : {};
8126
7987
  _context3.next = 3;
8127
- return this.client.post(this.client.baseURL + '/api/v2/moderation/flag', _objectSpread$2({
7988
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/flag', _objectSpread$3({
8128
7989
  entity_type: entityType,
8129
7990
  entity_id: entityId,
8130
7991
  entity_creator_id: entityCreatorID,
@@ -8169,7 +8030,7 @@ var Moderation = /*#__PURE__*/function () {
8169
8030
  case 0:
8170
8031
  options = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : {};
8171
8032
  _context4.next = 3;
8172
- return this.client.post(this.client.baseURL + '/api/v2/moderation/mute', _objectSpread$2({
8033
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/mute', _objectSpread$3({
8173
8034
  target_ids: [targetID]
8174
8035
  }, options));
8175
8036
 
@@ -8207,7 +8068,7 @@ var Moderation = /*#__PURE__*/function () {
8207
8068
  switch (_context5.prev = _context5.next) {
8208
8069
  case 0:
8209
8070
  _context5.next = 2;
8210
- return this.client.post(this.client.baseURL + '/api/v2/moderation/unmute', _objectSpread$2({
8071
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/unmute', _objectSpread$3({
8211
8072
  target_ids: [targetID]
8212
8073
  }, options));
8213
8074
 
@@ -8249,7 +8110,7 @@ var Moderation = /*#__PURE__*/function () {
8249
8110
  case 0:
8250
8111
  options = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : {};
8251
8112
  _context6.next = 3;
8252
- return this.client.get(this.client.baseURL + "/api/v2/moderation/user_report", _objectSpread$2({
8113
+ return this.client.get(this.client.baseURL + "/api/v2/moderation/user_report", _objectSpread$3({
8253
8114
  user_id: userID
8254
8115
  }, options));
8255
8116
 
@@ -8293,7 +8154,7 @@ var Moderation = /*#__PURE__*/function () {
8293
8154
  sort = _args7.length > 1 && _args7[1] !== undefined ? _args7[1] : [];
8294
8155
  options = _args7.length > 2 && _args7[2] !== undefined ? _args7[2] : {};
8295
8156
  _context7.next = 5;
8296
- return this.client.post(this.client.baseURL + '/api/v2/moderation/review_queue', _objectSpread$2({
8157
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/review_queue', _objectSpread$3({
8297
8158
  filter: filterConditions,
8298
8159
  sort: normalizeQuerySort(sort)
8299
8160
  }, options));
@@ -8396,7 +8257,7 @@ var Moderation = /*#__PURE__*/function () {
8396
8257
  case 0:
8397
8258
  options = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {};
8398
8259
  _context10.next = 3;
8399
- return this.client.post(this.client.baseURL + '/api/v2/moderation/submit_action', _objectSpread$2({
8260
+ return this.client.post(this.client.baseURL + '/api/v2/moderation/submit_action', _objectSpread$3({
8400
8261
  action_type: actionType,
8401
8262
  item_id: itemID
8402
8263
  }, options));
@@ -8423,15 +8284,15 @@ var Moderation = /*#__PURE__*/function () {
8423
8284
  return Moderation;
8424
8285
  }();
8425
8286
 
8426
- 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; } } }; }
8287
+ 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; } } }; }
8427
8288
 
8428
- 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); }
8289
+ 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); }
8429
8290
 
8430
- 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; }
8291
+ 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; }
8431
8292
 
8432
- 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; }
8293
+ 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; }
8433
8294
 
8434
- 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; }
8295
+ 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; }
8435
8296
  var DEFAULT_CONNECTION_RECOVERY_THROTTLE_DURATION = 1000;
8436
8297
  var MAX_QUERY_THREADS_LIMIT = 25;
8437
8298
  var ThreadManager = /*#__PURE__*/function () {
@@ -8511,15 +8372,15 @@ var ThreadManager = /*#__PURE__*/function () {
8511
8372
 
8512
8373
  _defineProperty__default['default'](this, "subscribeManageThreadSubscriptions", function () {
8513
8374
  return _this.state.subscribeWithSelector(function (nextValue) {
8514
- return [nextValue.threads];
8375
+ return {
8376
+ threads: nextValue.threads
8377
+ };
8515
8378
  }, function (_ref5, prev) {
8516
- var _ref6 = _slicedToArray__default['default'](_ref5, 1),
8517
- nextThreads = _ref6[0];
8379
+ var nextThreads = _ref5.threads;
8518
8380
 
8519
- var _ref7 = prev !== null && prev !== void 0 ? prev : [],
8520
- _ref8 = _slicedToArray__default['default'](_ref7, 1),
8521
- _ref8$ = _ref8[0],
8522
- prevThreads = _ref8$ === void 0 ? [] : _ref8$; // Thread instance was removed if there's no thread with the given id at all,
8381
+ var _ref6 = prev !== null && prev !== void 0 ? prev : {},
8382
+ _ref6$threads = _ref6.threads,
8383
+ prevThreads = _ref6$threads === void 0 ? [] : _ref6$threads; // Thread instance was removed if there's no thread with the given id at all,
8523
8384
  // or it was replaced with a new instance
8524
8385
 
8525
8386
 
@@ -8537,11 +8398,11 @@ var ThreadManager = /*#__PURE__*/function () {
8537
8398
 
8538
8399
  _defineProperty__default['default'](this, "subscribeReloadOnActivation", function () {
8539
8400
  return _this.state.subscribeWithSelector(function (nextValue) {
8540
- return [nextValue.active];
8541
- }, function (_ref9) {
8542
- var _ref10 = _slicedToArray__default['default'](_ref9, 1),
8543
- active = _ref10[0];
8544
-
8401
+ return {
8402
+ active: nextValue.active
8403
+ };
8404
+ }, function (_ref7) {
8405
+ var active = _ref7.active;
8545
8406
  if (active) _this.reload();
8546
8407
  });
8547
8408
  });
@@ -8575,7 +8436,7 @@ var ThreadManager = /*#__PURE__*/function () {
8575
8436
  var unsubscribeConnectionDropped = _this.client.on('connection.changed', function (event) {
8576
8437
  if (event.online === false) {
8577
8438
  _this.state.next(function (current) {
8578
- return current.lastConnectionDropAt ? current : _objectSpread$1(_objectSpread$1({}, current), {}, {
8439
+ return current.lastConnectionDropAt ? current : _objectSpread$2(_objectSpread$2({}, current), {}, {
8579
8440
  lastConnectionDropAt: new Date()
8580
8441
  });
8581
8442
  });
@@ -8616,8 +8477,8 @@ var ThreadManager = /*#__PURE__*/function () {
8616
8477
  });
8617
8478
 
8618
8479
  _defineProperty__default['default'](this, "reload", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee() {
8619
- var _ref12,
8620
- _ref12$force,
8480
+ var _ref9,
8481
+ _ref9$force,
8621
8482
  force,
8622
8483
  _this$state$getLatest3,
8623
8484
  threads,
@@ -8639,7 +8500,7 @@ var ThreadManager = /*#__PURE__*/function () {
8639
8500
  while (1) {
8640
8501
  switch (_context.prev = _context.next) {
8641
8502
  case 0:
8642
- _ref12 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref12$force = _ref12.force, force = _ref12$force === void 0 ? false : _ref12$force;
8503
+ _ref9 = _args.length > 0 && _args[0] !== undefined ? _args[0] : {}, _ref9$force = _ref9.force, force = _ref9$force === void 0 ? false : _ref9$force;
8643
8504
  _this$state$getLatest3 = _this.state.getLatestValue(), threads = _this$state$getLatest3.threads, unseenThreadIds = _this$state$getLatest3.unseenThreadIds, isThreadOrderStale = _this$state$getLatest3.isThreadOrderStale, pagination = _this$state$getLatest3.pagination, ready = _this$state$getLatest3.ready;
8644
8505
 
8645
8506
  if (!pagination.isLoading) {
@@ -8662,213 +8523,1219 @@ var ThreadManager = /*#__PURE__*/function () {
8662
8523
  _context.prev = 7;
8663
8524
 
8664
8525
  _this.state.next(function (current) {
8665
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8666
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8526
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8527
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8667
8528
  isLoading: true
8668
8529
  })
8669
8530
  });
8670
8531
  });
8671
8532
 
8672
- _context.next = 11;
8673
- return _this.queryThreads({
8674
- limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT) || MAX_QUERY_THREADS_LIMIT
8675
- });
8533
+ _context.next = 11;
8534
+ return _this.queryThreads({
8535
+ limit: Math.min(limit, MAX_QUERY_THREADS_LIMIT) || MAX_QUERY_THREADS_LIMIT
8536
+ });
8537
+
8538
+ case 11:
8539
+ response = _context.sent;
8540
+ currentThreads = _this.threadsById;
8541
+ nextThreads = [];
8542
+ _iterator = _createForOfIteratorHelper$2(response.threads);
8543
+
8544
+ try {
8545
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
8546
+ incomingThread = _step.value;
8547
+ existingThread = currentThreads[incomingThread.id];
8548
+
8549
+ if (existingThread) {
8550
+ // Reuse thread instances if possible
8551
+ nextThreads.push(existingThread);
8552
+
8553
+ if (existingThread.hasStaleState) {
8554
+ existingThread.hydrateState(incomingThread);
8555
+ }
8556
+ } else {
8557
+ nextThreads.push(incomingThread);
8558
+ }
8559
+ }
8560
+ } catch (err) {
8561
+ _iterator.e(err);
8562
+ } finally {
8563
+ _iterator.f();
8564
+ }
8565
+
8566
+ _this.state.next(function (current) {
8567
+ var _response$next;
8568
+
8569
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8570
+ threads: nextThreads,
8571
+ unseenThreadIds: [],
8572
+ isThreadOrderStale: false,
8573
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8574
+ isLoading: false,
8575
+ nextCursor: (_response$next = response.next) !== null && _response$next !== void 0 ? _response$next : null
8576
+ }),
8577
+ ready: true
8578
+ });
8579
+ });
8580
+
8581
+ _context.next = 23;
8582
+ break;
8583
+
8584
+ case 19:
8585
+ _context.prev = 19;
8586
+ _context.t0 = _context["catch"](7);
8587
+
8588
+ _this.client.logger('error', _context.t0.message);
8589
+
8590
+ _this.state.next(function (current) {
8591
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8592
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8593
+ isLoading: false
8594
+ })
8595
+ });
8596
+ });
8597
+
8598
+ case 23:
8599
+ case "end":
8600
+ return _context.stop();
8601
+ }
8602
+ }
8603
+ }, _callee, null, [[7, 19]]);
8604
+ })));
8605
+
8606
+ _defineProperty__default['default'](this, "queryThreads", function () {
8607
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8608
+ return _this.client.queryThreads(_objectSpread$2({
8609
+ limit: 25,
8610
+ participant_limit: 10,
8611
+ reply_limit: 10,
8612
+ watch: true
8613
+ }, options));
8614
+ });
8615
+
8616
+ _defineProperty__default['default'](this, "loadNextPage", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
8617
+ var options,
8618
+ _this$state$getLatest4,
8619
+ pagination,
8620
+ response,
8621
+ _args2 = arguments;
8622
+
8623
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
8624
+ while (1) {
8625
+ switch (_context2.prev = _context2.next) {
8626
+ case 0:
8627
+ options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
8628
+ _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
8629
+
8630
+ if (!(pagination.isLoadingNext || !pagination.nextCursor)) {
8631
+ _context2.next = 4;
8632
+ break;
8633
+ }
8634
+
8635
+ return _context2.abrupt("return");
8636
+
8637
+ case 4:
8638
+ _context2.prev = 4;
8639
+
8640
+ _this.state.partialNext({
8641
+ pagination: _objectSpread$2(_objectSpread$2({}, pagination), {}, {
8642
+ isLoadingNext: true
8643
+ })
8644
+ });
8645
+
8646
+ _context2.next = 8;
8647
+ return _this.queryThreads(_objectSpread$2(_objectSpread$2({}, options), {}, {
8648
+ next: pagination.nextCursor
8649
+ }));
8650
+
8651
+ case 8:
8652
+ response = _context2.sent;
8653
+
8654
+ _this.state.next(function (current) {
8655
+ var _response$next2;
8656
+
8657
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8658
+ threads: response.threads.length ? current.threads.concat(response.threads) : current.threads,
8659
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8660
+ nextCursor: (_response$next2 = response.next) !== null && _response$next2 !== void 0 ? _response$next2 : null,
8661
+ isLoadingNext: false
8662
+ })
8663
+ });
8664
+ });
8665
+
8666
+ _context2.next = 16;
8667
+ break;
8668
+
8669
+ case 12:
8670
+ _context2.prev = 12;
8671
+ _context2.t0 = _context2["catch"](4);
8672
+
8673
+ _this.client.logger('error', _context2.t0.message);
8674
+
8675
+ _this.state.next(function (current) {
8676
+ return _objectSpread$2(_objectSpread$2({}, current), {}, {
8677
+ pagination: _objectSpread$2(_objectSpread$2({}, current.pagination), {}, {
8678
+ isLoadingNext: false
8679
+ })
8680
+ });
8681
+ });
8682
+
8683
+ case 16:
8684
+ case "end":
8685
+ return _context2.stop();
8686
+ }
8687
+ }
8688
+ }, _callee2, null, [[4, 12]]);
8689
+ })));
8690
+
8691
+ this.client = client;
8692
+ this.state = new StateStore({
8693
+ active: false,
8694
+ isThreadOrderStale: false,
8695
+ threads: [],
8696
+ unreadThreadCount: 0,
8697
+ unseenThreadIds: [],
8698
+ lastConnectionDropAt: null,
8699
+ pagination: {
8700
+ isLoading: false,
8701
+ isLoadingNext: false,
8702
+ nextCursor: null
8703
+ },
8704
+ ready: false
8705
+ });
8706
+ this.threadsByIdGetterCache = {
8707
+ threads: [],
8708
+ threadsById: {}
8709
+ };
8710
+ }
8711
+
8712
+ _createClass__default['default'](ThreadManager, [{
8713
+ key: "threadsById",
8714
+ get: function get() {
8715
+ var _this$state$getLatest5 = this.state.getLatestValue(),
8716
+ threads = _this$state$getLatest5.threads;
8717
+
8718
+ if (threads === this.threadsByIdGetterCache.threads) {
8719
+ return this.threadsByIdGetterCache.threadsById;
8720
+ }
8721
+
8722
+ var threadsById = threads.reduce(function (newThreadsById, thread) {
8723
+ newThreadsById[thread.id] = thread;
8724
+ return newThreadsById;
8725
+ }, {});
8726
+ this.threadsByIdGetterCache.threads = threads;
8727
+ this.threadsByIdGetterCache.threadsById = threadsById;
8728
+ return threadsById;
8729
+ }
8730
+ }]);
8731
+
8732
+ return ThreadManager;
8733
+ }();
8734
+
8735
+ var _excluded$1 = ["own_votes", "id"],
8736
+ _excluded2$1 = ["id"];
8737
+
8738
+ 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; }
8739
+
8740
+ 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; }
8741
+
8742
+ var isPollUpdatedEvent = function isPollUpdatedEvent(e) {
8743
+ return e.type === 'poll.updated';
8744
+ };
8745
+
8746
+ var isPollClosedEventEvent = function isPollClosedEventEvent(e) {
8747
+ return e.type === 'poll.closed';
8748
+ };
8749
+
8750
+ var isPollVoteCastedEvent = function isPollVoteCastedEvent(e) {
8751
+ return e.type === 'poll.vote_casted';
8752
+ };
8753
+
8754
+ var isPollVoteChangedEvent = function isPollVoteChangedEvent(e) {
8755
+ return e.type === 'poll.vote_changed';
8756
+ };
8757
+
8758
+ var isPollVoteRemovedEvent = function isPollVoteRemovedEvent(e) {
8759
+ return e.type === 'poll.vote_removed';
8760
+ };
8761
+
8762
+ var isVoteAnswer = function isVoteAnswer(vote) {
8763
+ return !!(vote !== null && vote !== void 0 && vote.answer_text);
8764
+ };
8765
+ var Poll = /*#__PURE__*/function () {
8766
+ function Poll(_ref) {
8767
+ var _this = this;
8768
+
8769
+ var client = _ref.client,
8770
+ _poll = _ref.poll;
8771
+
8772
+ _classCallCheck__default['default'](this, Poll);
8773
+
8774
+ _defineProperty__default['default'](this, "state", void 0);
8775
+
8776
+ _defineProperty__default['default'](this, "id", void 0);
8777
+
8778
+ _defineProperty__default['default'](this, "client", void 0);
8779
+
8780
+ _defineProperty__default['default'](this, "unsubscribeFunctions", new Set());
8781
+
8782
+ _defineProperty__default['default'](this, "getInitialStateFromPollResponse", function (poll) {
8783
+ var _own_votes$reduce;
8784
+
8785
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
8786
+ var own_votes = poll.own_votes;
8787
+ poll.id;
8788
+ var pollResponseForState = _objectWithoutProperties__default['default'](poll, _excluded$1);
8789
+
8790
+ var _ref2 = (_own_votes$reduce = own_votes === null || own_votes === void 0 ? void 0 : own_votes.reduce(function (acc, voteOrAnswer) {
8791
+ if (isVoteAnswer(voteOrAnswer)) {
8792
+ acc.ownAnswer = voteOrAnswer;
8793
+ } else {
8794
+ acc.ownVotes.push(voteOrAnswer);
8795
+ }
8796
+
8797
+ return acc;
8798
+ }, {
8799
+ ownVotes: []
8800
+ })) !== null && _own_votes$reduce !== void 0 ? _own_votes$reduce : {
8801
+ ownVotes: []
8802
+ },
8803
+ ownAnswer = _ref2.ownAnswer,
8804
+ ownVotes = _ref2.ownVotes;
8805
+
8806
+ return _objectSpread$1(_objectSpread$1({}, pollResponseForState), {}, {
8807
+ lastActivityAt: new Date(),
8808
+ maxVotedOptionIds: getMaxVotedOptionIds(pollResponseForState.vote_counts_by_option),
8809
+ ownAnswer: ownAnswer,
8810
+ ownVotesByOptionId: getOwnVotesByOptionId(ownVotes)
8811
+ });
8812
+ });
8813
+
8814
+ _defineProperty__default['default'](this, "reinitializeState", function (poll) {
8815
+ _this.state.partialNext(_this.getInitialStateFromPollResponse(poll));
8816
+ });
8817
+
8818
+ _defineProperty__default['default'](this, "handlePollUpdated", function (event) {
8819
+ var _event$poll;
8820
+
8821
+ if ((_event$poll = event.poll) !== null && _event$poll !== void 0 && _event$poll.id && event.poll.id !== _this.id) return;
8822
+ if (!isPollUpdatedEvent(event)) return; // eslint-disable-next-line @typescript-eslint/no-unused-vars
8823
+
8824
+ var _extractPollData = extractPollData(event.poll),
8825
+ pollData = _objectWithoutProperties__default['default'](_extractPollData, _excluded2$1); // @ts-ignore
8826
+
8827
+
8828
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollData), {}, {
8829
+ lastActivityAt: new Date(event.created_at)
8830
+ }));
8831
+ });
8832
+
8833
+ _defineProperty__default['default'](this, "handlePollClosed", function (event) {
8834
+ var _event$poll2;
8835
+
8836
+ if ((_event$poll2 = event.poll) !== null && _event$poll2 !== void 0 && _event$poll2.id && event.poll.id !== _this.id) return;
8837
+ if (!isPollClosedEventEvent(event)) return; // @ts-ignore
8838
+
8839
+ _this.state.partialNext({
8840
+ is_closed: true,
8841
+ lastActivityAt: new Date(event.created_at)
8842
+ });
8843
+ });
8844
+
8845
+ _defineProperty__default['default'](this, "handleVoteCasted", function (event) {
8846
+ var _event$poll3;
8847
+
8848
+ if ((_event$poll3 = event.poll) !== null && _event$poll3 !== void 0 && _event$poll3.id && event.poll.id !== _this.id) return;
8849
+ if (!isPollVoteCastedEvent(event)) return;
8850
+ var currentState = _this.data;
8851
+ var isOwnVote = event.poll_vote.user_id === _this.client.userID;
8852
+
8853
+ var latestAnswers = _toConsumableArray__default['default'](currentState.latest_answers);
8854
+
8855
+ var ownAnswer = currentState.ownAnswer;
8856
+ var ownVotesByOptionId = currentState.ownVotesByOptionId;
8857
+ var maxVotedOptionIds = currentState.maxVotedOptionIds;
8858
+
8859
+ if (isOwnVote) {
8860
+ if (isVoteAnswer(event.poll_vote)) {
8861
+ ownAnswer = event.poll_vote;
8862
+ } else if (event.poll_vote.option_id) {
8863
+ ownVotesByOptionId[event.poll_vote.option_id] = event.poll_vote;
8864
+ }
8865
+ }
8866
+
8867
+ if (isVoteAnswer(event.poll_vote)) {
8868
+ latestAnswers = [event.poll_vote].concat(_toConsumableArray__default['default'](latestAnswers));
8869
+ } else {
8870
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8871
+ }
8872
+
8873
+ var pollEnrichData = extractPollEnrichedData(event.poll); // @ts-ignore
8874
+
8875
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollEnrichData), {}, {
8876
+ latest_answers: latestAnswers,
8877
+ lastActivityAt: new Date(event.created_at),
8878
+ ownAnswer: ownAnswer,
8879
+ ownVotesByOptionId: ownVotesByOptionId,
8880
+ maxVotedOptionIds: maxVotedOptionIds
8881
+ }));
8882
+ });
8883
+
8884
+ _defineProperty__default['default'](this, "handleVoteChanged", function (event) {
8885
+ var _event$poll4;
8886
+
8887
+ // this event is triggered only when event.poll.enforce_unique_vote === true
8888
+ if ((_event$poll4 = event.poll) !== null && _event$poll4 !== void 0 && _event$poll4.id && event.poll.id !== _this.id) return;
8889
+ if (!isPollVoteChangedEvent(event)) return;
8890
+ var currentState = _this.data;
8891
+ var isOwnVote = event.poll_vote.user_id === _this.client.userID;
8892
+
8893
+ var latestAnswers = _toConsumableArray__default['default'](currentState.latest_answers);
8894
+
8895
+ var ownAnswer = currentState.ownAnswer;
8896
+ var ownVotesByOptionId = currentState.ownVotesByOptionId;
8897
+ var maxVotedOptionIds = currentState.maxVotedOptionIds;
8898
+
8899
+ if (isOwnVote) {
8900
+ if (isVoteAnswer(event.poll_vote)) {
8901
+ latestAnswers = [event.poll_vote].concat(_toConsumableArray__default['default'](latestAnswers.filter(function (answer) {
8902
+ return answer.id !== event.poll_vote.id;
8903
+ })));
8904
+ ownAnswer = event.poll_vote;
8905
+ } else if (event.poll_vote.option_id) {
8906
+ var _ownAnswer;
8907
+
8908
+ if (event.poll.enforce_unique_votes) {
8909
+ ownVotesByOptionId = _defineProperty__default['default']({}, event.poll_vote.option_id, event.poll_vote);
8910
+ } else {
8911
+ ownVotesByOptionId = Object.entries(ownVotesByOptionId).reduce(function (acc, _ref3) {
8912
+ var _ref4 = _slicedToArray__default['default'](_ref3, 2),
8913
+ optionId = _ref4[0],
8914
+ vote = _ref4[1];
8915
+
8916
+ if (optionId !== event.poll_vote.option_id && vote.id === event.poll_vote.id) {
8917
+ return acc;
8918
+ }
8919
+
8920
+ acc[optionId] = vote;
8921
+ return acc;
8922
+ }, {});
8923
+ ownVotesByOptionId[event.poll_vote.option_id] = event.poll_vote;
8924
+ }
8925
+
8926
+ if (((_ownAnswer = ownAnswer) === null || _ownAnswer === void 0 ? void 0 : _ownAnswer.id) === event.poll_vote.id) {
8927
+ ownAnswer = undefined;
8928
+ }
8929
+
8930
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8931
+ }
8932
+ } else if (isVoteAnswer(event.poll_vote)) {
8933
+ latestAnswers = [event.poll_vote].concat(_toConsumableArray__default['default'](latestAnswers));
8934
+ } else {
8935
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8936
+ }
8937
+
8938
+ var pollEnrichData = extractPollEnrichedData(event.poll); // @ts-ignore
8939
+
8940
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollEnrichData), {}, {
8941
+ latest_answers: latestAnswers,
8942
+ lastActivityAt: new Date(event.created_at),
8943
+ ownAnswer: ownAnswer,
8944
+ ownVotesByOptionId: ownVotesByOptionId,
8945
+ maxVotedOptionIds: maxVotedOptionIds
8946
+ }));
8947
+ });
8948
+
8949
+ _defineProperty__default['default'](this, "handleVoteRemoved", function (event) {
8950
+ var _event$poll5;
8951
+
8952
+ if ((_event$poll5 = event.poll) !== null && _event$poll5 !== void 0 && _event$poll5.id && event.poll.id !== _this.id) return;
8953
+ if (!isPollVoteRemovedEvent(event)) return;
8954
+ var currentState = _this.data;
8955
+ var isOwnVote = event.poll_vote.user_id === _this.client.userID;
8956
+
8957
+ var latestAnswers = _toConsumableArray__default['default'](currentState.latest_answers);
8958
+
8959
+ var ownAnswer = currentState.ownAnswer;
8960
+
8961
+ var ownVotesByOptionId = _objectSpread$1({}, currentState.ownVotesByOptionId);
8962
+
8963
+ var maxVotedOptionIds = currentState.maxVotedOptionIds;
8964
+
8965
+ if (isVoteAnswer(event.poll_vote)) {
8966
+ latestAnswers = latestAnswers.filter(function (answer) {
8967
+ return answer.id !== event.poll_vote.id;
8968
+ });
8969
+
8970
+ if (isOwnVote) {
8971
+ ownAnswer = undefined;
8972
+ }
8973
+ } else {
8974
+ maxVotedOptionIds = getMaxVotedOptionIds(event.poll.vote_counts_by_option);
8975
+
8976
+ if (isOwnVote && event.poll_vote.option_id) {
8977
+ delete ownVotesByOptionId[event.poll_vote.option_id];
8978
+ }
8979
+ }
8980
+
8981
+ var pollEnrichData = extractPollEnrichedData(event.poll); // @ts-ignore
8982
+
8983
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, pollEnrichData), {}, {
8984
+ latest_answers: latestAnswers,
8985
+ lastActivityAt: new Date(event.created_at),
8986
+ ownAnswer: ownAnswer,
8987
+ ownVotesByOptionId: ownVotesByOptionId,
8988
+ maxVotedOptionIds: maxVotedOptionIds
8989
+ }));
8990
+ });
8991
+
8992
+ _defineProperty__default['default'](this, "query", /*#__PURE__*/function () {
8993
+ var _ref5 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(id) {
8994
+ var _yield$_this$client$g, poll;
8995
+
8996
+ return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
8997
+ while (1) {
8998
+ switch (_context.prev = _context.next) {
8999
+ case 0:
9000
+ _context.next = 2;
9001
+ return _this.client.getPoll(id);
9002
+
9003
+ case 2:
9004
+ _yield$_this$client$g = _context.sent;
9005
+ poll = _yield$_this$client$g.poll;
9006
+
9007
+ // @ts-ignore
9008
+ _this.state.partialNext(_objectSpread$1(_objectSpread$1({}, poll), {}, {
9009
+ lastActivityAt: new Date()
9010
+ }));
9011
+
9012
+ return _context.abrupt("return", poll);
9013
+
9014
+ case 6:
9015
+ case "end":
9016
+ return _context.stop();
9017
+ }
9018
+ }
9019
+ }, _callee);
9020
+ }));
9021
+
9022
+ return function (_x) {
9023
+ return _ref5.apply(this, arguments);
9024
+ };
9025
+ }());
9026
+
9027
+ _defineProperty__default['default'](this, "update", /*#__PURE__*/function () {
9028
+ var _ref6 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(data) {
9029
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
9030
+ while (1) {
9031
+ switch (_context2.prev = _context2.next) {
9032
+ case 0:
9033
+ _context2.next = 2;
9034
+ return _this.client.updatePoll(_objectSpread$1(_objectSpread$1({}, data), {}, {
9035
+ id: _this.id
9036
+ }));
9037
+
9038
+ case 2:
9039
+ return _context2.abrupt("return", _context2.sent);
9040
+
9041
+ case 3:
9042
+ case "end":
9043
+ return _context2.stop();
9044
+ }
9045
+ }
9046
+ }, _callee2);
9047
+ }));
9048
+
9049
+ return function (_x2) {
9050
+ return _ref6.apply(this, arguments);
9051
+ };
9052
+ }());
9053
+
9054
+ _defineProperty__default['default'](this, "partialUpdate", /*#__PURE__*/function () {
9055
+ var _ref7 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(partialPollObject) {
9056
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
9057
+ while (1) {
9058
+ switch (_context3.prev = _context3.next) {
9059
+ case 0:
9060
+ _context3.next = 2;
9061
+ return _this.client.partialUpdatePoll(_this.id, partialPollObject);
9062
+
9063
+ case 2:
9064
+ return _context3.abrupt("return", _context3.sent);
9065
+
9066
+ case 3:
9067
+ case "end":
9068
+ return _context3.stop();
9069
+ }
9070
+ }
9071
+ }, _callee3);
9072
+ }));
9073
+
9074
+ return function (_x3) {
9075
+ return _ref7.apply(this, arguments);
9076
+ };
9077
+ }());
9078
+
9079
+ _defineProperty__default['default'](this, "close", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee4() {
9080
+ return _regeneratorRuntime__default['default'].wrap(function _callee4$(_context4) {
9081
+ while (1) {
9082
+ switch (_context4.prev = _context4.next) {
9083
+ case 0:
9084
+ _context4.next = 2;
9085
+ return _this.client.closePoll(_this.id);
9086
+
9087
+ case 2:
9088
+ return _context4.abrupt("return", _context4.sent);
9089
+
9090
+ case 3:
9091
+ case "end":
9092
+ return _context4.stop();
9093
+ }
9094
+ }
9095
+ }, _callee4);
9096
+ })));
9097
+
9098
+ _defineProperty__default['default'](this, "delete", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee5() {
9099
+ return _regeneratorRuntime__default['default'].wrap(function _callee5$(_context5) {
9100
+ while (1) {
9101
+ switch (_context5.prev = _context5.next) {
9102
+ case 0:
9103
+ _context5.next = 2;
9104
+ return _this.client.deletePoll(_this.id);
9105
+
9106
+ case 2:
9107
+ return _context5.abrupt("return", _context5.sent);
9108
+
9109
+ case 3:
9110
+ case "end":
9111
+ return _context5.stop();
9112
+ }
9113
+ }
9114
+ }, _callee5);
9115
+ })));
9116
+
9117
+ _defineProperty__default['default'](this, "createOption", /*#__PURE__*/function () {
9118
+ var _ref10 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee6(option) {
9119
+ return _regeneratorRuntime__default['default'].wrap(function _callee6$(_context6) {
9120
+ while (1) {
9121
+ switch (_context6.prev = _context6.next) {
9122
+ case 0:
9123
+ _context6.next = 2;
9124
+ return _this.client.createPollOption(_this.id, option);
9125
+
9126
+ case 2:
9127
+ return _context6.abrupt("return", _context6.sent);
9128
+
9129
+ case 3:
9130
+ case "end":
9131
+ return _context6.stop();
9132
+ }
9133
+ }
9134
+ }, _callee6);
9135
+ }));
9136
+
9137
+ return function (_x4) {
9138
+ return _ref10.apply(this, arguments);
9139
+ };
9140
+ }());
9141
+
9142
+ _defineProperty__default['default'](this, "updateOption", /*#__PURE__*/function () {
9143
+ var _ref11 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee7(option) {
9144
+ return _regeneratorRuntime__default['default'].wrap(function _callee7$(_context7) {
9145
+ while (1) {
9146
+ switch (_context7.prev = _context7.next) {
9147
+ case 0:
9148
+ _context7.next = 2;
9149
+ return _this.client.updatePollOption(_this.id, option);
9150
+
9151
+ case 2:
9152
+ return _context7.abrupt("return", _context7.sent);
9153
+
9154
+ case 3:
9155
+ case "end":
9156
+ return _context7.stop();
9157
+ }
9158
+ }
9159
+ }, _callee7);
9160
+ }));
9161
+
9162
+ return function (_x5) {
9163
+ return _ref11.apply(this, arguments);
9164
+ };
9165
+ }());
9166
+
9167
+ _defineProperty__default['default'](this, "deleteOption", /*#__PURE__*/function () {
9168
+ var _ref12 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee8(optionId) {
9169
+ return _regeneratorRuntime__default['default'].wrap(function _callee8$(_context8) {
9170
+ while (1) {
9171
+ switch (_context8.prev = _context8.next) {
9172
+ case 0:
9173
+ _context8.next = 2;
9174
+ return _this.client.deletePollOption(_this.id, optionId);
9175
+
9176
+ case 2:
9177
+ return _context8.abrupt("return", _context8.sent);
9178
+
9179
+ case 3:
9180
+ case "end":
9181
+ return _context8.stop();
9182
+ }
9183
+ }
9184
+ }, _callee8);
9185
+ }));
9186
+
9187
+ return function (_x6) {
9188
+ return _ref12.apply(this, arguments);
9189
+ };
9190
+ }());
9191
+
9192
+ _defineProperty__default['default'](this, "castVote", /*#__PURE__*/function () {
9193
+ var _ref13 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee9(optionId, messageId) {
9194
+ var _this$data, max_votes_allowed, ownVotesByOptionId, reachedVoteLimit, _oldestVote2, oldestVote;
9195
+
9196
+ return _regeneratorRuntime__default['default'].wrap(function _callee9$(_context9) {
9197
+ while (1) {
9198
+ switch (_context9.prev = _context9.next) {
9199
+ case 0:
9200
+ _this$data = _this.data, max_votes_allowed = _this$data.max_votes_allowed, ownVotesByOptionId = _this$data.ownVotesByOptionId;
9201
+ reachedVoteLimit = max_votes_allowed && max_votes_allowed === Object.keys(ownVotesByOptionId).length;
9202
+
9203
+ if (!reachedVoteLimit) {
9204
+ _context9.next = 8;
9205
+ break;
9206
+ }
9207
+
9208
+ oldestVote = Object.values(ownVotesByOptionId)[0];
9209
+ Object.values(ownVotesByOptionId).slice(1).forEach(function (vote) {
9210
+ var _oldestVote;
9211
+
9212
+ if (!((_oldestVote = oldestVote) !== null && _oldestVote !== void 0 && _oldestVote.created_at) || new Date(vote.created_at) < new Date(oldestVote.created_at)) {
9213
+ oldestVote = vote;
9214
+ }
9215
+ });
9216
+
9217
+ if (!((_oldestVote2 = oldestVote) !== null && _oldestVote2 !== void 0 && _oldestVote2.id)) {
9218
+ _context9.next = 8;
9219
+ break;
9220
+ }
9221
+
9222
+ _context9.next = 8;
9223
+ return _this.removeVote(oldestVote.id, messageId);
9224
+
9225
+ case 8:
9226
+ _context9.next = 10;
9227
+ return _this.client.castPollVote(messageId, _this.id, {
9228
+ option_id: optionId
9229
+ });
9230
+
9231
+ case 10:
9232
+ return _context9.abrupt("return", _context9.sent);
9233
+
9234
+ case 11:
9235
+ case "end":
9236
+ return _context9.stop();
9237
+ }
9238
+ }
9239
+ }, _callee9);
9240
+ }));
9241
+
9242
+ return function (_x7, _x8) {
9243
+ return _ref13.apply(this, arguments);
9244
+ };
9245
+ }());
9246
+
9247
+ _defineProperty__default['default'](this, "removeVote", /*#__PURE__*/function () {
9248
+ var _ref14 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee10(voteId, messageId) {
9249
+ return _regeneratorRuntime__default['default'].wrap(function _callee10$(_context10) {
9250
+ while (1) {
9251
+ switch (_context10.prev = _context10.next) {
9252
+ case 0:
9253
+ _context10.next = 2;
9254
+ return _this.client.removePollVote(messageId, _this.id, voteId);
9255
+
9256
+ case 2:
9257
+ return _context10.abrupt("return", _context10.sent);
9258
+
9259
+ case 3:
9260
+ case "end":
9261
+ return _context10.stop();
9262
+ }
9263
+ }
9264
+ }, _callee10);
9265
+ }));
9266
+
9267
+ return function (_x9, _x10) {
9268
+ return _ref14.apply(this, arguments);
9269
+ };
9270
+ }());
9271
+
9272
+ _defineProperty__default['default'](this, "addAnswer", /*#__PURE__*/function () {
9273
+ var _ref15 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee11(answerText, messageId) {
9274
+ return _regeneratorRuntime__default['default'].wrap(function _callee11$(_context11) {
9275
+ while (1) {
9276
+ switch (_context11.prev = _context11.next) {
9277
+ case 0:
9278
+ _context11.next = 2;
9279
+ return _this.client.addPollAnswer(messageId, _this.id, answerText);
9280
+
9281
+ case 2:
9282
+ return _context11.abrupt("return", _context11.sent);
9283
+
9284
+ case 3:
9285
+ case "end":
9286
+ return _context11.stop();
9287
+ }
9288
+ }
9289
+ }, _callee11);
9290
+ }));
9291
+
9292
+ return function (_x11, _x12) {
9293
+ return _ref15.apply(this, arguments);
9294
+ };
9295
+ }());
9296
+
9297
+ _defineProperty__default['default'](this, "removeAnswer", /*#__PURE__*/function () {
9298
+ var _ref16 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee12(answerId, messageId) {
9299
+ return _regeneratorRuntime__default['default'].wrap(function _callee12$(_context12) {
9300
+ while (1) {
9301
+ switch (_context12.prev = _context12.next) {
9302
+ case 0:
9303
+ _context12.next = 2;
9304
+ return _this.client.removePollVote(messageId, _this.id, answerId);
9305
+
9306
+ case 2:
9307
+ return _context12.abrupt("return", _context12.sent);
9308
+
9309
+ case 3:
9310
+ case "end":
9311
+ return _context12.stop();
9312
+ }
9313
+ }
9314
+ }, _callee12);
9315
+ }));
9316
+
9317
+ return function (_x13, _x14) {
9318
+ return _ref16.apply(this, arguments);
9319
+ };
9320
+ }());
9321
+
9322
+ _defineProperty__default['default'](this, "queryAnswers", /*#__PURE__*/function () {
9323
+ var _ref17 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee13(params) {
9324
+ return _regeneratorRuntime__default['default'].wrap(function _callee13$(_context13) {
9325
+ while (1) {
9326
+ switch (_context13.prev = _context13.next) {
9327
+ case 0:
9328
+ _context13.next = 2;
9329
+ return _this.client.queryPollAnswers(_this.id, params.filter, params.sort, params.options);
9330
+
9331
+ case 2:
9332
+ return _context13.abrupt("return", _context13.sent);
9333
+
9334
+ case 3:
9335
+ case "end":
9336
+ return _context13.stop();
9337
+ }
9338
+ }
9339
+ }, _callee13);
9340
+ }));
9341
+
9342
+ return function (_x15) {
9343
+ return _ref17.apply(this, arguments);
9344
+ };
9345
+ }());
9346
+
9347
+ _defineProperty__default['default'](this, "queryOptionVotes", /*#__PURE__*/function () {
9348
+ var _ref18 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee14(params) {
9349
+ return _regeneratorRuntime__default['default'].wrap(function _callee14$(_context14) {
9350
+ while (1) {
9351
+ switch (_context14.prev = _context14.next) {
9352
+ case 0:
9353
+ _context14.next = 2;
9354
+ return _this.client.queryPollVotes(_this.id, params.filter, params.sort, params.options);
9355
+
9356
+ case 2:
9357
+ return _context14.abrupt("return", _context14.sent);
9358
+
9359
+ case 3:
9360
+ case "end":
9361
+ return _context14.stop();
9362
+ }
9363
+ }
9364
+ }, _callee14);
9365
+ }));
9366
+
9367
+ return function (_x16) {
9368
+ return _ref18.apply(this, arguments);
9369
+ };
9370
+ }());
9371
+
9372
+ this.client = client;
9373
+ this.id = _poll.id;
9374
+ this.state = new StateStore(this.getInitialStateFromPollResponse(_poll));
9375
+ }
9376
+
9377
+ _createClass__default['default'](Poll, [{
9378
+ key: "data",
9379
+ get: function get() {
9380
+ return this.state.getLatestValue();
9381
+ }
9382
+ }]);
9383
+
9384
+ return Poll;
9385
+ }();
9386
+
9387
+ function getMaxVotedOptionIds(voteCountsByOption) {
9388
+ var maxVotes = 0;
9389
+ var winningOptions = [];
9390
+
9391
+ for (var _i = 0, _Object$entries = Object.entries(voteCountsByOption !== null && voteCountsByOption !== void 0 ? voteCountsByOption : {}); _i < _Object$entries.length; _i++) {
9392
+ var _Object$entries$_i = _slicedToArray__default['default'](_Object$entries[_i], 2),
9393
+ id = _Object$entries$_i[0],
9394
+ count = _Object$entries$_i[1];
9395
+
9396
+ if (count > maxVotes) {
9397
+ winningOptions = [id];
9398
+ maxVotes = count;
9399
+ } else if (count === maxVotes) {
9400
+ winningOptions.push(id);
9401
+ }
9402
+ }
9403
+
9404
+ return winningOptions;
9405
+ }
9406
+
9407
+ function getOwnVotesByOptionId(ownVotes) {
9408
+ return !ownVotes ? {} : ownVotes.reduce(function (acc, vote) {
9409
+ if (isVoteAnswer(vote) || !vote.option_id) return acc;
9410
+ acc[vote.option_id] = vote;
9411
+ return acc;
9412
+ }, {});
9413
+ }
9414
+
9415
+ function extractPollData(pollResponse) {
9416
+ return {
9417
+ allow_answers: pollResponse.allow_answers,
9418
+ allow_user_suggested_options: pollResponse.allow_user_suggested_options,
9419
+ description: pollResponse.description,
9420
+ enforce_unique_vote: pollResponse.enforce_unique_vote,
9421
+ id: pollResponse.id,
9422
+ is_closed: pollResponse.is_closed,
9423
+ max_votes_allowed: pollResponse.max_votes_allowed,
9424
+ name: pollResponse.name,
9425
+ options: pollResponse.options,
9426
+ voting_visibility: pollResponse.voting_visibility
9427
+ };
9428
+ }
9429
+ function extractPollEnrichedData(pollResponse) {
9430
+ return {
9431
+ answers_count: pollResponse.answers_count,
9432
+ latest_votes_by_option: pollResponse.latest_votes_by_option,
9433
+ vote_count: pollResponse.vote_count,
9434
+ vote_counts_by_option: pollResponse.vote_counts_by_option
9435
+ };
9436
+ }
9437
+
9438
+ 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; } } }; }
9439
+
9440
+ 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); }
9441
+
9442
+ 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; }
9443
+ var PollManager = /*#__PURE__*/function () {
9444
+ // The pollCache contains only polls that have been created and sent as messages
9445
+ // (i.e only polls that are coupled with a message, can be voted on and require a
9446
+ // reactive state). It shall work as a basic look-up table for our SDK to be able
9447
+ // to quickly consume poll state that will be reactive even without the polls being
9448
+ // rendered within the UI.
9449
+ function PollManager(_ref) {
9450
+ var _this = this;
9451
+
9452
+ var client = _ref.client;
9453
+
9454
+ _classCallCheck__default['default'](this, PollManager);
9455
+
9456
+ _defineProperty__default['default'](this, "client", void 0);
9457
+
9458
+ _defineProperty__default['default'](this, "pollCache", new Map());
9459
+
9460
+ _defineProperty__default['default'](this, "unsubscribeFunctions", new Set());
9461
+
9462
+ _defineProperty__default['default'](this, "fromState", function (id) {
9463
+ return _this.pollCache.get(id);
9464
+ });
9465
+
9466
+ _defineProperty__default['default'](this, "registerSubscriptions", function () {
9467
+ if (_this.unsubscribeFunctions.size) {
9468
+ // Already listening for events and changes
9469
+ return;
9470
+ }
9471
+
9472
+ _this.unsubscribeFunctions.add(_this.subscribeMessageNew());
9473
+
9474
+ _this.unsubscribeFunctions.add(_this.subscribePollUpdated());
9475
+
9476
+ _this.unsubscribeFunctions.add(_this.subscribePollClosed());
9477
+
9478
+ _this.unsubscribeFunctions.add(_this.subscribeVoteCasted());
9479
+
9480
+ _this.unsubscribeFunctions.add(_this.subscribeVoteChanged());
9481
+
9482
+ _this.unsubscribeFunctions.add(_this.subscribeVoteRemoved());
9483
+ });
9484
+
9485
+ _defineProperty__default['default'](this, "unregisterSubscriptions", function () {
9486
+ _this.unsubscribeFunctions.forEach(function (cleanupFunction) {
9487
+ return cleanupFunction();
9488
+ });
9489
+
9490
+ _this.unsubscribeFunctions.clear();
9491
+ });
9492
+
9493
+ _defineProperty__default['default'](this, "createPoll", /*#__PURE__*/function () {
9494
+ var _ref2 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee(poll) {
9495
+ var _yield$_this$client$c, createdPoll;
9496
+
9497
+ return _regeneratorRuntime__default['default'].wrap(function _callee$(_context) {
9498
+ while (1) {
9499
+ switch (_context.prev = _context.next) {
9500
+ case 0:
9501
+ _context.next = 2;
9502
+ return _this.client.createPoll(poll);
9503
+
9504
+ case 2:
9505
+ _yield$_this$client$c = _context.sent;
9506
+ createdPoll = _yield$_this$client$c.poll;
9507
+ return _context.abrupt("return", new Poll({
9508
+ client: _this.client,
9509
+ poll: createdPoll
9510
+ }));
9511
+
9512
+ case 5:
9513
+ case "end":
9514
+ return _context.stop();
9515
+ }
9516
+ }
9517
+ }, _callee);
9518
+ }));
9519
+
9520
+ return function (_x) {
9521
+ return _ref2.apply(this, arguments);
9522
+ };
9523
+ }());
9524
+
9525
+ _defineProperty__default['default'](this, "getPoll", /*#__PURE__*/function () {
9526
+ var _ref3 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2(id) {
9527
+ var cachedPoll, _yield$_this$client$g, poll;
9528
+
9529
+ return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
9530
+ while (1) {
9531
+ switch (_context2.prev = _context2.next) {
9532
+ case 0:
9533
+ cachedPoll = _this.fromState(id); // optimistically return the cached poll if it exists and update in the background
9534
+
9535
+ if (!cachedPoll) {
9536
+ _context2.next = 4;
9537
+ break;
9538
+ }
9539
+
9540
+ _this.client.getPoll(id).then(function (_ref4) {
9541
+ var poll = _ref4.poll;
9542
+ return _this.setOrOverwriteInCache(poll, true);
9543
+ });
9544
+
9545
+ return _context2.abrupt("return", cachedPoll);
9546
+
9547
+ case 4:
9548
+ _context2.next = 6;
9549
+ return _this.client.getPoll(id);
9550
+
9551
+ case 6:
9552
+ _yield$_this$client$g = _context2.sent;
9553
+ poll = _yield$_this$client$g.poll;
9554
+
9555
+ _this.setOrOverwriteInCache(poll);
9556
+
9557
+ return _context2.abrupt("return", _this.fromState(id));
9558
+
9559
+ case 10:
9560
+ case "end":
9561
+ return _context2.stop();
9562
+ }
9563
+ }
9564
+ }, _callee2);
9565
+ }));
9566
+
9567
+ return function (_x2) {
9568
+ return _ref3.apply(this, arguments);
9569
+ };
9570
+ }());
9571
+
9572
+ _defineProperty__default['default'](this, "queryPolls", /*#__PURE__*/function () {
9573
+ var _ref5 = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee3(filter) {
9574
+ var sort,
9575
+ options,
9576
+ _yield$_this$client$q,
9577
+ polls,
9578
+ next,
9579
+ pollInstances,
9580
+ _args3 = arguments;
9581
+
9582
+ return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
9583
+ while (1) {
9584
+ switch (_context3.prev = _context3.next) {
9585
+ case 0:
9586
+ sort = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : [];
9587
+ options = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
9588
+ _context3.next = 4;
9589
+ return _this.client.queryPolls(filter, sort, options);
9590
+
9591
+ case 4:
9592
+ _yield$_this$client$q = _context3.sent;
9593
+ polls = _yield$_this$client$q.polls;
9594
+ next = _yield$_this$client$q.next;
9595
+ pollInstances = polls.map(function (poll) {
9596
+ _this.setOrOverwriteInCache(poll, true);
9597
+
9598
+ return _this.fromState(poll.id);
9599
+ });
9600
+ return _context3.abrupt("return", {
9601
+ polls: pollInstances,
9602
+ next: next
9603
+ });
9604
+
9605
+ case 9:
9606
+ case "end":
9607
+ return _context3.stop();
9608
+ }
9609
+ }
9610
+ }, _callee3);
9611
+ }));
9612
+
9613
+ return function (_x3) {
9614
+ return _ref5.apply(this, arguments);
9615
+ };
9616
+ }());
8676
9617
 
8677
- case 11:
8678
- response = _context.sent;
8679
- currentThreads = _this.threadsById;
8680
- nextThreads = [];
8681
- _iterator = _createForOfIteratorHelper$1(response.threads);
9618
+ _defineProperty__default['default'](this, "hydratePollCache", function (messages, overwriteState) {
9619
+ var _iterator = _createForOfIteratorHelper$1(messages),
9620
+ _step;
8682
9621
 
8683
- try {
8684
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
8685
- incomingThread = _step.value;
8686
- existingThread = currentThreads[incomingThread.id];
9622
+ try {
9623
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
9624
+ var message = _step.value;
8687
9625
 
8688
- if (existingThread) {
8689
- // Reuse thread instances if possible
8690
- nextThreads.push(existingThread);
9626
+ if (!message.poll) {
9627
+ continue;
9628
+ }
8691
9629
 
8692
- if (existingThread.hasStaleState) {
8693
- existingThread.hydrateState(incomingThread);
8694
- }
8695
- } else {
8696
- nextThreads.push(incomingThread);
8697
- }
8698
- }
8699
- } catch (err) {
8700
- _iterator.e(err);
8701
- } finally {
8702
- _iterator.f();
8703
- }
9630
+ var pollResponse = message.poll;
8704
9631
 
8705
- _this.state.next(function (current) {
8706
- var _response$next;
9632
+ _this.setOrOverwriteInCache(pollResponse, overwriteState);
9633
+ }
9634
+ } catch (err) {
9635
+ _iterator.e(err);
9636
+ } finally {
9637
+ _iterator.f();
9638
+ }
9639
+ });
8707
9640
 
8708
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8709
- threads: nextThreads,
8710
- unseenThreadIds: [],
8711
- isThreadOrderStale: false,
8712
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8713
- isLoading: false,
8714
- nextCursor: (_response$next = response.next) !== null && _response$next !== void 0 ? _response$next : null
8715
- }),
8716
- ready: true
8717
- });
8718
- });
9641
+ _defineProperty__default['default'](this, "setOrOverwriteInCache", function (pollResponse, overwriteState) {
9642
+ var pollFromCache = _this.fromState(pollResponse.id);
8719
9643
 
8720
- _context.next = 23;
8721
- break;
9644
+ if (!pollFromCache) {
9645
+ var poll = new Poll({
9646
+ client: _this.client,
9647
+ poll: pollResponse
9648
+ });
8722
9649
 
8723
- case 19:
8724
- _context.prev = 19;
8725
- _context.t0 = _context["catch"](7);
9650
+ _this.pollCache.set(poll.id, poll);
9651
+ } else if (overwriteState) {
9652
+ pollFromCache.reinitializeState(pollResponse);
9653
+ }
9654
+ });
8726
9655
 
8727
- _this.client.logger('error', _context.t0.message);
9656
+ _defineProperty__default['default'](this, "subscribePollUpdated", function () {
9657
+ return _this.client.on('poll.updated', function (event) {
9658
+ var _event$poll;
8728
9659
 
8729
- _this.state.next(function (current) {
8730
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8731
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8732
- isLoading: false
8733
- })
8734
- });
8735
- });
9660
+ if ((_event$poll = event.poll) !== null && _event$poll !== void 0 && _event$poll.id) {
9661
+ var _this$fromState;
8736
9662
 
8737
- case 23:
8738
- case "end":
8739
- return _context.stop();
8740
- }
9663
+ (_this$fromState = _this.fromState(event.poll.id)) === null || _this$fromState === void 0 ? void 0 : _this$fromState.handlePollUpdated(event);
8741
9664
  }
8742
- }, _callee, null, [[7, 19]]);
8743
- })));
8744
-
8745
- _defineProperty__default['default'](this, "queryThreads", function () {
8746
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8747
- return _this.client.queryThreads(_objectSpread$1({
8748
- limit: 25,
8749
- participant_limit: 10,
8750
- reply_limit: 10,
8751
- watch: true
8752
- }, options));
9665
+ }).unsubscribe;
8753
9666
  });
8754
9667
 
8755
- _defineProperty__default['default'](this, "loadNextPage", /*#__PURE__*/_asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
8756
- var options,
8757
- _this$state$getLatest4,
8758
- pagination,
8759
- response,
8760
- _args2 = arguments;
9668
+ _defineProperty__default['default'](this, "subscribePollClosed", function () {
9669
+ return _this.client.on('poll.closed', function (event) {
9670
+ var _event$poll2;
8761
9671
 
8762
- return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
8763
- while (1) {
8764
- switch (_context2.prev = _context2.next) {
8765
- case 0:
8766
- options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
8767
- _this$state$getLatest4 = _this.state.getLatestValue(), pagination = _this$state$getLatest4.pagination;
9672
+ if ((_event$poll2 = event.poll) !== null && _event$poll2 !== void 0 && _event$poll2.id) {
9673
+ var _this$fromState2;
8768
9674
 
8769
- if (!(pagination.isLoadingNext || !pagination.nextCursor)) {
8770
- _context2.next = 4;
8771
- break;
8772
- }
9675
+ (_this$fromState2 = _this.fromState(event.poll.id)) === null || _this$fromState2 === void 0 ? void 0 : _this$fromState2.handlePollClosed(event);
9676
+ }
9677
+ }).unsubscribe;
9678
+ });
8773
9679
 
8774
- return _context2.abrupt("return");
9680
+ _defineProperty__default['default'](this, "subscribeVoteCasted", function () {
9681
+ return _this.client.on('poll.vote_casted', function (event) {
9682
+ var _event$poll3;
8775
9683
 
8776
- case 4:
8777
- _context2.prev = 4;
9684
+ if ((_event$poll3 = event.poll) !== null && _event$poll3 !== void 0 && _event$poll3.id) {
9685
+ var _this$fromState3;
8778
9686
 
8779
- _this.state.partialNext({
8780
- pagination: _objectSpread$1(_objectSpread$1({}, pagination), {}, {
8781
- isLoadingNext: true
8782
- })
8783
- });
9687
+ (_this$fromState3 = _this.fromState(event.poll.id)) === null || _this$fromState3 === void 0 ? void 0 : _this$fromState3.handleVoteCasted(event);
9688
+ }
9689
+ }).unsubscribe;
9690
+ });
8784
9691
 
8785
- _context2.next = 8;
8786
- return _this.queryThreads(_objectSpread$1(_objectSpread$1({}, options), {}, {
8787
- next: pagination.nextCursor
8788
- }));
9692
+ _defineProperty__default['default'](this, "subscribeVoteChanged", function () {
9693
+ return _this.client.on('poll.vote_changed', function (event) {
9694
+ var _event$poll4;
8789
9695
 
8790
- case 8:
8791
- response = _context2.sent;
9696
+ if ((_event$poll4 = event.poll) !== null && _event$poll4 !== void 0 && _event$poll4.id) {
9697
+ var _this$fromState4;
8792
9698
 
8793
- _this.state.next(function (current) {
8794
- var _response$next2;
9699
+ (_this$fromState4 = _this.fromState(event.poll.id)) === null || _this$fromState4 === void 0 ? void 0 : _this$fromState4.handleVoteChanged(event);
9700
+ }
9701
+ }).unsubscribe;
9702
+ });
8795
9703
 
8796
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8797
- threads: response.threads.length ? current.threads.concat(response.threads) : current.threads,
8798
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8799
- nextCursor: (_response$next2 = response.next) !== null && _response$next2 !== void 0 ? _response$next2 : null,
8800
- isLoadingNext: false
8801
- })
8802
- });
8803
- });
9704
+ _defineProperty__default['default'](this, "subscribeVoteRemoved", function () {
9705
+ return _this.client.on('poll.vote_removed', function (event) {
9706
+ var _event$poll5;
8804
9707
 
8805
- _context2.next = 16;
8806
- break;
9708
+ if ((_event$poll5 = event.poll) !== null && _event$poll5 !== void 0 && _event$poll5.id) {
9709
+ var _this$fromState5;
8807
9710
 
8808
- case 12:
8809
- _context2.prev = 12;
8810
- _context2.t0 = _context2["catch"](4);
9711
+ (_this$fromState5 = _this.fromState(event.poll.id)) === null || _this$fromState5 === void 0 ? void 0 : _this$fromState5.handleVoteRemoved(event);
9712
+ }
9713
+ }).unsubscribe;
9714
+ });
8811
9715
 
8812
- _this.client.logger('error', _context2.t0.message);
9716
+ _defineProperty__default['default'](this, "subscribeMessageNew", function () {
9717
+ return _this.client.on('message.new', function (event) {
9718
+ var message = event.message;
8813
9719
 
8814
- _this.state.next(function (current) {
8815
- return _objectSpread$1(_objectSpread$1({}, current), {}, {
8816
- pagination: _objectSpread$1(_objectSpread$1({}, current.pagination), {}, {
8817
- isLoadingNext: false
8818
- })
8819
- });
8820
- });
9720
+ if (message) {
9721
+ var formattedMessage = formatMessage(message);
8821
9722
 
8822
- case 16:
8823
- case "end":
8824
- return _context2.stop();
8825
- }
9723
+ _this.hydratePollCache([formattedMessage]);
8826
9724
  }
8827
- }, _callee2, null, [[4, 12]]);
8828
- })));
9725
+ }).unsubscribe;
9726
+ });
8829
9727
 
8830
9728
  this.client = client;
8831
- this.state = new StateStore({
8832
- active: false,
8833
- isThreadOrderStale: false,
8834
- threads: [],
8835
- unreadThreadCount: 0,
8836
- unseenThreadIds: [],
8837
- lastConnectionDropAt: null,
8838
- pagination: {
8839
- isLoading: false,
8840
- isLoadingNext: false,
8841
- nextCursor: null
8842
- },
8843
- ready: false
8844
- });
8845
- this.threadsByIdGetterCache = {
8846
- threads: [],
8847
- threadsById: {}
8848
- };
8849
9729
  }
8850
9730
 
8851
- _createClass__default['default'](ThreadManager, [{
8852
- key: "threadsById",
9731
+ _createClass__default['default'](PollManager, [{
9732
+ key: "data",
8853
9733
  get: function get() {
8854
- var _this$state$getLatest5 = this.state.getLatestValue(),
8855
- threads = _this$state$getLatest5.threads;
8856
-
8857
- if (threads === this.threadsByIdGetterCache.threads) {
8858
- return this.threadsByIdGetterCache.threadsById;
8859
- }
8860
-
8861
- var threadsById = threads.reduce(function (newThreadsById, thread) {
8862
- newThreadsById[thread.id] = thread;
8863
- return newThreadsById;
8864
- }, {});
8865
- this.threadsByIdGetterCache.threads = threads;
8866
- this.threadsByIdGetterCache.threadsById = threadsById;
8867
- return threadsById;
9734
+ return this.pollCache;
8868
9735
  }
8869
9736
  }]);
8870
9737
 
8871
- return ThreadManager;
9738
+ return PollManager;
8872
9739
  }();
8873
9740
 
8874
9741
  var _excluded = ["created_at", "updated_at", "last_active", "online"],
@@ -8901,6 +9768,8 @@ var StreamChat = /*#__PURE__*/function () {
8901
9768
 
8902
9769
  _defineProperty__default['default'](this, "threads", void 0);
8903
9770
 
9771
+ _defineProperty__default['default'](this, "polls", void 0);
9772
+
8904
9773
  _defineProperty__default['default'](this, "anonymous", void 0);
8905
9774
 
8906
9775
  _defineProperty__default['default'](this, "persistUserOnConnectionFailure", void 0);
@@ -9799,6 +10668,9 @@ var StreamChat = /*#__PURE__*/function () {
9799
10668
  this.threads = new ThreadManager({
9800
10669
  client: this
9801
10670
  });
10671
+ this.polls = new PollManager({
10672
+ client: this
10673
+ });
9802
10674
  }
9803
10675
  /**
9804
10676
  * Get a client instance
@@ -11065,6 +11937,7 @@ var StreamChat = /*#__PURE__*/function () {
11065
11937
  returnedPage: channelState.messages,
11066
11938
  logger: this.logger
11067
11939
  }));
11940
+ this.polls.hydratePollCache(updatedMessagesSet.messages, true);
11068
11941
  }
11069
11942
 
11070
11943
  channels.push(c);
@@ -13366,7 +14239,7 @@ var StreamChat = /*#__PURE__*/function () {
13366
14239
  }, {
13367
14240
  key: "getUserAgent",
13368
14241
  value: function getUserAgent() {
13369
- return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.41.0");
14242
+ return this.userAgent || "stream-chat-javascript-client-".concat(this.node ? 'node' : 'browser', "-", "8.42.0");
13370
14243
  }
13371
14244
  }, {
13372
14245
  key: "setUserAgent",
@@ -14810,7 +15683,7 @@ var StreamChat = /*#__PURE__*/function () {
14810
15683
  }()
14811
15684
  /**
14812
15685
  * Creates a poll
14813
- * @param params PollData The poll that will be created
15686
+ * @param poll PollData The poll that will be created
14814
15687
  * @param userId string The user id (only serverside)
14815
15688
  * @returns {APIResponse & CreatePollAPIResponse} The poll
14816
15689
  */
@@ -15010,13 +15883,11 @@ var StreamChat = /*#__PURE__*/function () {
15010
15883
  while (1) {
15011
15884
  switch (_context103.prev = _context103.next) {
15012
15885
  case 0:
15013
- return _context103.abrupt("return", this.partialUpdatePoll(id, _objectSpread({
15886
+ return _context103.abrupt("return", this.partialUpdatePoll(id, {
15014
15887
  set: {
15015
15888
  is_closed: true
15016
15889
  }
15017
- }, userId ? {
15018
- user_id: userId
15019
- } : {})));
15890
+ }, userId));
15020
15891
 
15021
15892
  case 1:
15022
15893
  case "end":
@@ -15392,6 +16263,60 @@ var StreamChat = /*#__PURE__*/function () {
15392
16263
 
15393
16264
  return queryPollVotes;
15394
16265
  }()
16266
+ /**
16267
+ * Queries poll answers
16268
+ * @param pollId
16269
+ * @param filter
16270
+ * @param sort
16271
+ * @param options Option object, {limit: 10, offset:0}
16272
+ * @param userId string The user id (only serverside)
16273
+ * @returns {APIResponse & PollAnswersAPIResponse} The poll votes
16274
+ */
16275
+
16276
+ }, {
16277
+ key: "queryPollAnswers",
16278
+ value: function () {
16279
+ var _queryPollAnswers = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee113(pollId) {
16280
+ var filter,
16281
+ sort,
16282
+ options,
16283
+ userId,
16284
+ q,
16285
+ _args113 = arguments;
16286
+ return _regeneratorRuntime__default['default'].wrap(function _callee113$(_context113) {
16287
+ while (1) {
16288
+ switch (_context113.prev = _context113.next) {
16289
+ case 0:
16290
+ filter = _args113.length > 1 && _args113[1] !== undefined ? _args113[1] : {};
16291
+ sort = _args113.length > 2 && _args113[2] !== undefined ? _args113[2] : [];
16292
+ options = _args113.length > 3 && _args113[3] !== undefined ? _args113[3] : {};
16293
+ userId = _args113.length > 4 ? _args113[4] : undefined;
16294
+ q = userId ? "?user_id=".concat(userId) : '';
16295
+ _context113.next = 7;
16296
+ return this.post(this.baseURL + "/polls/".concat(encodeURIComponent(pollId), "/votes").concat(q), _objectSpread({
16297
+ filter: _objectSpread(_objectSpread({}, filter), {}, {
16298
+ is_answer: true
16299
+ }),
16300
+ sort: normalizeQuerySort(sort)
16301
+ }, options));
16302
+
16303
+ case 7:
16304
+ return _context113.abrupt("return", _context113.sent);
16305
+
16306
+ case 8:
16307
+ case "end":
16308
+ return _context113.stop();
16309
+ }
16310
+ }
16311
+ }, _callee113, this);
16312
+ }));
16313
+
16314
+ function queryPollAnswers(_x174) {
16315
+ return _queryPollAnswers.apply(this, arguments);
16316
+ }
16317
+
16318
+ return queryPollAnswers;
16319
+ }()
15395
16320
  /**
15396
16321
  * Query message history
15397
16322
  * @param filter
@@ -15403,33 +16328,33 @@ var StreamChat = /*#__PURE__*/function () {
15403
16328
  }, {
15404
16329
  key: "queryMessageHistory",
15405
16330
  value: function () {
15406
- var _queryMessageHistory = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee113() {
16331
+ var _queryMessageHistory = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee114() {
15407
16332
  var filter,
15408
16333
  sort,
15409
16334
  options,
15410
- _args113 = arguments;
15411
- return _regeneratorRuntime__default['default'].wrap(function _callee113$(_context113) {
16335
+ _args114 = arguments;
16336
+ return _regeneratorRuntime__default['default'].wrap(function _callee114$(_context114) {
15412
16337
  while (1) {
15413
- switch (_context113.prev = _context113.next) {
16338
+ switch (_context114.prev = _context114.next) {
15414
16339
  case 0:
15415
- filter = _args113.length > 0 && _args113[0] !== undefined ? _args113[0] : {};
15416
- sort = _args113.length > 1 && _args113[1] !== undefined ? _args113[1] : [];
15417
- options = _args113.length > 2 && _args113[2] !== undefined ? _args113[2] : {};
15418
- _context113.next = 5;
16340
+ filter = _args114.length > 0 && _args114[0] !== undefined ? _args114[0] : {};
16341
+ sort = _args114.length > 1 && _args114[1] !== undefined ? _args114[1] : [];
16342
+ options = _args114.length > 2 && _args114[2] !== undefined ? _args114[2] : {};
16343
+ _context114.next = 5;
15419
16344
  return this.post(this.baseURL + '/messages/history', _objectSpread({
15420
16345
  filter: filter,
15421
16346
  sort: normalizeQuerySort(sort)
15422
16347
  }, options));
15423
16348
 
15424
16349
  case 5:
15425
- return _context113.abrupt("return", _context113.sent);
16350
+ return _context114.abrupt("return", _context114.sent);
15426
16351
 
15427
16352
  case 6:
15428
16353
  case "end":
15429
- return _context113.stop();
16354
+ return _context114.stop();
15430
16355
  }
15431
16356
  }
15432
- }, _callee113, this);
16357
+ }, _callee114, this);
15433
16358
  }));
15434
16359
 
15435
16360
  function queryMessageHistory() {
@@ -15450,32 +16375,32 @@ var StreamChat = /*#__PURE__*/function () {
15450
16375
  }, {
15451
16376
  key: "updateFlags",
15452
16377
  value: function () {
15453
- var _updateFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee114(message_ids, reviewed_by) {
16378
+ var _updateFlags = _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee115(message_ids, reviewed_by) {
15454
16379
  var options,
15455
- _args114 = arguments;
15456
- return _regeneratorRuntime__default['default'].wrap(function _callee114$(_context114) {
16380
+ _args115 = arguments;
16381
+ return _regeneratorRuntime__default['default'].wrap(function _callee115$(_context115) {
15457
16382
  while (1) {
15458
- switch (_context114.prev = _context114.next) {
16383
+ switch (_context115.prev = _context115.next) {
15459
16384
  case 0:
15460
- options = _args114.length > 2 && _args114[2] !== undefined ? _args114[2] : {};
15461
- _context114.next = 3;
16385
+ options = _args115.length > 2 && _args115[2] !== undefined ? _args115[2] : {};
16386
+ _context115.next = 3;
15462
16387
  return this.post(this.baseURL + '/automod/v1/moderation/update_flags', _objectSpread({
15463
16388
  message_ids: message_ids,
15464
16389
  reviewed_by: reviewed_by
15465
16390
  }, options));
15466
16391
 
15467
16392
  case 3:
15468
- return _context114.abrupt("return", _context114.sent);
16393
+ return _context115.abrupt("return", _context115.sent);
15469
16394
 
15470
16395
  case 4:
15471
16396
  case "end":
15472
- return _context114.stop();
16397
+ return _context115.stop();
15473
16398
  }
15474
16399
  }
15475
- }, _callee114, this);
16400
+ }, _callee115, this);
15476
16401
  }));
15477
16402
 
15478
- function updateFlags(_x174, _x175) {
16403
+ function updateFlags(_x175, _x176) {
15479
16404
  return _updateFlags.apply(this, arguments);
15480
16405
  }
15481
16406
 
@@ -15657,6 +16582,8 @@ exports.MaxPriority = MaxPriority;
15657
16582
  exports.MinPriority = MinPriority;
15658
16583
  exports.Moderation = Moderation;
15659
16584
  exports.Permission = Permission;
16585
+ exports.Poll = Poll;
16586
+ exports.PollManager = PollManager;
15660
16587
  exports.Segment = Segment;
15661
16588
  exports.StableWSConnection = StableWSConnection;
15662
16589
  exports.StateStore = StateStore;
@@ -15670,8 +16597,11 @@ exports.buildWsSuccessAfterFailureInsight = buildWsSuccessAfterFailureInsight;
15670
16597
  exports.chatCodes = chatCodes;
15671
16598
  exports.decodeBase64 = decodeBase64;
15672
16599
  exports.encodeBase64 = encodeBase64;
16600
+ exports.extractPollData = extractPollData;
16601
+ exports.extractPollEnrichedData = extractPollEnrichedData;
15673
16602
  exports.formatMessage = formatMessage;
15674
16603
  exports.isOwnUser = isOwnUser;
16604
+ exports.isVoteAnswer = isVoteAnswer;
15675
16605
  exports.logChatPromiseExecution = logChatPromiseExecution;
15676
16606
  exports.postInsights = postInsights;
15677
16607
  //# sourceMappingURL=browser.js.map