@subiz/widget-v4 4.1.1 → 4.1.4

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.
Files changed (45) hide show
  1. package/compiled_src/chatbox/ChatButton.js +25 -0
  2. package/compiled_src/lib.js +18 -3
  3. package/compiled_src/store/api.js +116 -108
  4. package/compiled_src/store/api_fake.js +4 -5
  5. package/compiled_src/store/store.js +51 -36
  6. package/compiled_src/util/common.js +1 -1
  7. package/dist/132.js +30 -1
  8. package/dist/185588facf6.132.js +1 -0
  9. package/dist/{184d8eee275.178.js → 185588facf6.178.js} +0 -0
  10. package/dist/{184d8eee275.213.js → 185588facf6.213.js} +0 -0
  11. package/dist/{184d8eee275.335.js → 185588facf6.335.js} +0 -0
  12. package/dist/{184d8eee275.362.js → 185588facf6.362.js} +0 -0
  13. package/dist/185588facf6.441.js +1 -0
  14. package/dist/{184d8eee275.605.js → 185588facf6.605.js} +0 -0
  15. package/dist/{184d8eee275.678.js → 185588facf6.678.js} +0 -0
  16. package/dist/{184d8eee275.782.js → 185588facf6.782.js} +0 -0
  17. package/dist/185588facf6.app.js +1 -0
  18. package/dist/{184d8eee275.index.html → 185588facf6.index.html} +1 -1
  19. package/dist/{184d8eee275.library.html → 185588facf6.library.html} +1 -1
  20. package/dist/185588facf6.library.js +1 -0
  21. package/dist/{184d8eee275.preview.html → 185588facf6.preview.html} +1 -1
  22. package/dist/185588facf6.preview.js +1 -0
  23. package/dist/185588facf6.screenshoot.js +1 -0
  24. package/dist/185588facf6.webview.js +1 -0
  25. package/dist/441.js +51 -36
  26. package/dist/HASH +1 -1
  27. package/dist/screenshoot.html +1 -1
  28. package/dist/screenshoot.js +230 -195
  29. package/inject.js +2 -6
  30. package/package.json +9 -8
  31. package/src/chatbox/ChatButton.js +30 -0
  32. package/src/lib.js +23 -3
  33. package/src/store/api.js +139 -114
  34. package/src/store/api_fake.js +1 -2
  35. package/src/store/store.js +54 -45
  36. package/src/util/common.js +1 -1
  37. package/webpack.dev.js +1 -0
  38. package/webpack.prod.js +1 -0
  39. package/webview.js +43 -0
  40. package/dist/184d8eee275.132.js +0 -1
  41. package/dist/184d8eee275.441.js +0 -1
  42. package/dist/184d8eee275.app.js +0 -1
  43. package/dist/184d8eee275.library.js +0 -1
  44. package/dist/184d8eee275.preview.js +0 -1
  45. package/dist/184d8eee275.screenshoot.js +0 -1
@@ -310,6 +310,7 @@ class ChatButton extends _common.Com {
310
310
  defmsg = defmsg || 'Sent you a message';
311
311
  let message = _index.default.get(ev, 'data.message.text');
312
312
  var format = _index.default.get(ev, 'data.message.format');
313
+ if (format === 'delta') return this.renderDeltaMessagePreview(ev, defmsg);
313
314
  if (format && format !== 'plaintext') message = defmsg;
314
315
  if (!message && _index.default.size(_index.default.get(ev, 'data.message.attachments')) > 0) message = defmsg;
315
316
  if (!message) return null;
@@ -323,6 +324,30 @@ class ChatButton extends _common.Com {
323
324
  });
324
325
  return tags;
325
326
  }
327
+ renderDeltaMessagePreview(ev, defmsg) {
328
+ defmsg = defmsg || 'Sent you a message';
329
+ let message = _index.default.get(ev, 'data.message.quill_delta');
330
+ if (!message && _index.default.size(_index.default.get(ev, 'data.message.attachments')) > 0) message = defmsg;
331
+ if (!message) return;
332
+ let quilldeltas = _index.default.parseJSON(message) || {};
333
+ if (!quilldeltas || _index.default.size(quilldeltas.ops) === 0) return null;
334
+ let $deltas = _index.default.map(quilldeltas.ops, delta => {
335
+ let html = '';
336
+ let insert = delta.insert;
337
+ let attributes = delta.attributes;
338
+ if (insert.dynamicField) {
339
+ return _index.default.get(insert, 'dynamicField.text', '');
340
+ }
341
+ if (insert.emoji) return (0, _preact.h)(_Emoji.default, {
342
+ emojiCode: `:${insert.emoji}:`
343
+ });
344
+ if (typeof insert === 'string') {
345
+ return insert;
346
+ }
347
+ return null;
348
+ });
349
+ return $deltas;
350
+ }
326
351
  closePreview(e) {
327
352
  if (e) {
328
353
  e.preventDefault();
@@ -51,12 +51,27 @@ class Widget {
51
51
  this.domGate.open();
52
52
  return user;
53
53
  }
54
- logout(accid) {
55
- return this.store.logout();
54
+ logout(userref) {
55
+ return this.store.logout(userref);
56
+ }
57
+ async init(param, $container) {
58
+ param = param || {};
59
+ let accid = param.account_id;
60
+ let ref = param.ref;
61
+ let user = await this.store.init(accid, undefined, ref);
62
+ if (!$container) $container = document.body || document;
63
+ this.pluginMgr = new _plugin.default(this, $container);
64
+ let clean = setInterval(() => {
65
+ if ($container && $container.isConnected) return;
66
+ this.pluginMgr.destroy();
67
+ clearInterval(clean);
68
+ }, 1000);
69
+ this.domGate.open();
70
+ return user;
56
71
  }
57
72
  async setAccount(id, $container, mask, cb) {
58
73
  let outmask = await this.store.init(id, mask);
59
- if (!$container) $container = document.body;
74
+ if (!$container) $container = document.body || document;
60
75
  this.pluginMgr = new _plugin.default(this, $container);
61
76
  let clean = setInterval(() => {
62
77
  if ($container && $container.isConnected) return;
@@ -11,7 +11,6 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
11
11
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
12
  const ajax = require('@subiz/ajax/src/ajax.js');
13
13
  ajax.env.XMLHttpRequest = window.XMLHttpRequest;
14
- const findAnswer = challenge => challenge.answer;
15
14
  function jsonifyTextPlain(param, done) {
16
15
  let req = param.request;
17
16
  if (req.content_type === 'text/plain' && req.body !== undefined) req.body = _index.default.stringify(req.body);
@@ -19,8 +18,8 @@ function jsonifyTextPlain(param, done) {
19
18
  }
20
19
  class _default {
21
20
  constructor(ApiURL, FileURL) {
22
- _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get('/conversations'));
23
- _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`));
21
+ _defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
22
+ _defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/accounts/${this.accid}/conversations/${cid}/messages`));
24
23
  _defineProperty(this, "ajax", ajax);
25
24
  _defineProperty(this, "start", extraData => {
26
25
  let data = {
@@ -34,16 +33,16 @@ class _default {
34
33
  _index.default.each(extraData, (v, k) => {
35
34
  data[k] = v;
36
35
  });
37
- return this.apireq.post('/conversations', data);
36
+ return this.apireq.post(`/accounts/${this.accid}/conversations`, data);
38
37
  });
39
38
  _defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
40
39
  _defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
41
- _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`));
42
- _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`));
43
- _defineProperty(this, "getConversation", cid => this.apireq.get(`/conversations/${cid}`));
40
+ _defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/receive`));
41
+ _defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/seen`));
42
+ _defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
44
43
  _defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
45
- _defineProperty(this, "sendEvent", data => this.apireq.post(`/users/${this.uid}/events`, data));
46
- _defineProperty(this, "sendTyping", cid => this.apireq.post(`/conversations/${cid}/typing`));
44
+ _defineProperty(this, "sendEvent", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
45
+ _defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
47
46
  _defineProperty(this, "sendLostFocus", (device, productid, source_id, sku) => this.sendEvent({
48
47
  by: {
49
48
  id: this.uid,
@@ -95,9 +94,8 @@ class _default {
95
94
  url: this.FileURL + body.url
96
95
  };
97
96
  });
98
- _defineProperty(this, "getChallenge", accid => this.apireq.post(`/accounts/${accid}/scrypt-challenges`));
99
- _defineProperty(this, "time", _ => this.apireq.get('/time'));
100
- _defineProperty(this, "updateUser", data => this.apireq.post(`/users/${this.uid}`, data));
97
+ _defineProperty(this, "time", _ => ajax.setBaseUrl(this.ApiURL).withCredentials(true).setParser('json').get('/time'));
98
+ _defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
101
99
  _defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
102
100
  _defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
103
101
  _defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
@@ -129,99 +127,130 @@ class _default {
129
127
  });
130
128
  return;
131
129
  }
132
- if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
130
+ if (this.ref) param.request = param.request.addQuery('x-user-ref', this.ref);else if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
133
131
  return done(true);
134
132
  });
135
133
  }
136
134
  setAgentId(agid) {
137
135
  this.agentid = agid;
138
136
  }
139
- setAuth(obj) {
140
- this.accid = obj.accid;
137
+ async setAuth(obj) {
138
+ if (obj.accid) this.accid = obj.accid;
139
+ if (obj.ref) this.ref = obj.ref;
141
140
  this.mask = obj.mask;
142
- this.uid = obj.uid;
143
- }
144
- async setTokenGenerator(accid, uid, tokenGenerator) {
145
- this.tokensession = this.tokensession || 0;
146
- this.tokensession++;
147
- let tokensession = this.tokensession;
148
- if (!accid || !_index.default.startsWith(accid, 'ac')) return {
149
- error: 'invalid_account_id'
150
- };
151
- if (!uid) return {
152
- error: 'invalid_user_id'
153
- };
154
- if (typeof tokenGenerator !== 'function') return {
155
- error: 'invalid_token_generator'
156
- };
157
- this.accid = accid;
158
- this.profile_id = uid;
159
- this.token_generator = async force => {
160
- await this.refreshLock.lock();
161
- if (tokensession != this.tokensession) {
162
- this.refreshLock.unlock();
163
- return;
141
+ this.profile_id = obj.profile_id;
142
+ if (obj.ref) {
143
+ let outuser;
144
+ for (let i = 0; true; i++) {
145
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
146
+ if (!_index.default.get(outuser, 'body.id')) {
147
+ let sleeptime = Math.min(2000 + i * 200, 60000);
148
+ await _index.default.sleep(sleeptime);
149
+ continue;
150
+ }
151
+ break;
164
152
  }
165
- let age = (_index.default.Date.now() - (this.last_token_at || 0)) / 1000;
166
- if (!force && this.last_token && age < 1800) {
167
- this.refreshLock.unlock();
168
- return this.last_token;
153
+ if (outuser.error) {
154
+ if (_index.default.get(outuser.body.code)) return {
155
+ error: outuser.body.code
156
+ };
157
+ return outuser;
169
158
  }
170
- if (!force && this.last_token && age < 3000) {
171
- if (this.token_generator) setTimeout(async () => {
172
- let token, err;
173
- try {
174
- token = await tokenGenerator(uid);
175
- } catch (e) {
176
- err = e;
177
- }
178
- if (tokensession != this.tokensession) {
159
+ this.uid = outuser.body.id;
160
+ return outuser.body;
161
+ }
162
+ if (obj.tokenGenerator) {
163
+ this.tokensession = this.tokensession || 0;
164
+ this.tokensession++;
165
+ let tokensession = this.tokensession;
166
+ if (!this.accid || !_index.default.startsWith(this.accid, 'ac')) return {
167
+ error: 'invalid_account_id'
168
+ };
169
+ if (!this.profile_id) return {
170
+ error: 'invalid_profile_id'
171
+ };
172
+ if (typeof this.tokenGenerator !== 'function') return {
173
+ error: 'invalid_token_generator'
174
+ };
175
+ let profile_id = this.profile_id;
176
+ this.token_generator = async force => {
177
+ await this.refreshLock.lock();
178
+ if (tokensession != this.tokensession) {
179
+ this.refreshLock.unlock();
180
+ return;
181
+ }
182
+ let age = (_index.default.Date.now() - (this.last_token_at || 0)) / 1000;
183
+ if (!force && this.last_token && age < 1800) {
184
+ this.refreshLock.unlock();
185
+ return this.last_token;
186
+ }
187
+ if (!force && this.last_token && age < 3000) {
188
+ if (this.token_generator) setTimeout(async () => {
189
+ let token, err;
190
+ try {
191
+ token = await tokenGenerator(profile_id);
192
+ } catch (e) {
193
+ err = e;
194
+ }
195
+ if (tokensession != this.tokensession) {
196
+ this.refreshLock.unlock();
197
+ return;
198
+ }
199
+ if (err) this.last_token = 'error';else this.last_token = token;
200
+ this.last_token_at = _index.default.Date.now();
179
201
  this.refreshLock.unlock();
180
- return;
181
- }
182
- if (err) this.last_token = 'error';else this.last_token = token;
183
- this.last_token_at = _index.default.Date.now();
202
+ });
203
+ return this.last_token;
204
+ }
205
+ let token;
206
+ let err;
207
+ try {
208
+ token = await tokenGenerator(profile_id);
209
+ } catch (e) {
210
+ err = e;
211
+ }
212
+ if (tokensession != this.tokensession) {
184
213
  this.refreshLock.unlock();
185
- });
186
- return this.last_token;
187
- }
188
- let token;
189
- let err;
190
- try {
191
- token = await tokenGenerator(uid);
192
- } catch (e) {
193
- err = e;
194
- }
195
- if (tokensession != this.tokensession) {
214
+ return;
215
+ }
216
+ if (err) this.last_token = 'error';else this.last_token = token;
217
+ this.last_token_at = _index.default.Date.now();
196
218
  this.refreshLock.unlock();
197
- return;
219
+ return this.last_token;
220
+ };
221
+ let outuser;
222
+ for (let i = 0; true; i++) {
223
+ await this.token_generator(true);
224
+ if (tokensession != this.tokensession) break;
225
+ outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${accid}/users/${profile_id}`);
226
+ if (!_index.default.get(outuser, 'body.id')) {
227
+ let sleeptime = Math.min(2000 + i * 100, 120000);
228
+ await _index.default.sleep(sleeptime);
229
+ continue;
230
+ }
231
+ break;
198
232
  }
199
- if (err) this.last_token = 'error';else this.last_token = token;
200
- this.last_token_at = _index.default.Date.now();
201
- this.refreshLock.unlock();
202
- return this.last_token;
203
- };
204
- let outuser;
205
- for (let i = 0; true; i++) {
206
- await this.token_generator(true);
207
- if (tokensession != this.tokensession) break;
208
- outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${accid}/users/${uid}`);
209
- if (!_index.default.get(outuser, 'body.id')) {
210
- let sleeptime = Math.min(2000 + i * 100, 120000);
211
- await _index.default.sleep(sleeptime);
212
- continue;
233
+ if (outuser.error) {
234
+ if (_index.default.get(outuser.body.code)) return {
235
+ error: outuser.body.code
236
+ };
237
+ return outuser;
213
238
  }
214
- break;
239
+ this.uid = outuser.body.id;
240
+ return outuser.body;
215
241
  }
216
- if (outuser.error) {
217
- if (_index.default.get(outuser.body.code)) return {
218
- error: outuser.body.code
242
+ if (this.mask) {
243
+ let parts = this.mask.split('@');
244
+ this.uid = parts[1];
245
+ return {
246
+ id: this.uid
219
247
  };
220
- return outuser;
221
248
  }
222
- this.uid = outuser.body.id;
223
- return outuser.body;
249
+ return {
250
+ error: 'invalid_auth'
251
+ };
224
252
  }
253
+ async setTokenGenerator(accid, uid, tokenGenerator) {}
225
254
  sendContentView(device, pageUrl, pageTitle, id, source_id, sku) {
226
255
  if (!id) id = undefined;
227
256
  if (!source_id) source_id = undefined;
@@ -243,26 +272,5 @@ class _default {
243
272
  }
244
273
  });
245
274
  }
246
- async createUser(accid) {
247
- for (var i = 0; i < 10; i++) {
248
- const {
249
- body: challenge
250
- } = await this.getChallenge(accid);
251
- const answer = findAnswer(challenge);
252
- const data = {
253
- challenge_id: challenge.id,
254
- answer: '' + answer
255
- };
256
- let {
257
- body: user,
258
- error
259
- } = await this.apireq.post(`/accounts/${accid}/scrypt-challenges/users`, data);
260
- if (error) {
261
- await _index.default.sleep(1000);
262
- continue;
263
- }
264
- return user;
265
- }
266
- }
267
275
  }
268
276
  exports.default = _default;
@@ -56,11 +56,6 @@ class _default {
56
56
  _defineProperty(this, "sendContent", data => OK200);
57
57
  _defineProperty(this, "uploadToS3", async file => OK200);
58
58
  _defineProperty(this, "getChallenge", accid => OK200);
59
- _defineProperty(this, "createUser", accid => Promise.resolve({
60
- account_id: accid,
61
- id: 'usqzgtgfake',
62
- mask: 'fakemask'
63
- }));
64
59
  _defineProperty(this, "time", _ => Promise.resolve({
65
60
  code: 200,
66
61
  body: new _index.default.Date().toISOString()
@@ -89,6 +84,10 @@ class _default {
89
84
  this.accid = obj.accid;
90
85
  this.mask = obj.mask;
91
86
  this.uid = obj.uid;
87
+ return {
88
+ account_id: accid,
89
+ id: 'usqzgtgfake'
90
+ };
92
91
  }
93
92
  }
94
93
  exports.default = _default;
@@ -167,6 +167,13 @@ class Store {
167
167
  this.inmem = inmem;
168
168
  this.cookie = inmemCookie;
169
169
  }
170
+ if (!inmem) {
171
+ try {
172
+ this.cookie.get('_', '');
173
+ } catch (e) {
174
+ inmem = true;
175
+ }
176
+ }
170
177
  this.pubsub = new _index.default.Pubsub();
171
178
  this.kv = new _storage.default.kv(new _storage.default.lsdb('sbz2020', this.inmem), 'kv');
172
179
  this.cache = new _storage.default.kv(new _storage.default.lsdb('sbz2020', true), 'kv');
@@ -302,58 +309,64 @@ class Store {
302
309
  await this.readyGate.entry();
303
310
  if (!this.isInsync('account')) this.reconnect();
304
311
  }
305
- async init(accid, mask) {
312
+ async init(accid, mask, userRef) {
306
313
  this.readyGate.close();
307
314
  accid = (accid || '').trim();
308
315
  this.api.setAuth({
309
316
  accid: accid
310
317
  });
311
318
  this.g_sync = {};
312
- if (!mask) {
319
+ if (!userRef) {
313
320
  try {
314
- mask = this.cookie.get('__sbmask', '');
321
+ userRef = this.cookie.get('__sbref', '');
315
322
  } catch (e) {}
323
+ if (!userRef) {
324
+ if (!mask) {
325
+ try {
326
+ mask = this.cookie.get('__sbmask', '');
327
+ } catch (e) {}
328
+ }
329
+ if (mask) {
330
+ let parts = mask.split('@');
331
+ if (parts[0] != accid) {
332
+ userRef = _index.default.randomString(40);
333
+ this.new_visitor = true;
334
+ }
335
+ this.new_visitor = false;
336
+ this.cookie.set('__sbmask', mask);
337
+ } else {
338
+ userRef = _index.default.randomString(40);
339
+ this.new_visitor = true;
340
+ }
341
+ }
316
342
  }
317
- let localstorageMask = this.kv.match('mask');
318
- if (!mask && localstorageMask) mask = localstorageMask;
319
- if (mask && localstorageMask && mask !== localstorageMask) this.clearBrowserData();
320
- var userId = '';
321
- if (mask) {
322
- let parts = mask.split('@');
323
- if (parts[0] != accid) {
324
- mask = '';
325
- this.clearBrowserData();
326
- } else userId = parts[1];
327
- }
328
- if (!mask) {
329
- let user = await this.api.createUser(accid);
330
- this.new_visitor = true;
331
- mask = user.mask;
332
- userId = user.id;
333
- } else {
334
- this.new_visitor = false;
335
- }
336
- this.cookie.set('__sbmask', mask);
337
- this.kv.put('mask', mask);
343
+ if (userRef) this.cookie.set('__sbref', userRef);
344
+ let user = await this.api.setAuth({
345
+ accid: accid,
346
+ mask: mask,
347
+ ref: userRef
348
+ });
349
+ if (user.error) return;
338
350
  if (this.realtime) this.realtime.stop();
339
351
  if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, {
352
+ account_id: accid,
353
+ user_ref: userRef,
340
354
  user_mask: mask
341
355
  });
342
356
  this.realtime.onEvent(this.onWs.bind(this));
343
- this.realtime.onInterrupted(() => this.reconnectWs(accid, userId));
344
- this.api.setAuth({
345
- accid: accid,
346
- uid: userId,
347
- mask: mask
348
- });
357
+ this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id));
349
358
  this.seenLoop();
350
359
  await this.reconnect();
351
360
  this.readyGate.open();
352
- this.reconnectWs(accid, userId);
353
- return mask;
361
+ this.reconnectWs(accid, user.id);
362
+ return user;
354
363
  }
355
364
  async login(accid, user_id, tokenGenerator) {
356
- let user = await this.api.setTokenGenerator(accid, user_id, tokenGenerator);
365
+ let user = await this.api.setAuth({
366
+ accid: accid,
367
+ profile_id: user_id,
368
+ tokenGenerator: tokenGenerator
369
+ });
357
370
  if (user.error) return user;
358
371
  this.clearBrowserData();
359
372
  this.readyGate.close();
@@ -372,8 +385,10 @@ class Store {
372
385
  this.reconnectWs(accid, user.id);
373
386
  return user;
374
387
  }
375
- logout(user_id) {
376
- this.api.setTokenGenerator(undefined, undefined, undefined);
388
+ logout(userRef) {
389
+ return this.api.setAuth({
390
+ ref: userRef
391
+ });
377
392
  }
378
393
  seenLoop() {
379
394
  this.seenQueue = [];
@@ -393,7 +408,7 @@ class Store {
393
408
  this.api.markAsSeen(id, lastmsgsent.id);
394
409
  let convo = this.cache.match('convo_' + id) || {};
395
410
  let mem = _index.default.find(convo.members, m => m.id === user.id);
396
- mem.seen_at = Date.now();
411
+ if (mem) mem.seen_at = Date.now();
397
412
  this._setConvo(convo);
398
413
  this.g_haveSentSeenM[lastmsgsent.id] = true;
399
414
  });
@@ -341,7 +341,7 @@ function orderBy(a, k, d) {
341
341
  return clone;
342
342
  }
343
343
  function isPhone(phone) {
344
- var re = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im;
344
+ var re = /^[\+]?[(]?[0-9]{2,3}[)]?[-\s\.]?[0-9]{3,4}[-\s\.]?[0-9]{4,6}$/im;
345
345
  return re.test(String(phone));
346
346
  }
347
347
  function isURL(url) {
package/dist/132.js CHANGED
@@ -339,6 +339,7 @@ class ChatButton extends common/* Com */.up {
339
339
  defmsg = defmsg || 'Sent you a message';
340
340
  let message = util/* default.get */.Z.get(ev, 'data.message.text');
341
341
  var format = util/* default.get */.Z.get(ev, 'data.message.format');
342
+ if (format === 'delta') return this.renderDeltaMessagePreview(ev, defmsg);
342
343
  if (format && format !== 'plaintext') message = defmsg;
343
344
  if (!message && util/* default.size */.Z.size(util/* default.get */.Z.get(ev, 'data.message.attachments')) > 0) message = defmsg;
344
345
  if (!message) return null;
@@ -352,6 +353,30 @@ class ChatButton extends common/* Com */.up {
352
353
  });
353
354
  return tags;
354
355
  }
356
+ renderDeltaMessagePreview(ev, defmsg) {
357
+ defmsg = defmsg || 'Sent you a message';
358
+ let message = util/* default.get */.Z.get(ev, 'data.message.quill_delta');
359
+ if (!message && util/* default.size */.Z.size(util/* default.get */.Z.get(ev, 'data.message.attachments')) > 0) message = defmsg;
360
+ if (!message) return;
361
+ let quilldeltas = util/* default.parseJSON */.Z.parseJSON(message) || {};
362
+ if (!quilldeltas || util/* default.size */.Z.size(quilldeltas.ops) === 0) return null;
363
+ let $deltas = util/* default.map */.Z.map(quilldeltas.ops, delta => {
364
+ let html = '';
365
+ let insert = delta.insert;
366
+ let attributes = delta.attributes;
367
+ if (insert.dynamicField) {
368
+ return util/* default.get */.Z.get(insert, 'dynamicField.text', '');
369
+ }
370
+ if (insert.emoji) return (0,preact_module.h)(Emoji, {
371
+ emojiCode: `:${insert.emoji}:`
372
+ });
373
+ if (typeof insert === 'string') {
374
+ return insert;
375
+ }
376
+ return null;
377
+ });
378
+ return $deltas;
379
+ }
355
380
  closePreview(e) {
356
381
  if (e) {
357
382
  e.preventDefault();
@@ -740,7 +765,11 @@ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi
740
765
  return joined;
741
766
  }
742
767
  }
743
- let getJoinedNameMember = agents => util/* default.map */.Z.map(agents, agent => agent.name).join(', ');
768
+ let getJoinedNameMember = agents => {
769
+ agents = util/* default.filter */.Z.filter(agents, agent => util/* default.trim */.Z.trim(agent.fullname));
770
+ if (!agents.length) return null;
771
+ return util/* default.map */.Z.map(agents, agent => agent.fullname).join(', ');
772
+ };
744
773
  ;// CONCATENATED MODULE: ./src/chatbox/MessageInput.js
745
774
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
746
775
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }