qiscus-sdk-core 2.13.2 → 2.14.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 +496 -290
- package/dist/qiscus-sdk-core.js.map +1 -1
- package/dist/qiscus-sdk-core.min.js +3 -3
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +233 -106
- package/lib/lib/adapters/custom-event.js +3 -3
- package/lib/lib/adapters/expired-token.js +45 -60
- package/lib/lib/adapters/http.js +156 -82
- package/lib/lib/adapters/mqtt.js +26 -23
- package/lib/lib/adapters/sync.js +20 -7
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -56,6 +56,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
56
56
|
function QiscusSDK() {
|
|
57
57
|
var _this = this;
|
|
58
58
|
(0, _classCallCheck2["default"])(this, QiscusSDK);
|
|
59
|
+
(0, _defineProperty2["default"])(this, "_pendingComments", []);
|
|
60
|
+
// count of how much does a comment has been retried
|
|
61
|
+
(0, _defineProperty2["default"])(this, "_pendingCommentsCount", {});
|
|
59
62
|
(0, _defineProperty2["default"])(this, "_readComment", function (roomId, commentId) {
|
|
60
63
|
return _this._updateStatus(roomId, commentId);
|
|
61
64
|
});
|
|
@@ -467,9 +470,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
467
470
|
_this2.events.emit('room-cleared', room);
|
|
468
471
|
});
|
|
469
472
|
});
|
|
473
|
+
this.syncAdapter.on('synchronize', function () {
|
|
474
|
+
_this2._pendingComments.forEach(function (m) {
|
|
475
|
+
return _this2._retrySendComment(m);
|
|
476
|
+
});
|
|
477
|
+
});
|
|
470
478
|
this.customEventAdapter = (0, _customEvent["default"])(this.realtimeAdapter, this.user_id);
|
|
471
479
|
this.setEventListeners();
|
|
472
|
-
case
|
|
480
|
+
case 56:
|
|
473
481
|
case "end":
|
|
474
482
|
return _context3.stop();
|
|
475
483
|
}
|
|
@@ -646,6 +654,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
646
654
|
version: _this3.version,
|
|
647
655
|
getCustomHeader: function getCustomHeader() {
|
|
648
656
|
return _this3._customHeader;
|
|
657
|
+
},
|
|
658
|
+
expiredTokenAdapterGetter: function expiredTokenAdapterGetter() {
|
|
659
|
+
return _this3.expiredTokenAdapter;
|
|
649
660
|
}
|
|
650
661
|
});
|
|
651
662
|
_this3.HTTPAdapter.setToken(_this3.userData.token);
|
|
@@ -1610,7 +1621,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1610
1621
|
}, {
|
|
1611
1622
|
key: "sendComment",
|
|
1612
1623
|
value: (function () {
|
|
1613
|
-
var _sendComment = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
1624
|
+
var _sendComment = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee15(topicId, commentMessage, uniqueId) {
|
|
1614
1625
|
var _this13 = this;
|
|
1615
1626
|
var type,
|
|
1616
1627
|
payload,
|
|
@@ -1622,13 +1633,23 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1622
1633
|
repliedMessage,
|
|
1623
1634
|
extrasToBeSubmitted,
|
|
1624
1635
|
messageData,
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1636
|
+
sendComment,
|
|
1637
|
+
_this$options$comment,
|
|
1638
|
+
_this$options,
|
|
1639
|
+
res,
|
|
1640
|
+
commentIndex,
|
|
1641
|
+
_error$message$toLowe,
|
|
1642
|
+
_error$message,
|
|
1643
|
+
whitelistedErrorStatus,
|
|
1644
|
+
message,
|
|
1645
|
+
isOffline,
|
|
1646
|
+
_args15 = arguments;
|
|
1647
|
+
return _regenerator["default"].wrap(function _callee15$(_context15) {
|
|
1648
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
1628
1649
|
case 0:
|
|
1629
|
-
type =
|
|
1630
|
-
payload =
|
|
1631
|
-
extras =
|
|
1650
|
+
type = _args15.length > 3 && _args15[3] !== undefined ? _args15[3] : 'text';
|
|
1651
|
+
payload = _args15.length > 4 ? _args15[4] : undefined;
|
|
1652
|
+
extras = _args15.length > 5 ? _args15[5] : undefined;
|
|
1632
1653
|
self = this; // set extra data, etc
|
|
1633
1654
|
if (self.options.prePostCommentCallback) {
|
|
1634
1655
|
self.options.prePostCommentCallback(commentMessage);
|
|
@@ -1644,6 +1665,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1644
1665
|
}
|
|
1645
1666
|
self.pendingCommentId--;
|
|
1646
1667
|
commentData = {
|
|
1668
|
+
room_id: topicId,
|
|
1647
1669
|
message: commentMessage,
|
|
1648
1670
|
username_as: this.username,
|
|
1649
1671
|
username_real: this.user_id,
|
|
@@ -1672,64 +1694,169 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1672
1694
|
pendingComment.payload = parsedPayload;
|
|
1673
1695
|
}
|
|
1674
1696
|
extrasToBeSubmitted = extras || self.extras;
|
|
1675
|
-
|
|
1697
|
+
_context15.next = 13;
|
|
1676
1698
|
return this._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_SENT, _objectSpread(_objectSpread({}, pendingComment), {}, {
|
|
1677
1699
|
extras: extrasToBeSubmitted
|
|
1678
1700
|
}));
|
|
1679
1701
|
case 13:
|
|
1680
|
-
messageData =
|
|
1702
|
+
messageData = _context15.sent;
|
|
1681
1703
|
messageData = self.prepareCommentToBeSubmitted(messageData);
|
|
1682
1704
|
if (self.selected) self.selected.comments.push(messageData);
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1705
|
+
sendComment = function sendComment() {
|
|
1706
|
+
return _this13.userAdapter.postComment('' + topicId, messageData.message, messageData.unique_id, messageData.type, messageData.payload, messageData.extras);
|
|
1707
|
+
};
|
|
1708
|
+
_context15.prev = 17;
|
|
1709
|
+
_context15.next = 20;
|
|
1710
|
+
return sendComment();
|
|
1711
|
+
case 20:
|
|
1712
|
+
res = _context15.sent;
|
|
1713
|
+
_context15.next = 23;
|
|
1714
|
+
return this._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
|
|
1715
|
+
case 23:
|
|
1716
|
+
res = _context15.sent;
|
|
1717
|
+
Object.assign(messageData, res);
|
|
1718
|
+
if (self.selected) {
|
|
1719
|
+
_context15.next = 27;
|
|
1720
|
+
break;
|
|
1721
|
+
}
|
|
1722
|
+
return _context15.abrupt("return", Promise.resolve(messageData));
|
|
1723
|
+
case 27:
|
|
1724
|
+
// When the posting succeeded, we mark the Comment as sent,
|
|
1725
|
+
// so all the interested party can be notified.
|
|
1726
|
+
messageData.markAsSent();
|
|
1727
|
+
messageData.id = res.id;
|
|
1728
|
+
messageData.before_id = res.comment_before_id;
|
|
1729
|
+
// update the timestamp also then re-sort the comment list
|
|
1730
|
+
messageData.unix_timestamp = res.unix_timestamp;
|
|
1731
|
+
(_this$options$comment = (_this$options = this.options).commentSentCallback) === null || _this$options$comment === void 0 || _this$options$comment.call(_this$options, {
|
|
1732
|
+
comment: messageData
|
|
1733
|
+
});
|
|
1734
|
+
self.events.emit('comment-sent', messageData);
|
|
1735
|
+
self.sortComments();
|
|
1736
|
+
commentIndex = self._pendingComments.findIndex(function (c) {
|
|
1737
|
+
return c.unique_id === messageData.unique_id;
|
|
1738
|
+
});
|
|
1739
|
+
if (commentIndex > -1) {
|
|
1740
|
+
self._pendingComments.splice(commentIndex, 1);
|
|
1741
|
+
}
|
|
1742
|
+
return _context15.abrupt("return", messageData);
|
|
1743
|
+
case 39:
|
|
1744
|
+
_context15.prev = 39;
|
|
1745
|
+
_context15.t0 = _context15["catch"](17);
|
|
1746
|
+
messageData.markAsFailed();
|
|
1747
|
+
// From superagent: `https://forwardemail.github.io/superagent/#retrying-requests`
|
|
1748
|
+
whitelistedErrorStatus = [undefined, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524];
|
|
1749
|
+
message = (_error$message$toLowe = (_error$message = _context15.t0.message) === null || _error$message === void 0 ? void 0 : _error$message.toLowerCase()) !== null && _error$message$toLowe !== void 0 ? _error$message$toLowe : '';
|
|
1750
|
+
isOffline = message.includes('offline');
|
|
1751
|
+
if (whitelistedErrorStatus.includes(_context15.t0.status) || isOffline) {
|
|
1752
|
+
this._pendingComments.push(messageData);
|
|
1753
|
+
this.logger('Failed sending comment', _context15.t0);
|
|
1754
|
+
}
|
|
1755
|
+
return _context15.abrupt("return", Promise.reject(_context15.t0));
|
|
1756
|
+
case 47:
|
|
1757
|
+
case "end":
|
|
1758
|
+
return _context15.stop();
|
|
1759
|
+
}
|
|
1760
|
+
}, _callee15, this, [[17, 39]]);
|
|
1761
|
+
}));
|
|
1762
|
+
function sendComment(_x12, _x13, _x14) {
|
|
1763
|
+
return _sendComment.apply(this, arguments);
|
|
1764
|
+
}
|
|
1765
|
+
return sendComment;
|
|
1766
|
+
}())
|
|
1767
|
+
}, {
|
|
1768
|
+
key: "_retrySendComment",
|
|
1769
|
+
value: function () {
|
|
1770
|
+
var _retrySendComment2 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee17(comment) {
|
|
1771
|
+
var _this$_pendingComment,
|
|
1772
|
+
_this14 = this;
|
|
1773
|
+
var _this$options$comment2, _this$options2, index;
|
|
1774
|
+
return _regenerator["default"].wrap(function _callee17$(_context17) {
|
|
1775
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
1776
|
+
case 0:
|
|
1777
|
+
this.logger('Retrying send comment', comment);
|
|
1778
|
+
this._pendingCommentsCount[comment.unique_id] = ((_this$_pendingComment = this._pendingCommentsCount[comment.unique_id]) !== null && _this$_pendingComment !== void 0 ? _this$_pendingComment : 0) + 1;
|
|
1779
|
+
|
|
1780
|
+
// If it is exceeding the maximum retry count (which is 10), we will not retry anymore
|
|
1781
|
+
if (!(this._pendingCommentsCount[comment.unique_id] > 10)) {
|
|
1782
|
+
_context17.next = 10;
|
|
1783
|
+
break;
|
|
1784
|
+
}
|
|
1785
|
+
this.logger("Exceeding maximum retry count for comment ".concat(comment.unique_id, ", not retrying anymore"));
|
|
1786
|
+
(_this$options$comment2 = (_this$options2 = this.options).commentRetryExceedCallback) === null || _this$options$comment2 === void 0 || _this$options$comment2.call(_this$options2, comment);
|
|
1787
|
+
// Remove the comment from pending comments
|
|
1788
|
+
index = this._pendingComments.findIndex(function (c) {
|
|
1789
|
+
return c.unique_id === comment.unique_id;
|
|
1790
|
+
});
|
|
1791
|
+
if (index > -1) {
|
|
1792
|
+
this._pendingComments.splice(index, 1);
|
|
1793
|
+
}
|
|
1794
|
+
// Mark the comment as failed
|
|
1795
|
+
comment.markAsFailed();
|
|
1796
|
+
// Emit the event
|
|
1797
|
+
this.events.emit('comment-retry-exceed', comment);
|
|
1798
|
+
return _context17.abrupt("return", Promise.reject(new Error('Exceeding maximum retry count')));
|
|
1799
|
+
case 10:
|
|
1800
|
+
return _context17.abrupt("return", this.userAdapter.postComment('' + comment.room_id, comment.message, comment.unique_id, comment.type, comment.payload, comment.extras).then(/*#__PURE__*/function () {
|
|
1801
|
+
var _ref12 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16(res) {
|
|
1802
|
+
var _this14$selected, _this14$selected2, _this14$options$comme, _this14$options;
|
|
1803
|
+
var index, commentIndex;
|
|
1804
|
+
return _regenerator["default"].wrap(function _callee16$(_context16) {
|
|
1805
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
1687
1806
|
case 0:
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
case 2:
|
|
1691
|
-
res = _context15.sent;
|
|
1692
|
-
Object.assign(messageData, res);
|
|
1693
|
-
if (self.selected) {
|
|
1694
|
-
_context15.next = 6;
|
|
1807
|
+
if (!(((_this14$selected = _this14.selected) === null || _this14$selected === void 0 ? void 0 : _this14$selected.id) !== comment.room_id)) {
|
|
1808
|
+
_context16.next = 2;
|
|
1695
1809
|
break;
|
|
1696
1810
|
}
|
|
1697
|
-
return
|
|
1698
|
-
case
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1811
|
+
return _context16.abrupt("return", res);
|
|
1812
|
+
case 2:
|
|
1813
|
+
Object.assign(comment, res);
|
|
1814
|
+
comment.markAsSent();
|
|
1815
|
+
comment.id = res.id;
|
|
1816
|
+
comment.before_id = res.comment_before_id;
|
|
1817
|
+
comment.unix_timestamp = res.unix_timestamp;
|
|
1818
|
+
index = (_this14$selected2 = _this14.selected) === null || _this14$selected2 === void 0 ? void 0 : _this14$selected2.comments.findIndex(function (c) {
|
|
1819
|
+
return c.unique_id === comment.unique_id;
|
|
1820
|
+
});
|
|
1821
|
+
if (index > -1) {
|
|
1822
|
+
_this14.selected.comments[index] = comment;
|
|
1823
|
+
}
|
|
1824
|
+
_this14.sortComments();
|
|
1825
|
+
(_this14$options$comme = (_this14$options = _this14.options).commentSentCallback) === null || _this14$options$comme === void 0 || _this14$options$comme.call(_this14$options, {
|
|
1826
|
+
comment: comment
|
|
1827
|
+
});
|
|
1828
|
+
_this14.events.emit('comment-sent', comment);
|
|
1829
|
+
commentIndex = _this14._pendingComments.findIndex(function (c) {
|
|
1830
|
+
return c.unique_id === comment.unique_id;
|
|
1831
|
+
});
|
|
1832
|
+
if (commentIndex > -1) {
|
|
1833
|
+
_this14._pendingComments.splice(commentIndex, 1);
|
|
1834
|
+
}
|
|
1835
|
+
return _context16.abrupt("return", comment);
|
|
1836
|
+
case 15:
|
|
1709
1837
|
case "end":
|
|
1710
|
-
return
|
|
1838
|
+
return _context16.stop();
|
|
1711
1839
|
}
|
|
1712
|
-
},
|
|
1840
|
+
}, _callee16);
|
|
1713
1841
|
}));
|
|
1714
|
-
return function (
|
|
1842
|
+
return function (_x16) {
|
|
1715
1843
|
return _ref12.apply(this, arguments);
|
|
1716
1844
|
};
|
|
1717
1845
|
}())["catch"](function (err) {
|
|
1718
|
-
|
|
1846
|
+
comment.markAsFailed();
|
|
1719
1847
|
return Promise.reject(err);
|
|
1720
1848
|
}));
|
|
1721
|
-
case
|
|
1849
|
+
case 11:
|
|
1722
1850
|
case "end":
|
|
1723
|
-
return
|
|
1851
|
+
return _context17.stop();
|
|
1724
1852
|
}
|
|
1725
|
-
},
|
|
1853
|
+
}, _callee17, this);
|
|
1726
1854
|
}));
|
|
1727
|
-
function
|
|
1728
|
-
return
|
|
1855
|
+
function _retrySendComment(_x15) {
|
|
1856
|
+
return _retrySendComment2.apply(this, arguments);
|
|
1729
1857
|
}
|
|
1730
|
-
return
|
|
1858
|
+
return _retrySendComment;
|
|
1731
1859
|
}() // #endregion
|
|
1732
|
-
)
|
|
1733
1860
|
}, {
|
|
1734
1861
|
key: "getUsers",
|
|
1735
1862
|
value: function getUsers() {
|
|
@@ -1907,12 +2034,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1907
2034
|
}, {
|
|
1908
2035
|
key: "removeParticipantsFromGroup",
|
|
1909
2036
|
value: function removeParticipantsFromGroup(roomId, emails) {
|
|
1910
|
-
var
|
|
2037
|
+
var _this15 = this;
|
|
1911
2038
|
if (_is_js["default"].not.array(emails)) {
|
|
1912
2039
|
return Promise.reject(new Error('`emails` must have type of array'));
|
|
1913
2040
|
}
|
|
1914
2041
|
return this.roomAdapter.removeParticipantsFromGroup(roomId, emails).then(function (res) {
|
|
1915
|
-
|
|
2042
|
+
_this15.events.emit('participants-removed', emails);
|
|
1916
2043
|
return Promise.resolve(res);
|
|
1917
2044
|
});
|
|
1918
2045
|
}
|
|
@@ -2075,12 +2202,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2075
2202
|
}, {
|
|
2076
2203
|
key: "deleteComment",
|
|
2077
2204
|
value: function deleteComment(roomId, commentUniqueIds, isForEveryone, isHard) {
|
|
2078
|
-
var
|
|
2205
|
+
var _this16 = this;
|
|
2079
2206
|
if (!Array.isArray(commentUniqueIds)) {
|
|
2080
2207
|
throw new Error("unique ids' must be type of Array");
|
|
2081
2208
|
}
|
|
2082
2209
|
return this.userAdapter.deleteComment(roomId, commentUniqueIds, isForEveryone, isHard).then(function (res) {
|
|
2083
|
-
|
|
2210
|
+
_this16.events.emit('comment-deleted', {
|
|
2084
2211
|
roomId: roomId,
|
|
2085
2212
|
commentUniqueIds: commentUniqueIds,
|
|
2086
2213
|
isForEveryone: isForEveryone,
|
|
@@ -2094,7 +2221,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2094
2221
|
}, {
|
|
2095
2222
|
key: "clearRoomsCache",
|
|
2096
2223
|
value: function clearRoomsCache() {
|
|
2097
|
-
var
|
|
2224
|
+
var _this17 = this;
|
|
2098
2225
|
// remove all room except currently selected
|
|
2099
2226
|
if (this.selected) {
|
|
2100
2227
|
// clear the map
|
|
@@ -2102,14 +2229,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2102
2229
|
// get current index and array length
|
|
2103
2230
|
var roomLength = this.rooms.length;
|
|
2104
2231
|
var curIndex = this.rooms.findIndex(function (room) {
|
|
2105
|
-
return room.id ===
|
|
2232
|
+
return room.id === _this17.selected.id;
|
|
2106
2233
|
});
|
|
2107
2234
|
if (!(curIndex + 1 === roomLength)) {
|
|
2108
2235
|
this.rooms.splice(curIndex + 1, roomLength - (curIndex + 1));
|
|
2109
2236
|
}
|
|
2110
2237
|
// ambil ulang cur index nya, klo udah di awal ga perlu lagi kode dibawah ini
|
|
2111
2238
|
curIndex = this.rooms.findIndex(function (room) {
|
|
2112
|
-
return room.id ===
|
|
2239
|
+
return room.id === _this17.selected.id;
|
|
2113
2240
|
});
|
|
2114
2241
|
if (curIndex > 0 && this.rooms.length > 1) {
|
|
2115
2242
|
this.rooms.splice(1, this.rooms.length - 1);
|
|
@@ -2119,18 +2246,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2119
2246
|
}, {
|
|
2120
2247
|
key: "exitChatRoom",
|
|
2121
2248
|
value: function exitChatRoom() {
|
|
2122
|
-
var
|
|
2249
|
+
var _this18 = this;
|
|
2123
2250
|
// remove all subscriber
|
|
2124
2251
|
this.realtimeAdapter.unsubscribeTyping();
|
|
2125
2252
|
(0, _util.tryCatch)(function () {
|
|
2126
|
-
return
|
|
2127
|
-
return it.email !==
|
|
2253
|
+
return _this18.selected.participants.filter(function (it) {
|
|
2254
|
+
return it.email !== _this18.user_id;
|
|
2128
2255
|
}).map(function (it) {
|
|
2129
2256
|
return it.email;
|
|
2130
2257
|
});
|
|
2131
2258
|
}, null, this.noop, function (userIds) {
|
|
2132
2259
|
return userIds.forEach(function (userId) {
|
|
2133
|
-
return
|
|
2260
|
+
return _this18.realtimeAdapter.unsubscribeRoomPresence(userId);
|
|
2134
2261
|
});
|
|
2135
2262
|
});
|
|
2136
2263
|
this.selected = null;
|
|
@@ -2328,7 +2455,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2328
2455
|
}, {
|
|
2329
2456
|
key: "searchMessage",
|
|
2330
2457
|
value: (function () {
|
|
2331
|
-
var _searchMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2458
|
+
var _searchMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee18() {
|
|
2332
2459
|
var _ref13,
|
|
2333
2460
|
query,
|
|
2334
2461
|
_ref13$roomIds,
|
|
@@ -2341,20 +2468,20 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2341
2468
|
url,
|
|
2342
2469
|
isValidRoomType,
|
|
2343
2470
|
room,
|
|
2344
|
-
|
|
2345
|
-
return _regenerator["default"].wrap(function
|
|
2346
|
-
while (1) switch (
|
|
2471
|
+
_args18 = arguments;
|
|
2472
|
+
return _regenerator["default"].wrap(function _callee18$(_context18) {
|
|
2473
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
2347
2474
|
case 0:
|
|
2348
|
-
_ref13 =
|
|
2475
|
+
_ref13 = _args18.length > 0 && _args18[0] !== undefined ? _args18[0] : {}, query = _ref13.query, _ref13$roomIds = _ref13.roomIds, roomIds = _ref13$roomIds === void 0 ? [] : _ref13$roomIds, userId = _ref13.userId, type = _ref13.type, roomType = _ref13.roomType, page = _ref13.page, limit = _ref13.limit;
|
|
2349
2476
|
url = 'api/v2/sdk/search';
|
|
2350
2477
|
isValidRoomType = ['group', 'single', 'channel'].some(function (it) {
|
|
2351
2478
|
return it === roomType;
|
|
2352
2479
|
});
|
|
2353
2480
|
if (!(roomType != null && !isValidRoomType)) {
|
|
2354
|
-
|
|
2481
|
+
_context18.next = 5;
|
|
2355
2482
|
break;
|
|
2356
2483
|
}
|
|
2357
|
-
return
|
|
2484
|
+
return _context18.abrupt("return", Promise.reject('Invalid room type, valid room type are: `group`, `single`, and `channel`'));
|
|
2358
2485
|
case 5:
|
|
2359
2486
|
room = function (roomType) {
|
|
2360
2487
|
var rType = roomType == null ? undefined : roomType === 'single' ? 'single' : 'group';
|
|
@@ -2364,7 +2491,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2364
2491
|
isPublic: isPublic
|
|
2365
2492
|
};
|
|
2366
2493
|
}(roomType);
|
|
2367
|
-
return
|
|
2494
|
+
return _context18.abrupt("return", this.HTTPAdapter.post_json(url, {
|
|
2368
2495
|
token: this.token,
|
|
2369
2496
|
query: query,
|
|
2370
2497
|
sender: userId,
|
|
@@ -2381,9 +2508,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2381
2508
|
}));
|
|
2382
2509
|
case 7:
|
|
2383
2510
|
case "end":
|
|
2384
|
-
return
|
|
2511
|
+
return _context18.stop();
|
|
2385
2512
|
}
|
|
2386
|
-
},
|
|
2513
|
+
}, _callee18, this);
|
|
2387
2514
|
}));
|
|
2388
2515
|
function searchMessage() {
|
|
2389
2516
|
return _searchMessage.apply(this, arguments);
|
|
@@ -2407,7 +2534,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2407
2534
|
}, {
|
|
2408
2535
|
key: "getFileList",
|
|
2409
2536
|
value: (function () {
|
|
2410
|
-
var _getFileList = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2537
|
+
var _getFileList = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee19() {
|
|
2411
2538
|
var _ref14,
|
|
2412
2539
|
_ref14$roomIds,
|
|
2413
2540
|
roomIds,
|
|
@@ -2420,17 +2547,17 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2420
2547
|
excludeExtensions,
|
|
2421
2548
|
url,
|
|
2422
2549
|
opts,
|
|
2423
|
-
|
|
2424
|
-
return _regenerator["default"].wrap(function
|
|
2425
|
-
while (1) switch (
|
|
2550
|
+
_args19 = arguments;
|
|
2551
|
+
return _regenerator["default"].wrap(function _callee19$(_context19) {
|
|
2552
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
2426
2553
|
case 0:
|
|
2427
|
-
_ref14 =
|
|
2554
|
+
_ref14 = _args19.length > 0 && _args19[0] !== undefined ? _args19[0] : {}, _ref14$roomIds = _ref14.roomIds, roomIds = _ref14$roomIds === void 0 ? [] : _ref14$roomIds, fileType = _ref14.fileType, page = _ref14.page, limit = _ref14.limit, sender = _ref14.sender, userId = _ref14.userId, includeExtensions = _ref14.includeExtensions, excludeExtensions = _ref14.excludeExtensions;
|
|
2428
2555
|
url = 'api/v2/sdk/file_list';
|
|
2429
2556
|
if (this.isLogin) {
|
|
2430
|
-
|
|
2557
|
+
_context19.next = 4;
|
|
2431
2558
|
break;
|
|
2432
2559
|
}
|
|
2433
|
-
return
|
|
2560
|
+
return _context19.abrupt("return", Promise.reject('You need to login to use this method'));
|
|
2434
2561
|
case 4:
|
|
2435
2562
|
// intended to check for undefined, so user can provide user
|
|
2436
2563
|
// with null. If null, backend can determine that we want to
|
|
@@ -2452,14 +2579,14 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2452
2579
|
exclude_extensions: excludeExtensions
|
|
2453
2580
|
};
|
|
2454
2581
|
if (sender != null) opts['sender'] = sender;
|
|
2455
|
-
return
|
|
2582
|
+
return _context19.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
|
|
2456
2583
|
return res.body;
|
|
2457
2584
|
}));
|
|
2458
2585
|
case 9:
|
|
2459
2586
|
case "end":
|
|
2460
|
-
return
|
|
2587
|
+
return _context19.stop();
|
|
2461
2588
|
}
|
|
2462
|
-
},
|
|
2589
|
+
}, _callee19, this);
|
|
2463
2590
|
}));
|
|
2464
2591
|
function getFileList() {
|
|
2465
2592
|
return _getFileList.apply(this, arguments);
|
|
@@ -2589,18 +2716,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2589
2716
|
}, {
|
|
2590
2717
|
key: "updateMessage",
|
|
2591
2718
|
value: function () {
|
|
2592
|
-
var _updateMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2593
|
-
return _regenerator["default"].wrap(function
|
|
2594
|
-
while (1) switch (
|
|
2719
|
+
var _updateMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee20(message) {
|
|
2720
|
+
return _regenerator["default"].wrap(function _callee20$(_context20) {
|
|
2721
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
2595
2722
|
case 0:
|
|
2596
|
-
return
|
|
2723
|
+
return _context20.abrupt("return", this.userAdapter.updateMessage(message));
|
|
2597
2724
|
case 1:
|
|
2598
2725
|
case "end":
|
|
2599
|
-
return
|
|
2726
|
+
return _context20.stop();
|
|
2600
2727
|
}
|
|
2601
|
-
},
|
|
2728
|
+
}, _callee20, this);
|
|
2602
2729
|
}));
|
|
2603
|
-
function updateMessage(
|
|
2730
|
+
function updateMessage(_x17) {
|
|
2604
2731
|
return _updateMessage.apply(this, arguments);
|
|
2605
2732
|
}
|
|
2606
2733
|
return updateMessage;
|
|
@@ -2608,10 +2735,10 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2608
2735
|
}, {
|
|
2609
2736
|
key: "onMessageUpdated",
|
|
2610
2737
|
value: function onMessageUpdated(handler) {
|
|
2611
|
-
var
|
|
2738
|
+
var _this19 = this;
|
|
2612
2739
|
this.realtimeAdapter.on('message:updated', handler);
|
|
2613
2740
|
return function () {
|
|
2614
|
-
return
|
|
2741
|
+
return _this19.realtimeAdapter.off('message:updated', handler);
|
|
2615
2742
|
};
|
|
2616
2743
|
}
|
|
2617
2744
|
|
|
@@ -2622,16 +2749,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2622
2749
|
}, {
|
|
2623
2750
|
key: "closeRealtimeConnection",
|
|
2624
2751
|
value: (function () {
|
|
2625
|
-
var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2626
|
-
return _regenerator["default"].wrap(function
|
|
2627
|
-
while (1) switch (
|
|
2752
|
+
var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee21() {
|
|
2753
|
+
return _regenerator["default"].wrap(function _callee21$(_context21) {
|
|
2754
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
2628
2755
|
case 0:
|
|
2629
|
-
return
|
|
2756
|
+
return _context21.abrupt("return", this.realtimeAdapter.closeConnection());
|
|
2630
2757
|
case 1:
|
|
2631
2758
|
case "end":
|
|
2632
|
-
return
|
|
2759
|
+
return _context21.stop();
|
|
2633
2760
|
}
|
|
2634
|
-
},
|
|
2761
|
+
}, _callee21, this);
|
|
2635
2762
|
}));
|
|
2636
2763
|
function closeRealtimeConnection() {
|
|
2637
2764
|
return _closeRealtimeConnection.apply(this, arguments);
|
|
@@ -2646,16 +2773,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2646
2773
|
}, {
|
|
2647
2774
|
key: "openRealtimeConnection",
|
|
2648
2775
|
value: (function () {
|
|
2649
|
-
var _openRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2650
|
-
return _regenerator["default"].wrap(function
|
|
2651
|
-
while (1) switch (
|
|
2776
|
+
var _openRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee22() {
|
|
2777
|
+
return _regenerator["default"].wrap(function _callee22$(_context22) {
|
|
2778
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
2652
2779
|
case 0:
|
|
2653
|
-
return
|
|
2780
|
+
return _context22.abrupt("return", this.realtimeAdapter.openConnection());
|
|
2654
2781
|
case 1:
|
|
2655
2782
|
case "end":
|
|
2656
|
-
return
|
|
2783
|
+
return _context22.stop();
|
|
2657
2784
|
}
|
|
2658
|
-
},
|
|
2785
|
+
}, _callee22, this);
|
|
2659
2786
|
}));
|
|
2660
2787
|
function openRealtimeConnection() {
|
|
2661
2788
|
return _openRealtimeConnection.apply(this, arguments);
|
|
@@ -2665,16 +2792,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2665
2792
|
}, {
|
|
2666
2793
|
key: "startSync",
|
|
2667
2794
|
value: function () {
|
|
2668
|
-
var _startSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2669
|
-
return _regenerator["default"].wrap(function
|
|
2670
|
-
while (1) switch (
|
|
2795
|
+
var _startSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee23() {
|
|
2796
|
+
return _regenerator["default"].wrap(function _callee23$(_context23) {
|
|
2797
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
2671
2798
|
case 0:
|
|
2672
2799
|
this._forceEnableSync = true;
|
|
2673
2800
|
case 1:
|
|
2674
2801
|
case "end":
|
|
2675
|
-
return
|
|
2802
|
+
return _context23.stop();
|
|
2676
2803
|
}
|
|
2677
|
-
},
|
|
2804
|
+
}, _callee23, this);
|
|
2678
2805
|
}));
|
|
2679
2806
|
function startSync() {
|
|
2680
2807
|
return _startSync.apply(this, arguments);
|
|
@@ -2684,16 +2811,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2684
2811
|
}, {
|
|
2685
2812
|
key: "stopSync",
|
|
2686
2813
|
value: function () {
|
|
2687
|
-
var _stopSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function
|
|
2688
|
-
return _regenerator["default"].wrap(function
|
|
2689
|
-
while (1) switch (
|
|
2814
|
+
var _stopSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee24() {
|
|
2815
|
+
return _regenerator["default"].wrap(function _callee24$(_context24) {
|
|
2816
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
2690
2817
|
case 0:
|
|
2691
2818
|
this._forceEnableSync = false;
|
|
2692
2819
|
case 1:
|
|
2693
2820
|
case "end":
|
|
2694
|
-
return
|
|
2821
|
+
return _context24.stop();
|
|
2695
2822
|
}
|
|
2696
|
-
},
|
|
2823
|
+
}, _callee24, this);
|
|
2697
2824
|
}));
|
|
2698
2825
|
function stopSync() {
|
|
2699
2826
|
return _stopSync.apply(this, arguments);
|
|
@@ -28,7 +28,7 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
28
28
|
// ?
|
|
29
29
|
data: payload
|
|
30
30
|
});
|
|
31
|
-
mqttAdapter.
|
|
31
|
+
mqttAdapter.publish(getTopic(roomId), _payload);
|
|
32
32
|
},
|
|
33
33
|
subscribeEvent: function subscribeEvent(roomId, callback) {
|
|
34
34
|
if (_is_js["default"].undefined(roomId)) throw new Error('`roomId` required');
|
|
@@ -38,7 +38,7 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
38
38
|
var topic = getTopic(roomId);
|
|
39
39
|
// Only allow 1 subcription for now
|
|
40
40
|
if (subscribedTopics[topic]) return;
|
|
41
|
-
mqttAdapter.
|
|
41
|
+
mqttAdapter.subscribe(topic);
|
|
42
42
|
var cb = function cb(payload) {
|
|
43
43
|
var parsedPayload = JSON.parse(payload);
|
|
44
44
|
callback(parsedPayload);
|
|
@@ -51,7 +51,7 @@ function CustomEventAdapter(mqttAdapter, userId) {
|
|
|
51
51
|
if (_is_js["default"].not.string(roomId)) throw new TypeError('`roomId` must have type of string');
|
|
52
52
|
var topic = getTopic(roomId);
|
|
53
53
|
if (!subscribedTopics[topic]) return;
|
|
54
|
-
mqttAdapter.
|
|
54
|
+
mqttAdapter.unsubscribe(topic);
|
|
55
55
|
events.off(topic, subscribedTopics[topic]);
|
|
56
56
|
subscribedTopics[topic] = null;
|
|
57
57
|
delete subscribedTopics[topic];
|