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