qiscus-sdk-core 2.12.0 → 2.12.2

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
@@ -55,6 +55,8 @@ var _package = _interopRequireDefault(require("../package.json"));
55
55
 
56
56
  var _hook = require("./lib/adapters/hook");
57
57
 
58
+ var _expiredToken = require("./lib/adapters/expired-token");
59
+
58
60
  function ownKeys(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; }
59
61
 
60
62
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -121,7 +123,10 @@ var QiscusSDK = /*#__PURE__*/function () {
121
123
  this.enableEventReport = false;
122
124
  this.enableRealtime = true;
123
125
  this.enableRealtimeCheck = true;
126
+ this.enableSync = true;
127
+ this.enableSyncEvent = false;
124
128
  this.HTTPAdapter = null;
129
+ this.expiredTokenAdapter = null;
125
130
  this.realtimeAdapter = null;
126
131
  this.customEventAdapter = null;
127
132
  this.isInit = false;
@@ -155,7 +160,8 @@ var QiscusSDK = /*#__PURE__*/function () {
155
160
  this.templateFunction = null;
156
161
  this.debugMode = false;
157
162
  this.debugMQTTMode = false;
158
- this._customHeader = {}; // to prevent double receive newmessages callback
163
+ this._customHeader = {};
164
+ this._forceEnableSync = true; // to prevent double receive newmessages callback
159
165
 
160
166
  this.lastReceiveMessages = [];
161
167
  this._hookAdapter = (0, _hook.hookAdapterFactory)();
@@ -262,7 +268,7 @@ var QiscusSDK = /*#__PURE__*/function () {
262
268
  */
263
269
 
264
270
  setterHelper = function setterHelper(fromUser, fromServer, defaultValue) {
265
- if (fromServer == '') {
271
+ if (fromServer === '') {
266
272
  if (fromUser != null) {
267
273
  if (typeof fromUser !== 'string') return fromUser;
268
274
  if (fromUser.length > 0) return fromUser;
@@ -325,6 +331,8 @@ var QiscusSDK = /*#__PURE__*/function () {
325
331
  _this2.enableRealtimeCheck = setterHelper(null, cfg.enable_realtime_check, enableRealtimeCheck);
326
332
  _this2.enableEventReport = setterHelper(null, cfg.enable_event_report, enableEventReport);
327
333
  _this2.extras = setterHelper(null, cfg.extras, configExtras);
334
+ _this2.enableSync = setterHelper(null, cfg.enable_sync, _this2.enableSync);
335
+ _this2.enableSyncEvent = setterHelper(null, cfg.enable_sync_event, _this2.enableSyncEvent);
328
336
  })["catch"](function (err) {
329
337
  _this2.logger('got error when trying to get app config', err);
330
338
 
@@ -432,7 +440,7 @@ var QiscusSDK = /*#__PURE__*/function () {
432
440
  return _this2.syncInterval;
433
441
  },
434
442
  getShouldSync: function getShouldSync() {
435
- return _this2.isLogin && !_this2.realtimeAdapter.connected;
443
+ return _this2._forceEnableSync && _this2.isLogin && !_this2.realtimeAdapter.connected;
436
444
  },
437
445
  syncOnConnect: function syncOnConnect() {
438
446
  return _this2.syncOnConnect;
@@ -442,6 +450,12 @@ var QiscusSDK = /*#__PURE__*/function () {
442
450
  },
443
451
  statusLogin: function statusLogin() {
444
452
  return _this2.isLogin;
453
+ },
454
+ enableSync: function enableSync() {
455
+ return _this2.enableSync;
456
+ },
457
+ enableSyncEvent: function enableSyncEvent() {
458
+ return _this2.enableSyncEvent;
445
459
  }
446
460
  });
447
461
  this.syncAdapter.on('message.new', /*#__PURE__*/function () {
@@ -713,6 +727,27 @@ var QiscusSDK = /*#__PURE__*/function () {
713
727
 
714
728
  _this3.HTTPAdapter.setToken(_this3.userData.token);
715
729
 
730
+ var user = response.user;
731
+ _this3.expiredTokenAdapter = new _expiredToken.ExpiredTokenAdapter({
732
+ httpAdapter: _this3.HTTPAdapter,
733
+ refreshToken: user.refresh_token,
734
+ expiredAt: user.token_expires_at,
735
+ userId: _this3.user_id,
736
+ onTokenRefreshed: function onTokenRefreshed(token, refreshToken, expiredAt) {
737
+ _this3.userData.token = token;
738
+ _this3.userData.refresh_token = refreshToken;
739
+ _this3.userData.token_expires_at = expiredAt === null || expiredAt === void 0 ? void 0 : expiredAt.toJSON();
740
+
741
+ _this3.events.emit('token-refreshed', {
742
+ token: token,
743
+ refreshToken: refreshToken,
744
+ expiredAt: expiredAt
745
+ });
746
+ },
747
+ getAuthenticationStatus: function getAuthenticationStatus() {
748
+ return _this3.user_id != null && _this3.isLogin;
749
+ }
750
+ });
716
751
  _this3.userAdapter = new _user["default"](_this3.HTTPAdapter);
717
752
  _this3.roomAdapter = new _room["default"](_this3.HTTPAdapter);
718
753
 
@@ -742,6 +777,11 @@ var QiscusSDK = /*#__PURE__*/function () {
742
777
  self.options.loginErrorCallback(error);
743
778
  }
744
779
  });
780
+ self.events.on('token-refreshed', function (param) {
781
+ var _this3$options$authTo, _this3$options;
782
+
783
+ (_this3$options$authTo = (_this3$options = _this3.options).authTokenRefreshedCallback) === null || _this3$options$authTo === void 0 ? void 0 : _this3$options$authTo.call(_this3$options, param);
784
+ });
745
785
  self.events.on('room-cleared', function (room) {
746
786
  // find room
747
787
  if (self.selected) {
@@ -973,9 +1013,8 @@ var QiscusSDK = /*#__PURE__*/function () {
973
1013
  _this4.logger('Config Success!');
974
1014
 
975
1015
  self.events.emit('start-init');
976
- return self.authAdapter.loginOrRegister(params).then(function (response) {
1016
+ var login$ = self.authAdapter.loginOrRegister(params).then(function (response) {
977
1017
  self.isInit = true;
978
- console.log('response', response);
979
1018
  self.refresh_token = response.user.refresh_token;
980
1019
  self.events.emit('login-success', response);
981
1020
 
@@ -986,6 +1025,7 @@ var QiscusSDK = /*#__PURE__*/function () {
986
1025
  self.events.emit('login-error', error);
987
1026
  reject(error);
988
1027
  });
1028
+ return login$;
989
1029
  }
990
1030
  }, 300);
991
1031
  });
@@ -1019,34 +1059,22 @@ var QiscusSDK = /*#__PURE__*/function () {
1019
1059
  }, {
1020
1060
  key: "refreshAuthToken",
1021
1061
  value: function refreshAuthToken() {
1022
- var _this6 = this;
1023
-
1024
- return this.authAdapter.refreshAuthToken().then(function (r) {
1025
- console.log('resp:', r);
1026
- _this6.token = r.token;
1027
- _this6.HTTPAdapter.token = r.token;
1028
- return r;
1029
- });
1030
- }
1031
- }, {
1032
- key: "expiredAuthToken",
1033
- value: function expiredAuthToken() {
1034
- return this.authAdapter.expiredAuthToken();
1062
+ return this.expiredTokenAdapter.refreshAuthToken();
1035
1063
  }
1036
1064
  }, {
1037
1065
  key: "publishOnlinePresence",
1038
1066
  value: function publishOnlinePresence(val) {
1039
- var _this7 = this;
1067
+ var _this6 = this;
1040
1068
 
1041
1069
  if (val === true) {
1042
1070
  setBackToOnline = setInterval(function () {
1043
- _this7.realtimeAdapter.publishPresence(_this7.user_id, true);
1071
+ _this6.realtimeAdapter.publishPresence(_this6.user_id, true);
1044
1072
  }, 3500);
1045
1073
  } else {
1046
1074
  clearInterval(this.presensePublisherId);
1047
1075
  clearInterval(setBackToOnline);
1048
1076
  setTimeout(function () {
1049
- _this7.realtimeAdapter.publishPresence(_this7.user_id, false);
1077
+ _this6.realtimeAdapter.publishPresence(_this6.user_id, false);
1050
1078
  }, 3500);
1051
1079
  }
1052
1080
  }
@@ -1062,15 +1090,38 @@ var QiscusSDK = /*#__PURE__*/function () {
1062
1090
  }
1063
1091
  }, {
1064
1092
  key: "logout",
1065
- value: function logout() {
1066
- clearInterval(this.presensePublisherId);
1067
- this.publishOnlinePresence(false);
1068
- this.selected = null;
1069
- this.isInit = false;
1070
- this.isLogin = false;
1071
- this.realtimeAdapter.disconnect();
1072
- this.userData = {};
1073
- }
1093
+ value: function () {
1094
+ var _logout = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
1095
+ return _regenerator["default"].wrap(function _callee4$(_context4) {
1096
+ while (1) {
1097
+ switch (_context4.prev = _context4.next) {
1098
+ case 0:
1099
+ _context4.next = 2;
1100
+ return this.expiredTokenAdapter.logout();
1101
+
1102
+ case 2:
1103
+ clearInterval(this.presensePublisherId);
1104
+ this.publishOnlinePresence(false);
1105
+ this.selected = null;
1106
+ this.isInit = false;
1107
+ this.isLogin = false;
1108
+ this.realtimeAdapter.disconnect();
1109
+ this.userData = {};
1110
+
1111
+ case 9:
1112
+ case "end":
1113
+ return _context4.stop();
1114
+ }
1115
+ }
1116
+ }, _callee4, this);
1117
+ }));
1118
+
1119
+ function logout() {
1120
+ return _logout.apply(this, arguments);
1121
+ }
1122
+
1123
+ return logout;
1124
+ }()
1074
1125
  }, {
1075
1126
  key: "disconnect",
1076
1127
  value: function disconnect() {
@@ -1079,7 +1130,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1079
1130
  }, {
1080
1131
  key: "setActiveRoom",
1081
1132
  value: function setActiveRoom(room) {
1082
- var _this8 = this;
1133
+ var _this7 = this;
1083
1134
 
1084
1135
  // when we activate a room
1085
1136
  // we need to unsubscribe from typing event
@@ -1089,7 +1140,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1089
1140
 
1090
1141
  if (this.selected.room_type === 'single') {
1091
1142
  var unsubscribedUserId = this.selected.participants.filter(function (p) {
1092
- return p.email !== _this8.user_id;
1143
+ return p.email !== _this7.user_id;
1093
1144
  });
1094
1145
 
1095
1146
  if (unsubscribedUserId.length > 0) {
@@ -1100,7 +1151,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1100
1151
 
1101
1152
  if (room.participants == null) room.participants = [];
1102
1153
  var targetUserId = room.participants.find(function (p) {
1103
- return p.email !== _this8.user_id;
1154
+ return p.email !== _this7.user_id;
1104
1155
  });
1105
1156
  this.chatmateStatus = null;
1106
1157
  this.isTypingStatus = null;
@@ -1109,35 +1160,35 @@ var QiscusSDK = /*#__PURE__*/function () {
1109
1160
 
1110
1161
  var initialSubscribe = setInterval(function () {
1111
1162
  // Clear Interval when realtimeAdapter has been Populated
1112
- if (_this8.debugMode) {
1113
- _this8.logger('Trying Initial Subscribe');
1163
+ if (_this7.debugMode) {
1164
+ _this7.logger('Trying Initial Subscribe');
1114
1165
  }
1115
1166
 
1116
- if (_this8.realtimeAdapter != null) {
1117
- if (_this8.debugMode) {
1118
- _this8.logger('MQTT Connected');
1167
+ if (_this7.realtimeAdapter != null) {
1168
+ if (_this7.debugMode) {
1169
+ _this7.logger('MQTT Connected');
1119
1170
  }
1120
1171
 
1121
1172
  clearInterval(initialSubscribe); // before we unsubscribe, we need to get the userId first
1122
1173
  // and only unsubscribe if the previous room is having a type of 'single'
1123
1174
 
1124
1175
  if (room.room_type === 'single' && targetUserId != null) {
1125
- _this8.realtimeAdapter.subscribeRoomPresence(targetUserId.email);
1176
+ _this7.realtimeAdapter.subscribeRoomPresence(targetUserId.email);
1126
1177
  } // we need to subscribe to new room typing event now
1127
1178
 
1128
1179
 
1129
- if (_this8.selected != null && !_this8.selected.isChannel) {
1130
- _this8.realtimeAdapter.subscribeTyping(room.id);
1180
+ if (_this7.selected != null && !_this7.selected.isChannel) {
1181
+ _this7.realtimeAdapter.subscribeTyping(room.id);
1131
1182
 
1132
- _this8.events.emit('room-changed', _this8.selected);
1183
+ _this7.events.emit('room-changed', _this7.selected);
1133
1184
  }
1134
1185
 
1135
- if (_this8.debugMode && _this8.realtimeAdapter == null) {
1136
- _this8.logger('Retry');
1186
+ if (_this7.debugMode && _this7.realtimeAdapter == null) {
1187
+ _this7.logger('Retry');
1137
1188
  }
1138
1189
  } else {
1139
- if (_this8.debugMode) {
1140
- _this8.logger('MQTT Not Connected, yet');
1190
+ if (_this7.debugMode) {
1191
+ _this7.logger('MQTT Not Connected, yet');
1141
1192
  }
1142
1193
  }
1143
1194
  }, 3000);
@@ -1152,7 +1203,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1152
1203
  }, {
1153
1204
  key: "chatTarget",
1154
1205
  value: function chatTarget(userId) {
1155
- var _this9 = this;
1206
+ var _this8 = this;
1156
1207
 
1157
1208
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1158
1209
  // make sure data already loaded first (user already logged in)
@@ -1163,36 +1214,36 @@ var QiscusSDK = /*#__PURE__*/function () {
1163
1214
  this.isTypingStatus = ''; // Create room
1164
1215
 
1165
1216
  return this.roomAdapter.getOrCreateRoom(userId, options, distinctId).then( /*#__PURE__*/function () {
1166
- var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(resp) {
1217
+ var _ref6 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(resp) {
1167
1218
  var room, mapIntercept, lastComment, topicId;
1168
- return _regenerator["default"].wrap(function _callee5$(_context5) {
1219
+ return _regenerator["default"].wrap(function _callee6$(_context6) {
1169
1220
  while (1) {
1170
- switch (_context5.prev = _context5.next) {
1221
+ switch (_context6.prev = _context6.next) {
1171
1222
  case 0:
1172
1223
  room = new _Room["default"](resp);
1173
1224
 
1174
- _this9.updateLastReceivedComment(room.last_comment_id);
1225
+ _this8.updateLastReceivedComment(room.last_comment_id);
1175
1226
 
1176
- _this9.isLoading = false;
1227
+ _this8.isLoading = false;
1177
1228
 
1178
1229
  mapIntercept = /*#__PURE__*/function () {
1179
- var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(it) {
1180
- return _regenerator["default"].wrap(function _callee4$(_context4) {
1230
+ var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5(it) {
1231
+ return _regenerator["default"].wrap(function _callee5$(_context5) {
1181
1232
  while (1) {
1182
- switch (_context4.prev = _context4.next) {
1233
+ switch (_context5.prev = _context5.next) {
1183
1234
  case 0:
1184
- _context4.next = 2;
1185
- return _this9._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, it);
1235
+ _context5.next = 2;
1236
+ return _this8._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, it);
1186
1237
 
1187
1238
  case 2:
1188
- return _context4.abrupt("return", _context4.sent);
1239
+ return _context5.abrupt("return", _context5.sent);
1189
1240
 
1190
1241
  case 3:
1191
1242
  case "end":
1192
- return _context4.stop();
1243
+ return _context5.stop();
1193
1244
  }
1194
1245
  }
1195
- }, _callee4);
1246
+ }, _callee5);
1196
1247
  }));
1197
1248
 
1198
1249
  return function mapIntercept(_x5) {
@@ -1200,34 +1251,34 @@ var QiscusSDK = /*#__PURE__*/function () {
1200
1251
  };
1201
1252
  }();
1202
1253
 
1203
- _context5.next = 6;
1254
+ _context6.next = 6;
1204
1255
  return Promise.all(room.comments.map(function (comment) {
1205
1256
  return mapIntercept(comment);
1206
1257
  }));
1207
1258
 
1208
1259
  case 6:
1209
- room.comments = _context5.sent;
1260
+ room.comments = _context6.sent;
1210
1261
 
1211
- _this9.setActiveRoom(room); // id of last comment on this room
1262
+ _this8.setActiveRoom(room); // id of last comment on this room
1212
1263
 
1213
1264
 
1214
1265
  lastComment = room.comments[room.comments.length - 1];
1215
- if (lastComment) _this9.readComment(room.id, lastComment.id);
1266
+ if (lastComment) _this8.readComment(room.id, lastComment.id);
1216
1267
 
1217
- _this9.events.emit('chat-room-created', {
1268
+ _this8.events.emit('chat-room-created', {
1218
1269
  room: room
1219
1270
  });
1220
1271
 
1221
1272
  if (initialMessage) {
1222
- _context5.next = 13;
1273
+ _context6.next = 13;
1223
1274
  break;
1224
1275
  }
1225
1276
 
1226
- return _context5.abrupt("return", room);
1277
+ return _context6.abrupt("return", room);
1227
1278
 
1228
1279
  case 13:
1229
1280
  topicId = room.id;
1230
- return _context5.abrupt("return", _this9.sendComment(topicId, initialMessage).then(function () {
1281
+ return _context6.abrupt("return", _this8.sendComment(topicId, initialMessage).then(function () {
1231
1282
  return Promise.resolve(room);
1232
1283
  })["catch"](function (err) {
1233
1284
  console.error('Error when submit comment', err);
@@ -1235,10 +1286,10 @@ var QiscusSDK = /*#__PURE__*/function () {
1235
1286
 
1236
1287
  case 15:
1237
1288
  case "end":
1238
- return _context5.stop();
1289
+ return _context6.stop();
1239
1290
  }
1240
1291
  }
1241
- }, _callee5);
1292
+ }, _callee6);
1242
1293
  }));
1243
1294
 
1244
1295
  return function (_x4) {
@@ -1246,7 +1297,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1246
1297
  };
1247
1298
  }())["catch"](function (err) {
1248
1299
  console.error('Error when creating room', err);
1249
- _this9.isLoading = false;
1300
+ _this8.isLoading = false;
1250
1301
  return Promise.reject(err);
1251
1302
  });
1252
1303
  }
@@ -1278,61 +1329,61 @@ var QiscusSDK = /*#__PURE__*/function () {
1278
1329
  }, {
1279
1330
  key: "getRoomById",
1280
1331
  value: function getRoomById(id) {
1281
- var _this10 = this;
1332
+ var _this9 = this;
1282
1333
 
1283
1334
  if (!this.isInit) return;
1284
1335
  var self = this;
1285
1336
  self.isLoading = true;
1286
1337
  self.isTypingStatus = '';
1287
1338
  return self.roomAdapter.getRoomById(id).then( /*#__PURE__*/function () {
1288
- var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6(resp) {
1339
+ var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(resp) {
1289
1340
  var roomData, comments, _iterator, _step, comment, c, room, lastComment;
1290
1341
 
1291
- return _regenerator["default"].wrap(function _callee6$(_context6) {
1342
+ return _regenerator["default"].wrap(function _callee7$(_context7) {
1292
1343
  while (1) {
1293
- switch (_context6.prev = _context6.next) {
1344
+ switch (_context7.prev = _context7.next) {
1294
1345
  case 0:
1295
1346
  roomData = resp.results.room;
1296
1347
  comments = [];
1297
1348
  _iterator = _createForOfIteratorHelper(resp.results.comments.reverse());
1298
- _context6.prev = 3;
1349
+ _context7.prev = 3;
1299
1350
 
1300
1351
  _iterator.s();
1301
1352
 
1302
1353
  case 5:
1303
1354
  if ((_step = _iterator.n()).done) {
1304
- _context6.next = 13;
1355
+ _context7.next = 13;
1305
1356
  break;
1306
1357
  }
1307
1358
 
1308
1359
  comment = _step.value;
1309
- _context6.next = 9;
1310
- return _this10._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1360
+ _context7.next = 9;
1361
+ return _this9._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1311
1362
 
1312
1363
  case 9:
1313
- c = _context6.sent;
1364
+ c = _context7.sent;
1314
1365
  comments.push(c);
1315
1366
 
1316
1367
  case 11:
1317
- _context6.next = 5;
1368
+ _context7.next = 5;
1318
1369
  break;
1319
1370
 
1320
1371
  case 13:
1321
- _context6.next = 18;
1372
+ _context7.next = 18;
1322
1373
  break;
1323
1374
 
1324
1375
  case 15:
1325
- _context6.prev = 15;
1326
- _context6.t0 = _context6["catch"](3);
1376
+ _context7.prev = 15;
1377
+ _context7.t0 = _context7["catch"](3);
1327
1378
 
1328
- _iterator.e(_context6.t0);
1379
+ _iterator.e(_context7.t0);
1329
1380
 
1330
1381
  case 18:
1331
- _context6.prev = 18;
1382
+ _context7.prev = 18;
1332
1383
 
1333
1384
  _iterator.f();
1334
1385
 
1335
- return _context6.finish(18);
1386
+ return _context7.finish(18);
1336
1387
 
1337
1388
  case 21:
1338
1389
  // .map((it) =>
@@ -1350,17 +1401,17 @@ var QiscusSDK = /*#__PURE__*/function () {
1350
1401
  if (lastComment) self.readComment(room.id, lastComment.id);
1351
1402
 
1352
1403
  if (room.isChannel) {
1353
- _this10.realtimeAdapter.subscribeChannel(_this10.AppId, room.unique_id);
1404
+ _this9.realtimeAdapter.subscribeChannel(_this9.AppId, room.unique_id);
1354
1405
  }
1355
1406
 
1356
- return _context6.abrupt("return", room);
1407
+ return _context7.abrupt("return", room);
1357
1408
 
1358
1409
  case 29:
1359
1410
  case "end":
1360
- return _context6.stop();
1411
+ return _context7.stop();
1361
1412
  }
1362
1413
  }
1363
- }, _callee6, null, [[3, 15, 18, 21]]);
1414
+ }, _callee7, null, [[3, 15, 18, 21]]);
1364
1415
  }));
1365
1416
 
1366
1417
  return function (_x6) {
@@ -1381,40 +1432,40 @@ var QiscusSDK = /*#__PURE__*/function () {
1381
1432
  }, {
1382
1433
  key: "getOrCreateRoomByUniqueId",
1383
1434
  value: function getOrCreateRoomByUniqueId(id, roomName, avatarURL) {
1384
- var _this11 = this;
1435
+ var _this10 = this;
1385
1436
 
1386
1437
  var self = this;
1387
1438
  self.isLoading = true;
1388
1439
  self.isTypingStatus = '';
1389
1440
  return self.roomAdapter.getOrCreateRoomByUniqueId(id, roomName, avatarURL).then( /*#__PURE__*/function () {
1390
- var _ref9 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(response) {
1441
+ var _ref9 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9(response) {
1391
1442
  var room, mapIntercept, lastComment;
1392
- return _regenerator["default"].wrap(function _callee8$(_context8) {
1443
+ return _regenerator["default"].wrap(function _callee9$(_context9) {
1393
1444
  while (1) {
1394
- switch (_context8.prev = _context8.next) {
1445
+ switch (_context9.prev = _context9.next) {
1395
1446
  case 0:
1396
1447
  // make sure the room hasn't been pushed yet
1397
1448
  room = new _Room["default"](response);
1398
1449
  self.updateLastReceivedComment(room.last_comment_id);
1399
1450
 
1400
1451
  mapIntercept = /*#__PURE__*/function () {
1401
- var _ref10 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7(item) {
1402
- return _regenerator["default"].wrap(function _callee7$(_context7) {
1452
+ var _ref10 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(item) {
1453
+ return _regenerator["default"].wrap(function _callee8$(_context8) {
1403
1454
  while (1) {
1404
- switch (_context7.prev = _context7.next) {
1455
+ switch (_context8.prev = _context8.next) {
1405
1456
  case 0:
1406
- _context7.next = 2;
1407
- return _this11._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, item);
1457
+ _context8.next = 2;
1458
+ return _this10._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, item);
1408
1459
 
1409
1460
  case 2:
1410
- return _context7.abrupt("return", _context7.sent);
1461
+ return _context8.abrupt("return", _context8.sent);
1411
1462
 
1412
1463
  case 3:
1413
1464
  case "end":
1414
- return _context7.stop();
1465
+ return _context8.stop();
1415
1466
  }
1416
1467
  }
1417
- }, _callee7);
1468
+ }, _callee8);
1418
1469
  }));
1419
1470
 
1420
1471
  return function mapIntercept(_x8) {
@@ -1422,28 +1473,28 @@ var QiscusSDK = /*#__PURE__*/function () {
1422
1473
  };
1423
1474
  }();
1424
1475
 
1425
- _context8.next = 5;
1476
+ _context9.next = 5;
1426
1477
  return Promise.all(room.comments.map(function (it) {
1427
1478
  return mapIntercept(it);
1428
1479
  }));
1429
1480
 
1430
1481
  case 5:
1431
- room.comments = _context8.sent;
1482
+ room.comments = _context9.sent;
1432
1483
  self.setActiveRoom(room);
1433
1484
  self.isLoading = false;
1434
1485
  lastComment = room.comments[room.comments.length - 1];
1435
1486
  if (lastComment) self.readComment(room.id, lastComment.id);
1436
1487
 
1437
- _this11.realtimeAdapter.subscribeChannel(_this11.AppId, room.unique_id);
1488
+ _this10.realtimeAdapter.subscribeChannel(_this10.AppId, room.unique_id);
1438
1489
 
1439
- return _context8.abrupt("return", Promise.resolve(room));
1490
+ return _context9.abrupt("return", Promise.resolve(room));
1440
1491
 
1441
1492
  case 12:
1442
1493
  case "end":
1443
- return _context8.stop();
1494
+ return _context9.stop();
1444
1495
  }
1445
1496
  }
1446
- }, _callee8);
1497
+ }, _callee9);
1447
1498
  }));
1448
1499
 
1449
1500
  return function (_x7) {
@@ -1469,21 +1520,21 @@ var QiscusSDK = /*#__PURE__*/function () {
1469
1520
  }, {
1470
1521
  key: "loadRoomList",
1471
1522
  value: function () {
1472
- var _loadRoomList = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee9() {
1523
+ var _loadRoomList = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10() {
1473
1524
  var params,
1474
1525
  rooms,
1475
- _args9 = arguments;
1476
- return _regenerator["default"].wrap(function _callee9$(_context9) {
1526
+ _args10 = arguments;
1527
+ return _regenerator["default"].wrap(function _callee10$(_context10) {
1477
1528
  while (1) {
1478
- switch (_context9.prev = _context9.next) {
1529
+ switch (_context10.prev = _context10.next) {
1479
1530
  case 0:
1480
- params = _args9.length > 0 && _args9[0] !== undefined ? _args9[0] : {};
1481
- _context9.next = 3;
1531
+ params = _args10.length > 0 && _args10[0] !== undefined ? _args10[0] : {};
1532
+ _context10.next = 3;
1482
1533
  return this.userAdapter.loadRoomList(params);
1483
1534
 
1484
1535
  case 3:
1485
- rooms = _context9.sent;
1486
- return _context9.abrupt("return", rooms.map(function (room) {
1536
+ rooms = _context10.sent;
1537
+ return _context10.abrupt("return", rooms.map(function (room) {
1487
1538
  room.last_comment_id = room.last_comment.id;
1488
1539
  room.last_comment_message = room.last_comment.message;
1489
1540
  room.last_comment_message_created_at = room.last_comment.timestamp;
@@ -1494,10 +1545,10 @@ var QiscusSDK = /*#__PURE__*/function () {
1494
1545
 
1495
1546
  case 5:
1496
1547
  case "end":
1497
- return _context9.stop();
1548
+ return _context10.stop();
1498
1549
  }
1499
1550
  }
1500
- }, _callee9, this);
1551
+ }, _callee10, this);
1501
1552
  }));
1502
1553
 
1503
1554
  function loadRoomList() {
@@ -1509,75 +1560,75 @@ var QiscusSDK = /*#__PURE__*/function () {
1509
1560
  }, {
1510
1561
  key: "loadComments",
1511
1562
  value: function loadComments(roomId) {
1512
- var _this12 = this;
1563
+ var _this11 = this;
1513
1564
 
1514
1565
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1515
1566
  return this.userAdapter.loadComments(roomId, options).then( /*#__PURE__*/function () {
1516
- var _ref11 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee10(comments_) {
1567
+ var _ref11 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(comments_) {
1517
1568
  var comments, _iterator2, _step2, comment;
1518
1569
 
1519
- return _regenerator["default"].wrap(function _callee10$(_context10) {
1570
+ return _regenerator["default"].wrap(function _callee11$(_context11) {
1520
1571
  while (1) {
1521
- switch (_context10.prev = _context10.next) {
1572
+ switch (_context11.prev = _context11.next) {
1522
1573
  case 0:
1523
1574
  comments = [];
1524
1575
  _iterator2 = _createForOfIteratorHelper(comments_);
1525
- _context10.prev = 2;
1576
+ _context11.prev = 2;
1526
1577
 
1527
1578
  _iterator2.s();
1528
1579
 
1529
1580
  case 4:
1530
1581
  if ((_step2 = _iterator2.n()).done) {
1531
- _context10.next = 13;
1582
+ _context11.next = 13;
1532
1583
  break;
1533
1584
  }
1534
1585
 
1535
1586
  comment = _step2.value;
1536
- _context10.t0 = comments;
1537
- _context10.next = 9;
1538
- return _this12._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1587
+ _context11.t0 = comments;
1588
+ _context11.next = 9;
1589
+ return _this11._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
1539
1590
 
1540
1591
  case 9:
1541
- _context10.t1 = _context10.sent;
1592
+ _context11.t1 = _context11.sent;
1542
1593
 
1543
- _context10.t0.push.call(_context10.t0, _context10.t1);
1594
+ _context11.t0.push.call(_context11.t0, _context11.t1);
1544
1595
 
1545
1596
  case 11:
1546
- _context10.next = 4;
1597
+ _context11.next = 4;
1547
1598
  break;
1548
1599
 
1549
1600
  case 13:
1550
- _context10.next = 18;
1601
+ _context11.next = 18;
1551
1602
  break;
1552
1603
 
1553
1604
  case 15:
1554
- _context10.prev = 15;
1555
- _context10.t2 = _context10["catch"](2);
1605
+ _context11.prev = 15;
1606
+ _context11.t2 = _context11["catch"](2);
1556
1607
 
1557
- _iterator2.e(_context10.t2);
1608
+ _iterator2.e(_context11.t2);
1558
1609
 
1559
1610
  case 18:
1560
- _context10.prev = 18;
1611
+ _context11.prev = 18;
1561
1612
 
1562
1613
  _iterator2.f();
1563
1614
 
1564
- return _context10.finish(18);
1615
+ return _context11.finish(18);
1565
1616
 
1566
1617
  case 21:
1567
- if (_this12.selected != null) {
1568
- _this12.selected.receiveComments(comments.reverse());
1618
+ if (_this11.selected != null) {
1619
+ _this11.selected.receiveComments(comments.reverse());
1569
1620
 
1570
- _this12.sortComments();
1621
+ _this11.sortComments();
1571
1622
  }
1572
1623
 
1573
- return _context10.abrupt("return", comments);
1624
+ return _context11.abrupt("return", comments);
1574
1625
 
1575
1626
  case 23:
1576
1627
  case "end":
1577
- return _context10.stop();
1628
+ return _context11.stop();
1578
1629
  }
1579
1630
  }
1580
- }, _callee10, null, [[2, 15, 18, 21]]);
1631
+ }, _callee11, null, [[2, 15, 18, 21]]);
1581
1632
  }));
1582
1633
 
1583
1634
  return function (_x9) {
@@ -1597,16 +1648,16 @@ var QiscusSDK = /*#__PURE__*/function () {
1597
1648
  }, {
1598
1649
  key: "registerDeviceToken",
1599
1650
  value: function () {
1600
- var _registerDeviceToken = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee11(token) {
1651
+ var _registerDeviceToken = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(token) {
1601
1652
  var isDevelopment,
1602
1653
  res,
1603
- _args11 = arguments;
1604
- return _regenerator["default"].wrap(function _callee11$(_context11) {
1654
+ _args12 = arguments;
1655
+ return _regenerator["default"].wrap(function _callee12$(_context12) {
1605
1656
  while (1) {
1606
- switch (_context11.prev = _context11.next) {
1657
+ switch (_context12.prev = _context12.next) {
1607
1658
  case 0:
1608
- isDevelopment = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : false;
1609
- _context11.next = 3;
1659
+ isDevelopment = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
1660
+ _context12.next = 3;
1610
1661
  return this.HTTPAdapter.post('api/v2/sdk/set_user_device_token', {
1611
1662
  device_token: token,
1612
1663
  device_platform: 'rn',
@@ -1614,15 +1665,15 @@ var QiscusSDK = /*#__PURE__*/function () {
1614
1665
  });
1615
1666
 
1616
1667
  case 3:
1617
- res = _context11.sent;
1618
- return _context11.abrupt("return", res.body.results);
1668
+ res = _context12.sent;
1669
+ return _context12.abrupt("return", res.body.results);
1619
1670
 
1620
1671
  case 5:
1621
1672
  case "end":
1622
- return _context11.stop();
1673
+ return _context12.stop();
1623
1674
  }
1624
1675
  }
1625
- }, _callee11, this);
1676
+ }, _callee12, this);
1626
1677
  }));
1627
1678
 
1628
1679
  function registerDeviceToken(_x10) {
@@ -1634,16 +1685,16 @@ var QiscusSDK = /*#__PURE__*/function () {
1634
1685
  }, {
1635
1686
  key: "removeDeviceToken",
1636
1687
  value: function () {
1637
- var _removeDeviceToken = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee12(token) {
1688
+ var _removeDeviceToken = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13(token) {
1638
1689
  var isDevelopment,
1639
1690
  res,
1640
- _args12 = arguments;
1641
- return _regenerator["default"].wrap(function _callee12$(_context12) {
1691
+ _args13 = arguments;
1692
+ return _regenerator["default"].wrap(function _callee13$(_context13) {
1642
1693
  while (1) {
1643
- switch (_context12.prev = _context12.next) {
1694
+ switch (_context13.prev = _context13.next) {
1644
1695
  case 0:
1645
- isDevelopment = _args12.length > 1 && _args12[1] !== undefined ? _args12[1] : false;
1646
- _context12.next = 3;
1696
+ isDevelopment = _args13.length > 1 && _args13[1] !== undefined ? _args13[1] : false;
1697
+ _context13.next = 3;
1647
1698
  return this.HTTPAdapter.post('api/v2/sdk/remove_user_device_token', {
1648
1699
  device_token: token,
1649
1700
  device_platform: 'rn',
@@ -1651,15 +1702,15 @@ var QiscusSDK = /*#__PURE__*/function () {
1651
1702
  });
1652
1703
 
1653
1704
  case 3:
1654
- res = _context12.sent;
1655
- return _context12.abrupt("return", res.body.results);
1705
+ res = _context13.sent;
1706
+ return _context13.abrupt("return", res.body.results);
1656
1707
 
1657
1708
  case 5:
1658
1709
  case "end":
1659
- return _context12.stop();
1710
+ return _context13.stop();
1660
1711
  }
1661
1712
  }
1662
- }, _callee12, this);
1713
+ }, _callee13, this);
1663
1714
  }));
1664
1715
 
1665
1716
  function removeDeviceToken(_x11) {
@@ -1679,31 +1730,31 @@ var QiscusSDK = /*#__PURE__*/function () {
1679
1730
  }, {
1680
1731
  key: "searchMessages",
1681
1732
  value: function () {
1682
- var _searchMessages = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee13() {
1733
+ var _searchMessages = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14() {
1683
1734
  var params,
1684
1735
  messages,
1685
- _args13 = arguments;
1686
- return _regenerator["default"].wrap(function _callee13$(_context13) {
1736
+ _args14 = arguments;
1737
+ return _regenerator["default"].wrap(function _callee14$(_context14) {
1687
1738
  while (1) {
1688
- switch (_context13.prev = _context13.next) {
1739
+ switch (_context14.prev = _context14.next) {
1689
1740
  case 0:
1690
- params = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : {};
1741
+ params = _args14.length > 0 && _args14[0] !== undefined ? _args14[0] : {};
1691
1742
  console.warn('Deprecated: search message will be removed on next release');
1692
- _context13.next = 4;
1743
+ _context14.next = 4;
1693
1744
  return this.userAdapter.searchMessages(params);
1694
1745
 
1695
1746
  case 4:
1696
- messages = _context13.sent;
1697
- return _context13.abrupt("return", messages.map(function (message) {
1747
+ messages = _context14.sent;
1748
+ return _context14.abrupt("return", messages.map(function (message) {
1698
1749
  return new _Comment["default"](message);
1699
1750
  }));
1700
1751
 
1701
1752
  case 6:
1702
1753
  case "end":
1703
- return _context13.stop();
1754
+ return _context14.stop();
1704
1755
  }
1705
1756
  }
1706
- }, _callee13, this);
1757
+ }, _callee14, this);
1707
1758
  }));
1708
1759
 
1709
1760
  function searchMessages() {
@@ -1715,15 +1766,15 @@ var QiscusSDK = /*#__PURE__*/function () {
1715
1766
  }, {
1716
1767
  key: "updateProfile",
1717
1768
  value: function updateProfile(user) {
1718
- var _this13 = this;
1769
+ var _this12 = this;
1719
1770
 
1720
1771
  return this.userAdapter.updateProfile(user).then(function (res) {
1721
- _this13.events.emit('profile-updated', user);
1772
+ _this12.events.emit('profile-updated', user);
1722
1773
 
1723
- _this13.userData = res;
1774
+ _this12.userData = res;
1724
1775
  return Promise.resolve(res);
1725
1776
  }, function (err) {
1726
- return _this13.logger(err);
1777
+ return _this12.logger(err);
1727
1778
  });
1728
1779
  }
1729
1780
  }, {
@@ -1765,8 +1816,8 @@ var QiscusSDK = /*#__PURE__*/function () {
1765
1816
  }, {
1766
1817
  key: "sendComment",
1767
1818
  value: function () {
1768
- var _sendComment = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(topicId, commentMessage, uniqueId) {
1769
- var _this14 = this;
1819
+ var _sendComment = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16(topicId, commentMessage, uniqueId) {
1820
+ var _this13 = this;
1770
1821
 
1771
1822
  var type,
1772
1823
  payload,
@@ -1778,14 +1829,14 @@ var QiscusSDK = /*#__PURE__*/function () {
1778
1829
  repliedMessage,
1779
1830
  extrasToBeSubmitted,
1780
1831
  messageData,
1781
- _args15 = arguments;
1782
- return _regenerator["default"].wrap(function _callee15$(_context15) {
1832
+ _args16 = arguments;
1833
+ return _regenerator["default"].wrap(function _callee16$(_context16) {
1783
1834
  while (1) {
1784
- switch (_context15.prev = _context15.next) {
1835
+ switch (_context16.prev = _context16.next) {
1785
1836
  case 0:
1786
- type = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : 'text';
1787
- payload = _args15.length > 4 ? _args15[4] : undefined;
1788
- extras = _args15.length > 5 ? _args15[5] : undefined;
1837
+ type = _args16.length > 3 && _args16[3] !== undefined ? _args16[3] : 'text';
1838
+ payload = _args16.length > 4 ? _args16[4] : undefined;
1839
+ extras = _args16.length > 5 ? _args16[5] : undefined;
1789
1840
  self = this; // set extra data, etc
1790
1841
 
1791
1842
  if (self.options.prePostCommentCallback) {
@@ -1817,7 +1868,7 @@ var QiscusSDK = /*#__PURE__*/function () {
1817
1868
  payload: (0, _util.tryCatch)(function () {
1818
1869
  return JSON.parse(payload);
1819
1870
  }, payload, function (error) {
1820
- return _this14.logger('Error when parsing payload', error.message);
1871
+ return _this13.logger('Error when parsing payload', error.message);
1821
1872
  })
1822
1873
  };
1823
1874
  pendingComment = self.prepareCommentToBeSubmitted(commentData); // push this comment unto active room
@@ -1835,34 +1886,34 @@ var QiscusSDK = /*#__PURE__*/function () {
1835
1886
  }
1836
1887
 
1837
1888
  extrasToBeSubmitted = extras || self.extras;
1838
- _context15.next = 13;
1889
+ _context16.next = 13;
1839
1890
  return this._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_SENT, _objectSpread(_objectSpread({}, pendingComment), {}, {
1840
1891
  extras: extrasToBeSubmitted
1841
1892
  }));
1842
1893
 
1843
1894
  case 13:
1844
- messageData = _context15.sent;
1895
+ messageData = _context16.sent;
1845
1896
  messageData = self.prepareCommentToBeSubmitted(messageData);
1846
1897
  if (self.selected) self.selected.comments.push(messageData);
1847
- return _context15.abrupt("return", this.userAdapter.postComment('' + topicId, messageData.message, messageData.unique_id, messageData.type, messageData.payload, messageData.extras).then( /*#__PURE__*/function () {
1848
- var _ref12 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee14(res) {
1849
- return _regenerator["default"].wrap(function _callee14$(_context14) {
1898
+ return _context16.abrupt("return", this.userAdapter.postComment('' + topicId, messageData.message, messageData.unique_id, messageData.type, messageData.payload, messageData.extras).then( /*#__PURE__*/function () {
1899
+ var _ref12 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(res) {
1900
+ return _regenerator["default"].wrap(function _callee15$(_context15) {
1850
1901
  while (1) {
1851
- switch (_context14.prev = _context14.next) {
1902
+ switch (_context15.prev = _context15.next) {
1852
1903
  case 0:
1853
- _context14.next = 2;
1854
- return _this14._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
1904
+ _context15.next = 2;
1905
+ return _this13._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
1855
1906
 
1856
1907
  case 2:
1857
- res = _context14.sent;
1908
+ res = _context15.sent;
1858
1909
  Object.assign(messageData, res);
1859
1910
 
1860
1911
  if (self.selected) {
1861
- _context14.next = 6;
1912
+ _context15.next = 6;
1862
1913
  break;
1863
1914
  }
1864
1915
 
1865
- return _context14.abrupt("return", Promise.resolve(messageData));
1916
+ return _context15.abrupt("return", Promise.resolve(messageData));
1866
1917
 
1867
1918
  case 6:
1868
1919
  // When the posting succeeded, we mark the Comment as sent,
@@ -1873,14 +1924,14 @@ var QiscusSDK = /*#__PURE__*/function () {
1873
1924
 
1874
1925
  messageData.unix_timestamp = res.unix_timestamp;
1875
1926
  self.sortComments();
1876
- return _context14.abrupt("return", messageData);
1927
+ return _context15.abrupt("return", messageData);
1877
1928
 
1878
1929
  case 12:
1879
1930
  case "end":
1880
- return _context14.stop();
1931
+ return _context15.stop();
1881
1932
  }
1882
1933
  }
1883
- }, _callee14);
1934
+ }, _callee15);
1884
1935
  }));
1885
1936
 
1886
1937
  return function (_x15) {
@@ -1893,10 +1944,10 @@ var QiscusSDK = /*#__PURE__*/function () {
1893
1944
 
1894
1945
  case 17:
1895
1946
  case "end":
1896
- return _context15.stop();
1947
+ return _context16.stop();
1897
1948
  }
1898
1949
  }
1899
- }, _callee15, this);
1950
+ }, _callee16, this);
1900
1951
  }));
1901
1952
 
1902
1953
  function sendComment(_x12, _x13, _x14) {
@@ -2093,14 +2144,14 @@ var QiscusSDK = /*#__PURE__*/function () {
2093
2144
  }, {
2094
2145
  key: "removeParticipantsFromGroup",
2095
2146
  value: function removeParticipantsFromGroup(roomId, emails) {
2096
- var _this15 = this;
2147
+ var _this14 = this;
2097
2148
 
2098
2149
  if (_is_js["default"].not.array(emails)) {
2099
2150
  return Promise.reject(new Error('`emails` must have type of array'));
2100
2151
  }
2101
2152
 
2102
2153
  return this.roomAdapter.removeParticipantsFromGroup(roomId, emails).then(function (res) {
2103
- _this15.events.emit('participants-removed', emails);
2154
+ _this14.events.emit('participants-removed', emails);
2104
2155
 
2105
2156
  return Promise.resolve(res);
2106
2157
  });
@@ -2266,14 +2317,14 @@ var QiscusSDK = /*#__PURE__*/function () {
2266
2317
  }, {
2267
2318
  key: "deleteComment",
2268
2319
  value: function deleteComment(roomId, commentUniqueIds, isForEveryone, isHard) {
2269
- var _this16 = this;
2320
+ var _this15 = this;
2270
2321
 
2271
2322
  if (!Array.isArray(commentUniqueIds)) {
2272
2323
  throw new Error("unique ids' must be type of Array");
2273
2324
  }
2274
2325
 
2275
2326
  return this.userAdapter.deleteComment(roomId, commentUniqueIds, isForEveryone, isHard).then(function (res) {
2276
- _this16.events.emit('comment-deleted', {
2327
+ _this15.events.emit('comment-deleted', {
2277
2328
  roomId: roomId,
2278
2329
  commentUniqueIds: commentUniqueIds,
2279
2330
  isForEveryone: isForEveryone,
@@ -2288,7 +2339,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2288
2339
  }, {
2289
2340
  key: "clearRoomsCache",
2290
2341
  value: function clearRoomsCache() {
2291
- var _this17 = this;
2342
+ var _this16 = this;
2292
2343
 
2293
2344
  // remove all room except currently selected
2294
2345
  if (this.selected) {
@@ -2297,7 +2348,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2297
2348
 
2298
2349
  var roomLength = this.rooms.length;
2299
2350
  var curIndex = this.rooms.findIndex(function (room) {
2300
- return room.id === _this17.selected.id;
2351
+ return room.id === _this16.selected.id;
2301
2352
  });
2302
2353
 
2303
2354
  if (!(curIndex + 1 === roomLength)) {
@@ -2306,7 +2357,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2306
2357
 
2307
2358
 
2308
2359
  curIndex = this.rooms.findIndex(function (room) {
2309
- return room.id === _this17.selected.id;
2360
+ return room.id === _this16.selected.id;
2310
2361
  });
2311
2362
 
2312
2363
  if (curIndex > 0 && this.rooms.length > 1) {
@@ -2317,19 +2368,19 @@ var QiscusSDK = /*#__PURE__*/function () {
2317
2368
  }, {
2318
2369
  key: "exitChatRoom",
2319
2370
  value: function exitChatRoom() {
2320
- var _this18 = this;
2371
+ var _this17 = this;
2321
2372
 
2322
2373
  // remove all subscriber
2323
2374
  this.realtimeAdapter.unsubscribeTyping();
2324
2375
  (0, _util.tryCatch)(function () {
2325
- return _this18.selected.participants.filter(function (it) {
2326
- return it.email !== _this18.user_id;
2376
+ return _this17.selected.participants.filter(function (it) {
2377
+ return it.email !== _this17.user_id;
2327
2378
  }).map(function (it) {
2328
2379
  return it.email;
2329
2380
  });
2330
2381
  }, null, this.noop, function (userIds) {
2331
2382
  return userIds.forEach(function (userId) {
2332
- return _this18.realtimeAdapter.unsubscribeRoomPresence(userId);
2383
+ return _this17.realtimeAdapter.unsubscribeRoomPresence(userId);
2333
2384
  });
2334
2385
  });
2335
2386
  this.selected = null;
@@ -2514,7 +2565,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2514
2565
  }, {
2515
2566
  key: "searchMessage",
2516
2567
  value: function () {
2517
- var _searchMessage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee16() {
2568
+ var _searchMessage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17() {
2518
2569
  var _ref13,
2519
2570
  query,
2520
2571
  _ref13$roomIds,
@@ -2527,24 +2578,24 @@ var QiscusSDK = /*#__PURE__*/function () {
2527
2578
  url,
2528
2579
  isValidRoomType,
2529
2580
  room,
2530
- _args16 = arguments;
2581
+ _args17 = arguments;
2531
2582
 
2532
- return _regenerator["default"].wrap(function _callee16$(_context16) {
2583
+ return _regenerator["default"].wrap(function _callee17$(_context17) {
2533
2584
  while (1) {
2534
- switch (_context16.prev = _context16.next) {
2585
+ switch (_context17.prev = _context17.next) {
2535
2586
  case 0:
2536
- _ref13 = _args16.length > 0 && _args16[0] !== undefined ? _args16[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;
2587
+ _ref13 = _args17.length > 0 && _args17[0] !== undefined ? _args17[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;
2537
2588
  url = 'api/v2/sdk/search';
2538
2589
  isValidRoomType = ['group', 'single', 'channel'].some(function (it) {
2539
2590
  return it === roomType;
2540
2591
  });
2541
2592
 
2542
2593
  if (!(roomType != null && !isValidRoomType)) {
2543
- _context16.next = 5;
2594
+ _context17.next = 5;
2544
2595
  break;
2545
2596
  }
2546
2597
 
2547
- return _context16.abrupt("return", Promise.reject('Invalid room type, valid room type are: `group`, `single`, and `channel`'));
2598
+ return _context17.abrupt("return", Promise.reject('Invalid room type, valid room type are: `group`, `single`, and `channel`'));
2548
2599
 
2549
2600
  case 5:
2550
2601
  room = function (roomType) {
@@ -2556,7 +2607,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2556
2607
  };
2557
2608
  }(roomType);
2558
2609
 
2559
- return _context16.abrupt("return", this.HTTPAdapter.post_json(url, {
2610
+ return _context17.abrupt("return", this.HTTPAdapter.post_json(url, {
2560
2611
  token: this.token,
2561
2612
  query: query,
2562
2613
  sender: userId,
@@ -2574,10 +2625,10 @@ var QiscusSDK = /*#__PURE__*/function () {
2574
2625
 
2575
2626
  case 7:
2576
2627
  case "end":
2577
- return _context16.stop();
2628
+ return _context17.stop();
2578
2629
  }
2579
2630
  }
2580
- }, _callee16, this);
2631
+ }, _callee17, this);
2581
2632
  }));
2582
2633
 
2583
2634
  function searchMessage() {
@@ -2604,7 +2655,7 @@ var QiscusSDK = /*#__PURE__*/function () {
2604
2655
  }, {
2605
2656
  key: "getFileList",
2606
2657
  value: function () {
2607
- var _getFileList = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee17() {
2658
+ var _getFileList = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18() {
2608
2659
  var _ref14,
2609
2660
  _ref14$roomIds,
2610
2661
  roomIds,
@@ -2617,21 +2668,21 @@ var QiscusSDK = /*#__PURE__*/function () {
2617
2668
  excludeExtensions,
2618
2669
  url,
2619
2670
  opts,
2620
- _args17 = arguments;
2671
+ _args18 = arguments;
2621
2672
 
2622
- return _regenerator["default"].wrap(function _callee17$(_context17) {
2673
+ return _regenerator["default"].wrap(function _callee18$(_context18) {
2623
2674
  while (1) {
2624
- switch (_context17.prev = _context17.next) {
2675
+ switch (_context18.prev = _context18.next) {
2625
2676
  case 0:
2626
- _ref14 = _args17.length > 0 && _args17[0] !== undefined ? _args17[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;
2677
+ _ref14 = _args18.length > 0 && _args18[0] !== undefined ? _args18[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;
2627
2678
  url = 'api/v2/sdk/file_list';
2628
2679
 
2629
2680
  if (this.isLogin) {
2630
- _context17.next = 4;
2681
+ _context18.next = 4;
2631
2682
  break;
2632
2683
  }
2633
2684
 
2634
- return _context17.abrupt("return", Promise.reject('You need to login to use this method'));
2685
+ return _context18.abrupt("return", Promise.reject('You need to login to use this method'));
2635
2686
 
2636
2687
  case 4:
2637
2688
  // intended to check for undefined, so user can provide user
@@ -2656,16 +2707,16 @@ var QiscusSDK = /*#__PURE__*/function () {
2656
2707
  exclude_extensions: excludeExtensions
2657
2708
  };
2658
2709
  if (sender != null) opts['sender'] = sender;
2659
- return _context17.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
2710
+ return _context18.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
2660
2711
  return res.body;
2661
2712
  }));
2662
2713
 
2663
2714
  case 9:
2664
2715
  case "end":
2665
- return _context17.stop();
2716
+ return _context18.stop();
2666
2717
  }
2667
2718
  }
2668
- }, _callee17, this);
2719
+ }, _callee18, this);
2669
2720
  }));
2670
2721
 
2671
2722
  function getFileList() {
@@ -2797,19 +2848,19 @@ var QiscusSDK = /*#__PURE__*/function () {
2797
2848
  }, {
2798
2849
  key: "updateMessage",
2799
2850
  value: function () {
2800
- var _updateMessage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee18(message) {
2801
- return _regenerator["default"].wrap(function _callee18$(_context18) {
2851
+ var _updateMessage = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19(message) {
2852
+ return _regenerator["default"].wrap(function _callee19$(_context19) {
2802
2853
  while (1) {
2803
- switch (_context18.prev = _context18.next) {
2854
+ switch (_context19.prev = _context19.next) {
2804
2855
  case 0:
2805
- return _context18.abrupt("return", this.userAdapter.updateMessage(message));
2856
+ return _context19.abrupt("return", this.userAdapter.updateMessage(message));
2806
2857
 
2807
2858
  case 1:
2808
2859
  case "end":
2809
- return _context18.stop();
2860
+ return _context19.stop();
2810
2861
  }
2811
2862
  }
2812
- }, _callee18, this);
2863
+ }, _callee19, this);
2813
2864
  }));
2814
2865
 
2815
2866
  function updateMessage(_x16) {
@@ -2821,11 +2872,11 @@ var QiscusSDK = /*#__PURE__*/function () {
2821
2872
  }, {
2822
2873
  key: "onMessageUpdated",
2823
2874
  value: function onMessageUpdated(handler) {
2824
- var _this19 = this;
2875
+ var _this18 = this;
2825
2876
 
2826
2877
  this.realtimeAdapter.on('message:updated', handler);
2827
2878
  return function () {
2828
- return _this19.realtimeAdapter.off('message:updated', handler);
2879
+ return _this18.realtimeAdapter.off('message:updated', handler);
2829
2880
  };
2830
2881
  }
2831
2882
  /**
@@ -2836,19 +2887,19 @@ var QiscusSDK = /*#__PURE__*/function () {
2836
2887
  }, {
2837
2888
  key: "closeRealtimeConnection",
2838
2889
  value: function () {
2839
- var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee19() {
2840
- return _regenerator["default"].wrap(function _callee19$(_context19) {
2890
+ var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20() {
2891
+ return _regenerator["default"].wrap(function _callee20$(_context20) {
2841
2892
  while (1) {
2842
- switch (_context19.prev = _context19.next) {
2893
+ switch (_context20.prev = _context20.next) {
2843
2894
  case 0:
2844
- return _context19.abrupt("return", this.realtimeAdapter.closeConnection());
2895
+ return _context20.abrupt("return", this.realtimeAdapter.closeConnection());
2845
2896
 
2846
2897
  case 1:
2847
2898
  case "end":
2848
- return _context19.stop();
2899
+ return _context20.stop();
2849
2900
  }
2850
2901
  }
2851
- }, _callee19, this);
2902
+ }, _callee20, this);
2852
2903
  }));
2853
2904
 
2854
2905
  function closeRealtimeConnection() {
@@ -2865,19 +2916,19 @@ var QiscusSDK = /*#__PURE__*/function () {
2865
2916
  }, {
2866
2917
  key: "openRealtimeConnection",
2867
2918
  value: function () {
2868
- var _openRealtimeConnection = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee20() {
2869
- return _regenerator["default"].wrap(function _callee20$(_context20) {
2919
+ var _openRealtimeConnection = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee21() {
2920
+ return _regenerator["default"].wrap(function _callee21$(_context21) {
2870
2921
  while (1) {
2871
- switch (_context20.prev = _context20.next) {
2922
+ switch (_context21.prev = _context21.next) {
2872
2923
  case 0:
2873
- return _context20.abrupt("return", this.realtimeAdapter.openConnection());
2924
+ return _context21.abrupt("return", this.realtimeAdapter.openConnection());
2874
2925
 
2875
2926
  case 1:
2876
2927
  case "end":
2877
- return _context20.stop();
2928
+ return _context21.stop();
2878
2929
  }
2879
2930
  }
2880
- }, _callee20, this);
2931
+ }, _callee21, this);
2881
2932
  }));
2882
2933
 
2883
2934
  function openRealtimeConnection() {
@@ -2886,6 +2937,54 @@ var QiscusSDK = /*#__PURE__*/function () {
2886
2937
 
2887
2938
  return openRealtimeConnection;
2888
2939
  }()
2940
+ }, {
2941
+ key: "startSync",
2942
+ value: function () {
2943
+ var _startSync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee22() {
2944
+ return _regenerator["default"].wrap(function _callee22$(_context22) {
2945
+ while (1) {
2946
+ switch (_context22.prev = _context22.next) {
2947
+ case 0:
2948
+ this._forceEnableSync = true;
2949
+
2950
+ case 1:
2951
+ case "end":
2952
+ return _context22.stop();
2953
+ }
2954
+ }
2955
+ }, _callee22, this);
2956
+ }));
2957
+
2958
+ function startSync() {
2959
+ return _startSync.apply(this, arguments);
2960
+ }
2961
+
2962
+ return startSync;
2963
+ }()
2964
+ }, {
2965
+ key: "stopSync",
2966
+ value: function () {
2967
+ var _stopSync = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee23() {
2968
+ return _regenerator["default"].wrap(function _callee23$(_context23) {
2969
+ while (1) {
2970
+ switch (_context23.prev = _context23.next) {
2971
+ case 0:
2972
+ this._forceEnableSync = false;
2973
+
2974
+ case 1:
2975
+ case "end":
2976
+ return _context23.stop();
2977
+ }
2978
+ }
2979
+ }, _callee23, this);
2980
+ }));
2981
+
2982
+ function stopSync() {
2983
+ return _stopSync.apply(this, arguments);
2984
+ }
2985
+
2986
+ return stopSync;
2987
+ }()
2889
2988
  }, {
2890
2989
  key: "uploadURL",
2891
2990
  get: function get() {