qiscus-sdk-core 2.14.2 → 2.15.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/lib/index.js CHANGED
@@ -158,19 +158,19 @@ var QiscusSDK = /*#__PURE__*/function () {
158
158
  }, {
159
159
  key: "init",
160
160
  value: (function () {
161
- var _init = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(config) {
161
+ var _init = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(config) {
162
162
  var _this2 = this,
163
163
  _config$withConfig;
164
164
  var isDifferentBaseUrl, isDifferentMqttUrl, isDifferentBrokerLbUrl, setterHelper, mqttWssCheck;
165
- return _regenerator["default"].wrap(function _callee3$(_context3) {
166
- while (1) switch (_context3.prev = _context3.next) {
165
+ return _regenerator["default"].wrap(function (_context) {
166
+ while (1) switch (_context.prev = _context.next) {
167
167
  case 0:
168
168
  if (config.AppId) {
169
- _context3.next = 2;
169
+ _context.next = 1;
170
170
  break;
171
171
  }
172
172
  throw new Error('Please provide valid AppId');
173
- case 2:
173
+ case 1:
174
174
  this.AppId = config.AppId;
175
175
 
176
176
  // We need to disable realtime load balancing if user are using custom server
@@ -258,10 +258,10 @@ var QiscusSDK = /*#__PURE__*/function () {
258
258
  };
259
259
  this.withConfig = (_config$withConfig = config.withConfig) !== null && _config$withConfig !== void 0 ? _config$withConfig : true;
260
260
  if (!(this.withConfig === true)) {
261
- _context3.next = 32;
261
+ _context.next = 3;
262
262
  break;
263
263
  }
264
- _context3.next = 30;
264
+ _context.next = 2;
265
265
  return this.HTTPAdapter.get_request('api/v2/sdk/config').then(function (resp) {
266
266
  resp.status == 200 ? _this2.isConfigLoaded = true : _this2.isConfigLoaded = false;
267
267
  return resp.body.results;
@@ -293,204 +293,241 @@ var QiscusSDK = /*#__PURE__*/function () {
293
293
  _this2.logger('got error when trying to get app config', err);
294
294
  _this2.isConfigLoaded = true;
295
295
  });
296
- case 30:
297
- _context3.next = 33;
296
+ case 2:
297
+ _context.next = 4;
298
298
  break;
299
- case 32:
299
+ case 3:
300
300
  this.isConfigLoaded = true;
301
- case 33:
301
+ case 4:
302
302
  // set Event Listeners
303
-
303
+ this.setEventListeners();
304
+ case 5:
305
+ case "end":
306
+ return _context.stop();
307
+ }
308
+ }, _callee, this);
309
+ }));
310
+ function init(_x) {
311
+ return _init.apply(this, arguments);
312
+ }
313
+ return init;
314
+ }())
315
+ }, {
316
+ key: "_setupCustomEventAdapter",
317
+ value: function _setupCustomEventAdapter() {
318
+ this.customEventAdapter = (0, _customEvent["default"])(this.realtimeAdapter, this.user_id);
319
+ }
320
+ }, {
321
+ key: "_setupSyncAdapter",
322
+ value: function _setupSyncAdapter() {
323
+ var _this3 = this;
324
+ this.syncAdapter = (0, _sync["default"])(function () {
325
+ return _this3.HTTPAdapter;
326
+ }, {
327
+ getToken: function getToken() {
328
+ return _this3.userData.token;
329
+ },
330
+ syncInterval: function syncInterval() {
331
+ return _this3.syncInterval;
332
+ },
333
+ getShouldSync: function getShouldSync() {
334
+ return _this3._forceEnableSync && _this3.isLogin && !_this3.realtimeAdapter.connected;
335
+ },
336
+ syncOnConnect: function syncOnConnect() {
337
+ return _this3.syncOnConnect;
338
+ },
339
+ lastCommentId: function lastCommentId() {
340
+ return _this3.last_received_comment_id;
341
+ },
342
+ statusLogin: function statusLogin() {
343
+ return _this3.isLogin;
344
+ },
345
+ enableSync: function enableSync() {
346
+ return _this3.enableSync;
347
+ },
348
+ enableSyncEvent: function enableSyncEvent() {
349
+ return _this3.enableSyncEvent;
350
+ }
351
+ });
352
+ this.syncAdapter.on('message.new', /*#__PURE__*/function () {
353
+ var _ref = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(message) {
354
+ var index, _message;
355
+ return _regenerator["default"].wrap(function (_context2) {
356
+ while (1) switch (_context2.prev = _context2.next) {
357
+ case 0:
358
+ _context2.next = 1;
359
+ return _this3._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
360
+ case 1:
361
+ message = _context2.sent;
362
+ if (_this3.selected != null) {
363
+ index = _this3.selected.comments.findIndex(function (it) {
364
+ return it.id === message.id || it.unique_id === message.unique_temp_id;
365
+ });
366
+ if (index === -1) {
367
+ _message = new _Comment["default"](message);
368
+ if (_message.room_id === _this3.selected.id) {
369
+ _this3.selected.comments.push(_message);
370
+ _this3.sortComments();
371
+ }
372
+ _this3.events.emit('newmessages', [message]);
373
+ }
374
+ } else {
375
+ _this3.events.emit('newmessages', [message]);
376
+ }
377
+ case 2:
378
+ case "end":
379
+ return _context2.stop();
380
+ }
381
+ }, _callee2);
382
+ }));
383
+ return function (_x2) {
384
+ return _ref.apply(this, arguments);
385
+ };
386
+ }());
387
+ this.syncAdapter.on('message.delivered', function (message) {
388
+ _this3._setDelivered(message.comment_id, message.comment_unique_id, message.email);
389
+ });
390
+ this.syncAdapter.on('message.read', function (message) {
391
+ _this3._setRead(message.comment_id, message.comment_unique_id, message.email);
392
+ });
393
+ this.syncAdapter.on('message.deleted', function (data) {
394
+ data.deleted_messages.forEach(function (it) {
395
+ _this3.events.emit('comment-deleted', {
396
+ roomId: it.room_id,
397
+ commentUniqueIds: it.message_unique_ids,
398
+ isForEveryone: true,
399
+ isHard: true
400
+ });
401
+ });
402
+ });
403
+ this.syncAdapter.on('room.cleared', function (data) {
404
+ data.deleted_rooms.forEach(function (room) {
405
+ _this3.events.emit('room-cleared', room);
406
+ });
407
+ });
408
+ this.syncAdapter.on('synchronize', function () {
409
+ _this3._pendingComments.forEach(function (m) {
410
+ return _this3._retrySendComment(m);
411
+ });
412
+ });
413
+ this.syncAdapter.on('last-message-id.new', function (id) {
414
+ _this3.last_received_comment_id = id;
415
+ });
416
+ }
417
+ }, {
418
+ key: "_setupRealtimeAdapter",
419
+ value: function () {
420
+ var _setupRealtimeAdapter2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
421
+ var _this4 = this;
422
+ var res, mqttUsername, mqttPassword, mqttURL;
423
+ return _regenerator["default"].wrap(function (_context4) {
424
+ while (1) switch (_context4.prev = _context4.next) {
425
+ case 0:
304
426
  this._getMqttClientId = function () {
305
- return "".concat(_this2.AppId, "_").concat(_this2.user_id, "_").concat(Date.now());
427
+ return "".concat(_this4.AppId, "_").concat(_this4.user_id, "_").concat(Date.now());
306
428
  };
307
- this.realtimeAdapter = new _mqtt["default"](this.mqttURL, this, this.isLogin, {
429
+ _context4.next = 1;
430
+ return this.HTTPAdapter.get('api/v2/sdk/mqtt_config');
431
+ case 1:
432
+ res = _context4.sent;
433
+ mqttUsername = res.body.results.username;
434
+ mqttPassword = res.body.results.password;
435
+ mqttURL = "wss://".concat(res.body.results.url, ":1886/mqtt");
436
+ this.realtimeAdapter = new _mqtt["default"](mqttURL, this, this.isLogin, {
308
437
  brokerLbUrl: this.brokerLbUrl,
309
438
  enableLb: this.enableLb,
310
439
  shouldConnect: this.enableRealtime,
311
- getClientId: this._getMqttClientId
440
+ getClientId: this._getMqttClientId,
441
+ mqttUsername: mqttUsername,
442
+ mqttPassword: mqttPassword
312
443
  });
313
444
  this.realtimeAdapter.on('connected', function () {
314
- if (_this2.isLogin || !_this2.realtimeAdapter.connected) {
315
- _this2.last_received_comment_id = _this2.userData.last_comment_id;
316
- _this2.updateLastReceivedComment(_this2.last_received_comment_id);
445
+ if (_this4.isLogin || !_this4.realtimeAdapter.connected) {
446
+ _this4.last_received_comment_id = _this4.userData.last_comment_id;
447
+ _this4.updateLastReceivedComment(_this4.last_received_comment_id);
317
448
  }
318
449
  });
319
450
  this.realtimeAdapter.on('close', function () {});
320
451
  this.realtimeAdapter.on('reconnect', function () {
321
- var _this2$options$onReco, _this2$options;
322
- (_this2$options$onReco = (_this2$options = _this2.options).onReconnectCallback) === null || _this2$options$onReco === void 0 || _this2$options$onReco.call(_this2$options);
323
- });
324
- this.realtimeAdapter.on('message-delivered', function (_ref) {
325
- var commentId = _ref.commentId,
326
- commentUniqueId = _ref.commentUniqueId,
327
- userId = _ref.userId;
328
- return _this2._setDelivered(commentId, commentUniqueId, userId);
452
+ var _this4$options$onReco, _this4$options;
453
+ (_this4$options$onReco = (_this4$options = _this4.options).onReconnectCallback) === null || _this4$options$onReco === void 0 || _this4$options$onReco.call(_this4$options);
329
454
  });
330
- this.realtimeAdapter.on('message-read', function (_ref2) {
455
+ this.realtimeAdapter.on('message-delivered', function (_ref2) {
331
456
  var commentId = _ref2.commentId,
332
457
  commentUniqueId = _ref2.commentUniqueId,
333
458
  userId = _ref2.userId;
334
- return _this2._setRead(commentId, commentUniqueId, userId);
459
+ return _this4._setDelivered(commentId, commentUniqueId, userId);
460
+ });
461
+ this.realtimeAdapter.on('message-read', function (_ref3) {
462
+ var commentId = _ref3.commentId,
463
+ commentUniqueId = _ref3.commentUniqueId,
464
+ userId = _ref3.userId;
465
+ return _this4._setRead(commentId, commentUniqueId, userId);
335
466
  });
336
467
  this.realtimeAdapter.on('new-message', /*#__PURE__*/function () {
337
- var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(message) {
338
- return _regenerator["default"].wrap(function _callee$(_context) {
339
- while (1) switch (_context.prev = _context.next) {
468
+ var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(message) {
469
+ return _regenerator["default"].wrap(function (_context3) {
470
+ while (1) switch (_context3.prev = _context3.next) {
340
471
  case 0:
341
- _context.next = 2;
342
- return _this2._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
472
+ _context3.next = 1;
473
+ return _this4._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
474
+ case 1:
475
+ message = _context3.sent;
476
+ _this4.events.emit('newmessages', [message]);
343
477
  case 2:
344
- message = _context.sent;
345
- _this2.events.emit('newmessages', [message]);
346
- case 4:
347
478
  case "end":
348
- return _context.stop();
479
+ return _context3.stop();
349
480
  }
350
- }, _callee);
481
+ }, _callee3);
351
482
  }));
352
- return function (_x2) {
353
- return _ref3.apply(this, arguments);
483
+ return function (_x3) {
484
+ return _ref4.apply(this, arguments);
354
485
  };
355
486
  }());
356
487
  this.realtimeAdapter.on('presence', function (data) {
357
- return _this2.events.emit('presence', data);
488
+ return _this4.events.emit('presence', data);
358
489
  });
359
490
  this.realtimeAdapter.on('comment-deleted', function (data) {
360
- return _this2.events.emit('comment-deleted', data);
491
+ return _this4.events.emit('comment-deleted', data);
361
492
  });
362
493
  this.realtimeAdapter.on('room-cleared', function (data) {
363
- return _this2.events.emit('room-cleared', data);
494
+ return _this4.events.emit('room-cleared', data);
364
495
  });
365
496
  this.realtimeAdapter.on('typing', function (data) {
366
- return _this2.events.emit('typing', {
497
+ return _this4.events.emit('typing', {
367
498
  message: data.message,
368
499
  username: data.userId,
369
500
  room_id: data.roomId
370
501
  });
371
502
  });
372
503
  this.realtimeAdapter.on('message:updated', function (message) {
373
- if (_this2.options.messageUpdatedCallback != null) {
374
- _this2.options.messageUpdatedCallback(message);
504
+ if (_this4.options.messageUpdatedCallback != null) {
505
+ _this4.options.messageUpdatedCallback(message);
375
506
  }
376
507
  });
377
508
  this.realtimeAdapter.on('room-typing', function (data) {
378
- _this2.events.emit('typing', {
509
+ _this4.events.emit('typing', {
379
510
  message: data.text,
380
511
  username: data.sender_name,
381
512
  email: data.sender_id,
382
513
  room_id: data.room_id
383
514
  });
384
- if (_this2.options.onRoomTypingCallback != null) {
385
- _this2.events.emit('room-typing', data);
386
- _this2.options.onRoomTypingCallback(data);
387
- }
388
- });
389
- this.syncAdapter = (0, _sync["default"])(function () {
390
- return _this2.HTTPAdapter;
391
- }, {
392
- getToken: function getToken() {
393
- return _this2.userData.token;
394
- },
395
- syncInterval: function syncInterval() {
396
- return _this2.syncInterval;
397
- },
398
- getShouldSync: function getShouldSync() {
399
- return _this2._forceEnableSync && _this2.isLogin && !_this2.realtimeAdapter.connected;
400
- },
401
- syncOnConnect: function syncOnConnect() {
402
- return _this2.syncOnConnect;
403
- },
404
- lastCommentId: function lastCommentId() {
405
- return _this2.last_received_comment_id;
406
- },
407
- statusLogin: function statusLogin() {
408
- return _this2.isLogin;
409
- },
410
- enableSync: function enableSync() {
411
- return _this2.enableSync;
412
- },
413
- enableSyncEvent: function enableSyncEvent() {
414
- return _this2.enableSyncEvent;
515
+ if (_this4.options.onRoomTypingCallback != null) {
516
+ _this4.events.emit('room-typing', data);
517
+ _this4.options.onRoomTypingCallback(data);
415
518
  }
416
519
  });
417
- this.syncAdapter.on('message.new', /*#__PURE__*/function () {
418
- var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(message) {
419
- var index, _message;
420
- return _regenerator["default"].wrap(function _callee2$(_context2) {
421
- while (1) switch (_context2.prev = _context2.next) {
422
- case 0:
423
- _context2.next = 2;
424
- return _this2._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
425
- case 2:
426
- message = _context2.sent;
427
- if (_this2.selected != null) {
428
- index = _this2.selected.comments.findIndex(function (it) {
429
- return it.id === message.id || it.unique_id === message.unique_temp_id;
430
- });
431
- if (index === -1) {
432
- _message = new _Comment["default"](message);
433
- if (_message.room_id === _this2.selected.id) {
434
- _this2.selected.comments.push(_message);
435
- _this2.sortComments();
436
- }
437
- _this2.events.emit('newmessages', [message]);
438
- }
439
- } else {
440
- _this2.events.emit('newmessages', [message]);
441
- }
442
- case 4:
443
- case "end":
444
- return _context2.stop();
445
- }
446
- }, _callee2);
447
- }));
448
- return function (_x3) {
449
- return _ref4.apply(this, arguments);
450
- };
451
- }());
452
- this.syncAdapter.on('message.delivered', function (message) {
453
- _this2._setDelivered(message.comment_id, message.comment_unique_id, message.email);
454
- });
455
- this.syncAdapter.on('message.read', function (message) {
456
- _this2._setRead(message.comment_id, message.comment_unique_id, message.email);
457
- });
458
- this.syncAdapter.on('message.deleted', function (data) {
459
- data.deleted_messages.forEach(function (it) {
460
- _this2.events.emit('comment-deleted', {
461
- roomId: it.room_id,
462
- commentUniqueIds: it.message_unique_ids,
463
- isForEveryone: true,
464
- isHard: true
465
- });
466
- });
467
- });
468
- this.syncAdapter.on('room.cleared', function (data) {
469
- data.deleted_rooms.forEach(function (room) {
470
- _this2.events.emit('room-cleared', room);
471
- });
472
- });
473
- this.syncAdapter.on('synchronize', function () {
474
- _this2._pendingComments.forEach(function (m) {
475
- return _this2._retrySendComment(m);
476
- });
477
- });
478
- this.syncAdapter.on('last-message-id.new', function (id) {
479
- _this2.last_received_comment_id = id;
480
- });
481
- this.customEventAdapter = (0, _customEvent["default"])(this.realtimeAdapter, this.user_id);
482
- this.setEventListeners();
483
- case 57:
520
+ case 2:
484
521
  case "end":
485
- return _context3.stop();
522
+ return _context4.stop();
486
523
  }
487
- }, _callee3, this);
524
+ }, _callee4, this);
488
525
  }));
489
- function init(_x) {
490
- return _init.apply(this, arguments);
526
+ function _setupRealtimeAdapter() {
527
+ return _setupRealtimeAdapter2.apply(this, arguments);
491
528
  }
492
- return init;
493
- }())
529
+ return _setupRealtimeAdapter;
530
+ }()
494
531
  }, {
495
532
  key: "_setRead",
496
533
  value: function _setRead(messageId, messageUniqueId, userId) {
@@ -548,7 +585,7 @@ var QiscusSDK = /*#__PURE__*/function () {
548
585
  }, {
549
586
  key: "setEventListeners",
550
587
  value: function setEventListeners() {
551
- var _this3 = this;
588
+ var _this5 = this;
552
589
  var self = this;
553
590
  this.authAdapter = new _auth["default"](self.HTTPAdapter);
554
591
  if (this.userData.email != null) {
@@ -561,13 +598,13 @@ var QiscusSDK = /*#__PURE__*/function () {
561
598
  userId: self.user_id,
562
599
  version: self.version,
563
600
  getCustomHeader: function getCustomHeader() {
564
- return _this3._customHeader;
601
+ return _this5._customHeader;
565
602
  }
566
603
  });
567
604
  self.HTTPAdapter.setToken(self.userData.token);
568
605
  });
569
606
  self.events.on('room-changed', function (room) {
570
- _this3.logging('room changed', room);
607
+ _this5.logging('room changed', room);
571
608
  if (self.options.roomChangedCallback) {
572
609
  self.options.roomChangedCallback(room);
573
610
  }
@@ -593,13 +630,13 @@ var QiscusSDK = /*#__PURE__*/function () {
593
630
  self.events.on('newmessages', function (comments) {
594
631
  // let's convert the data into something we can use
595
632
  // first we need to make sure we sort this data out based on room_id
596
- _this3.logging('newmessages', comments);
597
- var lastReceivedMessageNotEmpty = _this3.lastReceiveMessages.length > 0;
598
- if (lastReceivedMessageNotEmpty && _this3.lastReceiveMessages[0].unique_temp_id === comments[0].unique_temp_id) {
599
- _this3.logging('lastReceiveMessages double', comments);
633
+ _this5.logging('newmessages', comments);
634
+ var lastReceivedMessageNotEmpty = _this5.lastReceiveMessages.length > 0;
635
+ if (lastReceivedMessageNotEmpty && _this5.lastReceiveMessages[0].unique_temp_id === comments[0].unique_temp_id) {
636
+ _this5.logging('lastReceiveMessages double', comments);
600
637
  return;
601
638
  }
602
- _this3.lastReceiveMessages = comments;
639
+ _this5.lastReceiveMessages = comments;
603
640
  self._callNewMessagesCallback(comments);
604
641
  comments.forEach(function (comment) {
605
642
  // we have this comment, so means it's already delivered, update it's delivered status
@@ -621,7 +658,7 @@ var QiscusSDK = /*#__PURE__*/function () {
621
658
  return c.id === lastComment.comment_before_id;
622
659
  });
623
660
  if (!lastComment.isPending && !commentBeforeThis) {
624
- _this3.logging('comment before id not found! ', comment.comment_before_id);
661
+ _this5.logging('comment before id not found! ', comment.comment_before_id);
625
662
  // need to fix, these method does not work
626
663
  self.synchronize(roomLastCommentId);
627
664
  }
@@ -635,7 +672,7 @@ var QiscusSDK = /*#__PURE__*/function () {
635
672
 
636
673
  // let's update last_received_comment_id
637
674
  self.updateLastReceivedComment(comment.id);
638
- _this3.sortComments();
675
+ _this5.sortComments();
639
676
  });
640
677
  });
641
678
 
@@ -643,72 +680,96 @@ var QiscusSDK = /*#__PURE__*/function () {
643
680
  * This event will be called when login is sucess
644
681
  * Basically, it sets up necessary properties for qiscusSDK
645
682
  */
646
- this.events.on('login-success', function (response) {
647
- _this3.isLogin = true;
648
- _this3.userData = response.user;
649
- _this3.last_received_comment_id = _this3.userData.last_comment_id;
650
- if (!_this3.realtimeAdapter.connected) _this3.updateLastReceivedComment(_this3.last_received_comment_id);
683
+ this.events.on('login-success', /*#__PURE__*/function () {
684
+ var _ref5 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(response) {
685
+ var user;
686
+ return _regenerator["default"].wrap(function (_context5) {
687
+ while (1) switch (_context5.prev = _context5.next) {
688
+ case 0:
689
+ _this5.isLogin = true;
690
+ _this5.userData = response.user;
691
+ _this5.last_received_comment_id = _this5.userData.last_comment_id;
651
692
 
652
- // now that we have the token, etc, we need to set all our adapters
653
- _this3.HTTPAdapter = new _http["default"]({
654
- baseURL: _this3.baseURL,
655
- AppId: _this3.AppId,
656
- userId: _this3.user_id,
657
- version: _this3.version,
658
- getCustomHeader: function getCustomHeader() {
659
- return _this3._customHeader;
660
- },
661
- expiredTokenAdapterGetter: function expiredTokenAdapterGetter() {
662
- return _this3.expiredTokenAdapter;
663
- }
664
- });
665
- _this3.HTTPAdapter.setToken(_this3.userData.token);
666
- var user = response.user;
667
- _this3._delayedSync = (0, _utils.delayed)(function () {
668
- _this3.synchronize();
669
- _this3.synchronizeEvent();
670
- }, 500);
671
- _this3.expiredTokenAdapter = new _expiredToken.ExpiredTokenAdapter({
672
- httpAdapter: _this3.HTTPAdapter,
673
- refreshToken: user.refresh_token,
674
- expiredAt: user.token_expires_at,
675
- userId: _this3.user_id,
676
- onTokenRefreshed: function onTokenRefreshed(token, refreshToken, expiredAt, oldToken) {
677
- _this3.userData.token = token;
678
- _this3.userData.refresh_token = refreshToken;
679
- _this3.userData.token_expires_at = expiredAt === null || expiredAt === void 0 ? void 0 : expiredAt.toJSON();
680
- _this3.events.emit('token-refreshed', {
681
- token: token,
682
- refreshToken: refreshToken,
683
- expiredAt: expiredAt,
684
- oldToken: oldToken
685
- });
686
- _this3.realtimeAdapter.unsusbcribeUserChannelByToken(oldToken);
687
- _this3.realtimeAdapter.subscribeUserChannelByToken(token);
688
- _this3._delayedSync();
689
- },
690
- getAuthenticationStatus: function getAuthenticationStatus() {
691
- return _this3.user_id != null && _this3.isLogin;
692
- }
693
- });
694
- _this3.userAdapter = new _user["default"](_this3.HTTPAdapter);
695
- _this3.roomAdapter = new _room["default"](_this3.HTTPAdapter);
696
- _this3.realtimeAdapter.subscribeUserChannel();
697
- if (_this3.presensePublisherId != null && _this3.presensePublisherId !== -1) {
698
- clearInterval(_this3.presensePublisherId);
699
- }
700
- _this3.presensePublisherId = setInterval(function () {
701
- _this3.realtimeAdapter.publishPresence(_this3.user_id, true);
702
- }, 3500);
693
+ // now that we have the token, etc, we need to set all our adapters
694
+ _this5.HTTPAdapter = new _http["default"]({
695
+ baseURL: _this5.baseURL,
696
+ AppId: _this5.AppId,
697
+ userId: _this5.user_id,
698
+ version: _this5.version,
699
+ getCustomHeader: function getCustomHeader() {
700
+ return _this5._customHeader;
701
+ },
702
+ expiredTokenAdapterGetter: function expiredTokenAdapterGetter() {
703
+ return _this5.expiredTokenAdapter;
704
+ }
705
+ });
706
+ _this5.HTTPAdapter.setToken(_this5.userData.token);
707
+ _context5.next = 1;
708
+ return _this5._setupRealtimeAdapter();
709
+ case 1:
710
+ _this5._setupSyncAdapter();
711
+ _this5._setupCustomEventAdapter();
712
+ _this5.realtimeAdapter.connect();
713
+ // this.setEventListeners()
703
714
 
704
- // if (this.sync === "http" || this.sync === "both") this.activateSync();
705
- if (_this3.options.loginSuccessCallback) {
706
- _this3.options.loginSuccessCallback(response);
707
- }
708
- _this3.authAdapter.userId = _this3.userData.email;
709
- _this3.authAdapter.refreshToken = _this3.userData.refresh_token;
710
- _this3.authAdapter.autoRefreshToken = _this3._autoRefreshToken;
711
- });
715
+ if (!_this5.realtimeAdapter.connected) {
716
+ _this5.updateLastReceivedComment(_this5.last_received_comment_id);
717
+ }
718
+ user = response.user;
719
+ _this5._delayedSync = (0, _utils.delayed)(function () {
720
+ _this5.synchronize();
721
+ _this5.synchronizeEvent();
722
+ }, 500);
723
+ _this5.expiredTokenAdapter = new _expiredToken.ExpiredTokenAdapter({
724
+ httpAdapter: _this5.HTTPAdapter,
725
+ refreshToken: user.refresh_token,
726
+ expiredAt: user.token_expires_at,
727
+ userId: _this5.user_id,
728
+ onTokenRefreshed: function onTokenRefreshed(token, refreshToken, expiredAt, oldToken) {
729
+ _this5.userData.token = token;
730
+ _this5.userData.refresh_token = refreshToken;
731
+ _this5.userData.token_expires_at = expiredAt === null || expiredAt === void 0 ? void 0 : expiredAt.toJSON();
732
+ _this5.events.emit('token-refreshed', {
733
+ token: token,
734
+ refreshToken: refreshToken,
735
+ expiredAt: expiredAt,
736
+ oldToken: oldToken
737
+ });
738
+ _this5.realtimeAdapter.unsusbcribeUserChannelByToken(oldToken);
739
+ _this5.realtimeAdapter.subscribeUserChannelByToken(token);
740
+ _this5._delayedSync();
741
+ },
742
+ getAuthenticationStatus: function getAuthenticationStatus() {
743
+ return _this5.user_id != null && _this5.isLogin;
744
+ }
745
+ });
746
+ _this5.userAdapter = new _user["default"](_this5.HTTPAdapter);
747
+ _this5.roomAdapter = new _room["default"](_this5.HTTPAdapter);
748
+ _this5.realtimeAdapter.subscribeUserChannel();
749
+ if (_this5.presensePublisherId != null && _this5.presensePublisherId !== -1) {
750
+ clearInterval(_this5.presensePublisherId);
751
+ }
752
+ _this5.presensePublisherId = setInterval(function () {
753
+ _this5.realtimeAdapter.publishPresence(_this5.user_id, true);
754
+ }, 3500);
755
+
756
+ // if (this.sync === "http" || this.sync === "both") this.activateSync();
757
+ if (_this5.options.loginSuccessCallback) {
758
+ _this5.options.loginSuccessCallback(response);
759
+ }
760
+ _this5.authAdapter.userId = _this5.userData.email;
761
+ _this5.authAdapter.refreshToken = _this5.userData.refresh_token;
762
+ _this5.authAdapter.autoRefreshToken = _this5._autoRefreshToken;
763
+ case 2:
764
+ case "end":
765
+ return _context5.stop();
766
+ }
767
+ }, _callee5);
768
+ }));
769
+ return function (_x4) {
770
+ return _ref5.apply(this, arguments);
771
+ };
772
+ }());
712
773
 
713
774
  /**
714
775
  * Called when there's something wrong when connecting to qiscus SDK
@@ -719,8 +780,8 @@ var QiscusSDK = /*#__PURE__*/function () {
719
780
  }
720
781
  });
721
782
  self.events.on('token-refreshed', function (param) {
722
- var _this3$options$authTo, _this3$options;
723
- (_this3$options$authTo = (_this3$options = _this3.options).authTokenRefreshedCallback) === null || _this3$options$authTo === void 0 || _this3$options$authTo.call(_this3$options, param);
783
+ var _this5$options$authTo, _this5$options;
784
+ (_this5$options$authTo = (_this5$options = _this5.options).authTokenRefreshedCallback) === null || _this5$options$authTo === void 0 || _this5$options$authTo.call(_this5$options, param);
724
785
  });
725
786
  self.events.on('room-cleared', function (room) {
726
787
  // find room
@@ -823,12 +884,12 @@ var QiscusSDK = /*#__PURE__*/function () {
823
884
  * Called when there's new presence data of currently subscribed target user (last seen timestamp)
824
885
  * @param {string} data MQTT Payload with format of "x:xxxxxxxxxxxxx"
825
886
  */
826
- self.events.on('presence', function (_ref5) {
827
- var message = _ref5.message,
828
- userId = _ref5.userId;
887
+ self.events.on('presence', function (_ref6) {
888
+ var message = _ref6.message,
889
+ userId = _ref6.userId;
829
890
  var payload = message.split(':');
830
- if (_this3.chatmateStatus !== payload[0]) {
831
- _this3.chatmateStatus = payload[0] === 1 ? 'Online' : "Last seen ".concat((0, _distance_in_words_to_now["default"])(Number(payload[1].substring(0, 13))));
891
+ if (_this5.chatmateStatus !== payload[0]) {
892
+ _this5.chatmateStatus = payload[0] === 1 ? 'Online' : "Last seen ".concat((0, _distance_in_words_to_now["default"])(Number(payload[1].substring(0, 13))));
832
893
  }
833
894
  if (self.options.presenceCallback) self.options.presenceCallback(message, userId);
834
895
  });
@@ -849,20 +910,20 @@ var QiscusSDK = /*#__PURE__*/function () {
849
910
  * Called when new particant was added into a group
850
911
  */
851
912
  self.events.on('participants-added', function (response) {
852
- var _this3$selected$parti;
853
- if (response == null || _this3.selected == null) return;
854
- (_this3$selected$parti = _this3.selected.participants).push.apply(_this3$selected$parti, (0, _toConsumableArray2["default"])(response));
913
+ var _this5$selected$parti;
914
+ if (response == null || _this5.selected == null) return;
915
+ (_this5$selected$parti = _this5.selected.participants).push.apply(_this5$selected$parti, (0, _toConsumableArray2["default"])(response));
855
916
  });
856
917
 
857
918
  /**
858
919
  * Called when particant was removed from a group
859
920
  */
860
921
  self.events.on('participants-removed', function (response) {
861
- if (response == null || _this3.selected == null) return;
862
- var participants = _this3.selected.participants.filter(function (participant) {
922
+ if (response == null || _this5.selected == null) return;
923
+ var participants = _this5.selected.participants.filter(function (participant) {
863
924
  return response.indexOf(participant.email) <= -1;
864
925
  });
865
- _this3.selected.participants = participants;
926
+ _this5.selected.participants = participants;
866
927
  });
867
928
 
868
929
  /**
@@ -917,7 +978,7 @@ var QiscusSDK = /*#__PURE__*/function () {
917
978
  }, {
918
979
  key: "setUser",
919
980
  value: function setUser(userId, key, username, avatarURL, extras) {
920
- var _this4 = this;
981
+ var _this6 = this;
921
982
  var self = this;
922
983
  self.user_id = userId;
923
984
  self.key = key;
@@ -932,19 +993,18 @@ var QiscusSDK = /*#__PURE__*/function () {
932
993
  if (this.avatar_url) params.avatar_url = this.avatar_url;
933
994
  return new Promise(function (resolve, reject) {
934
995
  var waitingConfig = setInterval(function () {
935
- if (!_this4.isConfigLoaded) {
936
- if (_this4.debugMode) {
937
- _this4.logger('Waiting for init config...');
996
+ if (!_this6.isConfigLoaded) {
997
+ if (_this6.debugMode) {
998
+ _this6.logger('Waiting for init config...');
938
999
  }
939
1000
  } else {
940
1001
  clearInterval(waitingConfig);
941
- _this4.logger('Config Success!');
1002
+ _this6.logger('Config Success!');
942
1003
  self.events.emit('start-init');
943
1004
  var login$ = self.authAdapter.loginOrRegister(params).then(function (response) {
944
1005
  self.isInit = true;
945
1006
  self.refresh_token = response.user.refresh_token;
946
1007
  self.events.emit('login-success', response);
947
- _this4.realtimeAdapter.connect();
948
1008
  resolve(response);
949
1009
  }, function (error) {
950
1010
  self.events.emit('login-error', error);
@@ -958,7 +1018,7 @@ var QiscusSDK = /*#__PURE__*/function () {
958
1018
  }, {
959
1019
  key: "setUserWithIdentityToken",
960
1020
  value: function setUserWithIdentityToken(data) {
961
- var _this5 = this;
1021
+ var _this7 = this;
962
1022
  if (!data || !('user' in data)) return this.events.emit('login-error', data);
963
1023
  this.email = data.user.email;
964
1024
  this.user_id = data.user.email;
@@ -967,14 +1027,14 @@ var QiscusSDK = /*#__PURE__*/function () {
967
1027
  this.avatar_url = data.user.avatar_url;
968
1028
  this.isInit = true;
969
1029
  var waitingConfig = setInterval(function () {
970
- if (!_this5.isConfigLoaded) {
971
- if (_this5.debugMode) {
972
- _this5.logger('Waiting for init config...');
1030
+ if (!_this7.isConfigLoaded) {
1031
+ if (_this7.debugMode) {
1032
+ _this7.logger('Waiting for init config...');
973
1033
  }
974
1034
  } else {
975
1035
  clearInterval(waitingConfig);
976
- _this5.logger('Config Success!');
977
- _this5.events.emit('login-success', data);
1036
+ _this7.logger('Config Success!');
1037
+ _this7.events.emit('login-success', data);
978
1038
  }
979
1039
  }, 300);
980
1040
  }
@@ -986,16 +1046,16 @@ var QiscusSDK = /*#__PURE__*/function () {
986
1046
  }, {
987
1047
  key: "publishOnlinePresence",
988
1048
  value: function publishOnlinePresence(val) {
989
- var _this6 = this;
1049
+ var _this8 = this;
990
1050
  if (val === true) {
991
1051
  setBackToOnline = setInterval(function () {
992
- _this6.realtimeAdapter.publishPresence(_this6.user_id, true);
1052
+ _this8.realtimeAdapter.publishPresence(_this8.user_id, true);
993
1053
  }, 3500);
994
1054
  } else {
995
1055
  clearInterval(this.presensePublisherId);
996
1056
  clearInterval(setBackToOnline);
997
1057
  setTimeout(function () {
998
- _this6.realtimeAdapter.publishPresence(_this6.user_id, false);
1058
+ _this8.realtimeAdapter.publishPresence(_this8.user_id, false);
999
1059
  }, 3500);
1000
1060
  }
1001
1061
  }
@@ -1012,13 +1072,15 @@ var QiscusSDK = /*#__PURE__*/function () {
1012
1072
  }, {
1013
1073
  key: "logout",
1014
1074
  value: function () {
1015
- var _logout = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
1016
- return _regenerator["default"].wrap(function _callee4$(_context4) {
1017
- while (1) switch (_context4.prev = _context4.next) {
1075
+ var _logout = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6() {
1076
+ var _t;
1077
+ return _regenerator["default"].wrap(function (_context6) {
1078
+ while (1) switch (_context6.prev = _context6.next) {
1018
1079
  case 0:
1019
- _context4.next = 2;
1080
+ _context6.prev = 0;
1081
+ _context6.next = 1;
1020
1082
  return this.expiredTokenAdapter.logout();
1021
- case 2:
1083
+ case 1:
1022
1084
  clearInterval(this.presensePublisherId);
1023
1085
  this.publishOnlinePresence(false);
1024
1086
  this.selected = null;
@@ -1026,11 +1088,16 @@ var QiscusSDK = /*#__PURE__*/function () {
1026
1088
  this.isLogin = false;
1027
1089
  this.realtimeAdapter.disconnect();
1028
1090
  this.userData = {};
1029
- case 9:
1091
+ _context6.next = 3;
1092
+ break;
1093
+ case 2:
1094
+ _context6.prev = 2;
1095
+ _t = _context6["catch"](0);
1096
+ case 3:
1030
1097
  case "end":
1031
- return _context4.stop();
1098
+ return _context6.stop();
1032
1099
  }
1033
- }, _callee4, this);
1100
+ }, _callee6, this, [[0, 2]]);
1034
1101
  }));
1035
1102
  function logout() {
1036
1103
  return _logout.apply(this, arguments);
@@ -1055,7 +1122,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1055
1122
  }, {
1056
1123
  key: "setActiveRoom",
1057
1124
  value: function setActiveRoom(room) {
1058
- var _this7 = this;
1125
+ var _this9 = this;
1059
1126
  // when we activate a room
1060
1127
  // we need to unsubscribe from typing event
1061
1128
  if (this.selected) {
@@ -1064,7 +1131,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1064
1131
  // and only unsubscribe if the previous room is having a type of 'single'
1065
1132
  if (this.selected.room_type === 'single') {
1066
1133
  var unsubscribedUserId = this.selected.participants.filter(function (p) {
1067
- return p.email !== _this7.user_id;
1134
+ return p.email !== _this9.user_id;
1068
1135
  });
1069
1136
  if (unsubscribedUserId.length > 0) {
1070
1137
  this.realtimeAdapter.unsubscribeRoomPresence(unsubscribedUserId[0].email);
@@ -1073,7 +1140,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1073
1140
  }
1074
1141
  if (room.participants == null) room.participants = [];
1075
1142
  var targetUserId = room.participants.find(function (p) {
1076
- return p.email !== _this7.user_id;
1143
+ return p.email !== _this9.user_id;
1077
1144
  });
1078
1145
  this.chatmateStatus = null;
1079
1146
  this.isTypingStatus = null;
@@ -1083,31 +1150,31 @@ var QiscusSDK = /*#__PURE__*/function () {
1083
1150
  var initialSubscribe = setInterval(function () {
1084
1151
  // Clear Interval when realtimeAdapter has been Populated
1085
1152
 
1086
- if (_this7.debugMode) {
1087
- _this7.logger('Trying Initial Subscribe');
1153
+ if (_this9.debugMode) {
1154
+ _this9.logger('Trying Initial Subscribe');
1088
1155
  }
1089
- if (_this7.realtimeAdapter != null) {
1090
- if (_this7.debugMode) {
1091
- _this7.logger('MQTT Connected');
1156
+ if (_this9.realtimeAdapter != null) {
1157
+ if (_this9.debugMode) {
1158
+ _this9.logger('MQTT Connected');
1092
1159
  }
1093
1160
  clearInterval(initialSubscribe);
1094
1161
 
1095
1162
  // before we unsubscribe, we need to get the userId first
1096
1163
  // and only unsubscribe if the previous room is having a type of 'single'
1097
1164
  if (room.room_type === 'single' && targetUserId != null) {
1098
- _this7.realtimeAdapter.subscribeRoomPresence(targetUserId.email);
1165
+ _this9.realtimeAdapter.subscribeRoomPresence(targetUserId.email);
1099
1166
  }
1100
1167
  // we need to subscribe to new room typing event now
1101
- if (_this7.selected != null && !_this7.selected.isChannel) {
1102
- _this7.realtimeAdapter.subscribeTyping(room.id);
1103
- _this7.events.emit('room-changed', _this7.selected);
1168
+ if (_this9.selected != null && !_this9.selected.isChannel) {
1169
+ _this9.realtimeAdapter.subscribeTyping(room.id);
1170
+ _this9.events.emit('room-changed', _this9.selected);
1104
1171
  }
1105
- if (_this7.debugMode && _this7.realtimeAdapter == null) {
1106
- _this7.logger('Retry');
1172
+ if (_this9.debugMode && _this9.realtimeAdapter == null) {
1173
+ _this9.logger('Retry');
1107
1174
  }
1108
1175
  } else {
1109
- if (_this7.debugMode) {
1110
- _this7.logger('MQTT Not Connected, yet');
1176
+ if (_this9.debugMode) {
1177
+ _this9.logger('MQTT Not Connected, yet');
1111
1178
  }
1112
1179
  }
1113
1180
  }, 3000);
@@ -1122,7 +1189,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1122
1189
  }, {
1123
1190
  key: "chatTarget",
1124
1191
  value: function chatTarget(userId) {
1125
- var _this8 = this;
1192
+ var _this0 = this;
1126
1193
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1127
1194
  // make sure data already loaded first (user already logged in)
1128
1195
  if (this.userData.length != null) return false;
@@ -1133,70 +1200,70 @@ var QiscusSDK = /*#__PURE__*/function () {
1133
1200
 
1134
1201
  // Create room
1135
1202
  return this.roomAdapter.getOrCreateRoom(userId, options, distinctId).then(/*#__PURE__*/function () {
1136
- var _ref6 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(resp) {
1203
+ var _ref7 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(resp) {
1137
1204
  var room, mapIntercept, lastComment, topicId;
1138
- return _regenerator["default"].wrap(function _callee6$(_context6) {
1139
- while (1) switch (_context6.prev = _context6.next) {
1205
+ return _regenerator["default"].wrap(function (_context8) {
1206
+ while (1) switch (_context8.prev = _context8.next) {
1140
1207
  case 0:
1141
1208
  room = new _Room["default"](resp);
1142
- _this8.updateLastReceivedComment(room.last_comment_id);
1143
- _this8.isLoading = false;
1209
+ _this0.updateLastReceivedComment(room.last_comment_id);
1210
+ _this0.isLoading = false;
1144
1211
  mapIntercept = /*#__PURE__*/function () {
1145
- var _ref7 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(it) {
1146
- return _regenerator["default"].wrap(function _callee5$(_context5) {
1147
- while (1) switch (_context5.prev = _context5.next) {
1212
+ var _ref8 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(it) {
1213
+ return _regenerator["default"].wrap(function (_context7) {
1214
+ while (1) switch (_context7.prev = _context7.next) {
1148
1215
  case 0:
1149
- _context5.next = 2;
1150
- return _this8._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, it);
1216
+ _context7.next = 1;
1217
+ return _this0._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, it);
1218
+ case 1:
1219
+ return _context7.abrupt("return", _context7.sent);
1151
1220
  case 2:
1152
- return _context5.abrupt("return", _context5.sent);
1153
- case 3:
1154
1221
  case "end":
1155
- return _context5.stop();
1222
+ return _context7.stop();
1156
1223
  }
1157
- }, _callee5);
1224
+ }, _callee7);
1158
1225
  }));
1159
- return function mapIntercept(_x5) {
1160
- return _ref7.apply(this, arguments);
1226
+ return function mapIntercept(_x6) {
1227
+ return _ref8.apply(this, arguments);
1161
1228
  };
1162
1229
  }();
1163
- _context6.next = 6;
1230
+ _context8.next = 1;
1164
1231
  return Promise.all(room.comments.map(function (comment) {
1165
1232
  return mapIntercept(comment);
1166
1233
  }));
1167
- case 6:
1168
- room.comments = _context6.sent;
1169
- _this8.setActiveRoom(room);
1234
+ case 1:
1235
+ room.comments = _context8.sent;
1236
+ _this0.setActiveRoom(room);
1170
1237
  // id of last comment on this room
1171
1238
  lastComment = room.comments[room.comments.length - 1];
1172
- if (lastComment) _this8.readComment(room.id, lastComment.id);
1173
- _this8.events.emit('chat-room-created', {
1239
+ if (lastComment) _this0.readComment(room.id, lastComment.id);
1240
+ _this0.events.emit('chat-room-created', {
1174
1241
  room: room
1175
1242
  });
1176
1243
  if (initialMessage) {
1177
- _context6.next = 13;
1244
+ _context8.next = 2;
1178
1245
  break;
1179
1246
  }
1180
- return _context6.abrupt("return", room);
1181
- case 13:
1247
+ return _context8.abrupt("return", room);
1248
+ case 2:
1182
1249
  topicId = room.id;
1183
- return _context6.abrupt("return", _this8.sendComment(topicId, initialMessage).then(function () {
1250
+ return _context8.abrupt("return", _this0.sendComment(topicId, initialMessage).then(function () {
1184
1251
  return Promise.resolve(room);
1185
1252
  })["catch"](function (err) {
1186
1253
  console.error('Error when submit comment', err);
1187
1254
  }));
1188
- case 15:
1255
+ case 3:
1189
1256
  case "end":
1190
- return _context6.stop();
1257
+ return _context8.stop();
1191
1258
  }
1192
- }, _callee6);
1259
+ }, _callee8);
1193
1260
  }));
1194
- return function (_x4) {
1195
- return _ref6.apply(this, arguments);
1261
+ return function (_x5) {
1262
+ return _ref7.apply(this, arguments);
1196
1263
  };
1197
1264
  }())["catch"](function (err) {
1198
1265
  console.error('Error when creating room', err);
1199
- _this8.isLoading = false;
1266
+ _this0.isLoading = false;
1200
1267
  return Promise.reject(err);
1201
1268
  });
1202
1269
  }
@@ -1228,48 +1295,48 @@ var QiscusSDK = /*#__PURE__*/function () {
1228
1295
  }, {
1229
1296
  key: "getRoomById",
1230
1297
  value: function getRoomById(id) {
1231
- var _this9 = this;
1298
+ var _this1 = this;
1232
1299
  if (!this.isInit) return;
1233
1300
  var self = this;
1234
1301
  self.isLoading = true;
1235
1302
  self.isTypingStatus = '';
1236
1303
  return self.roomAdapter.getRoomById(id).then(/*#__PURE__*/function () {
1237
- var _ref8 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(resp) {
1238
- var roomData, comments, _iterator, _step, comment, c, room, lastComment;
1239
- return _regenerator["default"].wrap(function _callee7$(_context7) {
1240
- while (1) switch (_context7.prev = _context7.next) {
1304
+ var _ref9 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9(resp) {
1305
+ var roomData, comments, _iterator, _step, comment, c, room, lastComment, _t2;
1306
+ return _regenerator["default"].wrap(function (_context9) {
1307
+ while (1) switch (_context9.prev = _context9.next) {
1241
1308
  case 0:
1242
1309
  roomData = resp.results.room;
1243
1310
  comments = [];
1244
1311
  _iterator = _createForOfIteratorHelper(resp.results.comments.reverse());
1245
- _context7.prev = 3;
1312
+ _context9.prev = 1;
1246
1313
  _iterator.s();
1247
- case 5:
1314
+ case 2:
1248
1315
  if ((_step = _iterator.n()).done) {
1249
- _context7.next = 13;
1316
+ _context9.next = 5;
1250
1317
  break;
1251
1318
  }
1252
1319
  comment = _step.value;
1253
- _context7.next = 9;
1254
- return _this9._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1255
- case 9:
1256
- c = _context7.sent;
1320
+ _context9.next = 3;
1321
+ return _this1._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1322
+ case 3:
1323
+ c = _context9.sent;
1257
1324
  comments.push(c);
1258
- case 11:
1259
- _context7.next = 5;
1325
+ case 4:
1326
+ _context9.next = 2;
1260
1327
  break;
1261
- case 13:
1262
- _context7.next = 18;
1328
+ case 5:
1329
+ _context9.next = 7;
1263
1330
  break;
1264
- case 15:
1265
- _context7.prev = 15;
1266
- _context7.t0 = _context7["catch"](3);
1267
- _iterator.e(_context7.t0);
1268
- case 18:
1269
- _context7.prev = 18;
1331
+ case 6:
1332
+ _context9.prev = 6;
1333
+ _t2 = _context9["catch"](1);
1334
+ _iterator.e(_t2);
1335
+ case 7:
1336
+ _context9.prev = 7;
1270
1337
  _iterator.f();
1271
- return _context7.finish(18);
1272
- case 21:
1338
+ return _context9.finish(7);
1339
+ case 8:
1273
1340
  // .map((it) =>
1274
1341
  // this._hookAdapter.trigger(Hooks.MESSAGE_BEFORE_RECEIVED, it)
1275
1342
  // );
@@ -1284,17 +1351,17 @@ var QiscusSDK = /*#__PURE__*/function () {
1284
1351
  lastComment = room.comments[room.comments.length - 1];
1285
1352
  if (lastComment) self.readComment(room.id, lastComment.id);
1286
1353
  if (room.isChannel) {
1287
- _this9.realtimeAdapter.subscribeChannel(_this9.AppId, room.unique_id);
1354
+ _this1.realtimeAdapter.subscribeChannel(_this1.AppId, room.unique_id);
1288
1355
  }
1289
- return _context7.abrupt("return", room);
1290
- case 29:
1356
+ return _context9.abrupt("return", room);
1357
+ case 9:
1291
1358
  case "end":
1292
- return _context7.stop();
1359
+ return _context9.stop();
1293
1360
  }
1294
- }, _callee7, null, [[3, 15, 18, 21]]);
1361
+ }, _callee9, null, [[1, 6, 7, 8]]);
1295
1362
  }));
1296
- return function (_x6) {
1297
- return _ref8.apply(this, arguments);
1363
+ return function (_x7) {
1364
+ return _ref9.apply(this, arguments);
1298
1365
  };
1299
1366
  }())["catch"](function (error) {
1300
1367
  console.error('Error getting room by id', error);
@@ -1316,53 +1383,53 @@ var QiscusSDK = /*#__PURE__*/function () {
1316
1383
  self.isLoading = true;
1317
1384
  self.isTypingStatus = '';
1318
1385
  return self.roomAdapter.getOrCreateRoomByUniqueId(id, roomName, avatarURL).then(/*#__PURE__*/function () {
1319
- var _ref9 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9(response) {
1386
+ var _ref0 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1(response) {
1320
1387
  var room, mapIntercept, lastComment;
1321
- return _regenerator["default"].wrap(function _callee9$(_context9) {
1322
- while (1) switch (_context9.prev = _context9.next) {
1388
+ return _regenerator["default"].wrap(function (_context1) {
1389
+ while (1) switch (_context1.prev = _context1.next) {
1323
1390
  case 0:
1324
1391
  // make sure the room hasn't been pushed yet
1325
1392
  room = new _Room["default"](response);
1326
1393
  self.updateLastReceivedComment(room.last_comment_id);
1327
1394
  mapIntercept = /*#__PURE__*/function () {
1328
- var _ref10 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(item) {
1329
- return _regenerator["default"].wrap(function _callee8$(_context8) {
1330
- while (1) switch (_context8.prev = _context8.next) {
1395
+ var _ref1 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0(item) {
1396
+ return _regenerator["default"].wrap(function (_context0) {
1397
+ while (1) switch (_context0.prev = _context0.next) {
1331
1398
  case 0:
1332
- _context8.next = 2;
1399
+ _context0.next = 1;
1333
1400
  return _this10._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, item);
1401
+ case 1:
1402
+ return _context0.abrupt("return", _context0.sent);
1334
1403
  case 2:
1335
- return _context8.abrupt("return", _context8.sent);
1336
- case 3:
1337
1404
  case "end":
1338
- return _context8.stop();
1405
+ return _context0.stop();
1339
1406
  }
1340
- }, _callee8);
1407
+ }, _callee0);
1341
1408
  }));
1342
- return function mapIntercept(_x8) {
1343
- return _ref10.apply(this, arguments);
1409
+ return function mapIntercept(_x9) {
1410
+ return _ref1.apply(this, arguments);
1344
1411
  };
1345
1412
  }();
1346
- _context9.next = 5;
1413
+ _context1.next = 1;
1347
1414
  return Promise.all(room.comments.map(function (it) {
1348
1415
  return mapIntercept(it);
1349
1416
  }));
1350
- case 5:
1351
- room.comments = _context9.sent;
1417
+ case 1:
1418
+ room.comments = _context1.sent;
1352
1419
  self.setActiveRoom(room);
1353
1420
  self.isLoading = false;
1354
1421
  lastComment = room.comments[room.comments.length - 1];
1355
1422
  if (lastComment) self.readComment(room.id, lastComment.id);
1356
1423
  _this10.realtimeAdapter.subscribeChannel(_this10.AppId, room.unique_id);
1357
- return _context9.abrupt("return", Promise.resolve(room));
1358
- case 12:
1424
+ return _context1.abrupt("return", Promise.resolve(room));
1425
+ case 2:
1359
1426
  case "end":
1360
- return _context9.stop();
1427
+ return _context1.stop();
1361
1428
  }
1362
- }, _callee9);
1429
+ }, _callee1);
1363
1430
  }));
1364
- return function (_x7) {
1365
- return _ref9.apply(this, arguments);
1431
+ return function (_x8) {
1432
+ return _ref0.apply(this, arguments);
1366
1433
  };
1367
1434
  }())["catch"](function (error) {
1368
1435
  // console.error('Error getting room by id', error)
@@ -1388,13 +1455,13 @@ var QiscusSDK = /*#__PURE__*/function () {
1388
1455
  var params,
1389
1456
  rooms,
1390
1457
  _args10 = arguments;
1391
- return _regenerator["default"].wrap(function _callee10$(_context10) {
1458
+ return _regenerator["default"].wrap(function (_context10) {
1392
1459
  while (1) switch (_context10.prev = _context10.next) {
1393
1460
  case 0:
1394
1461
  params = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1395
- _context10.next = 3;
1462
+ _context10.next = 1;
1396
1463
  return this.userAdapter.loadRoomList(params);
1397
- case 3:
1464
+ case 1:
1398
1465
  rooms = _context10.sent;
1399
1466
  return _context10.abrupt("return", rooms.map(function (room) {
1400
1467
  room.last_comment_id = room.last_comment.id;
@@ -1404,7 +1471,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1404
1471
  room.comments = [];
1405
1472
  return new _Room["default"](room);
1406
1473
  }));
1407
- case 5:
1474
+ case 2:
1408
1475
  case "end":
1409
1476
  return _context10.stop();
1410
1477
  }
@@ -1421,55 +1488,54 @@ var QiscusSDK = /*#__PURE__*/function () {
1421
1488
  var _this11 = this;
1422
1489
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1423
1490
  return this.userAdapter.loadComments(roomId, options).then(/*#__PURE__*/function () {
1424
- var _ref11 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11(comments_) {
1425
- var comments, _iterator2, _step2, comment;
1426
- return _regenerator["default"].wrap(function _callee11$(_context11) {
1491
+ var _ref10 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11(comments_) {
1492
+ var comments, _iterator2, _step2, comment, _t3, _t4;
1493
+ return _regenerator["default"].wrap(function (_context11) {
1427
1494
  while (1) switch (_context11.prev = _context11.next) {
1428
1495
  case 0:
1429
1496
  comments = [];
1430
1497
  _iterator2 = _createForOfIteratorHelper(comments_);
1431
- _context11.prev = 2;
1498
+ _context11.prev = 1;
1432
1499
  _iterator2.s();
1433
- case 4:
1500
+ case 2:
1434
1501
  if ((_step2 = _iterator2.n()).done) {
1435
- _context11.next = 13;
1502
+ _context11.next = 5;
1436
1503
  break;
1437
1504
  }
1438
1505
  comment = _step2.value;
1439
- _context11.t0 = comments;
1440
- _context11.next = 9;
1506
+ _t3 = comments;
1507
+ _context11.next = 3;
1441
1508
  return _this11._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1442
- case 9:
1443
- _context11.t1 = _context11.sent;
1444
- _context11.t0.push.call(_context11.t0, _context11.t1);
1445
- case 11:
1446
- _context11.next = 4;
1509
+ case 3:
1510
+ _t3.push.call(_t3, _context11.sent);
1511
+ case 4:
1512
+ _context11.next = 2;
1447
1513
  break;
1448
- case 13:
1449
- _context11.next = 18;
1514
+ case 5:
1515
+ _context11.next = 7;
1450
1516
  break;
1451
- case 15:
1452
- _context11.prev = 15;
1453
- _context11.t2 = _context11["catch"](2);
1454
- _iterator2.e(_context11.t2);
1455
- case 18:
1456
- _context11.prev = 18;
1517
+ case 6:
1518
+ _context11.prev = 6;
1519
+ _t4 = _context11["catch"](1);
1520
+ _iterator2.e(_t4);
1521
+ case 7:
1522
+ _context11.prev = 7;
1457
1523
  _iterator2.f();
1458
- return _context11.finish(18);
1459
- case 21:
1524
+ return _context11.finish(7);
1525
+ case 8:
1460
1526
  if (_this11.selected != null) {
1461
1527
  _this11.selected.receiveComments(comments.reverse());
1462
1528
  _this11.sortComments();
1463
1529
  }
1464
1530
  return _context11.abrupt("return", comments);
1465
- case 23:
1531
+ case 9:
1466
1532
  case "end":
1467
1533
  return _context11.stop();
1468
1534
  }
1469
- }, _callee11, null, [[2, 15, 18, 21]]);
1535
+ }, _callee11, null, [[1, 6, 7, 8]]);
1470
1536
  }));
1471
- return function (_x9) {
1472
- return _ref11.apply(this, arguments);
1537
+ return function (_x0) {
1538
+ return _ref10.apply(this, arguments);
1473
1539
  };
1474
1540
  }());
1475
1541
  }
@@ -1489,26 +1555,26 @@ var QiscusSDK = /*#__PURE__*/function () {
1489
1555
  var isDevelopment,
1490
1556
  res,
1491
1557
  _args12 = arguments;
1492
- return _regenerator["default"].wrap(function _callee12$(_context12) {
1558
+ return _regenerator["default"].wrap(function (_context12) {
1493
1559
  while (1) switch (_context12.prev = _context12.next) {
1494
1560
  case 0:
1495
1561
  isDevelopment = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
1496
- _context12.next = 3;
1562
+ _context12.next = 1;
1497
1563
  return this.HTTPAdapter.post('api/v2/sdk/set_user_device_token', {
1498
1564
  device_token: token,
1499
1565
  device_platform: 'rn',
1500
1566
  is_development: isDevelopment
1501
1567
  });
1502
- case 3:
1568
+ case 1:
1503
1569
  res = _context12.sent;
1504
1570
  return _context12.abrupt("return", res.body.results);
1505
- case 5:
1571
+ case 2:
1506
1572
  case "end":
1507
1573
  return _context12.stop();
1508
1574
  }
1509
1575
  }, _callee12, this);
1510
1576
  }));
1511
- function registerDeviceToken(_x10) {
1577
+ function registerDeviceToken(_x1) {
1512
1578
  return _registerDeviceToken.apply(this, arguments);
1513
1579
  }
1514
1580
  return registerDeviceToken;
@@ -1520,26 +1586,26 @@ var QiscusSDK = /*#__PURE__*/function () {
1520
1586
  var isDevelopment,
1521
1587
  res,
1522
1588
  _args13 = arguments;
1523
- return _regenerator["default"].wrap(function _callee13$(_context13) {
1589
+ return _regenerator["default"].wrap(function (_context13) {
1524
1590
  while (1) switch (_context13.prev = _context13.next) {
1525
1591
  case 0:
1526
1592
  isDevelopment = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
1527
- _context13.next = 3;
1593
+ _context13.next = 1;
1528
1594
  return this.HTTPAdapter.post('api/v2/sdk/remove_user_device_token', {
1529
1595
  device_token: token,
1530
1596
  device_platform: 'rn',
1531
1597
  is_development: isDevelopment
1532
1598
  });
1533
- case 3:
1599
+ case 1:
1534
1600
  res = _context13.sent;
1535
1601
  return _context13.abrupt("return", res.body.results);
1536
- case 5:
1602
+ case 2:
1537
1603
  case "end":
1538
1604
  return _context13.stop();
1539
1605
  }
1540
1606
  }, _callee13, this);
1541
1607
  }));
1542
- function removeDeviceToken(_x11) {
1608
+ function removeDeviceToken(_x10) {
1543
1609
  return _removeDeviceToken.apply(this, arguments);
1544
1610
  }
1545
1611
  return removeDeviceToken;
@@ -1558,19 +1624,19 @@ var QiscusSDK = /*#__PURE__*/function () {
1558
1624
  var params,
1559
1625
  messages,
1560
1626
  _args14 = arguments;
1561
- return _regenerator["default"].wrap(function _callee14$(_context14) {
1627
+ return _regenerator["default"].wrap(function (_context14) {
1562
1628
  while (1) switch (_context14.prev = _context14.next) {
1563
1629
  case 0:
1564
1630
  params = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
1565
1631
  console.warn('Deprecated: search message will be removed on next release');
1566
- _context14.next = 4;
1632
+ _context14.next = 1;
1567
1633
  return this.userAdapter.searchMessages(params);
1568
- case 4:
1634
+ case 1:
1569
1635
  messages = _context14.sent;
1570
1636
  return _context14.abrupt("return", messages.map(function (message) {
1571
1637
  return new _Comment["default"](message);
1572
1638
  }));
1573
- case 6:
1639
+ case 2:
1574
1640
  case "end":
1575
1641
  return _context14.stop();
1576
1642
  }
@@ -1654,8 +1720,9 @@ var QiscusSDK = /*#__PURE__*/function () {
1654
1720
  whitelistedErrorStatus,
1655
1721
  message,
1656
1722
  isOffline,
1657
- _args15 = arguments;
1658
- return _regenerator["default"].wrap(function _callee15$(_context15) {
1723
+ _args15 = arguments,
1724
+ _t5;
1725
+ return _regenerator["default"].wrap(function (_context15) {
1659
1726
  while (1) switch (_context15.prev = _context15.next) {
1660
1727
  case 0:
1661
1728
  type = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : 'text';
@@ -1705,33 +1772,33 @@ var QiscusSDK = /*#__PURE__*/function () {
1705
1772
  pendingComment.payload = parsedPayload;
1706
1773
  }
1707
1774
  extrasToBeSubmitted = extras || self.extras;
1708
- _context15.next = 13;
1775
+ _context15.next = 1;
1709
1776
  return this._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_SENT, _objectSpread(_objectSpread({}, pendingComment), {}, {
1710
1777
  extras: extrasToBeSubmitted
1711
1778
  }));
1712
- case 13:
1779
+ case 1:
1713
1780
  messageData = _context15.sent;
1714
1781
  messageData = self.prepareCommentToBeSubmitted(messageData);
1715
1782
  if (self.selected) self.selected.comments.push(messageData);
1716
1783
  sendComment = function sendComment() {
1717
1784
  return _this13.userAdapter.postComment('' + topicId, messageData.message, messageData.unique_id, messageData.type, messageData.payload, messageData.extras);
1718
1785
  };
1719
- _context15.prev = 17;
1720
- _context15.next = 20;
1786
+ _context15.prev = 2;
1787
+ _context15.next = 3;
1721
1788
  return sendComment();
1722
- case 20:
1789
+ case 3:
1723
1790
  res = _context15.sent;
1724
- _context15.next = 23;
1791
+ _context15.next = 4;
1725
1792
  return this._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
1726
- case 23:
1793
+ case 4:
1727
1794
  res = _context15.sent;
1728
1795
  Object.assign(messageData, res);
1729
1796
  if (self.selected) {
1730
- _context15.next = 27;
1797
+ _context15.next = 5;
1731
1798
  break;
1732
1799
  }
1733
1800
  return _context15.abrupt("return", Promise.resolve(messageData));
1734
- case 27:
1801
+ case 5:
1735
1802
  // When the posting succeeded, we mark the Comment as sent,
1736
1803
  // so all the interested party can be notified.
1737
1804
  messageData.markAsSent();
@@ -1751,26 +1818,26 @@ var QiscusSDK = /*#__PURE__*/function () {
1751
1818
  self._pendingComments.splice(commentIndex, 1);
1752
1819
  }
1753
1820
  return _context15.abrupt("return", messageData);
1754
- case 39:
1755
- _context15.prev = 39;
1756
- _context15.t0 = _context15["catch"](17);
1821
+ case 6:
1822
+ _context15.prev = 6;
1823
+ _t5 = _context15["catch"](2);
1757
1824
  messageData.markAsFailed();
1758
1825
  // From superagent: `https://forwardemail.github.io/superagent/#retrying-requests`
1759
1826
  whitelistedErrorStatus = [undefined, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524];
1760
- message = (_error$message$toLowe = (_error$message = _context15.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.toLowerCase()) !== null && _error$message$toLowe !== void 0 ? _error$message$toLowe : '';
1827
+ message = (_error$message$toLowe = (_error$message = _t5.message) === null || _error$message === void 0 ? void 0 : _error$message.toLowerCase()) !== null && _error$message$toLowe !== void 0 ? _error$message$toLowe : '';
1761
1828
  isOffline = message.includes('offline');
1762
- if (whitelistedErrorStatus.includes(_context15.t0.status) || isOffline) {
1829
+ if (whitelistedErrorStatus.includes(_t5.status) || isOffline) {
1763
1830
  this._pendingComments.push(messageData);
1764
- this.logger('Failed sending comment', _context15.t0);
1831
+ this.logger('Failed sending comment', _t5);
1765
1832
  }
1766
- return _context15.abrupt("return", Promise.reject(_context15.t0));
1767
- case 47:
1833
+ return _context15.abrupt("return", Promise.reject(_t5));
1834
+ case 7:
1768
1835
  case "end":
1769
1836
  return _context15.stop();
1770
1837
  }
1771
- }, _callee15, this, [[17, 39]]);
1838
+ }, _callee15, this, [[2, 6]]);
1772
1839
  }));
1773
- function sendComment(_x12, _x13, _x14) {
1840
+ function sendComment(_x11, _x12, _x13) {
1774
1841
  return _sendComment.apply(this, arguments);
1775
1842
  }
1776
1843
  return sendComment;
@@ -1782,7 +1849,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1782
1849
  var _this$_pendingComment,
1783
1850
  _this14 = this;
1784
1851
  var _this$options$comment2, _this$options2, index;
1785
- return _regenerator["default"].wrap(function _callee17$(_context17) {
1852
+ return _regenerator["default"].wrap(function (_context17) {
1786
1853
  while (1) switch (_context17.prev = _context17.next) {
1787
1854
  case 0:
1788
1855
  this.logger('Retrying send comment', comment);
@@ -1790,7 +1857,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1790
1857
 
1791
1858
  // If it is exceeding the maximum retry count (which is 10), we will not retry anymore
1792
1859
  if (!(this._pendingCommentsCount[comment.unique_id] > 10)) {
1793
- _context17.next = 10;
1860
+ _context17.next = 1;
1794
1861
  break;
1795
1862
  }
1796
1863
  this.logger("Exceeding maximum retry count for comment ".concat(comment.unique_id, ", not retrying anymore"));
@@ -1807,20 +1874,20 @@ var QiscusSDK = /*#__PURE__*/function () {
1807
1874
  // Emit the event
1808
1875
  this.events.emit('comment-retry-exceed', comment);
1809
1876
  return _context17.abrupt("return", Promise.reject(new Error('Exceeding maximum retry count')));
1810
- case 10:
1877
+ case 1:
1811
1878
  return _context17.abrupt("return", this.userAdapter.postComment('' + comment.room_id, comment.message, comment.unique_id, comment.type, comment.payload, comment.extras).then(/*#__PURE__*/function () {
1812
- var _ref12 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16(res) {
1879
+ var _ref11 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16(res) {
1813
1880
  var _this14$selected, _this14$selected2, _this14$options$comme, _this14$options;
1814
1881
  var index, commentIndex;
1815
- return _regenerator["default"].wrap(function _callee16$(_context16) {
1882
+ return _regenerator["default"].wrap(function (_context16) {
1816
1883
  while (1) switch (_context16.prev = _context16.next) {
1817
1884
  case 0:
1818
1885
  if (!(((_this14$selected = _this14.selected) === null || _this14$selected === void 0 ? void 0 : _this14$selected.id) !== comment.room_id)) {
1819
- _context16.next = 2;
1886
+ _context16.next = 1;
1820
1887
  break;
1821
1888
  }
1822
1889
  return _context16.abrupt("return", res);
1823
- case 2:
1890
+ case 1:
1824
1891
  Object.assign(comment, res);
1825
1892
  comment.markAsSent();
1826
1893
  comment.id = res.id;
@@ -1844,26 +1911,26 @@ var QiscusSDK = /*#__PURE__*/function () {
1844
1911
  _this14._pendingComments.splice(commentIndex, 1);
1845
1912
  }
1846
1913
  return _context16.abrupt("return", comment);
1847
- case 15:
1914
+ case 2:
1848
1915
  case "end":
1849
1916
  return _context16.stop();
1850
1917
  }
1851
1918
  }, _callee16);
1852
1919
  }));
1853
- return function (_x16) {
1854
- return _ref12.apply(this, arguments);
1920
+ return function (_x15) {
1921
+ return _ref11.apply(this, arguments);
1855
1922
  };
1856
1923
  }())["catch"](function (err) {
1857
1924
  comment.markAsFailed();
1858
1925
  return Promise.reject(err);
1859
1926
  }));
1860
- case 11:
1927
+ case 2:
1861
1928
  case "end":
1862
1929
  return _context17.stop();
1863
1930
  }
1864
1931
  }, _callee17, this);
1865
1932
  }));
1866
- function _retrySendComment(_x15) {
1933
+ function _retrySendComment(_x14) {
1867
1934
  return _retrySendComment2.apply(this, arguments);
1868
1935
  }
1869
1936
  return _retrySendComment;
@@ -2467,9 +2534,9 @@ var QiscusSDK = /*#__PURE__*/function () {
2467
2534
  key: "searchMessage",
2468
2535
  value: (function () {
2469
2536
  var _searchMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee18() {
2470
- var _ref13,
2537
+ var _ref12,
2471
2538
  query,
2472
- _ref13$roomIds,
2539
+ _ref12$roomIds,
2473
2540
  roomIds,
2474
2541
  userId,
2475
2542
  type,
@@ -2480,20 +2547,20 @@ var QiscusSDK = /*#__PURE__*/function () {
2480
2547
  isValidRoomType,
2481
2548
  room,
2482
2549
  _args18 = arguments;
2483
- return _regenerator["default"].wrap(function _callee18$(_context18) {
2550
+ return _regenerator["default"].wrap(function (_context18) {
2484
2551
  while (1) switch (_context18.prev = _context18.next) {
2485
2552
  case 0:
2486
- _ref13 = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {}, query = _ref13.query, _ref13$roomIds = _ref13.roomIds, roomIds = _ref13$roomIds === void 0 ? [] : _ref13$roomIds, userId = _ref13.userId, type = _ref13.type, roomType = _ref13.roomType, page = _ref13.page, limit = _ref13.limit;
2553
+ _ref12 = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {}, query = _ref12.query, _ref12$roomIds = _ref12.roomIds, roomIds = _ref12$roomIds === void 0 ? [] : _ref12$roomIds, userId = _ref12.userId, type = _ref12.type, roomType = _ref12.roomType, page = _ref12.page, limit = _ref12.limit;
2487
2554
  url = 'api/v2/sdk/search';
2488
2555
  isValidRoomType = ['group', 'single', 'channel'].some(function (it) {
2489
2556
  return it === roomType;
2490
2557
  });
2491
2558
  if (!(roomType != null && !isValidRoomType)) {
2492
- _context18.next = 5;
2559
+ _context18.next = 1;
2493
2560
  break;
2494
2561
  }
2495
2562
  return _context18.abrupt("return", Promise.reject('Invalid room type, valid room type are: `group`, `single`, and `channel`'));
2496
- case 5:
2563
+ case 1:
2497
2564
  room = function (roomType) {
2498
2565
  var rType = roomType == null ? undefined : roomType === 'single' ? 'single' : 'group';
2499
2566
  var isPublic = roomType == null ? undefined : roomType === 'channel' ? true : false;
@@ -2517,7 +2584,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2517
2584
  }).then(function (res) {
2518
2585
  return res.body;
2519
2586
  }));
2520
- case 7:
2587
+ case 2:
2521
2588
  case "end":
2522
2589
  return _context18.stop();
2523
2590
  }
@@ -2546,8 +2613,8 @@ var QiscusSDK = /*#__PURE__*/function () {
2546
2613
  key: "getFileList",
2547
2614
  value: (function () {
2548
2615
  var _getFileList = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee19() {
2549
- var _ref14,
2550
- _ref14$roomIds,
2616
+ var _ref13,
2617
+ _ref13$roomIds,
2551
2618
  roomIds,
2552
2619
  fileType,
2553
2620
  page,
@@ -2559,17 +2626,17 @@ var QiscusSDK = /*#__PURE__*/function () {
2559
2626
  url,
2560
2627
  opts,
2561
2628
  _args19 = arguments;
2562
- return _regenerator["default"].wrap(function _callee19$(_context19) {
2629
+ return _regenerator["default"].wrap(function (_context19) {
2563
2630
  while (1) switch (_context19.prev = _context19.next) {
2564
2631
  case 0:
2565
- _ref14 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, _ref14$roomIds = _ref14.roomIds, roomIds = _ref14$roomIds === void 0 ? [] : _ref14$roomIds, fileType = _ref14.fileType, page = _ref14.page, limit = _ref14.limit, sender = _ref14.sender, userId = _ref14.userId, includeExtensions = _ref14.includeExtensions, excludeExtensions = _ref14.excludeExtensions;
2632
+ _ref13 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, _ref13$roomIds = _ref13.roomIds, roomIds = _ref13$roomIds === void 0 ? [] : _ref13$roomIds, fileType = _ref13.fileType, page = _ref13.page, limit = _ref13.limit, sender = _ref13.sender, userId = _ref13.userId, includeExtensions = _ref13.includeExtensions, excludeExtensions = _ref13.excludeExtensions;
2566
2633
  url = 'api/v2/sdk/file_list';
2567
2634
  if (this.isLogin) {
2568
- _context19.next = 4;
2635
+ _context19.next = 1;
2569
2636
  break;
2570
2637
  }
2571
2638
  return _context19.abrupt("return", Promise.reject('You need to login to use this method'));
2572
- case 4:
2639
+ case 1:
2573
2640
  // intended to check for undefined, so user can provide user
2574
2641
  // with null. If null, backend can determine that we want to
2575
2642
  // list files for all users
@@ -2593,7 +2660,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2593
2660
  return _context19.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
2594
2661
  return res.body;
2595
2662
  }));
2596
- case 9:
2663
+ case 2:
2597
2664
  case "end":
2598
2665
  return _context19.stop();
2599
2666
  }
@@ -2611,10 +2678,10 @@ var QiscusSDK = /*#__PURE__*/function () {
2611
2678
  }
2612
2679
  }, {
2613
2680
  key: "generateMessage",
2614
- value: function generateMessage(_ref15) {
2615
- var roomId = _ref15.roomId,
2616
- text = _ref15.text,
2617
- extras = _ref15.extras;
2681
+ value: function generateMessage(_ref14) {
2682
+ var roomId = _ref14.roomId,
2683
+ text = _ref14.text,
2684
+ extras = _ref14.extras;
2618
2685
  var id = Date.now();
2619
2686
  var comment = new _Comment["default"]({
2620
2687
  id: id,
@@ -2633,15 +2700,15 @@ var QiscusSDK = /*#__PURE__*/function () {
2633
2700
  }
2634
2701
  }, {
2635
2702
  key: "generateFileAttachmentMessage",
2636
- value: function generateFileAttachmentMessage(_ref16) {
2637
- var roomId = _ref16.roomId,
2638
- caption = _ref16.caption,
2639
- url = _ref16.url,
2640
- _ref16$text = _ref16.text,
2641
- text = _ref16$text === void 0 ? 'File attachment' : _ref16$text,
2642
- extras = _ref16.extras,
2643
- filename = _ref16.filename,
2644
- size = _ref16.size;
2703
+ value: function generateFileAttachmentMessage(_ref15) {
2704
+ var roomId = _ref15.roomId,
2705
+ caption = _ref15.caption,
2706
+ url = _ref15.url,
2707
+ _ref15$text = _ref15.text,
2708
+ text = _ref15$text === void 0 ? 'File attachment' : _ref15$text,
2709
+ extras = _ref15.extras,
2710
+ filename = _ref15.filename,
2711
+ size = _ref15.size;
2645
2712
  var id = Date.now();
2646
2713
  var comment = new _Comment["default"]({
2647
2714
  id: id,
@@ -2666,12 +2733,12 @@ var QiscusSDK = /*#__PURE__*/function () {
2666
2733
  }
2667
2734
  }, {
2668
2735
  key: "generateCustomMessage",
2669
- value: function generateCustomMessage(_ref17) {
2670
- var roomId = _ref17.roomId,
2671
- text = _ref17.text,
2672
- type = _ref17.type,
2673
- payload = _ref17.payload,
2674
- extras = _ref17.extras;
2736
+ value: function generateCustomMessage(_ref16) {
2737
+ var roomId = _ref16.roomId,
2738
+ text = _ref16.text,
2739
+ type = _ref16.type,
2740
+ payload = _ref16.payload,
2741
+ extras = _ref16.extras;
2675
2742
  var id = Date.now();
2676
2743
  var comment = new _Comment["default"]({
2677
2744
  id: id,
@@ -2694,11 +2761,11 @@ var QiscusSDK = /*#__PURE__*/function () {
2694
2761
  }
2695
2762
  }, {
2696
2763
  key: "generateReplyMessage",
2697
- value: function generateReplyMessage(_ref18) {
2698
- var roomId = _ref18.roomId,
2699
- text = _ref18.text,
2700
- repliedMessage = _ref18.repliedMessage,
2701
- extras = _ref18.extras;
2764
+ value: function generateReplyMessage(_ref17) {
2765
+ var roomId = _ref17.roomId,
2766
+ text = _ref17.text,
2767
+ repliedMessage = _ref17.repliedMessage,
2768
+ extras = _ref17.extras;
2702
2769
  var id = Date.now();
2703
2770
  var comment = new _Comment["default"]({
2704
2771
  id: id,
@@ -2728,7 +2795,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2728
2795
  key: "updateMessage",
2729
2796
  value: function () {
2730
2797
  var _updateMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee20(message) {
2731
- return _regenerator["default"].wrap(function _callee20$(_context20) {
2798
+ return _regenerator["default"].wrap(function (_context20) {
2732
2799
  while (1) switch (_context20.prev = _context20.next) {
2733
2800
  case 0:
2734
2801
  return _context20.abrupt("return", this.userAdapter.updateMessage(message));
@@ -2738,7 +2805,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2738
2805
  }
2739
2806
  }, _callee20, this);
2740
2807
  }));
2741
- function updateMessage(_x17) {
2808
+ function updateMessage(_x16) {
2742
2809
  return _updateMessage.apply(this, arguments);
2743
2810
  }
2744
2811
  return updateMessage;
@@ -2761,7 +2828,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2761
2828
  key: "closeRealtimeConnection",
2762
2829
  value: (function () {
2763
2830
  var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee21() {
2764
- return _regenerator["default"].wrap(function _callee21$(_context21) {
2831
+ return _regenerator["default"].wrap(function (_context21) {
2765
2832
  while (1) switch (_context21.prev = _context21.next) {
2766
2833
  case 0:
2767
2834
  return _context21.abrupt("return", this.realtimeAdapter.closeConnection());
@@ -2785,7 +2852,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2785
2852
  key: "openRealtimeConnection",
2786
2853
  value: (function () {
2787
2854
  var _openRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee22() {
2788
- return _regenerator["default"].wrap(function _callee22$(_context22) {
2855
+ return _regenerator["default"].wrap(function (_context22) {
2789
2856
  while (1) switch (_context22.prev = _context22.next) {
2790
2857
  case 0:
2791
2858
  return _context22.abrupt("return", this.realtimeAdapter.openConnection());
@@ -2804,7 +2871,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2804
2871
  key: "startSync",
2805
2872
  value: function () {
2806
2873
  var _startSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee23() {
2807
- return _regenerator["default"].wrap(function _callee23$(_context23) {
2874
+ return _regenerator["default"].wrap(function (_context23) {
2808
2875
  while (1) switch (_context23.prev = _context23.next) {
2809
2876
  case 0:
2810
2877
  this._forceEnableSync = true;
@@ -2823,7 +2890,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2823
2890
  key: "stopSync",
2824
2891
  value: function () {
2825
2892
  var _stopSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee24() {
2826
- return _regenerator["default"].wrap(function _callee24$(_context24) {
2893
+ return _regenerator["default"].wrap(function (_context24) {
2827
2894
  while (1) switch (_context24.prev = _context24.next) {
2828
2895
  case 0:
2829
2896
  this._forceEnableSync = false;