qiscus-sdk-core 2.12.4 → 2.12.6-logger
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/qiscus-sdk-core.min.js +6 -8
- package/dist/qiscus-sdk-core.min.js.map +1 -1
- package/lib/index.js +1137 -1521
- package/lib/lib/Comment.js +20 -31
- package/lib/lib/Room.js +6 -19
- package/lib/lib/adapters/auth.js +2 -13
- package/lib/lib/adapters/custom-event.js +2 -13
- package/lib/lib/adapters/expired-token.js +84 -133
- package/lib/lib/adapters/hook.js +2 -8
- package/lib/lib/adapters/http.js +57 -58
- package/lib/lib/adapters/mqtt.js +386 -336
- package/lib/lib/adapters/room.js +2 -10
- package/lib/lib/adapters/sync.js +226 -328
- package/lib/lib/adapters/user.js +2 -20
- package/lib/lib/match.js +19 -61
- package/lib/lib/url-builder.js +0 -5
- package/lib/lib/util.js +5 -14
- package/lib/lib/utils.js +10 -24
- package/lib/logger.js +125 -0
- package/package.json +5 -3
package/lib/index.js
CHANGED
|
@@ -1,72 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
13
|
-
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
14
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
11
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
17
|
-
|
|
18
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
19
|
-
|
|
20
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
14
|
var _superagent = _interopRequireDefault(require("superagent"));
|
|
23
|
-
|
|
24
15
|
var _mitt = _interopRequireDefault(require("mitt"));
|
|
25
|
-
|
|
26
16
|
var _is_js = _interopRequireDefault(require("is_js"));
|
|
27
|
-
|
|
28
17
|
var _format = _interopRequireDefault(require("date-fns/format"));
|
|
29
|
-
|
|
30
18
|
var _distance_in_words_to_now = _interopRequireDefault(require("date-fns/distance_in_words_to_now"));
|
|
31
|
-
|
|
32
19
|
var _Comment = _interopRequireDefault(require("./lib/Comment"));
|
|
33
|
-
|
|
34
20
|
var _Room = _interopRequireDefault(require("./lib/Room"));
|
|
35
|
-
|
|
36
21
|
var _http = _interopRequireDefault(require("./lib/adapters/http"));
|
|
37
|
-
|
|
38
22
|
var _auth = _interopRequireDefault(require("./lib/adapters/auth"));
|
|
39
|
-
|
|
40
23
|
var _user = _interopRequireDefault(require("./lib/adapters/user"));
|
|
41
|
-
|
|
42
24
|
var _room = _interopRequireDefault(require("./lib/adapters/room"));
|
|
43
|
-
|
|
44
25
|
var _mqtt = _interopRequireDefault(require("./lib/adapters/mqtt"));
|
|
45
|
-
|
|
46
26
|
var _customEvent = _interopRequireDefault(require("./lib/adapters/custom-event"));
|
|
47
|
-
|
|
48
27
|
var _sync = _interopRequireDefault(require("./lib/adapters/sync"));
|
|
49
|
-
|
|
50
28
|
var _utils = require("./lib/utils");
|
|
51
|
-
|
|
52
29
|
var _util = require("./lib/util");
|
|
53
|
-
|
|
54
30
|
var _package = _interopRequireDefault(require("../package.json"));
|
|
55
|
-
|
|
56
31
|
var _hook = require("./lib/adapters/hook");
|
|
57
|
-
|
|
58
32
|
var _expiredToken = require("./lib/adapters/expired-token");
|
|
59
|
-
|
|
60
|
-
function ownKeys(
|
|
61
|
-
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
function
|
|
65
|
-
|
|
66
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
67
|
-
|
|
68
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
69
|
-
|
|
33
|
+
var _logger = require("./logger.js");
|
|
34
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
35
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
36
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
37
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
38
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
70
39
|
// helper for setup publishOnlinePresence status
|
|
71
40
|
var setBackToOnline;
|
|
72
41
|
var UpdateCommentStatusMode = Object.freeze({
|
|
@@ -74,21 +43,23 @@ var UpdateCommentStatusMode = Object.freeze({
|
|
|
74
43
|
throttled: 'UpdateCommentStatusMode.throttled',
|
|
75
44
|
enabled: 'UpdateCommentStatusMode.enabled'
|
|
76
45
|
});
|
|
46
|
+
|
|
77
47
|
/**
|
|
78
48
|
* Qiscus Web SDK Core Class
|
|
79
49
|
*
|
|
80
50
|
* @export
|
|
81
51
|
* @class QiscusSDK
|
|
82
52
|
*/
|
|
83
|
-
|
|
84
53
|
var QiscusSDK = /*#__PURE__*/function () {
|
|
85
54
|
/**
|
|
86
55
|
* Creates an instance of QiscusSDK.
|
|
87
56
|
*/
|
|
88
57
|
function QiscusSDK() {
|
|
89
58
|
var _this = this;
|
|
90
|
-
|
|
91
59
|
(0, _classCallCheck2["default"])(this, QiscusSDK);
|
|
60
|
+
(0, _defineProperty2["default"])(this, "_logger", new _logger.Logger('QiscusSDK', null, null, function () {
|
|
61
|
+
return _this.debugMode === true;
|
|
62
|
+
}));
|
|
92
63
|
(0, _defineProperty2["default"])(this, "_readComment", function (roomId, commentId) {
|
|
93
64
|
return _this._updateStatus(roomId, commentId);
|
|
94
65
|
});
|
|
@@ -113,8 +84,8 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
113
84
|
this.uploadedFiles = [];
|
|
114
85
|
this.chatmateStatus = null;
|
|
115
86
|
this.version = "WEB_".concat(_package["default"].version);
|
|
116
|
-
this.userData = {};
|
|
117
|
-
|
|
87
|
+
this.userData = {};
|
|
88
|
+
// SDK Configuration
|
|
118
89
|
this.AppId = null;
|
|
119
90
|
this.baseURL = 'https://api.qiscus.com';
|
|
120
91
|
this.mqttURL = 'wss://realtime-jogja.qiscus.com:1886/mqtt';
|
|
@@ -133,7 +104,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
133
104
|
this.isSynced = false;
|
|
134
105
|
this.syncInterval = 5000;
|
|
135
106
|
this.sync = 'socket'; // possible values 'socket', 'http', 'both'
|
|
136
|
-
|
|
137
107
|
this.enableLb = true;
|
|
138
108
|
this.httpsync = null;
|
|
139
109
|
this.eventsync = null;
|
|
@@ -145,8 +115,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
145
115
|
};
|
|
146
116
|
this.isConfigLoaded = false;
|
|
147
117
|
this.updateCommentStatusMode = QiscusSDK.UpdateCommentStatusMode.enabled;
|
|
148
|
-
this.updateCommentStatusThrottleDelay = 300;
|
|
118
|
+
this.updateCommentStatusThrottleDelay = 300;
|
|
149
119
|
|
|
120
|
+
// UI related Properties
|
|
150
121
|
this.UI = {};
|
|
151
122
|
this.mode = 'widget';
|
|
152
123
|
this.avatar = true;
|
|
@@ -161,389 +132,360 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
161
132
|
this.debugMode = false;
|
|
162
133
|
this.debugMQTTMode = false;
|
|
163
134
|
this._customHeader = {};
|
|
164
|
-
this._forceEnableSync = true;
|
|
135
|
+
this._forceEnableSync = true;
|
|
165
136
|
|
|
137
|
+
// to prevent double receive newmessages callback
|
|
166
138
|
this.lastReceiveMessages = [];
|
|
167
139
|
this._hookAdapter = (0, _hook.hookAdapterFactory)();
|
|
168
140
|
this._uploadURL = null;
|
|
169
141
|
this._autoRefreshToken = false;
|
|
170
|
-
}
|
|
142
|
+
}
|
|
171
143
|
|
|
172
|
-
|
|
173
|
-
(0, _createClass2["default"])(QiscusSDK, [{
|
|
174
|
-
key: "
|
|
144
|
+
// this.uploadURL = `${this.baseURL}/api/v2/sdk/upload`
|
|
145
|
+
return (0, _createClass2["default"])(QiscusSDK, [{
|
|
146
|
+
key: "uploadURL",
|
|
147
|
+
get: function get() {
|
|
148
|
+
return this._uploadURL || "".concat(this.baseURL, "/api/v2/sdk/upload");
|
|
149
|
+
},
|
|
150
|
+
set: function set(uploadURL) {
|
|
151
|
+
this._uploadURL = uploadURL;
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
key: "_getHttpAdapter",
|
|
155
|
+
value: function _getHttpAdapter() {
|
|
156
|
+
var _this2 = this;
|
|
157
|
+
return new _http["default"]({
|
|
158
|
+
baseURL: this.baseURL,
|
|
159
|
+
AppId: this.AppId,
|
|
160
|
+
userId: this.user_id,
|
|
161
|
+
version: this.version,
|
|
162
|
+
getCustomHeader: function getCustomHeader() {
|
|
163
|
+
return _this2._customHeader;
|
|
164
|
+
},
|
|
165
|
+
logger: this._logger
|
|
166
|
+
});
|
|
167
|
+
}
|
|
175
168
|
|
|
176
169
|
/**
|
|
177
170
|
* Initializing the SDK, set Event Listeners (callbacks)
|
|
178
|
-
* @param {
|
|
171
|
+
* @param {Object} config - Qiscus SDK Configurations
|
|
172
|
+
* @param {(level:string, message:string, ...data: any[]) => void} config.onLoggerLog - Callback for logger log
|
|
179
173
|
* @return {Promise<void>}
|
|
180
174
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
175
|
+
}, {
|
|
176
|
+
key: "init",
|
|
177
|
+
value: (function () {
|
|
178
|
+
var _init = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee3(config) {
|
|
179
|
+
var _config$withConfig,
|
|
180
|
+
_this3 = this;
|
|
186
181
|
var isDifferentBaseUrl, isDifferentMqttUrl, isDifferentBrokerLbUrl, setterHelper, mqttWssCheck;
|
|
187
|
-
return _regenerator["default"].wrap(function
|
|
188
|
-
while (1) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
182
|
+
return _regenerator["default"].wrap(function (_context3) {
|
|
183
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
184
|
+
case 0:
|
|
185
|
+
if (config.onLoggerLog != null) {
|
|
186
|
+
this._logger.onLog = config.onLoggerLog;
|
|
187
|
+
}
|
|
188
|
+
// set AppID
|
|
189
|
+
if (config.AppId) {
|
|
190
|
+
_context3.next = 1;
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
throw new Error('Please provide valid AppId');
|
|
194
|
+
case 1:
|
|
195
|
+
this.AppId = config.AppId;
|
|
196
|
+
|
|
197
|
+
// We need to disable realtime load balancing if user are using custom server
|
|
198
|
+
// and did not provide a brokerLbUrl
|
|
199
|
+
isDifferentBaseUrl = config.baseURL != null && this.baseURL !== config.baseURL;
|
|
200
|
+
isDifferentMqttUrl = config.mqttURL != null && this.mqttURL !== config.mqttURL;
|
|
201
|
+
isDifferentBrokerLbUrl = config.brokerLbURL != null && this.brokerLbUrl !== config.brokerLbURL; // disable realtime lb if user change baseUrl or mqttUrl but did not change
|
|
202
|
+
// broker lb url
|
|
203
|
+
if ((isDifferentBaseUrl || isDifferentMqttUrl) && !isDifferentBrokerLbUrl) {
|
|
204
|
+
this._logger.info('' + 'force disable load balancing for realtime server, because ' + '`baseURL` or `mqttURL` get changed but ' + 'did not provide `brokerLbURL`');
|
|
205
|
+
this.enableLb = false;
|
|
206
|
+
} else if (config.enableRealtimeLB != null) {
|
|
207
|
+
this.enableLb = config.enableRealtimeLB;
|
|
208
|
+
}
|
|
209
|
+
if (config.updateCommentStatusMode != null) this.updateCommentStatusMode = config.updateCommentStatusMode;
|
|
210
|
+
if (config.updateCommentStatusThrottleDelay != null) this.updateCommentStatusThrottleDelay = config.updateCommentStatusThrottleDelay;
|
|
211
|
+
if (config.baseURL) this.baseURL = config.baseURL;
|
|
212
|
+
if (config.mqttURL) this.mqttURL = config.brokerUrl || config.mqttURL;
|
|
213
|
+
if (config.mqttURL) this.brokerUrl = config.brokerUrl || config.mqttURL;
|
|
214
|
+
if (config.brokerLbURL) this.brokerLbUrl = config.brokerLbURL;
|
|
215
|
+
if (config.uploadURL) this.uploadURL = config.uploadURL;
|
|
216
|
+
if (config.sync) this.sync = config.sync;
|
|
217
|
+
if (config.mode) this.mode = config.mode;
|
|
218
|
+
if (config.syncInterval) this.syncInterval = config.syncInterval || 5000;
|
|
219
|
+
if (config.googleMapKey) this.googleMapKey = config.googleMapKey;
|
|
220
|
+
if (config.allowedFileTypes) {
|
|
221
|
+
this.allowedFileTypes = config.allowedFileTypes;
|
|
222
|
+
}
|
|
223
|
+
// Let's initialize the app based on options
|
|
224
|
+
if (config.options) {
|
|
225
|
+
this.options = Object.assign({}, this.options, config.options);
|
|
226
|
+
}
|
|
227
|
+
if (config.customTemplate) this.customTemplate = config.customTemplate;
|
|
228
|
+
if (config.templateFunction) {
|
|
229
|
+
this.templateFunction = config.templateFunction;
|
|
230
|
+
}
|
|
231
|
+
if (config.syncInterval != null) this.syncInterval = config.syncInterval;
|
|
232
|
+
// this._customHeader = {}
|
|
233
|
+
|
|
234
|
+
// set appConfig
|
|
235
|
+
this.HTTPAdapter = this._getHttpAdapter();
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @callback SetterCallback
|
|
239
|
+
* @param {string | number} value
|
|
240
|
+
* @return void
|
|
241
|
+
*/
|
|
242
|
+
/**
|
|
243
|
+
* @typedef {string | number | boolean | null} Parameter
|
|
244
|
+
*/
|
|
245
|
+
/**
|
|
246
|
+
*
|
|
247
|
+
* @param {Parameter} fromUser
|
|
248
|
+
* @param {Parameter} fromServer
|
|
249
|
+
* @param {Parameter} defaultValue
|
|
250
|
+
* @return {Parameter}
|
|
251
|
+
*/
|
|
252
|
+
setterHelper = function setterHelper(fromUser, fromServer, defaultValue) {
|
|
253
|
+
if (fromServer === '') {
|
|
254
|
+
if (fromUser != null) {
|
|
255
|
+
if (typeof fromUser !== 'string') return fromUser;
|
|
256
|
+
if (fromUser.length > 0) return fromUser;
|
|
257
|
+
}
|
|
194
258
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
case 2:
|
|
199
|
-
this.AppId = config.AppId; // We need to disable realtime load balancing if user are using custom server
|
|
200
|
-
// and did not provide a brokerLbUrl
|
|
201
|
-
|
|
202
|
-
isDifferentBaseUrl = config.baseURL != null && this.baseURL !== config.baseURL;
|
|
203
|
-
isDifferentMqttUrl = config.mqttURL != null && this.mqttURL !== config.mqttURL;
|
|
204
|
-
isDifferentBrokerLbUrl = config.brokerLbURL != null && this.brokerLbUrl !== config.brokerLbURL; // disable realtime lb if user change baseUrl or mqttUrl but did not change
|
|
205
|
-
// broker lb url
|
|
206
|
-
|
|
207
|
-
if ((isDifferentBaseUrl || isDifferentMqttUrl) && !isDifferentBrokerLbUrl) {
|
|
208
|
-
this.logger('' + 'force disable load balancing for realtime server, because ' + '`baseURL` or `mqttURL` get changed but ' + 'did not provide `brokerLbURL`');
|
|
209
|
-
this.enableLb = false;
|
|
210
|
-
} else if (config.enableRealtimeLB != null) {
|
|
211
|
-
this.enableLb = config.enableRealtimeLB;
|
|
259
|
+
if (fromServer != null) {
|
|
260
|
+
if (fromServer.length > 0) return fromServer;
|
|
261
|
+
if (typeof fromServer !== 'string') return fromServer;
|
|
212
262
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (config.uploadURL) this.uploadURL = config.uploadURL;
|
|
221
|
-
if (config.sync) this.sync = config.sync;
|
|
222
|
-
if (config.mode) this.mode = config.mode;
|
|
223
|
-
if (config.syncInterval) this.syncInterval = config.syncInterval || 5000;
|
|
224
|
-
if (config.googleMapKey) this.googleMapKey = config.googleMapKey;
|
|
225
|
-
|
|
226
|
-
if (config.allowedFileTypes) {
|
|
227
|
-
this.allowedFileTypes = config.allowedFileTypes;
|
|
228
|
-
} // Let's initialize the app based on options
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
if (config.options) {
|
|
232
|
-
this.options = Object.assign({}, this.options, config.options);
|
|
263
|
+
return defaultValue;
|
|
264
|
+
};
|
|
265
|
+
mqttWssCheck = function mqttWssCheck(mqttResult) {
|
|
266
|
+
if (mqttResult.includes('wss://')) {
|
|
267
|
+
return mqttResult;
|
|
268
|
+
} else {
|
|
269
|
+
return "wss://".concat(mqttResult, ":1886/mqtt");
|
|
233
270
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
271
|
+
};
|
|
272
|
+
this.withConfig = (_config$withConfig = config.withConfig) !== null && _config$withConfig !== void 0 ? _config$withConfig : true;
|
|
273
|
+
if (!(this.withConfig === true)) {
|
|
274
|
+
_context3.next = 3;
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
_context3.next = 2;
|
|
278
|
+
return this.HTTPAdapter.get_request('api/v2/sdk/config').then(function (resp) {
|
|
279
|
+
resp.status == 200 ? _this3.isConfigLoaded = true : _this3.isConfigLoaded = false;
|
|
280
|
+
return resp.body.results;
|
|
281
|
+
}).then(function (cfg) {
|
|
282
|
+
var baseUrl = _this3.baseURL; // default value for baseUrl
|
|
283
|
+
var brokerLbUrl = _this3.brokerLbUrl; // default value for brokerLbUrl
|
|
284
|
+
var mqttUrl = _this3.mqttURL; // default value for brokerUrl
|
|
285
|
+
var enableRealtime = _this3.enableRealtime; // default value for enableRealtime
|
|
286
|
+
var enableRealtimeCheck = _this3.enableRealtimeCheck; // default value for enableRealtimeCheck
|
|
287
|
+
var syncInterval = _this3.syncInterval; // default value for syncInterval
|
|
288
|
+
var syncIntervalWhenConnected = _this3.syncOnConnect; // default value for syncIntervalWhenConnected
|
|
289
|
+
var enableEventReport = _this3.enableEventReport; // default value for enableEventReport
|
|
290
|
+
var configExtras = {}; // default value for extras
|
|
291
|
+
|
|
292
|
+
_this3.baseURL = setterHelper(config.baseURL, cfg.base_url, baseUrl);
|
|
293
|
+
_this3.brokerLbUrl = setterHelper(config.brokerLbURL, cfg.broker_lb_url, brokerLbUrl);
|
|
294
|
+
_this3.mqttURL = mqttWssCheck(setterHelper(config.mqttURL, cfg.broker_url, mqttUrl));
|
|
295
|
+
_this3.enableRealtime = setterHelper(config.enableRealtime, cfg.enable_realtime, enableRealtime);
|
|
296
|
+
_this3.syncInterval = setterHelper(config.syncInterval, cfg.sync_interval, syncInterval);
|
|
297
|
+
_this3.syncOnConnect = setterHelper(config.syncOnConnect, cfg.sync_on_connect, syncIntervalWhenConnected);
|
|
298
|
+
// since user never provide this value
|
|
299
|
+
_this3.enableRealtimeCheck = setterHelper(null, cfg.enable_realtime_check, enableRealtimeCheck);
|
|
300
|
+
_this3.enableEventReport = setterHelper(null, cfg.enable_event_report, enableEventReport);
|
|
301
|
+
_this3.extras = setterHelper(null, cfg.extras, configExtras);
|
|
302
|
+
_this3.enableSync = setterHelper(null, cfg.enable_sync, _this3.enableSync);
|
|
303
|
+
_this3.enableSyncEvent = setterHelper(null, cfg.enable_sync_event, _this3.enableSyncEvent);
|
|
304
|
+
_this3._autoRefreshToken = setterHelper(null, cfg.auto_refresh_token, false);
|
|
305
|
+
})["catch"](function (err) {
|
|
306
|
+
_this3._logger.error('got error when trying to get app config', err);
|
|
307
|
+
_this3.isConfigLoaded = true;
|
|
308
|
+
});
|
|
309
|
+
case 2:
|
|
310
|
+
_context3.next = 4;
|
|
311
|
+
break;
|
|
312
|
+
case 3:
|
|
313
|
+
this.isConfigLoaded = true;
|
|
314
|
+
case 4:
|
|
315
|
+
// set Event Listeners
|
|
316
|
+
|
|
317
|
+
this._getMqttClientId = function () {
|
|
318
|
+
return "".concat(_this3.AppId, "_").concat(_this3.user_id, "_").concat(Date.now());
|
|
319
|
+
};
|
|
320
|
+
this.realtimeAdapter = new _mqtt["default"](this.mqttURL, this, this.isLogin, {
|
|
321
|
+
brokerLbUrl: this.brokerLbUrl,
|
|
322
|
+
enableLb: this.enableLb,
|
|
323
|
+
shouldConnect: this.enableRealtime,
|
|
324
|
+
getClientId: this._getMqttClientId,
|
|
325
|
+
logger: this._logger
|
|
326
|
+
});
|
|
327
|
+
this.realtimeAdapter.on('connected', function () {
|
|
328
|
+
if (_this3.isLogin || !_this3.realtimeAdapter.connected) {
|
|
329
|
+
_this3.last_received_comment_id = _this3.userData.last_comment_id;
|
|
330
|
+
_this3.updateLastReceivedComment(_this3.last_received_comment_id);
|
|
239
331
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
setterHelper = function setterHelper(fromUser, fromServer, defaultValue) {
|
|
272
|
-
if (fromServer === '') {
|
|
273
|
-
if (fromUser != null) {
|
|
274
|
-
if (typeof fromUser !== 'string') return fromUser;
|
|
275
|
-
if (fromUser.length > 0) return fromUser;
|
|
332
|
+
});
|
|
333
|
+
this.realtimeAdapter.on('close', function () {});
|
|
334
|
+
this.realtimeAdapter.on('reconnect', function () {
|
|
335
|
+
var _this3$options$onReco, _this3$options;
|
|
336
|
+
(_this3$options$onReco = (_this3$options = _this3.options).onReconnectCallback) === null || _this3$options$onReco === void 0 || _this3$options$onReco.call(_this3$options);
|
|
337
|
+
});
|
|
338
|
+
this.realtimeAdapter.on('message-delivered', function (_ref) {
|
|
339
|
+
var commentId = _ref.commentId,
|
|
340
|
+
commentUniqueId = _ref.commentUniqueId,
|
|
341
|
+
userId = _ref.userId;
|
|
342
|
+
return _this3._setDelivered(commentId, commentUniqueId, userId);
|
|
343
|
+
});
|
|
344
|
+
this.realtimeAdapter.on('message-read', function (_ref2) {
|
|
345
|
+
var commentId = _ref2.commentId,
|
|
346
|
+
commentUniqueId = _ref2.commentUniqueId,
|
|
347
|
+
userId = _ref2.userId;
|
|
348
|
+
return _this3._setRead(commentId, commentUniqueId, userId);
|
|
349
|
+
});
|
|
350
|
+
this.realtimeAdapter.on('new-message', /*#__PURE__*/function () {
|
|
351
|
+
var _ref3 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee(message) {
|
|
352
|
+
return _regenerator["default"].wrap(function (_context) {
|
|
353
|
+
while (1) switch (_context.prev = _context.next) {
|
|
354
|
+
case 0:
|
|
355
|
+
_context.next = 1;
|
|
356
|
+
return _this3._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
|
|
357
|
+
case 1:
|
|
358
|
+
message = _context.sent;
|
|
359
|
+
_this3.events.emit('newmessages', [message]);
|
|
360
|
+
case 2:
|
|
361
|
+
case "end":
|
|
362
|
+
return _context.stop();
|
|
276
363
|
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
if (typeof fromServer !== 'string') return fromServer;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
return defaultValue;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
mqttWssCheck = function mqttWssCheck(mqttResult) {
|
|
288
|
-
if (mqttResult.includes('wss://')) {
|
|
289
|
-
return mqttResult;
|
|
290
|
-
} else {
|
|
291
|
-
return "wss://".concat(mqttResult, ":1886/mqtt");
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
this.withConfig = (_config$withConfig = config.withConfig) !== null && _config$withConfig !== void 0 ? _config$withConfig : true;
|
|
296
|
-
|
|
297
|
-
if (!(this.withConfig === true)) {
|
|
298
|
-
_context3.next = 32;
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
_context3.next = 30;
|
|
303
|
-
return this.HTTPAdapter.get_request('api/v2/sdk/config').then(function (resp) {
|
|
304
|
-
resp.status == 200 ? _this2.isConfigLoaded = true : _this2.isConfigLoaded = false;
|
|
305
|
-
return resp.body.results;
|
|
306
|
-
}).then(function (cfg) {
|
|
307
|
-
var baseUrl = _this2.baseURL; // default value for baseUrl
|
|
308
|
-
|
|
309
|
-
var brokerLbUrl = _this2.brokerLbUrl; // default value for brokerLbUrl
|
|
310
|
-
|
|
311
|
-
var mqttUrl = _this2.mqttURL; // default value for brokerUrl
|
|
312
|
-
|
|
313
|
-
var enableRealtime = _this2.enableRealtime; // default value for enableRealtime
|
|
314
|
-
|
|
315
|
-
var enableRealtimeCheck = _this2.enableRealtimeCheck; // default value for enableRealtimeCheck
|
|
316
|
-
|
|
317
|
-
var syncInterval = _this2.syncInterval; // default value for syncInterval
|
|
318
|
-
|
|
319
|
-
var syncIntervalWhenConnected = _this2.syncOnConnect; // default value for syncIntervalWhenConnected
|
|
320
|
-
|
|
321
|
-
var enableEventReport = _this2.enableEventReport; // default value for enableEventReport
|
|
322
|
-
|
|
323
|
-
var configExtras = {}; // default value for extras
|
|
324
|
-
|
|
325
|
-
_this2.baseURL = setterHelper(config.baseURL, cfg.base_url, baseUrl);
|
|
326
|
-
_this2.brokerLbUrl = setterHelper(config.brokerLbURL, cfg.broker_lb_url, brokerLbUrl);
|
|
327
|
-
_this2.mqttURL = mqttWssCheck(setterHelper(config.mqttURL, cfg.broker_url, mqttUrl));
|
|
328
|
-
_this2.enableRealtime = setterHelper(config.enableRealtime, cfg.enable_realtime, enableRealtime);
|
|
329
|
-
_this2.syncInterval = setterHelper(config.syncInterval, cfg.sync_interval, syncInterval);
|
|
330
|
-
_this2.syncOnConnect = setterHelper(config.syncOnConnect, cfg.sync_on_connect, syncIntervalWhenConnected); // since user never provide this value
|
|
331
|
-
|
|
332
|
-
_this2.enableRealtimeCheck = setterHelper(null, cfg.enable_realtime_check, enableRealtimeCheck);
|
|
333
|
-
_this2.enableEventReport = setterHelper(null, cfg.enable_event_report, enableEventReport);
|
|
334
|
-
_this2.extras = setterHelper(null, cfg.extras, configExtras);
|
|
335
|
-
_this2.enableSync = setterHelper(null, cfg.enable_sync, _this2.enableSync);
|
|
336
|
-
_this2.enableSyncEvent = setterHelper(null, cfg.enable_sync_event, _this2.enableSyncEvent);
|
|
337
|
-
_this2._autoRefreshToken = setterHelper(null, cfg.auto_refresh_token, false);
|
|
338
|
-
})["catch"](function (err) {
|
|
339
|
-
_this2.logger('got error when trying to get app config', err);
|
|
340
|
-
|
|
341
|
-
_this2.isConfigLoaded = true;
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
case 30:
|
|
345
|
-
_context3.next = 33;
|
|
346
|
-
break;
|
|
347
|
-
|
|
348
|
-
case 32:
|
|
349
|
-
this.isConfigLoaded = true;
|
|
350
|
-
|
|
351
|
-
case 33:
|
|
352
|
-
// set Event Listeners
|
|
353
|
-
this._getMqttClientId = function () {
|
|
354
|
-
return "".concat(_this2.AppId, "_").concat(_this2.user_id, "_").concat(Date.now());
|
|
364
|
+
}, _callee);
|
|
365
|
+
}));
|
|
366
|
+
return function (_x2) {
|
|
367
|
+
return _ref3.apply(this, arguments);
|
|
355
368
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
this.realtimeAdapter.on('reconnect', function () {
|
|
372
|
-
var _this2$options$onReco, _this2$options;
|
|
373
|
-
|
|
374
|
-
(_this2$options$onReco = (_this2$options = _this2.options).onReconnectCallback) === null || _this2$options$onReco === void 0 ? void 0 : _this2$options$onReco.call(_this2$options);
|
|
375
|
-
});
|
|
376
|
-
this.realtimeAdapter.on('message-delivered', function (_ref) {
|
|
377
|
-
var commentId = _ref.commentId,
|
|
378
|
-
commentUniqueId = _ref.commentUniqueId,
|
|
379
|
-
userId = _ref.userId;
|
|
380
|
-
return _this2._setDelivered(commentId, commentUniqueId, userId);
|
|
381
|
-
});
|
|
382
|
-
this.realtimeAdapter.on('message-read', function (_ref2) {
|
|
383
|
-
var commentId = _ref2.commentId,
|
|
384
|
-
commentUniqueId = _ref2.commentUniqueId,
|
|
385
|
-
userId = _ref2.userId;
|
|
386
|
-
return _this2._setRead(commentId, commentUniqueId, userId);
|
|
387
|
-
});
|
|
388
|
-
this.realtimeAdapter.on('new-message', /*#__PURE__*/function () {
|
|
389
|
-
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(message) {
|
|
390
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
391
|
-
while (1) {
|
|
392
|
-
switch (_context.prev = _context.next) {
|
|
393
|
-
case 0:
|
|
394
|
-
_context.next = 2;
|
|
395
|
-
return _this2._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
|
|
396
|
-
|
|
397
|
-
case 2:
|
|
398
|
-
message = _context.sent;
|
|
399
|
-
|
|
400
|
-
_this2.events.emit('newmessages', [message]);
|
|
401
|
-
|
|
402
|
-
case 4:
|
|
403
|
-
case "end":
|
|
404
|
-
return _context.stop();
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}, _callee);
|
|
408
|
-
}));
|
|
409
|
-
|
|
410
|
-
return function (_x2) {
|
|
411
|
-
return _ref3.apply(this, arguments);
|
|
412
|
-
};
|
|
413
|
-
}());
|
|
414
|
-
this.realtimeAdapter.on('presence', function (data) {
|
|
415
|
-
return _this2.events.emit('presence', data);
|
|
416
|
-
});
|
|
417
|
-
this.realtimeAdapter.on('comment-deleted', function (data) {
|
|
418
|
-
return _this2.events.emit('comment-deleted', data);
|
|
419
|
-
});
|
|
420
|
-
this.realtimeAdapter.on('room-cleared', function (data) {
|
|
421
|
-
return _this2.events.emit('room-cleared', data);
|
|
369
|
+
}());
|
|
370
|
+
this.realtimeAdapter.on('presence', function (data) {
|
|
371
|
+
return _this3.events.emit('presence', data);
|
|
372
|
+
});
|
|
373
|
+
this.realtimeAdapter.on('comment-deleted', function (data) {
|
|
374
|
+
return _this3.events.emit('comment-deleted', data);
|
|
375
|
+
});
|
|
376
|
+
this.realtimeAdapter.on('room-cleared', function (data) {
|
|
377
|
+
return _this3.events.emit('room-cleared', data);
|
|
378
|
+
});
|
|
379
|
+
this.realtimeAdapter.on('typing', function (data) {
|
|
380
|
+
return _this3.events.emit('typing', {
|
|
381
|
+
message: data.message,
|
|
382
|
+
username: data.userId,
|
|
383
|
+
room_id: data.roomId
|
|
422
384
|
});
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (_this2.selected != null) {
|
|
478
|
-
index = _this2.selected.comments.findIndex(function (it) {
|
|
479
|
-
return it.id === message.id || it.unique_id === message.unique_temp_id;
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
if (index === -1) {
|
|
483
|
-
_message = new _Comment["default"](message);
|
|
484
|
-
|
|
485
|
-
if (_message.room_id === _this2.selected.id) {
|
|
486
|
-
_this2.selected.comments.push(_message);
|
|
487
|
-
|
|
488
|
-
_this2.sortComments();
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
_this2.events.emit('newmessages', [message]);
|
|
492
|
-
}
|
|
493
|
-
} else {
|
|
494
|
-
_this2.events.emit('newmessages', [message]);
|
|
385
|
+
});
|
|
386
|
+
this.realtimeAdapter.on('message:updated', function (message) {
|
|
387
|
+
if (_this3.options.messageUpdatedCallback != null) {
|
|
388
|
+
_this3.options.messageUpdatedCallback(message);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
this.syncAdapter = (0, _sync["default"])(function () {
|
|
392
|
+
return _this3.HTTPAdapter;
|
|
393
|
+
}, {
|
|
394
|
+
logger: this._logger,
|
|
395
|
+
getToken: function getToken() {
|
|
396
|
+
return _this3.userData.token;
|
|
397
|
+
},
|
|
398
|
+
syncInterval: function syncInterval() {
|
|
399
|
+
return _this3.syncInterval;
|
|
400
|
+
},
|
|
401
|
+
getShouldSync: function getShouldSync() {
|
|
402
|
+
return _this3._forceEnableSync && _this3.isLogin && !_this3.realtimeAdapter.connected;
|
|
403
|
+
},
|
|
404
|
+
syncOnConnect: function syncOnConnect() {
|
|
405
|
+
return _this3.syncOnConnect;
|
|
406
|
+
},
|
|
407
|
+
lastCommentId: function lastCommentId() {
|
|
408
|
+
return _this3.last_received_comment_id;
|
|
409
|
+
},
|
|
410
|
+
statusLogin: function statusLogin() {
|
|
411
|
+
return _this3.isLogin;
|
|
412
|
+
},
|
|
413
|
+
enableSync: function enableSync() {
|
|
414
|
+
return _this3.enableSync;
|
|
415
|
+
},
|
|
416
|
+
enableSyncEvent: function enableSyncEvent() {
|
|
417
|
+
return _this3.enableSyncEvent;
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
this.syncAdapter.on('message.new', /*#__PURE__*/function () {
|
|
421
|
+
var _ref4 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee2(message) {
|
|
422
|
+
var index, _message;
|
|
423
|
+
return _regenerator["default"].wrap(function (_context2) {
|
|
424
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
425
|
+
case 0:
|
|
426
|
+
_context2.next = 1;
|
|
427
|
+
return _this3._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, message);
|
|
428
|
+
case 1:
|
|
429
|
+
message = _context2.sent;
|
|
430
|
+
if (_this3.selected != null) {
|
|
431
|
+
index = _this3.selected.comments.findIndex(function (it) {
|
|
432
|
+
return it.id === message.id || it.unique_id === message.unique_temp_id;
|
|
433
|
+
});
|
|
434
|
+
if (index === -1) {
|
|
435
|
+
_message = new _Comment["default"](message);
|
|
436
|
+
if (_message.room_id === _this3.selected.id) {
|
|
437
|
+
_this3.selected.comments.push(_message);
|
|
438
|
+
_this3.sortComments();
|
|
495
439
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
440
|
+
_this3.events.emit('newmessages', [message]);
|
|
441
|
+
}
|
|
442
|
+
} else {
|
|
443
|
+
_this3.events.emit('newmessages', [message]);
|
|
500
444
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
445
|
+
case 2:
|
|
446
|
+
case "end":
|
|
447
|
+
return _context2.stop();
|
|
448
|
+
}
|
|
449
|
+
}, _callee2);
|
|
450
|
+
}));
|
|
451
|
+
return function (_x3) {
|
|
452
|
+
return _ref4.apply(this, arguments);
|
|
453
|
+
};
|
|
454
|
+
}());
|
|
455
|
+
this.syncAdapter.on('message.delivered', function (message) {
|
|
456
|
+
_this3._setDelivered(message.comment_id, message.comment_unique_id, message.email);
|
|
457
|
+
});
|
|
458
|
+
this.syncAdapter.on('message.read', function (message) {
|
|
459
|
+
_this3._setRead(message.comment_id, message.comment_unique_id, message.email);
|
|
460
|
+
});
|
|
461
|
+
this.syncAdapter.on('message.deleted', function (data) {
|
|
462
|
+
data.deleted_messages.forEach(function (it) {
|
|
463
|
+
_this3.events.emit('comment-deleted', {
|
|
464
|
+
roomId: it.room_id,
|
|
465
|
+
commentUniqueIds: it.message_unique_ids,
|
|
466
|
+
isForEveryone: true,
|
|
467
|
+
isHard: true
|
|
523
468
|
});
|
|
524
469
|
});
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
470
|
+
});
|
|
471
|
+
this.syncAdapter.on('room.cleared', function (data) {
|
|
472
|
+
data.deleted_rooms.forEach(function (room) {
|
|
473
|
+
_this3.events.emit('room-cleared', room);
|
|
529
474
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
}
|
|
475
|
+
});
|
|
476
|
+
this.customEventAdapter = (0, _customEvent["default"])(this.realtimeAdapter, this.user_id);
|
|
477
|
+
this.setEventListeners();
|
|
478
|
+
case 5:
|
|
479
|
+
case "end":
|
|
480
|
+
return _context3.stop();
|
|
537
481
|
}
|
|
538
482
|
}, _callee3, this);
|
|
539
483
|
}));
|
|
540
|
-
|
|
541
484
|
function init(_x) {
|
|
542
485
|
return _init.apply(this, arguments);
|
|
543
486
|
}
|
|
544
|
-
|
|
545
487
|
return init;
|
|
546
|
-
}()
|
|
488
|
+
}())
|
|
547
489
|
}, {
|
|
548
490
|
key: "_setRead",
|
|
549
491
|
value: function _setRead(messageId, messageUniqueId, userId) {
|
|
@@ -601,30 +543,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
601
543
|
}, {
|
|
602
544
|
key: "setEventListeners",
|
|
603
545
|
value: function setEventListeners() {
|
|
604
|
-
var
|
|
605
|
-
|
|
546
|
+
var _this4 = this;
|
|
606
547
|
var self = this;
|
|
607
548
|
this.authAdapter = new _auth["default"](self.HTTPAdapter);
|
|
608
|
-
|
|
609
549
|
if (this.userData.email != null) {
|
|
610
550
|
this.authAdapter.userId = this.userData.email;
|
|
611
551
|
}
|
|
612
|
-
|
|
613
552
|
self.events.on('start-init', function () {
|
|
614
|
-
self.HTTPAdapter =
|
|
615
|
-
baseURL: self.baseURL,
|
|
616
|
-
AppId: self.AppId,
|
|
617
|
-
userId: self.user_id,
|
|
618
|
-
version: self.version,
|
|
619
|
-
getCustomHeader: function getCustomHeader() {
|
|
620
|
-
return _this3._customHeader;
|
|
621
|
-
}
|
|
622
|
-
});
|
|
553
|
+
self.HTTPAdapter = _this4._getHttpAdapter();
|
|
623
554
|
self.HTTPAdapter.setToken(self.userData.token);
|
|
624
555
|
});
|
|
625
556
|
self.events.on('room-changed', function (room) {
|
|
626
|
-
|
|
627
|
-
|
|
557
|
+
_this4._logger.info('room changed', room);
|
|
628
558
|
if (self.options.roomChangedCallback) {
|
|
629
559
|
self.options.roomChangedCallback(room);
|
|
630
560
|
}
|
|
@@ -637,165 +567,138 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
637
567
|
self.events.on('profile-updated', function (user) {
|
|
638
568
|
self.username = user.name;
|
|
639
569
|
self.avatar_url = user.avatar_url;
|
|
640
|
-
|
|
641
570
|
if (self.options.updateProfileCallback) {
|
|
642
571
|
self.options.updateProfileCallback(user);
|
|
643
572
|
}
|
|
644
573
|
});
|
|
574
|
+
|
|
645
575
|
/**
|
|
646
576
|
* This event will be called when there's new post messages
|
|
647
577
|
* @param {string} data - JSON Response from SYNC API / MQTT
|
|
648
578
|
* @return {void}
|
|
649
579
|
*/
|
|
650
|
-
|
|
651
580
|
self.events.on('newmessages', function (comments) {
|
|
652
581
|
// let's convert the data into something we can use
|
|
653
582
|
// first we need to make sure we sort this data out based on room_id
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
if (lastReceivedMessageNotEmpty && _this3.lastReceiveMessages[0].unique_temp_id === comments[0].unique_temp_id) {
|
|
659
|
-
_this3.logging('lastReceiveMessages double', comments);
|
|
660
|
-
|
|
583
|
+
_this4._logger.info('newmessages', comments);
|
|
584
|
+
var lastReceivedMessageNotEmpty = _this4.lastReceiveMessages.length > 0;
|
|
585
|
+
if (lastReceivedMessageNotEmpty && _this4.lastReceiveMessages[0].unique_temp_id === comments[0].unique_temp_id) {
|
|
586
|
+
_this4._logger.info('lastReceiveMessages double', comments);
|
|
661
587
|
return;
|
|
662
588
|
}
|
|
663
|
-
|
|
664
|
-
_this3.lastReceiveMessages = comments;
|
|
665
|
-
|
|
589
|
+
_this4.lastReceiveMessages = comments;
|
|
666
590
|
self._callNewMessagesCallback(comments);
|
|
667
|
-
|
|
668
591
|
comments.forEach(function (comment) {
|
|
669
592
|
// we have this comment, so means it's already delivered, update it's delivered status
|
|
670
593
|
self.receiveComment(comment.room_id, comment.id);
|
|
671
594
|
var isActiveRoom = self.selected ? comment.room_id === self.selected.id : false;
|
|
672
|
-
var isAlreadyRead = comment.id <= self.last_received_comment_id;
|
|
595
|
+
var isAlreadyRead = comment.id <= self.last_received_comment_id;
|
|
673
596
|
|
|
597
|
+
// kalau comment ini ada di currently selected
|
|
674
598
|
if (isActiveRoom) {
|
|
675
599
|
var selected = self.selected;
|
|
676
|
-
var lastComment = self.selected.comments[self.selected.comments.length - 1];
|
|
677
|
-
|
|
600
|
+
var lastComment = self.selected.comments[self.selected.comments.length - 1];
|
|
601
|
+
// kirim event read kalau ini bukan komen kita sendiri
|
|
678
602
|
if (!lastComment.isPending && !isAlreadyRead && self.user_id !== comment.email) {
|
|
679
603
|
self.readComment(comment.room_id, comment.id);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
|
|
604
|
+
}
|
|
605
|
+
// pastiin sync
|
|
683
606
|
var roomLastCommentId = lastComment.id;
|
|
684
607
|
var commentBeforeThis = self.selected.comments.find(function (c) {
|
|
685
608
|
return c.id === lastComment.comment_before_id;
|
|
686
609
|
});
|
|
687
|
-
|
|
688
610
|
if (!lastComment.isPending && !commentBeforeThis) {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
611
|
+
_this4._logger.info('comment before id not found! ', comment.comment_before_id);
|
|
612
|
+
// need to fix, these method does not work
|
|
692
613
|
self.synchronize(roomLastCommentId);
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
614
|
+
}
|
|
615
|
+
// pastikan dulu komen ini komen baru, klo komen lama ga usah panggil cb
|
|
616
|
+
var pendingComment = new _Comment["default"](comment);
|
|
617
|
+
// fetch the comment inside the room
|
|
698
618
|
selected.receiveComment(pendingComment);
|
|
699
619
|
selected.last_comment_id = pendingComment.id;
|
|
700
620
|
selected.last_comment_message = pendingComment.message;
|
|
701
|
-
}
|
|
702
|
-
|
|
621
|
+
}
|
|
703
622
|
|
|
623
|
+
// let's update last_received_comment_id
|
|
704
624
|
self.updateLastReceivedComment(comment.id);
|
|
705
|
-
|
|
706
|
-
_this3.sortComments();
|
|
625
|
+
_this4.sortComments();
|
|
707
626
|
});
|
|
708
627
|
});
|
|
628
|
+
|
|
709
629
|
/**
|
|
710
630
|
* This event will be called when login is sucess
|
|
711
631
|
* Basically, it sets up necessary properties for qiscusSDK
|
|
712
632
|
*/
|
|
713
|
-
|
|
714
633
|
this.events.on('login-success', function (response) {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
if (!
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
userId: _this3.user_id,
|
|
724
|
-
version: _this3.version,
|
|
725
|
-
getCustomHeader: function getCustomHeader() {
|
|
726
|
-
return _this3._customHeader;
|
|
727
|
-
}
|
|
728
|
-
});
|
|
729
|
-
|
|
730
|
-
_this3.HTTPAdapter.setToken(_this3.userData.token);
|
|
731
|
-
|
|
634
|
+
_this4.isLogin = true;
|
|
635
|
+
_this4.userData = response.user;
|
|
636
|
+
_this4.last_received_comment_id = _this4.userData.last_comment_id;
|
|
637
|
+
if (!_this4.realtimeAdapter.connected) _this4.updateLastReceivedComment(_this4.last_received_comment_id);
|
|
638
|
+
|
|
639
|
+
// now that we have the token, etc, we need to set all our adapters
|
|
640
|
+
_this4.HTTPAdapter = _this4._getHttpAdapter();
|
|
641
|
+
_this4.HTTPAdapter.setToken(_this4.userData.token);
|
|
732
642
|
var user = response.user;
|
|
733
|
-
|
|
734
|
-
httpAdapter:
|
|
643
|
+
_this4.expiredTokenAdapter = new _expiredToken.ExpiredTokenAdapter({
|
|
644
|
+
httpAdapter: _this4.HTTPAdapter,
|
|
735
645
|
refreshToken: user.refresh_token,
|
|
736
646
|
expiredAt: user.token_expires_at,
|
|
737
|
-
userId:
|
|
647
|
+
userId: _this4.user_id,
|
|
738
648
|
onTokenRefreshed: function onTokenRefreshed(token, refreshToken, expiredAt) {
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
_this3.events.emit('token-refreshed', {
|
|
649
|
+
_this4.userData.token = token;
|
|
650
|
+
_this4.userData.refresh_token = refreshToken;
|
|
651
|
+
_this4.userData.token_expires_at = expiredAt === null || expiredAt === void 0 ? void 0 : expiredAt.toJSON();
|
|
652
|
+
_this4.events.emit('token-refreshed', {
|
|
744
653
|
token: token,
|
|
745
654
|
refreshToken: refreshToken,
|
|
746
655
|
expiredAt: expiredAt
|
|
747
656
|
});
|
|
748
657
|
},
|
|
749
658
|
getAuthenticationStatus: function getAuthenticationStatus() {
|
|
750
|
-
return
|
|
659
|
+
return _this4.user_id != null && _this4.isLogin;
|
|
751
660
|
}
|
|
752
661
|
});
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
if (_this3.presensePublisherId != null && _this3.presensePublisherId !== -1) {
|
|
759
|
-
clearInterval(_this3.presensePublisherId);
|
|
662
|
+
_this4.userAdapter = new _user["default"](_this4.HTTPAdapter);
|
|
663
|
+
_this4.roomAdapter = new _room["default"](_this4.HTTPAdapter);
|
|
664
|
+
_this4.realtimeAdapter.subscribeUserChannel();
|
|
665
|
+
if (_this4.presensePublisherId != null && _this4.presensePublisherId !== -1) {
|
|
666
|
+
clearInterval(_this4.presensePublisherId);
|
|
760
667
|
}
|
|
668
|
+
_this4.presensePublisherId = setInterval(function () {
|
|
669
|
+
_this4.realtimeAdapter.publishPresence(_this4.user_id, true);
|
|
670
|
+
}, 3500);
|
|
761
671
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
if (_this3.options.loginSuccessCallback) {
|
|
767
|
-
_this3.options.loginSuccessCallback(response);
|
|
672
|
+
// if (this.sync === "http" || this.sync === "both") this.activateSync();
|
|
673
|
+
if (_this4.options.loginSuccessCallback) {
|
|
674
|
+
_this4.options.loginSuccessCallback(response);
|
|
768
675
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
_this3.authAdapter.autoRefreshToken = _this3._autoRefreshToken;
|
|
676
|
+
_this4.authAdapter.userId = _this4.userData.email;
|
|
677
|
+
_this4.authAdapter.refreshToken = _this4.userData.refresh_token;
|
|
678
|
+
_this4.authAdapter.autoRefreshToken = _this4._autoRefreshToken;
|
|
773
679
|
});
|
|
680
|
+
|
|
774
681
|
/**
|
|
775
682
|
* Called when there's something wrong when connecting to qiscus SDK
|
|
776
683
|
*/
|
|
777
|
-
|
|
778
684
|
self.events.on('login-error', function (error) {
|
|
779
685
|
if (self.options.loginErrorCallback) {
|
|
780
686
|
self.options.loginErrorCallback(error);
|
|
781
687
|
}
|
|
782
688
|
});
|
|
783
689
|
self.events.on('token-refreshed', function (param) {
|
|
784
|
-
var
|
|
785
|
-
|
|
786
|
-
(_this3$options$authTo = (_this3$options = _this3.options).authTokenRefreshedCallback) === null || _this3$options$authTo === void 0 ? void 0 : _this3$options$authTo.call(_this3$options, param);
|
|
690
|
+
var _this4$options$authTo, _this4$options;
|
|
691
|
+
(_this4$options$authTo = (_this4$options = _this4.options).authTokenRefreshedCallback) === null || _this4$options$authTo === void 0 || _this4$options$authTo.call(_this4$options, param);
|
|
787
692
|
});
|
|
788
693
|
self.events.on('room-cleared', function (room) {
|
|
789
694
|
// find room
|
|
790
695
|
if (self.selected) {
|
|
791
696
|
var currentRoom = self.selected;
|
|
792
|
-
|
|
793
697
|
if (self.selected.unique_id === room.unique_id) {
|
|
794
698
|
self.selected = null;
|
|
795
699
|
self.selected = currentRoom;
|
|
796
700
|
}
|
|
797
701
|
}
|
|
798
|
-
|
|
799
702
|
if (self.options.roomClearedCallback) {
|
|
800
703
|
self.options.roomClearedCallback(room);
|
|
801
704
|
}
|
|
@@ -803,17 +706,15 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
803
706
|
self.events.on('comment-deleted', function (data) {
|
|
804
707
|
// get to the room id and delete the comment
|
|
805
708
|
var roomId = data.roomId,
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
709
|
+
commentUniqueIds = data.commentUniqueIds,
|
|
710
|
+
isForEveryone = data.isForEveryone,
|
|
711
|
+
isHard = data.isHard;
|
|
810
712
|
if (self.selected && self.selected.id == roomId) {
|
|
811
713
|
// loop through the array of unique_ids
|
|
812
714
|
commentUniqueIds.map(function (id) {
|
|
813
715
|
var commentToBeFound = self.selected.comments.findIndex(function (comment) {
|
|
814
716
|
return comment.unique_id === id;
|
|
815
717
|
});
|
|
816
|
-
|
|
817
718
|
if (commentToBeFound > -1) {
|
|
818
719
|
if (isHard) {
|
|
819
720
|
self.selected.comments.splice(commentToBeFound, 1);
|
|
@@ -823,133 +724,122 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
823
724
|
}
|
|
824
725
|
});
|
|
825
726
|
}
|
|
826
|
-
|
|
827
727
|
if (self.options.commentDeletedCallback) {
|
|
828
728
|
self.options.commentDeletedCallback(data);
|
|
829
729
|
}
|
|
830
730
|
});
|
|
731
|
+
|
|
831
732
|
/**
|
|
832
733
|
* Called when the comment has been delivered
|
|
833
734
|
*/
|
|
834
|
-
|
|
835
735
|
self.events.on('comment-delivered', function (response) {
|
|
836
|
-
self.
|
|
736
|
+
self._logger.info('comment-delivered', response);
|
|
837
737
|
if (!response) return false;
|
|
838
|
-
|
|
839
738
|
if (self.options.commentDeliveredCallback) {
|
|
840
739
|
return self.options.commentDeliveredCallback(response);
|
|
841
|
-
}
|
|
740
|
+
}
|
|
741
|
+
// find comment with the id or unique id listed from response
|
|
842
742
|
// const commentToFind = self.selected.comments.find(comment =>
|
|
843
743
|
// comment.id === response.id || comment.uniqueId === response.uniqueId);
|
|
844
|
-
|
|
845
744
|
});
|
|
745
|
+
|
|
846
746
|
/**
|
|
847
747
|
* Called when new chatroom has been created
|
|
848
748
|
*/
|
|
849
|
-
|
|
850
749
|
self.events.on('chat-room-created', function (response) {
|
|
851
750
|
self.isLoading = false;
|
|
852
|
-
|
|
853
751
|
if (self.options.chatRoomCreatedCallback) {
|
|
854
752
|
self.options.chatRoomCreatedCallback(response);
|
|
855
753
|
}
|
|
856
754
|
});
|
|
755
|
+
|
|
857
756
|
/**
|
|
858
757
|
* Called when a new room with type of group has been created
|
|
859
758
|
*/
|
|
860
|
-
|
|
861
759
|
self.events.on('group-room-created', function (response) {
|
|
862
760
|
self.isLoading = false;
|
|
863
|
-
|
|
864
761
|
if (self.options.groupRoomCreatedCallback) {
|
|
865
762
|
self.options.groupRoomCreatedCallback(response);
|
|
866
763
|
}
|
|
867
764
|
});
|
|
765
|
+
|
|
868
766
|
/**
|
|
869
767
|
* Called when user clicked on Chat SDK Header
|
|
870
768
|
*/
|
|
871
|
-
|
|
872
769
|
self.events.on('header-clicked', function (response) {
|
|
873
770
|
if (self.options.headerClickedCallback) {
|
|
874
771
|
self.options.headerClickedCallback(response);
|
|
875
772
|
}
|
|
876
773
|
});
|
|
774
|
+
|
|
877
775
|
/**
|
|
878
776
|
* Called when a comment has been read
|
|
879
777
|
*/
|
|
880
|
-
|
|
881
778
|
self.events.on('comment-read', function (response) {
|
|
882
|
-
self.
|
|
883
|
-
|
|
779
|
+
self._logger.info('comment-read', response);
|
|
884
780
|
if (self.options.commentReadCallback) {
|
|
885
781
|
self.options.commentReadCallback(response);
|
|
886
782
|
}
|
|
887
783
|
});
|
|
784
|
+
|
|
888
785
|
/**
|
|
889
786
|
* Called when there's new presence data of currently subscribed target user (last seen timestamp)
|
|
890
787
|
* @param {string} data MQTT Payload with format of "x:xxxxxxxxxxxxx"
|
|
891
788
|
*/
|
|
892
|
-
|
|
893
789
|
self.events.on('presence', function (_ref5) {
|
|
894
790
|
var message = _ref5.message,
|
|
895
|
-
|
|
791
|
+
userId = _ref5.userId;
|
|
896
792
|
var payload = message.split(':');
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
_this3.chatmateStatus = payload[0] === 1 ? 'Online' : "Last seen ".concat((0, _distance_in_words_to_now["default"])(Number(payload[1].substring(0, 13))));
|
|
793
|
+
if (_this4.chatmateStatus !== payload[0]) {
|
|
794
|
+
_this4.chatmateStatus = payload[0] === 1 ? 'Online' : "Last seen ".concat((0, _distance_in_words_to_now["default"])(Number(payload[1].substring(0, 13))));
|
|
900
795
|
}
|
|
901
|
-
|
|
902
796
|
if (self.options.presenceCallback) self.options.presenceCallback(message, userId);
|
|
903
797
|
});
|
|
904
798
|
self.events.on('typing', function (data) {
|
|
905
799
|
if (self.options.typingCallback) self.options.typingCallback(data);
|
|
906
800
|
});
|
|
801
|
+
|
|
907
802
|
/**
|
|
908
803
|
* Called when user clicked on Message Info
|
|
909
804
|
*/
|
|
910
|
-
|
|
911
805
|
self.events.on('message-info', function (response) {
|
|
912
806
|
if (self.options.messageInfoCallback) {
|
|
913
807
|
self.options.messageInfoCallback(response);
|
|
914
808
|
}
|
|
915
809
|
});
|
|
810
|
+
|
|
916
811
|
/**
|
|
917
812
|
* Called when new particant was added into a group
|
|
918
813
|
*/
|
|
919
|
-
|
|
920
814
|
self.events.on('participants-added', function (response) {
|
|
921
|
-
var
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
(_this3$selected$parti = _this3.selected.participants).push.apply(_this3$selected$parti, (0, _toConsumableArray2["default"])(response));
|
|
815
|
+
var _this4$selected$parti;
|
|
816
|
+
if (response == null || _this4.selected == null) return;
|
|
817
|
+
(_this4$selected$parti = _this4.selected.participants).push.apply(_this4$selected$parti, (0, _toConsumableArray2["default"])(response));
|
|
926
818
|
});
|
|
819
|
+
|
|
927
820
|
/**
|
|
928
821
|
* Called when particant was removed from a group
|
|
929
822
|
*/
|
|
930
|
-
|
|
931
823
|
self.events.on('participants-removed', function (response) {
|
|
932
|
-
if (response == null ||
|
|
933
|
-
|
|
934
|
-
var participants = _this3.selected.participants.filter(function (participant) {
|
|
824
|
+
if (response == null || _this4.selected == null) return;
|
|
825
|
+
var participants = _this4.selected.participants.filter(function (participant) {
|
|
935
826
|
return response.indexOf(participant.email) <= -1;
|
|
936
827
|
});
|
|
937
|
-
|
|
938
|
-
_this3.selected.participants = participants;
|
|
828
|
+
_this4.selected.participants = participants;
|
|
939
829
|
});
|
|
830
|
+
|
|
940
831
|
/**
|
|
941
832
|
* Called when user was added to blocked list
|
|
942
833
|
*/
|
|
943
|
-
|
|
944
834
|
self.events.on('block-user', function (response) {
|
|
945
835
|
if (self.options.blockUserCallback) {
|
|
946
836
|
self.options.blockUserCallback(response);
|
|
947
837
|
}
|
|
948
838
|
});
|
|
839
|
+
|
|
949
840
|
/**
|
|
950
841
|
* Called when user was removed from blocked list
|
|
951
842
|
*/
|
|
952
|
-
|
|
953
843
|
self.events.on('unblock-user', function (response) {
|
|
954
844
|
if (self.options.unblockUserCallback) {
|
|
955
845
|
self.options.unblockUserCallback(response);
|
|
@@ -977,6 +867,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
977
867
|
this.last_received_comment_id = id;
|
|
978
868
|
}
|
|
979
869
|
}
|
|
870
|
+
|
|
980
871
|
/**
|
|
981
872
|
* Setting Up User Credentials for next API Request
|
|
982
873
|
* @param userId {string} - client userId (will be used for login or register)
|
|
@@ -986,12 +877,10 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
986
877
|
* @param extras {object} - extra data for user
|
|
987
878
|
* @return {Promise}
|
|
988
879
|
*/
|
|
989
|
-
|
|
990
880
|
}, {
|
|
991
881
|
key: "setUser",
|
|
992
882
|
value: function setUser(userId, key, username, avatarURL, extras) {
|
|
993
|
-
var
|
|
994
|
-
|
|
883
|
+
var _this5 = this;
|
|
995
884
|
var self = this;
|
|
996
885
|
self.user_id = userId;
|
|
997
886
|
self.key = key;
|
|
@@ -1006,23 +895,17 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1006
895
|
if (this.avatar_url) params.avatar_url = this.avatar_url;
|
|
1007
896
|
return new Promise(function (resolve, reject) {
|
|
1008
897
|
var waitingConfig = setInterval(function () {
|
|
1009
|
-
if (!
|
|
1010
|
-
|
|
1011
|
-
_this4.logger('Waiting for init config...');
|
|
1012
|
-
}
|
|
898
|
+
if (!_this5.isConfigLoaded) {
|
|
899
|
+
_this5._logger.info('Waiting for init config...');
|
|
1013
900
|
} else {
|
|
1014
901
|
clearInterval(waitingConfig);
|
|
1015
|
-
|
|
1016
|
-
_this4.logger('Config Success!');
|
|
1017
|
-
|
|
902
|
+
_this5._logger.info('Config Success!');
|
|
1018
903
|
self.events.emit('start-init');
|
|
1019
904
|
var login$ = self.authAdapter.loginOrRegister(params).then(function (response) {
|
|
1020
905
|
self.isInit = true;
|
|
1021
906
|
self.refresh_token = response.user.refresh_token;
|
|
1022
907
|
self.events.emit('login-success', response);
|
|
1023
|
-
|
|
1024
|
-
_this4.realtimeAdapter.connect();
|
|
1025
|
-
|
|
908
|
+
_this5.realtimeAdapter.connect();
|
|
1026
909
|
resolve(response);
|
|
1027
910
|
}, function (error) {
|
|
1028
911
|
self.events.emit('login-error', error);
|
|
@@ -1036,8 +919,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1036
919
|
}, {
|
|
1037
920
|
key: "setUserWithIdentityToken",
|
|
1038
921
|
value: function setUserWithIdentityToken(data) {
|
|
1039
|
-
var
|
|
1040
|
-
|
|
922
|
+
var _this6 = this;
|
|
1041
923
|
if (!data || !('user' in data)) return this.events.emit('login-error', data);
|
|
1042
924
|
this.email = data.user.email;
|
|
1043
925
|
this.user_id = data.user.email;
|
|
@@ -1046,16 +928,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1046
928
|
this.avatar_url = data.user.avatar_url;
|
|
1047
929
|
this.isInit = true;
|
|
1048
930
|
var waitingConfig = setInterval(function () {
|
|
1049
|
-
if (!
|
|
1050
|
-
|
|
1051
|
-
_this5.logger('Waiting for init config...');
|
|
1052
|
-
}
|
|
931
|
+
if (!_this6.isConfigLoaded) {
|
|
932
|
+
_this6._logger.info('Waiting for init config...');
|
|
1053
933
|
} else {
|
|
1054
934
|
clearInterval(waitingConfig);
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
_this5.events.emit('login-success', data);
|
|
935
|
+
_this6._logger.info('Config Success!');
|
|
936
|
+
_this6.events.emit('login-success', data);
|
|
1059
937
|
}
|
|
1060
938
|
}, 300);
|
|
1061
939
|
}
|
|
@@ -1067,17 +945,16 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1067
945
|
}, {
|
|
1068
946
|
key: "publishOnlinePresence",
|
|
1069
947
|
value: function publishOnlinePresence(val) {
|
|
1070
|
-
var
|
|
1071
|
-
|
|
948
|
+
var _this7 = this;
|
|
1072
949
|
if (val === true) {
|
|
1073
950
|
setBackToOnline = setInterval(function () {
|
|
1074
|
-
|
|
951
|
+
_this7.realtimeAdapter.publishPresence(_this7.user_id, true);
|
|
1075
952
|
}, 3500);
|
|
1076
953
|
} else {
|
|
1077
954
|
clearInterval(this.presensePublisherId);
|
|
1078
955
|
clearInterval(setBackToOnline);
|
|
1079
956
|
setTimeout(function () {
|
|
1080
|
-
|
|
957
|
+
_this7.realtimeAdapter.publishPresence(_this7.user_id, false);
|
|
1081
958
|
}, 3500);
|
|
1082
959
|
}
|
|
1083
960
|
}
|
|
@@ -1094,37 +971,41 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1094
971
|
}, {
|
|
1095
972
|
key: "logout",
|
|
1096
973
|
value: function () {
|
|
1097
|
-
var _logout = (0, _asyncToGenerator2["default"])(
|
|
1098
|
-
return _regenerator["default"].wrap(function
|
|
1099
|
-
while (1) {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
case 9:
|
|
1115
|
-
case "end":
|
|
1116
|
-
return _context4.stop();
|
|
1117
|
-
}
|
|
974
|
+
var _logout = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee4() {
|
|
975
|
+
return _regenerator["default"].wrap(function (_context4) {
|
|
976
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
977
|
+
case 0:
|
|
978
|
+
_context4.next = 1;
|
|
979
|
+
return this.expiredTokenAdapter.logout();
|
|
980
|
+
case 1:
|
|
981
|
+
clearInterval(this.presensePublisherId);
|
|
982
|
+
this.publishOnlinePresence(false);
|
|
983
|
+
this.selected = null;
|
|
984
|
+
this.isInit = false;
|
|
985
|
+
this.isLogin = false;
|
|
986
|
+
this.realtimeAdapter.disconnect();
|
|
987
|
+
this.userData = {};
|
|
988
|
+
case 2:
|
|
989
|
+
case "end":
|
|
990
|
+
return _context4.stop();
|
|
1118
991
|
}
|
|
1119
992
|
}, _callee4, this);
|
|
1120
993
|
}));
|
|
1121
|
-
|
|
1122
994
|
function logout() {
|
|
1123
995
|
return _logout.apply(this, arguments);
|
|
1124
996
|
}
|
|
1125
|
-
|
|
1126
997
|
return logout;
|
|
1127
998
|
}()
|
|
999
|
+
}, {
|
|
1000
|
+
key: "synchronize",
|
|
1001
|
+
get: function get() {
|
|
1002
|
+
return this.syncAdapter.synchronize;
|
|
1003
|
+
}
|
|
1004
|
+
}, {
|
|
1005
|
+
key: "synchronizeEvent",
|
|
1006
|
+
get: function get() {
|
|
1007
|
+
return this.syncAdapter.synchronizeEvent;
|
|
1008
|
+
}
|
|
1128
1009
|
}, {
|
|
1129
1010
|
key: "disconnect",
|
|
1130
1011
|
value: function disconnect() {
|
|
@@ -1133,177 +1014,146 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1133
1014
|
}, {
|
|
1134
1015
|
key: "setActiveRoom",
|
|
1135
1016
|
value: function setActiveRoom(room) {
|
|
1136
|
-
var
|
|
1137
|
-
|
|
1017
|
+
var _this8 = this;
|
|
1138
1018
|
// when we activate a room
|
|
1139
1019
|
// we need to unsubscribe from typing event
|
|
1140
1020
|
if (this.selected) {
|
|
1141
|
-
this.realtimeAdapter.unsubscribeTyping();
|
|
1021
|
+
this.realtimeAdapter.unsubscribeTyping();
|
|
1022
|
+
// before we unsubscribe, we need to get the userId first
|
|
1142
1023
|
// and only unsubscribe if the previous room is having a type of 'single'
|
|
1143
|
-
|
|
1144
1024
|
if (this.selected.room_type === 'single') {
|
|
1145
1025
|
var unsubscribedUserId = this.selected.participants.filter(function (p) {
|
|
1146
|
-
return p.email !==
|
|
1026
|
+
return p.email !== _this8.user_id;
|
|
1147
1027
|
});
|
|
1148
|
-
|
|
1149
1028
|
if (unsubscribedUserId.length > 0) {
|
|
1150
1029
|
this.realtimeAdapter.unsubscribeRoomPresence(unsubscribedUserId[0].email);
|
|
1151
1030
|
}
|
|
1152
1031
|
}
|
|
1153
1032
|
}
|
|
1154
|
-
|
|
1155
1033
|
if (room.participants == null) room.participants = [];
|
|
1156
1034
|
var targetUserId = room.participants.find(function (p) {
|
|
1157
|
-
return p.email !==
|
|
1035
|
+
return p.email !== _this8.user_id;
|
|
1158
1036
|
});
|
|
1159
1037
|
this.chatmateStatus = null;
|
|
1160
1038
|
this.isTypingStatus = null;
|
|
1161
|
-
this.selected = room;
|
|
1039
|
+
this.selected = room;
|
|
1040
|
+
// found a bug where there's a race condition, subscribing to mqtt
|
|
1162
1041
|
// while mqtt is still connecting, so we'll have to do this hack
|
|
1163
|
-
|
|
1164
1042
|
var initialSubscribe = setInterval(function () {
|
|
1165
1043
|
// Clear Interval when realtimeAdapter has been Populated
|
|
1166
|
-
if (_this7.debugMode) {
|
|
1167
|
-
_this7.logger('Trying Initial Subscribe');
|
|
1168
|
-
}
|
|
1169
1044
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1045
|
+
_this8._logger.info('Trying Initial Subscribe');
|
|
1046
|
+
if (_this8.realtimeAdapter != null) {
|
|
1047
|
+
_this8._logger.info('MQTT Connected');
|
|
1048
|
+
clearInterval(initialSubscribe);
|
|
1174
1049
|
|
|
1175
|
-
|
|
1050
|
+
// before we unsubscribe, we need to get the userId first
|
|
1176
1051
|
// and only unsubscribe if the previous room is having a type of 'single'
|
|
1177
|
-
|
|
1178
1052
|
if (room.room_type === 'single' && targetUserId != null) {
|
|
1179
|
-
|
|
1180
|
-
} // we need to subscribe to new room typing event now
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
if (_this7.selected != null && !_this7.selected.isChannel) {
|
|
1184
|
-
_this7.realtimeAdapter.subscribeTyping(room.id);
|
|
1185
|
-
|
|
1186
|
-
_this7.events.emit('room-changed', _this7.selected);
|
|
1053
|
+
_this8.realtimeAdapter.subscribeRoomPresence(targetUserId.email);
|
|
1187
1054
|
}
|
|
1188
|
-
|
|
1189
|
-
if (
|
|
1190
|
-
|
|
1055
|
+
// we need to subscribe to new room typing event now
|
|
1056
|
+
if (_this8.selected != null && !_this8.selected.isChannel) {
|
|
1057
|
+
_this8.realtimeAdapter.subscribeTyping(room.id);
|
|
1058
|
+
_this8.events.emit('room-changed', _this8.selected);
|
|
1191
1059
|
}
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
_this7.logger('MQTT Not Connected, yet');
|
|
1060
|
+
if (_this8.realtimeAdapter == null) {
|
|
1061
|
+
_this8._logger.info('Retry');
|
|
1195
1062
|
}
|
|
1063
|
+
} else {
|
|
1064
|
+
_this8._logger.info('MQTT Not Connected, yet');
|
|
1196
1065
|
}
|
|
1197
1066
|
}, 3000);
|
|
1198
1067
|
}
|
|
1068
|
+
|
|
1199
1069
|
/**
|
|
1200
1070
|
* Chat with targetted email
|
|
1201
1071
|
* @param userId {string} - target userId
|
|
1202
1072
|
* @param options {object} - optional data sent to qiscus database
|
|
1203
1073
|
* @return room <Room>
|
|
1204
1074
|
*/
|
|
1205
|
-
|
|
1206
1075
|
}, {
|
|
1207
1076
|
key: "chatTarget",
|
|
1208
1077
|
value: function chatTarget(userId) {
|
|
1209
|
-
var
|
|
1210
|
-
|
|
1078
|
+
var _this9 = this;
|
|
1211
1079
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1212
1080
|
// make sure data already loaded first (user already logged in)
|
|
1213
1081
|
if (this.userData.length != null) return false;
|
|
1214
1082
|
var initialMessage = options ? options.message : null;
|
|
1215
1083
|
var distinctId = options.distinctId;
|
|
1216
1084
|
this.isLoading = true;
|
|
1217
|
-
this.isTypingStatus = '';
|
|
1085
|
+
this.isTypingStatus = '';
|
|
1218
1086
|
|
|
1219
|
-
|
|
1220
|
-
|
|
1087
|
+
// Create room
|
|
1088
|
+
return this.roomAdapter.getOrCreateRoom(userId, options, distinctId).then(/*#__PURE__*/function () {
|
|
1089
|
+
var _ref6 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee6(resp) {
|
|
1221
1090
|
var room, mapIntercept, lastComment, topicId;
|
|
1222
|
-
return _regenerator["default"].wrap(function
|
|
1223
|
-
while (1) {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
return _context5.abrupt("return", _context5.sent);
|
|
1243
|
-
|
|
1244
|
-
case 3:
|
|
1245
|
-
case "end":
|
|
1246
|
-
return _context5.stop();
|
|
1247
|
-
}
|
|
1248
|
-
}
|
|
1249
|
-
}, _callee5);
|
|
1250
|
-
}));
|
|
1251
|
-
|
|
1252
|
-
return function mapIntercept(_x5) {
|
|
1253
|
-
return _ref7.apply(this, arguments);
|
|
1254
|
-
};
|
|
1255
|
-
}();
|
|
1256
|
-
|
|
1257
|
-
_context6.next = 6;
|
|
1258
|
-
return Promise.all(room.comments.map(function (comment) {
|
|
1259
|
-
return mapIntercept(comment);
|
|
1260
|
-
}));
|
|
1261
|
-
|
|
1262
|
-
case 6:
|
|
1263
|
-
room.comments = _context6.sent;
|
|
1264
|
-
|
|
1265
|
-
_this8.setActiveRoom(room); // id of last comment on this room
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
lastComment = room.comments[room.comments.length - 1];
|
|
1269
|
-
if (lastComment) _this8.readComment(room.id, lastComment.id);
|
|
1270
|
-
|
|
1271
|
-
_this8.events.emit('chat-room-created', {
|
|
1272
|
-
room: room
|
|
1273
|
-
});
|
|
1274
|
-
|
|
1275
|
-
if (initialMessage) {
|
|
1276
|
-
_context6.next = 13;
|
|
1277
|
-
break;
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
return _context6.abrupt("return", room);
|
|
1281
|
-
|
|
1282
|
-
case 13:
|
|
1283
|
-
topicId = room.id;
|
|
1284
|
-
return _context6.abrupt("return", _this8.sendComment(topicId, initialMessage).then(function () {
|
|
1285
|
-
return Promise.resolve(room);
|
|
1286
|
-
})["catch"](function (err) {
|
|
1287
|
-
console.error('Error when submit comment', err);
|
|
1091
|
+
return _regenerator["default"].wrap(function (_context6) {
|
|
1092
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
1093
|
+
case 0:
|
|
1094
|
+
room = new _Room["default"](resp);
|
|
1095
|
+
_this9.updateLastReceivedComment(room.last_comment_id);
|
|
1096
|
+
_this9.isLoading = false;
|
|
1097
|
+
mapIntercept = /*#__PURE__*/function () {
|
|
1098
|
+
var _ref7 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee5(it) {
|
|
1099
|
+
return _regenerator["default"].wrap(function (_context5) {
|
|
1100
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
1101
|
+
case 0:
|
|
1102
|
+
_context5.next = 1;
|
|
1103
|
+
return _this9._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, it);
|
|
1104
|
+
case 1:
|
|
1105
|
+
return _context5.abrupt("return", _context5.sent);
|
|
1106
|
+
case 2:
|
|
1107
|
+
case "end":
|
|
1108
|
+
return _context5.stop();
|
|
1109
|
+
}
|
|
1110
|
+
}, _callee5);
|
|
1288
1111
|
}));
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1112
|
+
return function mapIntercept(_x5) {
|
|
1113
|
+
return _ref7.apply(this, arguments);
|
|
1114
|
+
};
|
|
1115
|
+
}();
|
|
1116
|
+
_context6.next = 1;
|
|
1117
|
+
return Promise.all(room.comments.map(function (comment) {
|
|
1118
|
+
return mapIntercept(comment);
|
|
1119
|
+
}));
|
|
1120
|
+
case 1:
|
|
1121
|
+
room.comments = _context6.sent;
|
|
1122
|
+
_this9.setActiveRoom(room);
|
|
1123
|
+
// id of last comment on this room
|
|
1124
|
+
lastComment = room.comments[room.comments.length - 1];
|
|
1125
|
+
if (lastComment) _this9.readComment(room.id, lastComment.id);
|
|
1126
|
+
_this9.events.emit('chat-room-created', {
|
|
1127
|
+
room: room
|
|
1128
|
+
});
|
|
1129
|
+
if (initialMessage) {
|
|
1130
|
+
_context6.next = 2;
|
|
1131
|
+
break;
|
|
1132
|
+
}
|
|
1133
|
+
return _context6.abrupt("return", room);
|
|
1134
|
+
case 2:
|
|
1135
|
+
topicId = room.id;
|
|
1136
|
+
return _context6.abrupt("return", _this9.sendComment(topicId, initialMessage).then(function () {
|
|
1137
|
+
return Promise.resolve(room);
|
|
1138
|
+
})["catch"](function (err) {
|
|
1139
|
+
console.error('Error when submit comment', err);
|
|
1140
|
+
}));
|
|
1141
|
+
case 3:
|
|
1142
|
+
case "end":
|
|
1143
|
+
return _context6.stop();
|
|
1294
1144
|
}
|
|
1295
1145
|
}, _callee6);
|
|
1296
1146
|
}));
|
|
1297
|
-
|
|
1298
1147
|
return function (_x4) {
|
|
1299
1148
|
return _ref6.apply(this, arguments);
|
|
1300
1149
|
};
|
|
1301
1150
|
}())["catch"](function (err) {
|
|
1302
1151
|
console.error('Error when creating room', err);
|
|
1303
|
-
|
|
1152
|
+
_this9.isLoading = false;
|
|
1304
1153
|
return Promise.reject(err);
|
|
1305
1154
|
});
|
|
1306
1155
|
}
|
|
1156
|
+
|
|
1307
1157
|
/**
|
|
1308
1158
|
*
|
|
1309
1159
|
* Open a group chat or target a specific room id
|
|
@@ -1312,7 +1162,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1312
1162
|
* @returns Room <Room>
|
|
1313
1163
|
* @memberof QiscusSDK
|
|
1314
1164
|
*/
|
|
1315
|
-
|
|
1316
1165
|
}, {
|
|
1317
1166
|
key: "chatGroup",
|
|
1318
1167
|
value: function chatGroup(id) {
|
|
@@ -1324,99 +1173,79 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1324
1173
|
return Promise.reject(err);
|
|
1325
1174
|
});
|
|
1326
1175
|
}
|
|
1176
|
+
|
|
1327
1177
|
/**
|
|
1328
1178
|
* @param {int} id - Room Id
|
|
1329
1179
|
* @return {Room} Room data
|
|
1330
1180
|
*/
|
|
1331
|
-
|
|
1332
1181
|
}, {
|
|
1333
1182
|
key: "getRoomById",
|
|
1334
1183
|
value: function getRoomById(id) {
|
|
1335
|
-
var
|
|
1336
|
-
|
|
1184
|
+
var _this0 = this;
|
|
1337
1185
|
if (!this.isInit) return;
|
|
1338
1186
|
var self = this;
|
|
1339
1187
|
self.isLoading = true;
|
|
1340
1188
|
self.isTypingStatus = '';
|
|
1341
|
-
return self.roomAdapter.getRoomById(id).then(
|
|
1342
|
-
var _ref8 = (0, _asyncToGenerator2["default"])(
|
|
1343
|
-
var roomData, comments, _iterator, _step, comment, c, room, lastComment;
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
_iterator.s();
|
|
1355
|
-
|
|
1356
|
-
case 5:
|
|
1357
|
-
if ((_step = _iterator.n()).done) {
|
|
1358
|
-
_context7.next = 13;
|
|
1359
|
-
break;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
comment = _step.value;
|
|
1363
|
-
_context7.next = 9;
|
|
1364
|
-
return _this9._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
|
|
1365
|
-
|
|
1366
|
-
case 9:
|
|
1367
|
-
c = _context7.sent;
|
|
1368
|
-
comments.push(c);
|
|
1369
|
-
|
|
1370
|
-
case 11:
|
|
1189
|
+
return self.roomAdapter.getRoomById(id).then(/*#__PURE__*/function () {
|
|
1190
|
+
var _ref8 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee7(resp) {
|
|
1191
|
+
var roomData, comments, _iterator, _step, comment, c, room, lastComment, _t;
|
|
1192
|
+
return _regenerator["default"].wrap(function (_context7) {
|
|
1193
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
1194
|
+
case 0:
|
|
1195
|
+
roomData = resp.results.room;
|
|
1196
|
+
comments = [];
|
|
1197
|
+
_iterator = _createForOfIteratorHelper(resp.results.comments.reverse());
|
|
1198
|
+
_context7.prev = 1;
|
|
1199
|
+
_iterator.s();
|
|
1200
|
+
case 2:
|
|
1201
|
+
if ((_step = _iterator.n()).done) {
|
|
1371
1202
|
_context7.next = 5;
|
|
1372
1203
|
break;
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
}
|
|
1204
|
+
}
|
|
1205
|
+
comment = _step.value;
|
|
1206
|
+
_context7.next = 3;
|
|
1207
|
+
return _this0._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
|
|
1208
|
+
case 3:
|
|
1209
|
+
c = _context7.sent;
|
|
1210
|
+
comments.push(c);
|
|
1211
|
+
case 4:
|
|
1212
|
+
_context7.next = 2;
|
|
1213
|
+
break;
|
|
1214
|
+
case 5:
|
|
1215
|
+
_context7.next = 7;
|
|
1216
|
+
break;
|
|
1217
|
+
case 6:
|
|
1218
|
+
_context7.prev = 6;
|
|
1219
|
+
_t = _context7["catch"](1);
|
|
1220
|
+
_iterator.e(_t);
|
|
1221
|
+
case 7:
|
|
1222
|
+
_context7.prev = 7;
|
|
1223
|
+
_iterator.f();
|
|
1224
|
+
return _context7.finish(7);
|
|
1225
|
+
case 8:
|
|
1226
|
+
// .map((it) =>
|
|
1227
|
+
// this._hookAdapter.trigger(Hooks.MESSAGE_BEFORE_RECEIVED, it)
|
|
1228
|
+
// );
|
|
1229
|
+
room = new _Room["default"](_objectSpread(_objectSpread({}, roomData), {}, {
|
|
1230
|
+
comments: comments,
|
|
1231
|
+
name: roomData.room_name
|
|
1232
|
+
}));
|
|
1233
|
+
self.updateLastReceivedComment(room.last_comment_id);
|
|
1234
|
+
self.setActiveRoom(room);
|
|
1235
|
+
self.isLoading = false;
|
|
1236
|
+
// id of last comment on this room
|
|
1237
|
+
lastComment = room.comments[room.comments.length - 1];
|
|
1238
|
+
if (lastComment) self.readComment(room.id, lastComment.id);
|
|
1239
|
+
if (room.isChannel) {
|
|
1240
|
+
_this0.realtimeAdapter.subscribeChannel(_this0.AppId, room.unique_id);
|
|
1241
|
+
}
|
|
1242
|
+
return _context7.abrupt("return", room);
|
|
1243
|
+
case 9:
|
|
1244
|
+
case "end":
|
|
1245
|
+
return _context7.stop();
|
|
1416
1246
|
}
|
|
1417
|
-
}, _callee7, null, [[
|
|
1247
|
+
}, _callee7, null, [[1, 6, 7, 8]]);
|
|
1418
1248
|
}));
|
|
1419
|
-
|
|
1420
1249
|
return function (_x6) {
|
|
1421
1250
|
return _ref8.apply(this, arguments);
|
|
1422
1251
|
};
|
|
@@ -1425,81 +1254,66 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1425
1254
|
return Promise.reject(error);
|
|
1426
1255
|
});
|
|
1427
1256
|
}
|
|
1257
|
+
|
|
1428
1258
|
/**
|
|
1429
1259
|
* @param {int} id - Room Id
|
|
1430
1260
|
* @param {string} roomName
|
|
1431
1261
|
* @param {string} avatarURL
|
|
1432
1262
|
* @return {Room} Room data
|
|
1433
1263
|
*/
|
|
1434
|
-
|
|
1435
1264
|
}, {
|
|
1436
1265
|
key: "getOrCreateRoomByUniqueId",
|
|
1437
1266
|
value: function getOrCreateRoomByUniqueId(id, roomName, avatarURL) {
|
|
1438
|
-
var
|
|
1439
|
-
|
|
1267
|
+
var _this1 = this;
|
|
1440
1268
|
var self = this;
|
|
1441
1269
|
self.isLoading = true;
|
|
1442
1270
|
self.isTypingStatus = '';
|
|
1443
|
-
return self.roomAdapter.getOrCreateRoomByUniqueId(id, roomName, avatarURL).then(
|
|
1444
|
-
var _ref9 = (0, _asyncToGenerator2["default"])(
|
|
1271
|
+
return self.roomAdapter.getOrCreateRoomByUniqueId(id, roomName, avatarURL).then(/*#__PURE__*/function () {
|
|
1272
|
+
var _ref9 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee9(response) {
|
|
1445
1273
|
var room, mapIntercept, lastComment;
|
|
1446
|
-
return _regenerator["default"].wrap(function
|
|
1447
|
-
while (1) {
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
case 3:
|
|
1467
|
-
case "end":
|
|
1468
|
-
return _context8.stop();
|
|
1469
|
-
}
|
|
1470
|
-
}
|
|
1471
|
-
}, _callee8);
|
|
1472
|
-
}));
|
|
1473
|
-
|
|
1474
|
-
return function mapIntercept(_x8) {
|
|
1475
|
-
return _ref10.apply(this, arguments);
|
|
1476
|
-
};
|
|
1477
|
-
}();
|
|
1478
|
-
|
|
1479
|
-
_context9.next = 5;
|
|
1480
|
-
return Promise.all(room.comments.map(function (it) {
|
|
1481
|
-
return mapIntercept(it);
|
|
1274
|
+
return _regenerator["default"].wrap(function (_context9) {
|
|
1275
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
1276
|
+
case 0:
|
|
1277
|
+
// make sure the room hasn't been pushed yet
|
|
1278
|
+
room = new _Room["default"](response);
|
|
1279
|
+
self.updateLastReceivedComment(room.last_comment_id);
|
|
1280
|
+
mapIntercept = /*#__PURE__*/function () {
|
|
1281
|
+
var _ref0 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee8(item) {
|
|
1282
|
+
return _regenerator["default"].wrap(function (_context8) {
|
|
1283
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
1284
|
+
case 0:
|
|
1285
|
+
_context8.next = 1;
|
|
1286
|
+
return _this1._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, item);
|
|
1287
|
+
case 1:
|
|
1288
|
+
return _context8.abrupt("return", _context8.sent);
|
|
1289
|
+
case 2:
|
|
1290
|
+
case "end":
|
|
1291
|
+
return _context8.stop();
|
|
1292
|
+
}
|
|
1293
|
+
}, _callee8);
|
|
1482
1294
|
}));
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1295
|
+
return function mapIntercept(_x8) {
|
|
1296
|
+
return _ref0.apply(this, arguments);
|
|
1297
|
+
};
|
|
1298
|
+
}();
|
|
1299
|
+
_context9.next = 1;
|
|
1300
|
+
return Promise.all(room.comments.map(function (it) {
|
|
1301
|
+
return mapIntercept(it);
|
|
1302
|
+
}));
|
|
1303
|
+
case 1:
|
|
1304
|
+
room.comments = _context9.sent;
|
|
1305
|
+
self.setActiveRoom(room);
|
|
1306
|
+
self.isLoading = false;
|
|
1307
|
+
lastComment = room.comments[room.comments.length - 1];
|
|
1308
|
+
if (lastComment) self.readComment(room.id, lastComment.id);
|
|
1309
|
+
_this1.realtimeAdapter.subscribeChannel(_this1.AppId, room.unique_id);
|
|
1310
|
+
return _context9.abrupt("return", Promise.resolve(room));
|
|
1311
|
+
case 2:
|
|
1312
|
+
case "end":
|
|
1313
|
+
return _context9.stop();
|
|
1499
1314
|
}
|
|
1500
1315
|
}, _callee9);
|
|
1501
1316
|
}));
|
|
1502
|
-
|
|
1503
1317
|
return function (_x7) {
|
|
1504
1318
|
return _ref9.apply(this, arguments);
|
|
1505
1319
|
};
|
|
@@ -1523,119 +1337,92 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1523
1337
|
}, {
|
|
1524
1338
|
key: "loadRoomList",
|
|
1525
1339
|
value: function () {
|
|
1526
|
-
var _loadRoomList = (0, _asyncToGenerator2["default"])(
|
|
1340
|
+
var _loadRoomList = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee0() {
|
|
1527
1341
|
var params,
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
return _regenerator["default"].wrap(function
|
|
1531
|
-
while (1) {
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
case 5:
|
|
1550
|
-
case "end":
|
|
1551
|
-
return _context10.stop();
|
|
1552
|
-
}
|
|
1342
|
+
rooms,
|
|
1343
|
+
_args0 = arguments;
|
|
1344
|
+
return _regenerator["default"].wrap(function (_context0) {
|
|
1345
|
+
while (1) switch (_context0.prev = _context0.next) {
|
|
1346
|
+
case 0:
|
|
1347
|
+
params = _args0.length > 0 && _args0[0] !== undefined ? _args0[0] : {};
|
|
1348
|
+
_context0.next = 1;
|
|
1349
|
+
return this.userAdapter.loadRoomList(params);
|
|
1350
|
+
case 1:
|
|
1351
|
+
rooms = _context0.sent;
|
|
1352
|
+
return _context0.abrupt("return", rooms.map(function (room) {
|
|
1353
|
+
room.last_comment_id = room.last_comment.id;
|
|
1354
|
+
room.last_comment_message = room.last_comment.message;
|
|
1355
|
+
room.last_comment_message_created_at = room.last_comment.timestamp;
|
|
1356
|
+
room.room_type = room.chat_type;
|
|
1357
|
+
room.comments = [];
|
|
1358
|
+
return new _Room["default"](room);
|
|
1359
|
+
}));
|
|
1360
|
+
case 2:
|
|
1361
|
+
case "end":
|
|
1362
|
+
return _context0.stop();
|
|
1553
1363
|
}
|
|
1554
|
-
},
|
|
1364
|
+
}, _callee0, this);
|
|
1555
1365
|
}));
|
|
1556
|
-
|
|
1557
1366
|
function loadRoomList() {
|
|
1558
1367
|
return _loadRoomList.apply(this, arguments);
|
|
1559
1368
|
}
|
|
1560
|
-
|
|
1561
1369
|
return loadRoomList;
|
|
1562
1370
|
}()
|
|
1563
1371
|
}, {
|
|
1564
1372
|
key: "loadComments",
|
|
1565
1373
|
value: function loadComments(roomId) {
|
|
1566
|
-
var
|
|
1567
|
-
|
|
1374
|
+
var _this10 = this;
|
|
1568
1375
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1569
|
-
return this.userAdapter.loadComments(roomId, options).then(
|
|
1570
|
-
var
|
|
1571
|
-
var comments, _iterator2, _step2, comment;
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
case 4:
|
|
1584
|
-
if ((_step2 = _iterator2.n()).done) {
|
|
1585
|
-
_context11.next = 13;
|
|
1586
|
-
break;
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
|
-
comment = _step2.value;
|
|
1590
|
-
_context11.t0 = comments;
|
|
1591
|
-
_context11.next = 9;
|
|
1592
|
-
return _this11._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
|
|
1593
|
-
|
|
1594
|
-
case 9:
|
|
1595
|
-
_context11.t1 = _context11.sent;
|
|
1596
|
-
|
|
1597
|
-
_context11.t0.push.call(_context11.t0, _context11.t1);
|
|
1598
|
-
|
|
1599
|
-
case 11:
|
|
1600
|
-
_context11.next = 4;
|
|
1601
|
-
break;
|
|
1602
|
-
|
|
1603
|
-
case 13:
|
|
1604
|
-
_context11.next = 18;
|
|
1376
|
+
return this.userAdapter.loadComments(roomId, options).then(/*#__PURE__*/function () {
|
|
1377
|
+
var _ref1 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee1(comments_) {
|
|
1378
|
+
var comments, _iterator2, _step2, comment, _t2, _t3, _t4;
|
|
1379
|
+
return _regenerator["default"].wrap(function (_context1) {
|
|
1380
|
+
while (1) switch (_context1.prev = _context1.next) {
|
|
1381
|
+
case 0:
|
|
1382
|
+
comments = [];
|
|
1383
|
+
_iterator2 = _createForOfIteratorHelper(comments_);
|
|
1384
|
+
_context1.prev = 1;
|
|
1385
|
+
_iterator2.s();
|
|
1386
|
+
case 2:
|
|
1387
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
1388
|
+
_context1.next = 5;
|
|
1605
1389
|
break;
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1390
|
+
}
|
|
1391
|
+
comment = _step2.value;
|
|
1392
|
+
_t2 = comments;
|
|
1393
|
+
_context1.next = 3;
|
|
1394
|
+
return _this10._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, comment);
|
|
1395
|
+
case 3:
|
|
1396
|
+
_t3 = _context1.sent;
|
|
1397
|
+
_t2.push.call(_t2, _t3);
|
|
1398
|
+
case 4:
|
|
1399
|
+
_context1.next = 2;
|
|
1400
|
+
break;
|
|
1401
|
+
case 5:
|
|
1402
|
+
_context1.next = 7;
|
|
1403
|
+
break;
|
|
1404
|
+
case 6:
|
|
1405
|
+
_context1.prev = 6;
|
|
1406
|
+
_t4 = _context1["catch"](1);
|
|
1407
|
+
_iterator2.e(_t4);
|
|
1408
|
+
case 7:
|
|
1409
|
+
_context1.prev = 7;
|
|
1410
|
+
_iterator2.f();
|
|
1411
|
+
return _context1.finish(7);
|
|
1412
|
+
case 8:
|
|
1413
|
+
if (_this10.selected != null) {
|
|
1414
|
+
_this10.selected.receiveComments(comments.reverse());
|
|
1415
|
+
_this10.sortComments();
|
|
1416
|
+
}
|
|
1417
|
+
return _context1.abrupt("return", comments);
|
|
1418
|
+
case 9:
|
|
1419
|
+
case "end":
|
|
1420
|
+
return _context1.stop();
|
|
1633
1421
|
}
|
|
1634
|
-
},
|
|
1422
|
+
}, _callee1, null, [[1, 6, 7, 8]]);
|
|
1635
1423
|
}));
|
|
1636
|
-
|
|
1637
1424
|
return function (_x9) {
|
|
1638
|
-
return
|
|
1425
|
+
return _ref1.apply(this, arguments);
|
|
1639
1426
|
};
|
|
1640
1427
|
}());
|
|
1641
1428
|
}
|
|
@@ -1651,75 +1438,63 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1651
1438
|
}, {
|
|
1652
1439
|
key: "registerDeviceToken",
|
|
1653
1440
|
value: function () {
|
|
1654
|
-
var _registerDeviceToken = (0, _asyncToGenerator2["default"])(
|
|
1441
|
+
var _registerDeviceToken = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee10(token) {
|
|
1655
1442
|
var isDevelopment,
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
return _regenerator["default"].wrap(function
|
|
1659
|
-
while (1) {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
case 5:
|
|
1675
|
-
case "end":
|
|
1676
|
-
return _context12.stop();
|
|
1677
|
-
}
|
|
1443
|
+
res,
|
|
1444
|
+
_args10 = arguments;
|
|
1445
|
+
return _regenerator["default"].wrap(function (_context10) {
|
|
1446
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
1447
|
+
case 0:
|
|
1448
|
+
isDevelopment = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : false;
|
|
1449
|
+
_context10.next = 1;
|
|
1450
|
+
return this.HTTPAdapter.post('api/v2/sdk/set_user_device_token', {
|
|
1451
|
+
device_token: token,
|
|
1452
|
+
device_platform: 'rn',
|
|
1453
|
+
is_development: isDevelopment
|
|
1454
|
+
});
|
|
1455
|
+
case 1:
|
|
1456
|
+
res = _context10.sent;
|
|
1457
|
+
return _context10.abrupt("return", res.body.results);
|
|
1458
|
+
case 2:
|
|
1459
|
+
case "end":
|
|
1460
|
+
return _context10.stop();
|
|
1678
1461
|
}
|
|
1679
|
-
},
|
|
1462
|
+
}, _callee10, this);
|
|
1680
1463
|
}));
|
|
1681
|
-
|
|
1682
|
-
function registerDeviceToken(_x10) {
|
|
1464
|
+
function registerDeviceToken(_x0) {
|
|
1683
1465
|
return _registerDeviceToken.apply(this, arguments);
|
|
1684
1466
|
}
|
|
1685
|
-
|
|
1686
1467
|
return registerDeviceToken;
|
|
1687
1468
|
}()
|
|
1688
1469
|
}, {
|
|
1689
1470
|
key: "removeDeviceToken",
|
|
1690
1471
|
value: function () {
|
|
1691
|
-
var _removeDeviceToken = (0, _asyncToGenerator2["default"])(
|
|
1472
|
+
var _removeDeviceToken = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee11(token) {
|
|
1692
1473
|
var isDevelopment,
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
return _regenerator["default"].wrap(function
|
|
1696
|
-
while (1) {
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
case 5:
|
|
1712
|
-
case "end":
|
|
1713
|
-
return _context13.stop();
|
|
1714
|
-
}
|
|
1474
|
+
res,
|
|
1475
|
+
_args11 = arguments;
|
|
1476
|
+
return _regenerator["default"].wrap(function (_context11) {
|
|
1477
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
1478
|
+
case 0:
|
|
1479
|
+
isDevelopment = _args11.length > 1 && _args11[1] !== undefined ? _args11[1] : false;
|
|
1480
|
+
_context11.next = 1;
|
|
1481
|
+
return this.HTTPAdapter.post('api/v2/sdk/remove_user_device_token', {
|
|
1482
|
+
device_token: token,
|
|
1483
|
+
device_platform: 'rn',
|
|
1484
|
+
is_development: isDevelopment
|
|
1485
|
+
});
|
|
1486
|
+
case 1:
|
|
1487
|
+
res = _context11.sent;
|
|
1488
|
+
return _context11.abrupt("return", res.body.results);
|
|
1489
|
+
case 2:
|
|
1490
|
+
case "end":
|
|
1491
|
+
return _context11.stop();
|
|
1715
1492
|
}
|
|
1716
|
-
},
|
|
1493
|
+
}, _callee11, this);
|
|
1717
1494
|
}));
|
|
1718
|
-
|
|
1719
|
-
function removeDeviceToken(_x11) {
|
|
1495
|
+
function removeDeviceToken(_x1) {
|
|
1720
1496
|
return _removeDeviceToken.apply(this, arguments);
|
|
1721
1497
|
}
|
|
1722
|
-
|
|
1723
1498
|
return removeDeviceToken;
|
|
1724
1499
|
}()
|
|
1725
1500
|
/**
|
|
@@ -1729,55 +1504,46 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1729
1504
|
* @param {any} [params={query,room_id,last_comment_id}]
|
|
1730
1505
|
* @memberof qiscusSDK
|
|
1731
1506
|
*/
|
|
1732
|
-
|
|
1733
1507
|
}, {
|
|
1734
1508
|
key: "searchMessages",
|
|
1735
|
-
value: function () {
|
|
1736
|
-
var _searchMessages = (0, _asyncToGenerator2["default"])(
|
|
1509
|
+
value: (function () {
|
|
1510
|
+
var _searchMessages = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee12() {
|
|
1737
1511
|
var params,
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
return _regenerator["default"].wrap(function
|
|
1741
|
-
while (1) {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
case 6:
|
|
1756
|
-
case "end":
|
|
1757
|
-
return _context14.stop();
|
|
1758
|
-
}
|
|
1512
|
+
messages,
|
|
1513
|
+
_args12 = arguments;
|
|
1514
|
+
return _regenerator["default"].wrap(function (_context12) {
|
|
1515
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
1516
|
+
case 0:
|
|
1517
|
+
params = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : {};
|
|
1518
|
+
console.warn('Deprecated: search message will be removed on next release');
|
|
1519
|
+
_context12.next = 1;
|
|
1520
|
+
return this.userAdapter.searchMessages(params);
|
|
1521
|
+
case 1:
|
|
1522
|
+
messages = _context12.sent;
|
|
1523
|
+
return _context12.abrupt("return", messages.map(function (message) {
|
|
1524
|
+
return new _Comment["default"](message);
|
|
1525
|
+
}));
|
|
1526
|
+
case 2:
|
|
1527
|
+
case "end":
|
|
1528
|
+
return _context12.stop();
|
|
1759
1529
|
}
|
|
1760
|
-
},
|
|
1530
|
+
}, _callee12, this);
|
|
1761
1531
|
}));
|
|
1762
|
-
|
|
1763
1532
|
function searchMessages() {
|
|
1764
1533
|
return _searchMessages.apply(this, arguments);
|
|
1765
1534
|
}
|
|
1766
|
-
|
|
1767
1535
|
return searchMessages;
|
|
1768
|
-
}()
|
|
1536
|
+
}())
|
|
1769
1537
|
}, {
|
|
1770
1538
|
key: "updateProfile",
|
|
1771
1539
|
value: function updateProfile(user) {
|
|
1772
|
-
var
|
|
1773
|
-
|
|
1540
|
+
var _this11 = this;
|
|
1774
1541
|
return this.userAdapter.updateProfile(user).then(function (res) {
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
_this12.userData = res;
|
|
1542
|
+
_this11.events.emit('profile-updated', user);
|
|
1543
|
+
_this11.userData = res;
|
|
1778
1544
|
return Promise.resolve(res);
|
|
1779
1545
|
}, function (err) {
|
|
1780
|
-
return
|
|
1546
|
+
return _this11._logger.error(err);
|
|
1781
1547
|
});
|
|
1782
1548
|
}
|
|
1783
1549
|
}, {
|
|
@@ -1800,6 +1566,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1800
1566
|
return Promise.reject(err);
|
|
1801
1567
|
});
|
|
1802
1568
|
}
|
|
1569
|
+
|
|
1803
1570
|
/**
|
|
1804
1571
|
*
|
|
1805
1572
|
* Step of submitting:
|
|
@@ -1815,151 +1582,129 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
1815
1582
|
* @return {Promise}
|
|
1816
1583
|
*/
|
|
1817
1584
|
// #region sendComment
|
|
1818
|
-
|
|
1819
1585
|
}, {
|
|
1820
1586
|
key: "sendComment",
|
|
1821
|
-
value: function () {
|
|
1822
|
-
var _sendComment = (0, _asyncToGenerator2["default"])(
|
|
1823
|
-
var
|
|
1824
|
-
|
|
1587
|
+
value: (function () {
|
|
1588
|
+
var _sendComment = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee14(topicId, commentMessage, uniqueId) {
|
|
1589
|
+
var _this12 = this;
|
|
1825
1590
|
var type,
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
return _regenerator["default"].wrap(function
|
|
1837
|
-
while (1) {
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
case 0:
|
|
1907
|
-
_context15.next = 2;
|
|
1908
|
-
return _this13._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
|
|
1909
|
-
|
|
1910
|
-
case 2:
|
|
1911
|
-
res = _context15.sent;
|
|
1912
|
-
Object.assign(messageData, res);
|
|
1913
|
-
|
|
1914
|
-
if (self.selected) {
|
|
1915
|
-
_context15.next = 6;
|
|
1916
|
-
break;
|
|
1917
|
-
}
|
|
1918
|
-
|
|
1919
|
-
return _context15.abrupt("return", Promise.resolve(messageData));
|
|
1920
|
-
|
|
1921
|
-
case 6:
|
|
1922
|
-
// When the posting succeeded, we mark the Comment as sent,
|
|
1923
|
-
// so all the interested party can be notified.
|
|
1924
|
-
messageData.markAsSent();
|
|
1925
|
-
messageData.id = res.id;
|
|
1926
|
-
messageData.before_id = res.comment_before_id; // update the timestamp also then re-sort the comment list
|
|
1927
|
-
|
|
1928
|
-
messageData.unix_timestamp = res.unix_timestamp;
|
|
1929
|
-
self.sortComments();
|
|
1930
|
-
return _context15.abrupt("return", messageData);
|
|
1931
|
-
|
|
1932
|
-
case 12:
|
|
1933
|
-
case "end":
|
|
1934
|
-
return _context15.stop();
|
|
1591
|
+
payload,
|
|
1592
|
+
extras,
|
|
1593
|
+
self,
|
|
1594
|
+
commentData,
|
|
1595
|
+
pendingComment,
|
|
1596
|
+
parsedPayload,
|
|
1597
|
+
repliedMessage,
|
|
1598
|
+
extrasToBeSubmitted,
|
|
1599
|
+
messageData,
|
|
1600
|
+
_args14 = arguments;
|
|
1601
|
+
return _regenerator["default"].wrap(function (_context14) {
|
|
1602
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
1603
|
+
case 0:
|
|
1604
|
+
type = _args14.length > 3 && _args14[3] !== undefined ? _args14[3] : 'text';
|
|
1605
|
+
payload = _args14.length > 4 ? _args14[4] : undefined;
|
|
1606
|
+
extras = _args14.length > 5 ? _args14[5] : undefined;
|
|
1607
|
+
self = this; // set extra data, etc
|
|
1608
|
+
if (self.options.prePostCommentCallback) {
|
|
1609
|
+
self.options.prePostCommentCallback(commentMessage);
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* example:
|
|
1613
|
+
* commentFormaterCallback(msg) {
|
|
1614
|
+
* return filterBadWords(msg) // define your own filter function and return its' value
|
|
1615
|
+
* }
|
|
1616
|
+
*/
|
|
1617
|
+
if (self.options.commentFormaterCallback) {
|
|
1618
|
+
commentMessage = self.options.commentFormaterCallback(commentMessage);
|
|
1619
|
+
}
|
|
1620
|
+
self.pendingCommentId--;
|
|
1621
|
+
commentData = {
|
|
1622
|
+
message: commentMessage,
|
|
1623
|
+
username_as: this.username,
|
|
1624
|
+
username_real: this.user_id,
|
|
1625
|
+
user_avatar_url: this.userData.avatar_url,
|
|
1626
|
+
user_extras: this.userData.user_extras,
|
|
1627
|
+
id: Math.round(Date.now() * 1e6 + Date.now()),
|
|
1628
|
+
type: type || 'text',
|
|
1629
|
+
timestamp: (0, _format["default"])(new Date()),
|
|
1630
|
+
unique_id: uniqueId ? String(uniqueId) : null,
|
|
1631
|
+
payload: (0, _util.tryCatch)(function () {
|
|
1632
|
+
return JSON.parse(payload);
|
|
1633
|
+
}, payload, function (error) {
|
|
1634
|
+
return _this12._logger.error('Error when parsing payload', error.message);
|
|
1635
|
+
})
|
|
1636
|
+
};
|
|
1637
|
+
pendingComment = self.prepareCommentToBeSubmitted(commentData); // push this comment unto active room
|
|
1638
|
+
if (type === 'reply') {
|
|
1639
|
+
// change payload for pendingComment
|
|
1640
|
+
// get the comment for current replied id
|
|
1641
|
+
parsedPayload = JSON.parse(payload);
|
|
1642
|
+
repliedMessage = self.selected.comments.find(function (cmt) {
|
|
1643
|
+
return cmt.id === parsedPayload.replied_comment_id;
|
|
1644
|
+
});
|
|
1645
|
+
parsedPayload.replied_comment_message = repliedMessage.type === 'reply' ? repliedMessage.payload.text : repliedMessage.message;
|
|
1646
|
+
parsedPayload.replied_comment_sender_username = repliedMessage.username_as;
|
|
1647
|
+
pendingComment.payload = parsedPayload;
|
|
1648
|
+
}
|
|
1649
|
+
extrasToBeSubmitted = extras || self.extras;
|
|
1650
|
+
_context14.next = 1;
|
|
1651
|
+
return this._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_SENT, _objectSpread(_objectSpread({}, pendingComment), {}, {
|
|
1652
|
+
extras: extrasToBeSubmitted
|
|
1653
|
+
}));
|
|
1654
|
+
case 1:
|
|
1655
|
+
messageData = _context14.sent;
|
|
1656
|
+
messageData = self.prepareCommentToBeSubmitted(messageData);
|
|
1657
|
+
if (self.selected) self.selected.comments.push(messageData);
|
|
1658
|
+
return _context14.abrupt("return", this.userAdapter.postComment('' + topicId, messageData.message, messageData.unique_id, messageData.type, messageData.payload, messageData.extras).then(/*#__PURE__*/function () {
|
|
1659
|
+
var _ref10 = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee13(res) {
|
|
1660
|
+
return _regenerator["default"].wrap(function (_context13) {
|
|
1661
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
1662
|
+
case 0:
|
|
1663
|
+
_context13.next = 1;
|
|
1664
|
+
return _this12._hookAdapter.trigger(_hook.Hooks.MESSAGE_BEFORE_RECEIVED, res);
|
|
1665
|
+
case 1:
|
|
1666
|
+
res = _context13.sent;
|
|
1667
|
+
Object.assign(messageData, res);
|
|
1668
|
+
if (self.selected) {
|
|
1669
|
+
_context13.next = 2;
|
|
1670
|
+
break;
|
|
1935
1671
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1672
|
+
return _context13.abrupt("return", Promise.resolve(messageData));
|
|
1673
|
+
case 2:
|
|
1674
|
+
// When the posting succeeded, we mark the Comment as sent,
|
|
1675
|
+
// so all the interested party can be notified.
|
|
1676
|
+
messageData.markAsSent();
|
|
1677
|
+
messageData.id = res.id;
|
|
1678
|
+
messageData.before_id = res.comment_before_id;
|
|
1679
|
+
// update the timestamp also then re-sort the comment list
|
|
1680
|
+
messageData.unix_timestamp = res.unix_timestamp;
|
|
1681
|
+
self.sortComments();
|
|
1682
|
+
return _context13.abrupt("return", messageData);
|
|
1683
|
+
case 3:
|
|
1684
|
+
case "end":
|
|
1685
|
+
return _context13.stop();
|
|
1686
|
+
}
|
|
1687
|
+
}, _callee13);
|
|
1946
1688
|
}));
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1689
|
+
return function (_x13) {
|
|
1690
|
+
return _ref10.apply(this, arguments);
|
|
1691
|
+
};
|
|
1692
|
+
}())["catch"](function (err) {
|
|
1693
|
+
messageData.markAsFailed();
|
|
1694
|
+
return Promise.reject(err);
|
|
1695
|
+
}));
|
|
1696
|
+
case 2:
|
|
1697
|
+
case "end":
|
|
1698
|
+
return _context14.stop();
|
|
1952
1699
|
}
|
|
1953
|
-
},
|
|
1700
|
+
}, _callee14, this);
|
|
1954
1701
|
}));
|
|
1955
|
-
|
|
1956
|
-
function sendComment(_x12, _x13, _x14) {
|
|
1702
|
+
function sendComment(_x10, _x11, _x12) {
|
|
1957
1703
|
return _sendComment.apply(this, arguments);
|
|
1958
1704
|
}
|
|
1959
|
-
|
|
1960
1705
|
return sendComment;
|
|
1961
1706
|
}() // #endregion
|
|
1962
|
-
|
|
1707
|
+
)
|
|
1963
1708
|
}, {
|
|
1964
1709
|
key: "getUsers",
|
|
1965
1710
|
value: function getUsers() {
|
|
@@ -2029,9 +1774,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2029
1774
|
key: "prepareCommentToBeSubmitted",
|
|
2030
1775
|
value: function prepareCommentToBeSubmitted(comment) {
|
|
2031
1776
|
var commentToBeSubmitted, uniqueId;
|
|
2032
|
-
commentToBeSubmitted = new _Comment["default"](comment);
|
|
1777
|
+
commentToBeSubmitted = new _Comment["default"](comment);
|
|
1778
|
+
// We're gonna use timestamp for uniqueId for now.
|
|
2033
1779
|
// "bq" stands for "Bonjour Qiscus" by the way.
|
|
2034
|
-
|
|
2035
1780
|
uniqueId = 'bq' + Date.now();
|
|
2036
1781
|
if (comment.unique_id) uniqueId = comment.unique_id;
|
|
2037
1782
|
commentToBeSubmitted.attachUniqueId(uniqueId);
|
|
@@ -2042,12 +1787,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2042
1787
|
commentToBeSubmitted.unix_timestamp = Math.round(new Date().getTime() / 1000);
|
|
2043
1788
|
return commentToBeSubmitted;
|
|
2044
1789
|
}
|
|
1790
|
+
|
|
2045
1791
|
/**
|
|
2046
1792
|
* Update room
|
|
2047
1793
|
* @param {id, room_name, avatar_url, options} args
|
|
2048
1794
|
* @return Promise
|
|
2049
1795
|
*/
|
|
2050
|
-
|
|
2051
1796
|
}, {
|
|
2052
1797
|
key: "updateRoom",
|
|
2053
1798
|
value: function updateRoom(args) {
|
|
@@ -2058,48 +1803,40 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2058
1803
|
value: function removeSelectedRoomParticipants() {
|
|
2059
1804
|
var values = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
2060
1805
|
var payload = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'id';
|
|
2061
|
-
|
|
2062
1806
|
if (_is_js["default"].not.array(values)) {
|
|
2063
1807
|
return Promise.reject(new Error('`values` must have type of array'));
|
|
2064
1808
|
}
|
|
2065
|
-
|
|
2066
1809
|
var participants = this.selected.participants;
|
|
2067
|
-
|
|
2068
1810
|
if (!participants) {
|
|
2069
1811
|
return Promise.reject(new Error('Nothing selected room chat.'));
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
|
|
1812
|
+
}
|
|
1813
|
+
// start to changes selected participants with newest values
|
|
2073
1814
|
var participantsExclude = participants;
|
|
2074
|
-
|
|
2075
1815
|
if (payload === 'id') {
|
|
2076
1816
|
participantsExclude = participants.filter(function (participant) {
|
|
2077
1817
|
return values.indexOf(participant.id) <= -1;
|
|
2078
1818
|
});
|
|
2079
1819
|
}
|
|
2080
|
-
|
|
2081
1820
|
if (payload === 'email') {
|
|
2082
1821
|
participantsExclude = participants.filter(function (participant) {
|
|
2083
1822
|
return values.indexOf(participant.email) <= -1;
|
|
2084
1823
|
});
|
|
2085
1824
|
}
|
|
2086
|
-
|
|
2087
1825
|
if (payload === 'username') {
|
|
2088
1826
|
participantsExclude = participants.filter(function (participant) {
|
|
2089
1827
|
return values.indexOf(participant.username) <= -1;
|
|
2090
1828
|
});
|
|
2091
1829
|
}
|
|
2092
|
-
|
|
2093
1830
|
this.selected.participants = participantsExclude;
|
|
2094
1831
|
return Promise.resolve(participants);
|
|
2095
1832
|
}
|
|
1833
|
+
|
|
2096
1834
|
/**
|
|
2097
1835
|
* Create group chat room
|
|
2098
1836
|
* @param {string} name - Chat room name
|
|
2099
1837
|
* @param {string[]} emails - Participant to be invited
|
|
2100
1838
|
* @returns {Promise.<Room, Error>} - Room detail
|
|
2101
1839
|
*/
|
|
2102
|
-
|
|
2103
1840
|
}, {
|
|
2104
1841
|
key: "createGroupRoom",
|
|
2105
1842
|
value: function createGroupRoom(name, emails, options) {
|
|
@@ -2110,6 +1847,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2110
1847
|
return Promise.resolve(res);
|
|
2111
1848
|
});
|
|
2112
1849
|
}
|
|
1850
|
+
|
|
2113
1851
|
/**
|
|
2114
1852
|
* Add array of participant into a group
|
|
2115
1853
|
*
|
|
@@ -2118,16 +1856,13 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2118
1856
|
* @returns Promise
|
|
2119
1857
|
* @memberof QiscusSDK
|
|
2120
1858
|
*/
|
|
2121
|
-
|
|
2122
1859
|
}, {
|
|
2123
1860
|
key: "addParticipantsToGroup",
|
|
2124
1861
|
value: function addParticipantsToGroup(roomId, emails) {
|
|
2125
1862
|
var self = this;
|
|
2126
|
-
|
|
2127
1863
|
if (!Array.isArray(emails)) {
|
|
2128
1864
|
throw new Error("emails' must be type of Array");
|
|
2129
1865
|
}
|
|
2130
|
-
|
|
2131
1866
|
return self.roomAdapter.addParticipantsToGroup(roomId, emails).then(function (res) {
|
|
2132
1867
|
self.events.emit('participants-added', res);
|
|
2133
1868
|
return Promise.resolve(res);
|
|
@@ -2135,6 +1870,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2135
1870
|
return Promise.reject(err);
|
|
2136
1871
|
});
|
|
2137
1872
|
}
|
|
1873
|
+
|
|
2138
1874
|
/**
|
|
2139
1875
|
* Remove array of participant from a group
|
|
2140
1876
|
*
|
|
@@ -2143,22 +1879,19 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2143
1879
|
* @returns Promise
|
|
2144
1880
|
* @memberof QiscusSDK
|
|
2145
1881
|
*/
|
|
2146
|
-
|
|
2147
1882
|
}, {
|
|
2148
1883
|
key: "removeParticipantsFromGroup",
|
|
2149
1884
|
value: function removeParticipantsFromGroup(roomId, emails) {
|
|
2150
|
-
var
|
|
2151
|
-
|
|
1885
|
+
var _this13 = this;
|
|
2152
1886
|
if (_is_js["default"].not.array(emails)) {
|
|
2153
1887
|
return Promise.reject(new Error('`emails` must have type of array'));
|
|
2154
1888
|
}
|
|
2155
|
-
|
|
2156
1889
|
return this.roomAdapter.removeParticipantsFromGroup(roomId, emails).then(function (res) {
|
|
2157
|
-
|
|
2158
|
-
|
|
1890
|
+
_this13.events.emit('participants-removed', emails);
|
|
2159
1891
|
return Promise.resolve(res);
|
|
2160
1892
|
});
|
|
2161
1893
|
}
|
|
1894
|
+
|
|
2162
1895
|
/**
|
|
2163
1896
|
* Get user block list
|
|
2164
1897
|
*
|
|
@@ -2167,7 +1900,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2167
1900
|
* @returns Promise
|
|
2168
1901
|
* @memberof QiscusSDK
|
|
2169
1902
|
*/
|
|
2170
|
-
|
|
2171
1903
|
}, {
|
|
2172
1904
|
key: "getBlockedUser",
|
|
2173
1905
|
value: function getBlockedUser() {
|
|
@@ -2180,6 +1912,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2180
1912
|
return Promise.reject(err);
|
|
2181
1913
|
});
|
|
2182
1914
|
}
|
|
1915
|
+
|
|
2183
1916
|
/**
|
|
2184
1917
|
* Add user to block list
|
|
2185
1918
|
*
|
|
@@ -2187,7 +1920,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2187
1920
|
* @returns Promise
|
|
2188
1921
|
* @memberof QiscusSDK
|
|
2189
1922
|
*/
|
|
2190
|
-
|
|
2191
1923
|
}, {
|
|
2192
1924
|
key: "blockUser",
|
|
2193
1925
|
value: function blockUser(email) {
|
|
@@ -2199,6 +1931,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2199
1931
|
return Promise.reject(err);
|
|
2200
1932
|
});
|
|
2201
1933
|
}
|
|
1934
|
+
|
|
2202
1935
|
/**
|
|
2203
1936
|
* Remove user from block list
|
|
2204
1937
|
*
|
|
@@ -2206,7 +1939,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2206
1939
|
* @returns Promise
|
|
2207
1940
|
* @memberof QiscusSDK
|
|
2208
1941
|
*/
|
|
2209
|
-
|
|
2210
1942
|
}, {
|
|
2211
1943
|
key: "unblockUser",
|
|
2212
1944
|
value: function unblockUser(email) {
|
|
@@ -2222,11 +1954,9 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2222
1954
|
key: "getUserPresences",
|
|
2223
1955
|
value: function getUserPresences() {
|
|
2224
1956
|
var email = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
2225
|
-
|
|
2226
1957
|
if (_is_js["default"].not.array(email)) {
|
|
2227
1958
|
return Promise.reject(new Error('`email` must have type of array'));
|
|
2228
1959
|
}
|
|
2229
|
-
|
|
2230
1960
|
var self = this;
|
|
2231
1961
|
return self.userAdapter.getUserPresences(email).then(function (res) {
|
|
2232
1962
|
self.events.emit('user-status', res);
|
|
@@ -2239,7 +1969,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2239
1969
|
key: "upload",
|
|
2240
1970
|
value: function upload(file, callback) {
|
|
2241
1971
|
var req = _superagent["default"].post(this.uploadURL);
|
|
2242
|
-
|
|
2243
1972
|
req = this.HTTPAdapter.setupHeaders(req);
|
|
2244
1973
|
return req.attach('file', file).on('progress', function (event) {
|
|
2245
1974
|
if (event.direction === 'upload') callback(null, event);
|
|
@@ -2252,6 +1981,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2252
1981
|
return Promise.reject(error);
|
|
2253
1982
|
});
|
|
2254
1983
|
}
|
|
1984
|
+
|
|
2255
1985
|
/**
|
|
2256
1986
|
* Upload a file to qiscus sdk server
|
|
2257
1987
|
*
|
|
@@ -2260,7 +1990,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2260
1990
|
* @returns Promise
|
|
2261
1991
|
* @memberof QiscusSDK
|
|
2262
1992
|
*/
|
|
2263
|
-
|
|
2264
1993
|
}, {
|
|
2265
1994
|
key: "uploadFile",
|
|
2266
1995
|
value: function uploadFile(roomId, file) {
|
|
@@ -2272,19 +2001,17 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2272
2001
|
xhr.setRequestHeader('qiscus_sdk_app_id', "".concat(self.AppId));
|
|
2273
2002
|
xhr.setRequestHeader('qiscus_sdk_user_id', "".concat(self.user_id));
|
|
2274
2003
|
xhr.setRequestHeader('qiscus_sdk_token', "".concat(self.userData.token));
|
|
2275
|
-
|
|
2276
2004
|
xhr.onload = function () {
|
|
2277
2005
|
if (xhr.status === 200) {
|
|
2278
2006
|
// file(s) uploaded), let's post to comment
|
|
2279
2007
|
var url = JSON.parse(xhr.response).results.file.url;
|
|
2280
|
-
self.events.emit('fileupload', url);
|
|
2281
|
-
|
|
2008
|
+
self.events.emit('fileupload', url);
|
|
2009
|
+
// send
|
|
2282
2010
|
return self.sendComment(roomId, "[file] ".concat(url, " [/file]"));
|
|
2283
2011
|
} else {
|
|
2284
2012
|
return Promise.reject(xhr);
|
|
2285
2013
|
}
|
|
2286
2014
|
};
|
|
2287
|
-
|
|
2288
2015
|
xhr.send(formData);
|
|
2289
2016
|
}
|
|
2290
2017
|
}, {
|
|
@@ -2305,6 +2032,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2305
2032
|
value: function publishTyping(val) {
|
|
2306
2033
|
this.realtimeAdapter.publishTyping(val);
|
|
2307
2034
|
}
|
|
2035
|
+
|
|
2308
2036
|
/**
|
|
2309
2037
|
* Params consisted of
|
|
2310
2038
|
* @param {room_ids} array of room ids
|
|
@@ -2314,7 +2042,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2314
2042
|
* @returns
|
|
2315
2043
|
* @memberof QiscusSDK
|
|
2316
2044
|
*/
|
|
2317
|
-
|
|
2318
2045
|
}, {
|
|
2319
2046
|
key: "getRoomsInfo",
|
|
2320
2047
|
value: function getRoomsInfo(params) {
|
|
@@ -2323,20 +2050,17 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2323
2050
|
}, {
|
|
2324
2051
|
key: "deleteComment",
|
|
2325
2052
|
value: function deleteComment(roomId, commentUniqueIds, isForEveryone, isHard) {
|
|
2326
|
-
var
|
|
2327
|
-
|
|
2053
|
+
var _this14 = this;
|
|
2328
2054
|
if (!Array.isArray(commentUniqueIds)) {
|
|
2329
2055
|
throw new Error("unique ids' must be type of Array");
|
|
2330
2056
|
}
|
|
2331
|
-
|
|
2332
2057
|
return this.userAdapter.deleteComment(roomId, commentUniqueIds, isForEveryone, isHard).then(function (res) {
|
|
2333
|
-
|
|
2058
|
+
_this14.events.emit('comment-deleted', {
|
|
2334
2059
|
roomId: roomId,
|
|
2335
2060
|
commentUniqueIds: commentUniqueIds,
|
|
2336
2061
|
isForEveryone: isForEveryone,
|
|
2337
2062
|
isHard: isHard
|
|
2338
2063
|
});
|
|
2339
|
-
|
|
2340
2064
|
return Promise.resolve(res);
|
|
2341
2065
|
}, function (err) {
|
|
2342
2066
|
return Promise.reject(err);
|
|
@@ -2345,27 +2069,23 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2345
2069
|
}, {
|
|
2346
2070
|
key: "clearRoomsCache",
|
|
2347
2071
|
value: function clearRoomsCache() {
|
|
2348
|
-
var
|
|
2349
|
-
|
|
2072
|
+
var _this15 = this;
|
|
2350
2073
|
// remove all room except currently selected
|
|
2351
2074
|
if (this.selected) {
|
|
2352
2075
|
// clear the map
|
|
2353
|
-
this.room_name_id_map = (0, _defineProperty2["default"])({}, this.selected.name, this.selected.id);
|
|
2354
|
-
|
|
2076
|
+
this.room_name_id_map = (0, _defineProperty2["default"])({}, this.selected.name, this.selected.id);
|
|
2077
|
+
// get current index and array length
|
|
2355
2078
|
var roomLength = this.rooms.length;
|
|
2356
2079
|
var curIndex = this.rooms.findIndex(function (room) {
|
|
2357
|
-
return room.id ===
|
|
2080
|
+
return room.id === _this15.selected.id;
|
|
2358
2081
|
});
|
|
2359
|
-
|
|
2360
2082
|
if (!(curIndex + 1 === roomLength)) {
|
|
2361
2083
|
this.rooms.splice(curIndex + 1, roomLength - (curIndex + 1));
|
|
2362
|
-
}
|
|
2363
|
-
|
|
2364
|
-
|
|
2084
|
+
}
|
|
2085
|
+
// ambil ulang cur index nya, klo udah di awal ga perlu lagi kode dibawah ini
|
|
2365
2086
|
curIndex = this.rooms.findIndex(function (room) {
|
|
2366
|
-
return room.id ===
|
|
2087
|
+
return room.id === _this15.selected.id;
|
|
2367
2088
|
});
|
|
2368
|
-
|
|
2369
2089
|
if (curIndex > 0 && this.rooms.length > 1) {
|
|
2370
2090
|
this.rooms.splice(1, this.rooms.length - 1);
|
|
2371
2091
|
}
|
|
@@ -2374,19 +2094,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2374
2094
|
}, {
|
|
2375
2095
|
key: "exitChatRoom",
|
|
2376
2096
|
value: function exitChatRoom() {
|
|
2377
|
-
var
|
|
2378
|
-
|
|
2097
|
+
var _this16 = this;
|
|
2379
2098
|
// remove all subscriber
|
|
2380
2099
|
this.realtimeAdapter.unsubscribeTyping();
|
|
2381
2100
|
(0, _util.tryCatch)(function () {
|
|
2382
|
-
return
|
|
2383
|
-
return it.email !==
|
|
2101
|
+
return _this16.selected.participants.filter(function (it) {
|
|
2102
|
+
return it.email !== _this16.user_id;
|
|
2384
2103
|
}).map(function (it) {
|
|
2385
2104
|
return it.email;
|
|
2386
2105
|
});
|
|
2387
2106
|
}, null, this.noop, function (userIds) {
|
|
2388
2107
|
return userIds.forEach(function (userId) {
|
|
2389
|
-
return
|
|
2108
|
+
return _this16.realtimeAdapter.unsubscribeRoomPresence(userId);
|
|
2390
2109
|
});
|
|
2391
2110
|
});
|
|
2392
2111
|
this.selected = null;
|
|
@@ -2397,18 +2116,8 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2397
2116
|
if (!Array.isArray(roomIds)) {
|
|
2398
2117
|
throw new Error('room_ids must be type of array');
|
|
2399
2118
|
}
|
|
2400
|
-
|
|
2401
2119
|
return this.userAdapter.clearRoomMessages(roomIds);
|
|
2402
2120
|
}
|
|
2403
|
-
}, {
|
|
2404
|
-
key: "logging",
|
|
2405
|
-
value: function logging(message) {
|
|
2406
|
-
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
2407
|
-
|
|
2408
|
-
if (this.debugMode) {
|
|
2409
|
-
console.log(message, params);
|
|
2410
|
-
}
|
|
2411
|
-
}
|
|
2412
2121
|
}, {
|
|
2413
2122
|
key: "getTotalUnreadCount",
|
|
2414
2123
|
value: function getTotalUnreadCount() {
|
|
@@ -2427,21 +2136,18 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2427
2136
|
key: "publishEvent",
|
|
2428
2137
|
value: function publishEvent() {
|
|
2429
2138
|
var _this$customEventAdap;
|
|
2430
|
-
|
|
2431
2139
|
(_this$customEventAdap = this.customEventAdapter).publishEvent.apply(_this$customEventAdap, arguments);
|
|
2432
2140
|
}
|
|
2433
2141
|
}, {
|
|
2434
2142
|
key: "subscribeEvent",
|
|
2435
2143
|
value: function subscribeEvent() {
|
|
2436
2144
|
var _this$customEventAdap2;
|
|
2437
|
-
|
|
2438
2145
|
(_this$customEventAdap2 = this.customEventAdapter).subscribeEvent.apply(_this$customEventAdap2, arguments);
|
|
2439
2146
|
}
|
|
2440
2147
|
}, {
|
|
2441
2148
|
key: "unsubscribeEvent",
|
|
2442
2149
|
value: function unsubscribeEvent() {
|
|
2443
2150
|
var _this$customEventAdap3;
|
|
2444
|
-
|
|
2445
2151
|
(_this$customEventAdap3 = this.customEventAdapter).unsubscribeEvent.apply(_this$customEventAdap3, arguments);
|
|
2446
2152
|
}
|
|
2447
2153
|
}, {
|
|
@@ -2450,7 +2156,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2450
2156
|
if (_is_js["default"].not.json(headers)) {
|
|
2451
2157
|
throw new TypeError('`headers` must have type of object');
|
|
2452
2158
|
}
|
|
2453
|
-
|
|
2454
2159
|
this._customHeader = headers;
|
|
2455
2160
|
}
|
|
2456
2161
|
}, {
|
|
@@ -2458,6 +2163,11 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2458
2163
|
value: function getUserProfile() {
|
|
2459
2164
|
return this.userAdapter.getProfile();
|
|
2460
2165
|
}
|
|
2166
|
+
}, {
|
|
2167
|
+
key: "Interceptor",
|
|
2168
|
+
get: function get() {
|
|
2169
|
+
return _hook.Hooks;
|
|
2170
|
+
}
|
|
2461
2171
|
}, {
|
|
2462
2172
|
key: "intercept",
|
|
2463
2173
|
value: function intercept(interceptor, callback) {
|
|
@@ -2482,6 +2192,19 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2482
2192
|
}, {
|
|
2483
2193
|
key: "noop",
|
|
2484
2194
|
value: function noop() {}
|
|
2195
|
+
}, {
|
|
2196
|
+
key: "_throttleDelay",
|
|
2197
|
+
get: function get() {
|
|
2198
|
+
if (this.updateCommentStatusMode === QiscusSDK.UpdateCommentStatusMode.enabled) {
|
|
2199
|
+
return 0;
|
|
2200
|
+
}
|
|
2201
|
+
return this.updateCommentStatusThrottleDelay || 300;
|
|
2202
|
+
}
|
|
2203
|
+
}, {
|
|
2204
|
+
key: "_updateStatusEnabled",
|
|
2205
|
+
get: function get() {
|
|
2206
|
+
return this.updateCommentStatusMode !== QiscusSDK.UpdateCommentStatusMode.disabled;
|
|
2207
|
+
}
|
|
2485
2208
|
}, {
|
|
2486
2209
|
key: "_updateStatus",
|
|
2487
2210
|
value: function _updateStatus(roomId) {
|
|
@@ -2496,30 +2219,21 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2496
2219
|
// - it is prohibited to send command if current room are channel
|
|
2497
2220
|
// - it is prohibited to send command if no room selected (but why was this a thing?)
|
|
2498
2221
|
// - it is ok to send command when `updateCommentStatusMode` is `disabled`
|
|
2222
|
+
|
|
2499
2223
|
var isReceiveCommand = commentId2 != null;
|
|
2500
2224
|
var isReadCommand = commentId1 != null;
|
|
2501
2225
|
var isSelected = this.selected != null && this.selected.id === roomId || false;
|
|
2502
2226
|
var isChannel = this.selected != null && this.selected.isChannel || false;
|
|
2503
2227
|
var isUpdateStatusDisabled = !this._updateStatusEnabled;
|
|
2504
|
-
|
|
2505
2228
|
var command = function () {
|
|
2506
2229
|
if (isReadCommand) return 'read';
|
|
2507
2230
|
if (isReceiveCommand) return 'receive';
|
|
2508
2231
|
}();
|
|
2509
|
-
|
|
2510
2232
|
var isAbleToRunCommand = function () {
|
|
2511
2233
|
if (isChannel) return false;
|
|
2512
2234
|
if (isReceiveCommand && isUpdateStatusDisabled) return false;
|
|
2513
2235
|
return true;
|
|
2514
2236
|
}();
|
|
2515
|
-
|
|
2516
|
-
if (this.debugMode) {
|
|
2517
|
-
console.group('update-command-status');
|
|
2518
|
-
console.log('run:', command, "on: roomId(".concat(roomId, ") commentId(").concat(commentId1 || commentId2, ")"));
|
|
2519
|
-
console.log('is able to run command?', isAbleToRunCommand);
|
|
2520
|
-
console.groupEnd();
|
|
2521
|
-
}
|
|
2522
|
-
|
|
2523
2237
|
if (!isAbleToRunCommand) return false;
|
|
2524
2238
|
this.userAdapter.updateCommentStatus(roomId, commentId1, commentId2)["catch"](function (err) {});
|
|
2525
2239
|
}
|
|
@@ -2541,7 +2255,6 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2541
2255
|
var isWaiting = false;
|
|
2542
2256
|
return function () {
|
|
2543
2257
|
var waitTime = getWait();
|
|
2544
|
-
|
|
2545
2258
|
if (!isWaiting) {
|
|
2546
2259
|
func.apply(void 0, arguments);
|
|
2547
2260
|
isWaiting = true;
|
|
@@ -2551,6 +2264,7 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2551
2264
|
}
|
|
2552
2265
|
};
|
|
2553
2266
|
}
|
|
2267
|
+
|
|
2554
2268
|
/**
|
|
2555
2269
|
* @typedef {Object} SearchMessageParams
|
|
2556
2270
|
* @property {string} query
|
|
@@ -2561,86 +2275,74 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2561
2275
|
* @property {number} page
|
|
2562
2276
|
* @property {number} limit
|
|
2563
2277
|
*/
|
|
2564
|
-
|
|
2565
2278
|
/**
|
|
2566
2279
|
*
|
|
2567
2280
|
* @param {SearchMessageParams} param0
|
|
2568
2281
|
* @returns {Array.<Object>}
|
|
2569
2282
|
*/
|
|
2570
|
-
|
|
2571
2283
|
}, {
|
|
2572
2284
|
key: "searchMessage",
|
|
2573
|
-
value: function () {
|
|
2574
|
-
var _searchMessage = (0, _asyncToGenerator2["default"])(
|
|
2575
|
-
var
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
}).then(function (res) {
|
|
2629
|
-
return res.body;
|
|
2630
|
-
}));
|
|
2631
|
-
|
|
2632
|
-
case 7:
|
|
2633
|
-
case "end":
|
|
2634
|
-
return _context17.stop();
|
|
2635
|
-
}
|
|
2285
|
+
value: (function () {
|
|
2286
|
+
var _searchMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee15() {
|
|
2287
|
+
var _ref11,
|
|
2288
|
+
query,
|
|
2289
|
+
_ref11$roomIds,
|
|
2290
|
+
roomIds,
|
|
2291
|
+
userId,
|
|
2292
|
+
type,
|
|
2293
|
+
roomType,
|
|
2294
|
+
page,
|
|
2295
|
+
limit,
|
|
2296
|
+
url,
|
|
2297
|
+
isValidRoomType,
|
|
2298
|
+
room,
|
|
2299
|
+
_args15 = arguments;
|
|
2300
|
+
return _regenerator["default"].wrap(function (_context15) {
|
|
2301
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
2302
|
+
case 0:
|
|
2303
|
+
_ref11 = _args15.length > 0 && _args15[0] !== undefined ? _args15[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;
|
|
2304
|
+
url = 'api/v2/sdk/search';
|
|
2305
|
+
isValidRoomType = ['group', 'single', 'channel'].some(function (it) {
|
|
2306
|
+
return it === roomType;
|
|
2307
|
+
});
|
|
2308
|
+
if (!(roomType != null && !isValidRoomType)) {
|
|
2309
|
+
_context15.next = 1;
|
|
2310
|
+
break;
|
|
2311
|
+
}
|
|
2312
|
+
return _context15.abrupt("return", Promise.reject('Invalid room type, valid room type are: `group`, `single`, and `channel`'));
|
|
2313
|
+
case 1:
|
|
2314
|
+
room = function (roomType) {
|
|
2315
|
+
var rType = roomType == null ? undefined : roomType === 'single' ? 'single' : 'group';
|
|
2316
|
+
var isPublic = roomType == null ? undefined : roomType === 'channel' ? true : false;
|
|
2317
|
+
return {
|
|
2318
|
+
type: rType,
|
|
2319
|
+
isPublic: isPublic
|
|
2320
|
+
};
|
|
2321
|
+
}(roomType);
|
|
2322
|
+
return _context15.abrupt("return", this.HTTPAdapter.post_json(url, {
|
|
2323
|
+
token: this.token,
|
|
2324
|
+
query: query,
|
|
2325
|
+
sender: userId,
|
|
2326
|
+
type: type,
|
|
2327
|
+
room_ids: roomIds.map(function (it) {
|
|
2328
|
+
return String(it);
|
|
2329
|
+
}),
|
|
2330
|
+
room_type: room.type || undefined,
|
|
2331
|
+
is_public: room.isPublic || undefined,
|
|
2332
|
+
page: page,
|
|
2333
|
+
limit: limit
|
|
2334
|
+
}).then(function (res) {
|
|
2335
|
+
return res.body;
|
|
2336
|
+
}));
|
|
2337
|
+
case 2:
|
|
2338
|
+
case "end":
|
|
2339
|
+
return _context15.stop();
|
|
2636
2340
|
}
|
|
2637
|
-
},
|
|
2341
|
+
}, _callee15, this);
|
|
2638
2342
|
}));
|
|
2639
|
-
|
|
2640
2343
|
function searchMessage() {
|
|
2641
2344
|
return _searchMessage.apply(this, arguments);
|
|
2642
2345
|
}
|
|
2643
|
-
|
|
2644
2346
|
return searchMessage;
|
|
2645
2347
|
}()
|
|
2646
2348
|
/**
|
|
@@ -2653,84 +2355,72 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2653
2355
|
* @property {String} excludeExtensions
|
|
2654
2356
|
* @property {String} userId
|
|
2655
2357
|
*/
|
|
2656
|
-
|
|
2657
2358
|
/**
|
|
2658
2359
|
* @param {GetFileListParams} param0
|
|
2659
2360
|
*/
|
|
2660
|
-
|
|
2361
|
+
)
|
|
2661
2362
|
}, {
|
|
2662
2363
|
key: "getFileList",
|
|
2663
|
-
value: function () {
|
|
2664
|
-
var _getFileList = (0, _asyncToGenerator2["default"])(
|
|
2665
|
-
var
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
if (sender != null) opts['sender'] = sender;
|
|
2716
|
-
return _context18.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
|
|
2717
|
-
return res.body;
|
|
2718
|
-
}));
|
|
2719
|
-
|
|
2720
|
-
case 9:
|
|
2721
|
-
case "end":
|
|
2722
|
-
return _context18.stop();
|
|
2723
|
-
}
|
|
2364
|
+
value: (function () {
|
|
2365
|
+
var _getFileList = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee16() {
|
|
2366
|
+
var _ref12,
|
|
2367
|
+
_ref12$roomIds,
|
|
2368
|
+
roomIds,
|
|
2369
|
+
fileType,
|
|
2370
|
+
page,
|
|
2371
|
+
limit,
|
|
2372
|
+
sender,
|
|
2373
|
+
userId,
|
|
2374
|
+
includeExtensions,
|
|
2375
|
+
excludeExtensions,
|
|
2376
|
+
url,
|
|
2377
|
+
opts,
|
|
2378
|
+
_args16 = arguments;
|
|
2379
|
+
return _regenerator["default"].wrap(function (_context16) {
|
|
2380
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
2381
|
+
case 0:
|
|
2382
|
+
_ref12 = _args16.length > 0 && _args16[0] !== undefined ? _args16[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;
|
|
2383
|
+
url = 'api/v2/sdk/file_list';
|
|
2384
|
+
if (this.isLogin) {
|
|
2385
|
+
_context16.next = 1;
|
|
2386
|
+
break;
|
|
2387
|
+
}
|
|
2388
|
+
return _context16.abrupt("return", Promise.reject('You need to login to use this method'));
|
|
2389
|
+
case 1:
|
|
2390
|
+
// intended to check for undefined, so user can provide user
|
|
2391
|
+
// with null. If null, backend can determine that we want to
|
|
2392
|
+
// list files for all users
|
|
2393
|
+
if (sender === undefined) {
|
|
2394
|
+
sender = this.user_id;
|
|
2395
|
+
}
|
|
2396
|
+
if (userId === undefined) {
|
|
2397
|
+
sender = userId = this.user_id;
|
|
2398
|
+
}
|
|
2399
|
+
opts = {
|
|
2400
|
+
room_ids: roomIds.map(function (it) {
|
|
2401
|
+
return String(it);
|
|
2402
|
+
}),
|
|
2403
|
+
file_type: fileType,
|
|
2404
|
+
page: page,
|
|
2405
|
+
limit: limit,
|
|
2406
|
+
include_extensions: includeExtensions,
|
|
2407
|
+
exclude_extensions: excludeExtensions
|
|
2408
|
+
};
|
|
2409
|
+
if (sender != null) opts['sender'] = sender;
|
|
2410
|
+
return _context16.abrupt("return", this.HTTPAdapter.post_json(url, opts).then(function (res) {
|
|
2411
|
+
return res.body;
|
|
2412
|
+
}));
|
|
2413
|
+
case 2:
|
|
2414
|
+
case "end":
|
|
2415
|
+
return _context16.stop();
|
|
2724
2416
|
}
|
|
2725
|
-
},
|
|
2417
|
+
}, _callee16, this);
|
|
2726
2418
|
}));
|
|
2727
|
-
|
|
2728
2419
|
function getFileList() {
|
|
2729
2420
|
return _getFileList.apply(this, arguments);
|
|
2730
2421
|
}
|
|
2731
|
-
|
|
2732
2422
|
return getFileList;
|
|
2733
|
-
}()
|
|
2423
|
+
}())
|
|
2734
2424
|
}, {
|
|
2735
2425
|
key: "_generateUniqueId",
|
|
2736
2426
|
value: function _generateUniqueId() {
|
|
@@ -2738,10 +2428,10 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2738
2428
|
}
|
|
2739
2429
|
}, {
|
|
2740
2430
|
key: "generateMessage",
|
|
2741
|
-
value: function generateMessage(
|
|
2742
|
-
var roomId =
|
|
2743
|
-
|
|
2744
|
-
|
|
2431
|
+
value: function generateMessage(_ref13) {
|
|
2432
|
+
var roomId = _ref13.roomId,
|
|
2433
|
+
text = _ref13.text,
|
|
2434
|
+
extras = _ref13.extras;
|
|
2745
2435
|
var id = Date.now();
|
|
2746
2436
|
var comment = new _Comment["default"]({
|
|
2747
2437
|
id: id,
|
|
@@ -2760,15 +2450,15 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2760
2450
|
}
|
|
2761
2451
|
}, {
|
|
2762
2452
|
key: "generateFileAttachmentMessage",
|
|
2763
|
-
value: function generateFileAttachmentMessage(
|
|
2764
|
-
var roomId =
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2453
|
+
value: function generateFileAttachmentMessage(_ref14) {
|
|
2454
|
+
var roomId = _ref14.roomId,
|
|
2455
|
+
caption = _ref14.caption,
|
|
2456
|
+
url = _ref14.url,
|
|
2457
|
+
_ref14$text = _ref14.text,
|
|
2458
|
+
text = _ref14$text === void 0 ? 'File attachment' : _ref14$text,
|
|
2459
|
+
extras = _ref14.extras,
|
|
2460
|
+
filename = _ref14.filename,
|
|
2461
|
+
size = _ref14.size;
|
|
2772
2462
|
var id = Date.now();
|
|
2773
2463
|
var comment = new _Comment["default"]({
|
|
2774
2464
|
id: id,
|
|
@@ -2793,12 +2483,12 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2793
2483
|
}
|
|
2794
2484
|
}, {
|
|
2795
2485
|
key: "generateCustomMessage",
|
|
2796
|
-
value: function generateCustomMessage(
|
|
2797
|
-
var roomId =
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2486
|
+
value: function generateCustomMessage(_ref15) {
|
|
2487
|
+
var roomId = _ref15.roomId,
|
|
2488
|
+
text = _ref15.text,
|
|
2489
|
+
type = _ref15.type,
|
|
2490
|
+
payload = _ref15.payload,
|
|
2491
|
+
extras = _ref15.extras;
|
|
2802
2492
|
var id = Date.now();
|
|
2803
2493
|
var comment = new _Comment["default"]({
|
|
2804
2494
|
id: id,
|
|
@@ -2821,11 +2511,11 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2821
2511
|
}
|
|
2822
2512
|
}, {
|
|
2823
2513
|
key: "generateReplyMessage",
|
|
2824
|
-
value: function generateReplyMessage(
|
|
2825
|
-
var roomId =
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2514
|
+
value: function generateReplyMessage(_ref16) {
|
|
2515
|
+
var roomId = _ref16.roomId,
|
|
2516
|
+
text = _ref16.text,
|
|
2517
|
+
repliedMessage = _ref16.repliedMessage,
|
|
2518
|
+
extras = _ref16.extras;
|
|
2829
2519
|
var id = Date.now();
|
|
2830
2520
|
var comment = new _Comment["default"]({
|
|
2831
2521
|
id: id,
|
|
@@ -2854,200 +2544,126 @@ var QiscusSDK = /*#__PURE__*/function () {
|
|
|
2854
2544
|
}, {
|
|
2855
2545
|
key: "updateMessage",
|
|
2856
2546
|
value: function () {
|
|
2857
|
-
var _updateMessage = (0, _asyncToGenerator2["default"])(
|
|
2858
|
-
return _regenerator["default"].wrap(function
|
|
2859
|
-
while (1) {
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
case "end":
|
|
2866
|
-
return _context19.stop();
|
|
2867
|
-
}
|
|
2547
|
+
var _updateMessage = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee17(message) {
|
|
2548
|
+
return _regenerator["default"].wrap(function (_context17) {
|
|
2549
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
2550
|
+
case 0:
|
|
2551
|
+
return _context17.abrupt("return", this.userAdapter.updateMessage(message));
|
|
2552
|
+
case 1:
|
|
2553
|
+
case "end":
|
|
2554
|
+
return _context17.stop();
|
|
2868
2555
|
}
|
|
2869
|
-
},
|
|
2556
|
+
}, _callee17, this);
|
|
2870
2557
|
}));
|
|
2871
|
-
|
|
2872
|
-
function updateMessage(_x16) {
|
|
2558
|
+
function updateMessage(_x14) {
|
|
2873
2559
|
return _updateMessage.apply(this, arguments);
|
|
2874
2560
|
}
|
|
2875
|
-
|
|
2876
2561
|
return updateMessage;
|
|
2877
2562
|
}()
|
|
2878
2563
|
}, {
|
|
2879
2564
|
key: "onMessageUpdated",
|
|
2880
2565
|
value: function onMessageUpdated(handler) {
|
|
2881
|
-
var
|
|
2882
|
-
|
|
2566
|
+
var _this17 = this;
|
|
2883
2567
|
this.realtimeAdapter.on('message:updated', handler);
|
|
2884
2568
|
return function () {
|
|
2885
|
-
return
|
|
2569
|
+
return _this17.realtimeAdapter.off('message:updated', handler);
|
|
2886
2570
|
};
|
|
2887
2571
|
}
|
|
2572
|
+
|
|
2888
2573
|
/**
|
|
2889
2574
|
* Manually close connection to mqtt server
|
|
2890
2575
|
* @return {Promise<boolean>} Wheter successfully close mqtt connection or not
|
|
2891
2576
|
*/
|
|
2892
|
-
|
|
2893
2577
|
}, {
|
|
2894
2578
|
key: "closeRealtimeConnection",
|
|
2895
|
-
value: function () {
|
|
2896
|
-
var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])(
|
|
2897
|
-
return _regenerator["default"].wrap(function
|
|
2898
|
-
while (1) {
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
case "end":
|
|
2905
|
-
return _context20.stop();
|
|
2906
|
-
}
|
|
2579
|
+
value: (function () {
|
|
2580
|
+
var _closeRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee18() {
|
|
2581
|
+
return _regenerator["default"].wrap(function (_context18) {
|
|
2582
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
2583
|
+
case 0:
|
|
2584
|
+
return _context18.abrupt("return", this.realtimeAdapter.closeConnection());
|
|
2585
|
+
case 1:
|
|
2586
|
+
case "end":
|
|
2587
|
+
return _context18.stop();
|
|
2907
2588
|
}
|
|
2908
|
-
},
|
|
2589
|
+
}, _callee18, this);
|
|
2909
2590
|
}));
|
|
2910
|
-
|
|
2911
2591
|
function closeRealtimeConnection() {
|
|
2912
2592
|
return _closeRealtimeConnection.apply(this, arguments);
|
|
2913
2593
|
}
|
|
2914
|
-
|
|
2915
2594
|
return closeRealtimeConnection;
|
|
2916
2595
|
}()
|
|
2917
2596
|
/**
|
|
2918
2597
|
* Manually open connection to mqtt server
|
|
2919
2598
|
* @return {Promise<boolean>} Wheter successfully connect to mqtt server or not
|
|
2920
2599
|
*/
|
|
2921
|
-
|
|
2600
|
+
)
|
|
2922
2601
|
}, {
|
|
2923
2602
|
key: "openRealtimeConnection",
|
|
2924
|
-
value: function () {
|
|
2925
|
-
var _openRealtimeConnection = (0, _asyncToGenerator2["default"])(
|
|
2926
|
-
return _regenerator["default"].wrap(function
|
|
2927
|
-
while (1) {
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
case "end":
|
|
2934
|
-
return _context21.stop();
|
|
2935
|
-
}
|
|
2603
|
+
value: (function () {
|
|
2604
|
+
var _openRealtimeConnection = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee19() {
|
|
2605
|
+
return _regenerator["default"].wrap(function (_context19) {
|
|
2606
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
2607
|
+
case 0:
|
|
2608
|
+
return _context19.abrupt("return", this.realtimeAdapter.openConnection());
|
|
2609
|
+
case 1:
|
|
2610
|
+
case "end":
|
|
2611
|
+
return _context19.stop();
|
|
2936
2612
|
}
|
|
2937
|
-
},
|
|
2613
|
+
}, _callee19, this);
|
|
2938
2614
|
}));
|
|
2939
|
-
|
|
2940
2615
|
function openRealtimeConnection() {
|
|
2941
2616
|
return _openRealtimeConnection.apply(this, arguments);
|
|
2942
2617
|
}
|
|
2943
|
-
|
|
2944
2618
|
return openRealtimeConnection;
|
|
2945
|
-
}()
|
|
2619
|
+
}())
|
|
2946
2620
|
}, {
|
|
2947
2621
|
key: "startSync",
|
|
2948
2622
|
value: function () {
|
|
2949
|
-
var _startSync = (0, _asyncToGenerator2["default"])(
|
|
2950
|
-
return _regenerator["default"].wrap(function
|
|
2951
|
-
while (1) {
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
case "end":
|
|
2958
|
-
return _context22.stop();
|
|
2959
|
-
}
|
|
2623
|
+
var _startSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee20() {
|
|
2624
|
+
return _regenerator["default"].wrap(function (_context20) {
|
|
2625
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
2626
|
+
case 0:
|
|
2627
|
+
this._forceEnableSync = true;
|
|
2628
|
+
case 1:
|
|
2629
|
+
case "end":
|
|
2630
|
+
return _context20.stop();
|
|
2960
2631
|
}
|
|
2961
|
-
},
|
|
2632
|
+
}, _callee20, this);
|
|
2962
2633
|
}));
|
|
2963
|
-
|
|
2964
2634
|
function startSync() {
|
|
2965
2635
|
return _startSync.apply(this, arguments);
|
|
2966
2636
|
}
|
|
2967
|
-
|
|
2968
2637
|
return startSync;
|
|
2969
2638
|
}()
|
|
2970
2639
|
}, {
|
|
2971
2640
|
key: "stopSync",
|
|
2972
2641
|
value: function () {
|
|
2973
|
-
var _stopSync = (0, _asyncToGenerator2["default"])(
|
|
2974
|
-
return _regenerator["default"].wrap(function
|
|
2975
|
-
while (1) {
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
case "end":
|
|
2982
|
-
return _context23.stop();
|
|
2983
|
-
}
|
|
2642
|
+
var _stopSync = (0, _asyncToGenerator2["default"])(/*#__PURE__*/_regenerator["default"].mark(function _callee21() {
|
|
2643
|
+
return _regenerator["default"].wrap(function (_context21) {
|
|
2644
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
2645
|
+
case 0:
|
|
2646
|
+
this._forceEnableSync = false;
|
|
2647
|
+
case 1:
|
|
2648
|
+
case "end":
|
|
2649
|
+
return _context21.stop();
|
|
2984
2650
|
}
|
|
2985
|
-
},
|
|
2651
|
+
}, _callee21, this);
|
|
2986
2652
|
}));
|
|
2987
|
-
|
|
2988
2653
|
function stopSync() {
|
|
2989
2654
|
return _stopSync.apply(this, arguments);
|
|
2990
2655
|
}
|
|
2991
|
-
|
|
2992
2656
|
return stopSync;
|
|
2993
2657
|
}()
|
|
2994
|
-
}, {
|
|
2995
|
-
key: "uploadURL",
|
|
2996
|
-
get: function get() {
|
|
2997
|
-
return this._uploadURL || "".concat(this.baseURL, "/api/v2/sdk/upload");
|
|
2998
|
-
},
|
|
2999
|
-
set: function set(uploadURL) {
|
|
3000
|
-
this._uploadURL = uploadURL;
|
|
3001
|
-
}
|
|
3002
|
-
}, {
|
|
3003
|
-
key: "synchronize",
|
|
3004
|
-
get: function get() {
|
|
3005
|
-
return this.syncAdapter.synchronize;
|
|
3006
|
-
}
|
|
3007
|
-
}, {
|
|
3008
|
-
key: "synchronizeEvent",
|
|
3009
|
-
get: function get() {
|
|
3010
|
-
return this.syncAdapter.synchronizeEvent;
|
|
3011
|
-
}
|
|
3012
|
-
}, {
|
|
3013
|
-
key: "Interceptor",
|
|
3014
|
-
get: function get() {
|
|
3015
|
-
return _hook.Hooks;
|
|
3016
|
-
}
|
|
3017
|
-
}, {
|
|
3018
|
-
key: "logger",
|
|
3019
|
-
get: function get() {
|
|
3020
|
-
if (this.debugMode) return console.log.bind(console, 'Qiscus ->');
|
|
3021
|
-
return this.noop;
|
|
3022
|
-
}
|
|
3023
|
-
}, {
|
|
3024
|
-
key: "_throttleDelay",
|
|
3025
|
-
get: function get() {
|
|
3026
|
-
if (this.updateCommentStatusMode === QiscusSDK.UpdateCommentStatusMode.enabled) {
|
|
3027
|
-
return 0;
|
|
3028
|
-
}
|
|
3029
|
-
|
|
3030
|
-
return this.updateCommentStatusThrottleDelay || 300;
|
|
3031
|
-
}
|
|
3032
|
-
}, {
|
|
3033
|
-
key: "_updateStatusEnabled",
|
|
3034
|
-
get: function get() {
|
|
3035
|
-
return this.updateCommentStatusMode !== QiscusSDK.UpdateCommentStatusMode.disabled;
|
|
3036
|
-
}
|
|
3037
2658
|
}]);
|
|
3038
|
-
return QiscusSDK;
|
|
3039
2659
|
}();
|
|
3040
|
-
|
|
3041
2660
|
(0, _defineProperty2["default"])(QiscusSDK, "UpdateCommentStatusMode", UpdateCommentStatusMode);
|
|
3042
2661
|
(0, _defineProperty2["default"])(QiscusSDK, "Interceptor", _hook.Hooks);
|
|
3043
|
-
|
|
3044
|
-
var FileUploaded = function FileUploaded(name, roomId) {
|
|
2662
|
+
var FileUploaded = /*#__PURE__*/(0, _createClass2["default"])(function FileUploaded(name, roomId) {
|
|
3045
2663
|
(0, _classCallCheck2["default"])(this, FileUploaded);
|
|
3046
2664
|
this.name = name;
|
|
3047
2665
|
this.roomId = roomId;
|
|
3048
2666
|
this.progress = 0;
|
|
3049
|
-
};
|
|
3050
|
-
|
|
3051
|
-
var _default = QiscusSDK;
|
|
3052
|
-
exports["default"] = _default;
|
|
2667
|
+
});
|
|
2668
|
+
var _default = exports["default"] = QiscusSDK;
|
|
3053
2669
|
module.exports = exports.default;
|