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