qiscus-sdk-core 2.11.1 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/qiscus-sdk-core.min.js +6 -4
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +107 -65
- package/lib/lib/adapters/auth.js +38 -2
- package/lib/lib/adapters/http.js +68 -11
- package/lib/lib/adapters/mqtt.js +2 -1
- package/package.json +18 -19
package/lib/index.js
CHANGED
|
@@ -173,7 +173,8 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
173
173
|
*/
|
|
174
174
|
value: function () {
|
|
175
175
|
var _init = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(config) {
|
|
176
|
-
var _this2 = this
|
|
176
|
+
var _this2 = this,
|
|
177
|
+
_config$withConfig;
|
|
177
178
|
|
|
178
179
|
var isDifferentBaseUrl, isDifferentMqttUrl, isDifferentBrokerLbUrl, setterHelper, mqttWssCheck;
|
|
179
180
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
@@ -284,7 +285,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
284
285
|
}
|
|
285
286
|
};
|
|
286
287
|
|
|
287
|
-
|
|
288
|
+
this.withConfig = (_config$withConfig = config.withConfig) !== null && _config$withConfig !== void 0 ? _config$withConfig : true;
|
|
289
|
+
|
|
290
|
+
if (!(this.withConfig === true)) {
|
|
291
|
+
_context3.next = 32;
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
_context3.next = 30;
|
|
288
296
|
return this.HTTPAdapter.get_request('api/v2/sdk/config').then(function (resp) {
|
|
289
297
|
resp.status == 200 ? _this2.isConfigLoaded = true : _this2.isConfigLoaded = false;
|
|
290
298
|
return resp.body.results;
|
|
@@ -323,7 +331,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
323
331
|
_this2.isConfigLoaded = true;
|
|
324
332
|
});
|
|
325
333
|
|
|
326
|
-
case
|
|
334
|
+
case 30:
|
|
335
|
+
_context3.next = 33;
|
|
336
|
+
break;
|
|
337
|
+
|
|
338
|
+
case 32:
|
|
339
|
+
this.isConfigLoaded = true;
|
|
340
|
+
|
|
341
|
+
case 33:
|
|
327
342
|
// set Event Listeners
|
|
328
343
|
this._getMqttClientId = function () {
|
|
329
344
|
return "".concat(_this2.AppId, "_").concat(_this2.user_id, "_").concat(Date.now());
|
|
@@ -499,7 +514,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
499
514
|
this.customEventAdapter = (0, _customEvent["default"])(this.realtimeAdapter, this.user_id);
|
|
500
515
|
this.setEventListeners();
|
|
501
516
|
|
|
502
|
-
case
|
|
517
|
+
case 54:
|
|
503
518
|
case "end":
|
|
504
519
|
return _context3.stop();
|
|
505
520
|
}
|
|
@@ -573,6 +588,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
573
588
|
var _this3 = this;
|
|
574
589
|
|
|
575
590
|
var self = this;
|
|
591
|
+
this.authAdapter = new _auth["default"](self.HTTPAdapter);
|
|
592
|
+
|
|
593
|
+
if (this.userData.email != null) {
|
|
594
|
+
this.authAdapter.userId = this.userData.email;
|
|
595
|
+
}
|
|
596
|
+
|
|
576
597
|
self.events.on('start-init', function () {
|
|
577
598
|
self.HTTPAdapter = new _http["default"]({
|
|
578
599
|
baseURL: self.baseURL,
|
|
@@ -584,7 +605,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
584
605
|
}
|
|
585
606
|
});
|
|
586
607
|
self.HTTPAdapter.setToken(self.userData.token);
|
|
587
|
-
self.authAdapter = new _auth["default"](self.HTTPAdapter);
|
|
588
608
|
});
|
|
589
609
|
self.events.on('room-changed', function (room) {
|
|
590
610
|
_this3.logging('room changed', room);
|
|
@@ -709,6 +729,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
709
729
|
if (_this3.options.loginSuccessCallback) {
|
|
710
730
|
_this3.options.loginSuccessCallback(response);
|
|
711
731
|
}
|
|
732
|
+
|
|
733
|
+
_this3.authAdapter.userId = _this3.userData.email;
|
|
734
|
+
_this3.authAdapter.refreshToken = _this3.userData.refresh_token;
|
|
712
735
|
});
|
|
713
736
|
/**
|
|
714
737
|
* Called when there's something wrong when connecting to qiscus SDK
|
|
@@ -952,6 +975,8 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
952
975
|
self.events.emit('start-init');
|
|
953
976
|
return self.authAdapter.loginOrRegister(params).then(function (response) {
|
|
954
977
|
self.isInit = true;
|
|
978
|
+
console.log('response', response);
|
|
979
|
+
self.refresh_token = response.user.refresh_token;
|
|
955
980
|
self.events.emit('login-success', response);
|
|
956
981
|
|
|
957
982
|
_this4.realtimeAdapter.connect();
|
|
@@ -991,20 +1016,37 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
991
1016
|
}
|
|
992
1017
|
}, 300);
|
|
993
1018
|
}
|
|
1019
|
+
}, {
|
|
1020
|
+
key: "refreshAuthToken",
|
|
1021
|
+
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();
|
|
1035
|
+
}
|
|
994
1036
|
}, {
|
|
995
1037
|
key: "publishOnlinePresence",
|
|
996
1038
|
value: function publishOnlinePresence(val) {
|
|
997
|
-
var
|
|
1039
|
+
var _this7 = this;
|
|
998
1040
|
|
|
999
1041
|
if (val === true) {
|
|
1000
1042
|
setBackToOnline = setInterval(function () {
|
|
1001
|
-
|
|
1043
|
+
_this7.realtimeAdapter.publishPresence(_this7.user_id, true);
|
|
1002
1044
|
}, 3500);
|
|
1003
1045
|
} else {
|
|
1004
1046
|
clearInterval(this.presensePublisherId);
|
|
1005
1047
|
clearInterval(setBackToOnline);
|
|
1006
1048
|
setTimeout(function () {
|
|
1007
|
-
|
|
1049
|
+
_this7.realtimeAdapter.publishPresence(_this7.user_id, false);
|
|
1008
1050
|
}, 3500);
|
|
1009
1051
|
}
|
|
1010
1052
|
}
|
|
@@ -1037,7 +1079,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1037
1079
|
}, {
|
|
1038
1080
|
key: "setActiveRoom",
|
|
1039
1081
|
value: function setActiveRoom(room) {
|
|
1040
|
-
var
|
|
1082
|
+
var _this8 = this;
|
|
1041
1083
|
|
|
1042
1084
|
// when we activate a room
|
|
1043
1085
|
// we need to unsubscribe from typing event
|
|
@@ -1047,7 +1089,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1047
1089
|
|
|
1048
1090
|
if (this.selected.room_type === 'single') {
|
|
1049
1091
|
var unsubscribedUserId = this.selected.participants.filter(function (p) {
|
|
1050
|
-
return p.email !==
|
|
1092
|
+
return p.email !== _this8.user_id;
|
|
1051
1093
|
});
|
|
1052
1094
|
|
|
1053
1095
|
if (unsubscribedUserId.length > 0) {
|
|
@@ -1058,7 +1100,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1058
1100
|
|
|
1059
1101
|
if (room.participants == null) room.participants = [];
|
|
1060
1102
|
var targetUserId = room.participants.find(function (p) {
|
|
1061
|
-
return p.email !==
|
|
1103
|
+
return p.email !== _this8.user_id;
|
|
1062
1104
|
});
|
|
1063
1105
|
this.chatmateStatus = null;
|
|
1064
1106
|
this.isTypingStatus = null;
|
|
@@ -1067,35 +1109,35 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1067
1109
|
|
|
1068
1110
|
var initialSubscribe = setInterval(function () {
|
|
1069
1111
|
// Clear Interval when realtimeAdapter has been Populated
|
|
1070
|
-
if (
|
|
1071
|
-
|
|
1112
|
+
if (_this8.debugMode) {
|
|
1113
|
+
_this8.logger('Trying Initial Subscribe');
|
|
1072
1114
|
}
|
|
1073
1115
|
|
|
1074
|
-
if (
|
|
1075
|
-
if (
|
|
1076
|
-
|
|
1116
|
+
if (_this8.realtimeAdapter != null) {
|
|
1117
|
+
if (_this8.debugMode) {
|
|
1118
|
+
_this8.logger('MQTT Connected');
|
|
1077
1119
|
}
|
|
1078
1120
|
|
|
1079
1121
|
clearInterval(initialSubscribe); // before we unsubscribe, we need to get the userId first
|
|
1080
1122
|
// and only unsubscribe if the previous room is having a type of 'single'
|
|
1081
1123
|
|
|
1082
1124
|
if (room.room_type === 'single' && targetUserId != null) {
|
|
1083
|
-
|
|
1125
|
+
_this8.realtimeAdapter.subscribeRoomPresence(targetUserId.email);
|
|
1084
1126
|
} // we need to subscribe to new room typing event now
|
|
1085
1127
|
|
|
1086
1128
|
|
|
1087
|
-
if (
|
|
1088
|
-
|
|
1129
|
+
if (_this8.selected != null && !_this8.selected.isChannel) {
|
|
1130
|
+
_this8.realtimeAdapter.subscribeTyping(room.id);
|
|
1089
1131
|
|
|
1090
|
-
|
|
1132
|
+
_this8.events.emit('room-changed', _this8.selected);
|
|
1091
1133
|
}
|
|
1092
1134
|
|
|
1093
|
-
if (
|
|
1094
|
-
|
|
1135
|
+
if (_this8.debugMode && _this8.realtimeAdapter == null) {
|
|
1136
|
+
_this8.logger('Retry');
|
|
1095
1137
|
}
|
|
1096
1138
|
} else {
|
|
1097
|
-
if (
|
|
1098
|
-
|
|
1139
|
+
if (_this8.debugMode) {
|
|
1140
|
+
_this8.logger('MQTT Not Connected, yet');
|
|
1099
1141
|
}
|
|
1100
1142
|
}
|
|
1101
1143
|
}, 3000);
|
|
@@ -1110,7 +1152,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1110
1152
|
}, {
|
|
1111
1153
|
key: "chatTarget",
|
|
1112
1154
|
value: function chatTarget(userId) {
|
|
1113
|
-
var
|
|
1155
|
+
var _this9 = this;
|
|
1114
1156
|
|
|
1115
1157
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1116
1158
|
// make sure data already loaded first (user already logged in)
|
|
@@ -1129,9 +1171,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1129
1171
|
case 0:
|
|
1130
1172
|
room = new _Room["default"](resp);
|
|
1131
1173
|
|
|
1132
|
-
|
|
1174
|
+
_this9.updateLastReceivedComment(room.last_comment_id);
|
|
1133
1175
|
|
|
1134
|
-
|
|
1176
|
+
_this9.isLoading = false;
|
|
1135
1177
|
|
|
1136
1178
|
mapIntercept = /*#__PURE__*/function () {
|
|
1137
1179
|
var _ref7 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(it) {
|
|
@@ -1140,7 +1182,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1140
1182
|
switch (_context4.prev = _context4.next) {
|
|
1141
1183
|
case 0:
|
|
1142
1184
|
_context4.next = 2;
|
|
1143
|
-
return
|
|
1185
|
+
return _this9._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, it);
|
|
1144
1186
|
|
|
1145
1187
|
case 2:
|
|
1146
1188
|
return _context4.abrupt("return", _context4.sent);
|
|
@@ -1166,13 +1208,13 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1166
1208
|
case 6:
|
|
1167
1209
|
room.comments = _context5.sent;
|
|
1168
1210
|
|
|
1169
|
-
|
|
1211
|
+
_this9.setActiveRoom(room); // id of last comment on this room
|
|
1170
1212
|
|
|
1171
1213
|
|
|
1172
1214
|
lastComment = room.comments[room.comments.length - 1];
|
|
1173
|
-
if (lastComment)
|
|
1215
|
+
if (lastComment) _this9.readComment(room.id, lastComment.id);
|
|
1174
1216
|
|
|
1175
|
-
|
|
1217
|
+
_this9.events.emit('chat-room-created', {
|
|
1176
1218
|
room: room
|
|
1177
1219
|
});
|
|
1178
1220
|
|
|
@@ -1185,7 +1227,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1185
1227
|
|
|
1186
1228
|
case 13:
|
|
1187
1229
|
topicId = room.id;
|
|
1188
|
-
return _context5.abrupt("return",
|
|
1230
|
+
return _context5.abrupt("return", _this9.sendComment(topicId, initialMessage).then(function () {
|
|
1189
1231
|
return Promise.resolve(room);
|
|
1190
1232
|
})["catch"](function (err) {
|
|
1191
1233
|
console.error('Error when submit comment', err);
|
|
@@ -1204,7 +1246,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1204
1246
|
};
|
|
1205
1247
|
}())["catch"](function (err) {
|
|
1206
1248
|
console.error('Error when creating room', err);
|
|
1207
|
-
|
|
1249
|
+
_this9.isLoading = false;
|
|
1208
1250
|
return Promise.reject(err);
|
|
1209
1251
|
});
|
|
1210
1252
|
}
|
|
@@ -1236,7 +1278,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1236
1278
|
}, {
|
|
1237
1279
|
key: "getRoomById",
|
|
1238
1280
|
value: function getRoomById(id) {
|
|
1239
|
-
var
|
|
1281
|
+
var _this10 = this;
|
|
1240
1282
|
|
|
1241
1283
|
if (!this.isInit) return;
|
|
1242
1284
|
var self = this;
|
|
@@ -1265,7 +1307,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1265
1307
|
|
|
1266
1308
|
comment = _step.value;
|
|
1267
1309
|
_context6.next = 9;
|
|
1268
|
-
return
|
|
1310
|
+
return _this10._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
|
|
1269
1311
|
|
|
1270
1312
|
case 9:
|
|
1271
1313
|
c = _context6.sent;
|
|
@@ -1308,7 +1350,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1308
1350
|
if (lastComment) self.readComment(room.id, lastComment.id);
|
|
1309
1351
|
|
|
1310
1352
|
if (room.isChannel) {
|
|
1311
|
-
|
|
1353
|
+
_this10.realtimeAdapter.subscribeChannel(_this10.AppId, room.unique_id);
|
|
1312
1354
|
}
|
|
1313
1355
|
|
|
1314
1356
|
return _context6.abrupt("return", room);
|
|
@@ -1339,7 +1381,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1339
1381
|
}, {
|
|
1340
1382
|
key: "getOrCreateRoomByUniqueId",
|
|
1341
1383
|
value: function getOrCreateRoomByUniqueId(id, roomName, avatarURL) {
|
|
1342
|
-
var
|
|
1384
|
+
var _this11 = this;
|
|
1343
1385
|
|
|
1344
1386
|
var self = this;
|
|
1345
1387
|
self.isLoading = true;
|
|
@@ -1362,7 +1404,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1362
1404
|
switch (_context7.prev = _context7.next) {
|
|
1363
1405
|
case 0:
|
|
1364
1406
|
_context7.next = 2;
|
|
1365
|
-
return
|
|
1407
|
+
return _this11._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, item);
|
|
1366
1408
|
|
|
1367
1409
|
case 2:
|
|
1368
1410
|
return _context7.abrupt("return", _context7.sent);
|
|
@@ -1392,7 +1434,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1392
1434
|
lastComment = room.comments[room.comments.length - 1];
|
|
1393
1435
|
if (lastComment) self.readComment(room.id, lastComment.id);
|
|
1394
1436
|
|
|
1395
|
-
|
|
1437
|
+
_this11.realtimeAdapter.subscribeChannel(_this11.AppId, room.unique_id);
|
|
1396
1438
|
|
|
1397
1439
|
return _context8.abrupt("return", Promise.resolve(room));
|
|
1398
1440
|
|
|
@@ -1467,7 +1509,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1467
1509
|
}, {
|
|
1468
1510
|
key: "loadComments",
|
|
1469
1511
|
value: function loadComments(roomId) {
|
|
1470
|
-
var
|
|
1512
|
+
var _this12 = this;
|
|
1471
1513
|
|
|
1472
1514
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1473
1515
|
return this.userAdapter.loadComments(roomId, options).then( /*#__PURE__*/function () {
|
|
@@ -1493,7 +1535,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1493
1535
|
comment = _step2.value;
|
|
1494
1536
|
_context10.t0 = comments;
|
|
1495
1537
|
_context10.next = 9;
|
|
1496
|
-
return
|
|
1538
|
+
return _this12._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
|
|
1497
1539
|
|
|
1498
1540
|
case 9:
|
|
1499
1541
|
_context10.t1 = _context10.sent;
|
|
@@ -1522,10 +1564,10 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1522
1564
|
return _context10.finish(18);
|
|
1523
1565
|
|
|
1524
1566
|
case 21:
|
|
1525
|
-
if (
|
|
1526
|
-
|
|
1567
|
+
if (_this12.selected != null) {
|
|
1568
|
+
_this12.selected.receiveComments(comments.reverse());
|
|
1527
1569
|
|
|
1528
|
-
|
|
1570
|
+
_this12.sortComments();
|
|
1529
1571
|
}
|
|
1530
1572
|
|
|
1531
1573
|
return _context10.abrupt("return", comments);
|
|
@@ -1673,15 +1715,15 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1673
1715
|
}, {
|
|
1674
1716
|
key: "updateProfile",
|
|
1675
1717
|
value: function updateProfile(user) {
|
|
1676
|
-
var
|
|
1718
|
+
var _this13 = this;
|
|
1677
1719
|
|
|
1678
1720
|
return this.userAdapter.updateProfile(user).then(function (res) {
|
|
1679
|
-
|
|
1721
|
+
_this13.events.emit('profile-updated', user);
|
|
1680
1722
|
|
|
1681
|
-
|
|
1723
|
+
_this13.userData = res;
|
|
1682
1724
|
return Promise.resolve(res);
|
|
1683
1725
|
}, function (err) {
|
|
1684
|
-
return
|
|
1726
|
+
return _this13.logger(err);
|
|
1685
1727
|
});
|
|
1686
1728
|
}
|
|
1687
1729
|
}, {
|
|
@@ -1724,7 +1766,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1724
1766
|
key: "sendComment",
|
|
1725
1767
|
value: function () {
|
|
1726
1768
|
var _sendComment = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee15(topicId, commentMessage, uniqueId) {
|
|
1727
|
-
var
|
|
1769
|
+
var _this14 = this;
|
|
1728
1770
|
|
|
1729
1771
|
var type,
|
|
1730
1772
|
payload,
|
|
@@ -1768,14 +1810,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1768
1810
|
username_real: this.user_id,
|
|
1769
1811
|
user_avatar_url: this.userData.avatar_url,
|
|
1770
1812
|
user_extras: this.userData.user_extras,
|
|
1771
|
-
id: Math.round(
|
|
1813
|
+
id: Math.round(Date.now() * 1e6 + Date.now()),
|
|
1772
1814
|
type: type || 'text',
|
|
1773
1815
|
timestamp: (0, _format["default"])(new Date()),
|
|
1774
1816
|
unique_id: uniqueId ? String(uniqueId) : null,
|
|
1775
1817
|
payload: (0, _util.tryCatch)(function () {
|
|
1776
1818
|
return JSON.parse(payload);
|
|
1777
1819
|
}, payload, function (error) {
|
|
1778
|
-
return
|
|
1820
|
+
return _this14.logger('Error when parsing payload', error.message);
|
|
1779
1821
|
})
|
|
1780
1822
|
};
|
|
1781
1823
|
pendingComment = self.prepareCommentToBeSubmitted(commentData); // push this comment unto active room
|
|
@@ -1809,7 +1851,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1809
1851
|
switch (_context14.prev = _context14.next) {
|
|
1810
1852
|
case 0:
|
|
1811
1853
|
_context14.next = 2;
|
|
1812
|
-
return
|
|
1854
|
+
return _this14._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
|
|
1813
1855
|
|
|
1814
1856
|
case 2:
|
|
1815
1857
|
res = _context14.sent;
|
|
@@ -2051,14 +2093,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2051
2093
|
}, {
|
|
2052
2094
|
key: "removeParticipantsFromGroup",
|
|
2053
2095
|
value: function removeParticipantsFromGroup(roomId, emails) {
|
|
2054
|
-
var
|
|
2096
|
+
var _this15 = this;
|
|
2055
2097
|
|
|
2056
2098
|
if (_is_js["default"].not.array(emails)) {
|
|
2057
2099
|
return Promise.reject(new Error('`emails` must have type of array'));
|
|
2058
2100
|
}
|
|
2059
2101
|
|
|
2060
2102
|
return this.roomAdapter.removeParticipantsFromGroup(roomId, emails).then(function (res) {
|
|
2061
|
-
|
|
2103
|
+
_this15.events.emit('participants-removed', emails);
|
|
2062
2104
|
|
|
2063
2105
|
return Promise.resolve(res);
|
|
2064
2106
|
});
|
|
@@ -2224,14 +2266,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2224
2266
|
}, {
|
|
2225
2267
|
key: "deleteComment",
|
|
2226
2268
|
value: function deleteComment(roomId, commentUniqueIds, isForEveryone, isHard) {
|
|
2227
|
-
var
|
|
2269
|
+
var _this16 = this;
|
|
2228
2270
|
|
|
2229
2271
|
if (!Array.isArray(commentUniqueIds)) {
|
|
2230
2272
|
throw new Error("unique ids' must be type of Array");
|
|
2231
2273
|
}
|
|
2232
2274
|
|
|
2233
2275
|
return this.userAdapter.deleteComment(roomId, commentUniqueIds, isForEveryone, isHard).then(function (res) {
|
|
2234
|
-
|
|
2276
|
+
_this16.events.emit('comment-deleted', {
|
|
2235
2277
|
roomId: roomId,
|
|
2236
2278
|
commentUniqueIds: commentUniqueIds,
|
|
2237
2279
|
isForEveryone: isForEveryone,
|
|
@@ -2246,7 +2288,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2246
2288
|
}, {
|
|
2247
2289
|
key: "clearRoomsCache",
|
|
2248
2290
|
value: function clearRoomsCache() {
|
|
2249
|
-
var
|
|
2291
|
+
var _this17 = this;
|
|
2250
2292
|
|
|
2251
2293
|
// remove all room except currently selected
|
|
2252
2294
|
if (this.selected) {
|
|
@@ -2255,7 +2297,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2255
2297
|
|
|
2256
2298
|
var roomLength = this.rooms.length;
|
|
2257
2299
|
var curIndex = this.rooms.findIndex(function (room) {
|
|
2258
|
-
return room.id ===
|
|
2300
|
+
return room.id === _this17.selected.id;
|
|
2259
2301
|
});
|
|
2260
2302
|
|
|
2261
2303
|
if (!(curIndex + 1 === roomLength)) {
|
|
@@ -2264,7 +2306,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2264
2306
|
|
|
2265
2307
|
|
|
2266
2308
|
curIndex = this.rooms.findIndex(function (room) {
|
|
2267
|
-
return room.id ===
|
|
2309
|
+
return room.id === _this17.selected.id;
|
|
2268
2310
|
});
|
|
2269
2311
|
|
|
2270
2312
|
if (curIndex > 0 && this.rooms.length > 1) {
|
|
@@ -2275,19 +2317,19 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2275
2317
|
}, {
|
|
2276
2318
|
key: "exitChatRoom",
|
|
2277
2319
|
value: function exitChatRoom() {
|
|
2278
|
-
var
|
|
2320
|
+
var _this18 = this;
|
|
2279
2321
|
|
|
2280
2322
|
// remove all subscriber
|
|
2281
2323
|
this.realtimeAdapter.unsubscribeTyping();
|
|
2282
2324
|
(0, _util.tryCatch)(function () {
|
|
2283
|
-
return
|
|
2284
|
-
return it.email !==
|
|
2325
|
+
return _this18.selected.participants.filter(function (it) {
|
|
2326
|
+
return it.email !== _this18.user_id;
|
|
2285
2327
|
}).map(function (it) {
|
|
2286
2328
|
return it.email;
|
|
2287
2329
|
});
|
|
2288
2330
|
}, null, this.noop, function (userIds) {
|
|
2289
2331
|
return userIds.forEach(function (userId) {
|
|
2290
|
-
return
|
|
2332
|
+
return _this18.realtimeAdapter.unsubscribeRoomPresence(userId);
|
|
2291
2333
|
});
|
|
2292
2334
|
});
|
|
2293
2335
|
this.selected = null;
|
|
@@ -2779,11 +2821,11 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2779
2821
|
}, {
|
|
2780
2822
|
key: "onMessageUpdated",
|
|
2781
2823
|
value: function onMessageUpdated(handler) {
|
|
2782
|
-
var
|
|
2824
|
+
var _this19 = this;
|
|
2783
2825
|
|
|
2784
2826
|
this.realtimeAdapter.on('message:updated', handler);
|
|
2785
2827
|
return function () {
|
|
2786
|
-
return
|
|
2828
|
+
return _this19.realtimeAdapter.off('message:updated', handler);
|
|
2787
2829
|
};
|
|
2788
2830
|
}
|
|
2789
2831
|
/**
|
package/lib/lib/adapters/auth.js
CHANGED
|
@@ -21,6 +21,8 @@ var AuthAdapter = /*#__PURE__*/function () {
|
|
|
21
21
|
function AuthAdapter(HTTPAdapter) {
|
|
22
22
|
(0, _classCallCheck2["default"])(this, AuthAdapter);
|
|
23
23
|
this.HTTPAdapter = HTTPAdapter;
|
|
24
|
+
this.refreshToken = null;
|
|
25
|
+
this.userId = null;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
(0, _createClass2["default"])(AuthAdapter, [{
|
|
@@ -33,18 +35,52 @@ var AuthAdapter = /*#__PURE__*/function () {
|
|
|
33
35
|
}, {
|
|
34
36
|
key: "loginOrRegister",
|
|
35
37
|
value: function loginOrRegister(params) {
|
|
38
|
+
var _this = this;
|
|
39
|
+
|
|
36
40
|
return this.HTTPAdapter.post('api/v2/sdk/login_or_register', params).then(function (resp) {
|
|
37
41
|
if (resp.body.status !== 200) return Promise.reject(resp);
|
|
38
|
-
|
|
42
|
+
var result = resp.body.results;
|
|
43
|
+
_this.userId = result.user.email;
|
|
44
|
+
_this.refreshToken = result.user.refresh_token;
|
|
45
|
+
return result;
|
|
39
46
|
});
|
|
40
47
|
}
|
|
41
48
|
}, {
|
|
42
49
|
key: "verifyIdentityToken",
|
|
43
50
|
value: function verifyIdentityToken(token) {
|
|
51
|
+
var _this2 = this;
|
|
52
|
+
|
|
44
53
|
return this.HTTPAdapter.post('api/v2/sdk/auth/verify_identity_token', {
|
|
45
54
|
identity_token: token
|
|
46
55
|
}).then(function (resp) {
|
|
47
|
-
|
|
56
|
+
var result = resp.body.results;
|
|
57
|
+
_this2.userId = result.user.email;
|
|
58
|
+
_this2.refreshToken = result.user.refresh_token;
|
|
59
|
+
return result;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "refreshAuthToken",
|
|
64
|
+
value: function refreshAuthToken() {
|
|
65
|
+
var _this3 = this;
|
|
66
|
+
|
|
67
|
+
return this.HTTPAdapter.post('api/v2/sdk/refresh_user_token', {
|
|
68
|
+
user_id: this.userId,
|
|
69
|
+
refresh_token: this.refreshToken
|
|
70
|
+
}).then(function (r) {
|
|
71
|
+
var res = r.body.results;
|
|
72
|
+
_this3.refreshToken = res.refresh_token;
|
|
73
|
+
_this3.HTTPAdapter.token = res.token;
|
|
74
|
+
return res;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}, {
|
|
78
|
+
key: "expiredAuthToken",
|
|
79
|
+
value: function expiredAuthToken() {
|
|
80
|
+
return this.HTTPAdapter.post("api/v2/sdk/expire_user_token", {
|
|
81
|
+
user_id: this.userId
|
|
82
|
+
}).then(function (r) {
|
|
83
|
+
return r.body.results;
|
|
48
84
|
});
|
|
49
85
|
}
|
|
50
86
|
}]);
|