@subiz/widget-v4 4.1.162 → 4.1.165

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 (52) hide show
  1. package/compiled_src/chatbox/ChatButton.js +4 -0
  2. package/compiled_src/chatbox/Event.js +2 -6
  3. package/compiled_src/chatbox/Header.js +1 -0
  4. package/compiled_src/chatbox/TextMessage.js +2 -7
  5. package/compiled_src/chatbox/Widget.js +1 -1
  6. package/compiled_src/chatbox/main.js +6 -0
  7. package/compiled_src/store/inmem_localstorage.js +1 -0
  8. package/compiled_src/store/lsdb.js +5 -1
  9. package/compiled_src/store/store.js +21 -8
  10. package/compiled_src/util/common.js +11 -0
  11. package/dist/198a3089a0c.app.js +1 -0
  12. package/dist/{198a2601817.chat.html → 198a3089a0c.chat.html} +1 -1
  13. package/dist/198a3089a0c.chat.js +1 -0
  14. package/dist/{198a2601817.form.html → 198a3089a0c.form.html} +1 -1
  15. package/dist/198a3089a0c.form.js +1 -0
  16. package/dist/{198a2601817.index.html → 198a3089a0c.index.html} +1 -1
  17. package/dist/{198a2601817.library.html → 198a3089a0c.library.html} +1 -1
  18. package/dist/198a3089a0c.library.js +1 -0
  19. package/dist/{198a2601817.preview.html → 198a3089a0c.preview.html} +1 -1
  20. package/dist/198a3089a0c.preview.js +1 -0
  21. package/dist/198a3089a0c.webview.js +1 -0
  22. package/dist/HASH +1 -1
  23. package/dist/screenshoot.js +13 -11
  24. package/package.json +1 -1
  25. package/src/chatbox/ChatButton.js +5 -1
  26. package/src/chatbox/Event.js +2 -6
  27. package/src/chatbox/Header.js +1 -0
  28. package/src/chatbox/TextMessage.js +1 -13
  29. package/src/chatbox/Widget.js +1 -1
  30. package/src/chatbox/main.js +6 -0
  31. package/src/store/inmem_localstorage.js +1 -0
  32. package/src/store/kv.js +0 -1
  33. package/src/store/lsdb.js +6 -1
  34. package/src/store/store.js +21 -9
  35. package/src/util/common.js +21 -4
  36. package/tracking.js +45 -0
  37. package/dist/198a2601817.app.js +0 -1
  38. package/dist/198a2601817.chat.js +0 -1
  39. package/dist/198a2601817.form.js +0 -1
  40. package/dist/198a2601817.library.js +0 -1
  41. package/dist/198a2601817.preview.js +0 -1
  42. package/dist/198a2601817.webview.js +0 -1
  43. /package/dist/{198a2601817.127.js → 198a3089a0c.127.js} +0 -0
  44. /package/dist/{198a2601817.132.js → 198a3089a0c.132.js} +0 -0
  45. /package/dist/{198a2601817.185.js → 198a3089a0c.185.js} +0 -0
  46. /package/dist/{198a2601817.27.js → 198a3089a0c.27.js} +0 -0
  47. /package/dist/{198a2601817.278.js → 198a3089a0c.278.js} +0 -0
  48. /package/dist/{198a2601817.339.js → 198a3089a0c.339.js} +0 -0
  49. /package/dist/{198a2601817.459.js → 198a3089a0c.459.js} +0 -0
  50. /package/dist/{198a2601817.490.js → 198a3089a0c.490.js} +0 -0
  51. /package/dist/{198a2601817.74.js → 198a3089a0c.74.js} +0 -0
  52. /package/dist/{198a2601817.997.js → 198a3089a0c.997.js} +0 -0
@@ -157,6 +157,9 @@ class ChatButton extends _common.Com {
157
157
  let lastview = this.props.store.matchLastview();
158
158
  if (_index.default.get(lastview, 'view')) {
159
159
  if (lastview.view !== 'list' || _index.default.size(this.props.store.matchConvo('*')) > 0) {
160
+ if (lastview.view == 'chat' && !_index.default.get(lastview, 'opts.cid')) {
161
+ return this.onPreviewClick();
162
+ }
160
163
  return this.props.onClick && this.props.onClick(Object.assign({}, lastview.opts, {
161
164
  view: lastview.view
162
165
  }));
@@ -187,6 +190,7 @@ class ChatButton extends _common.Com {
187
190
  }
188
191
  renderPreview() {
189
192
  let account = this.props.store.matchAccount();
193
+ if (!account) return null;
190
194
  let accountSetting = this.props.plugin.chatbox;
191
195
  let byid = _index.default.get(this.state.previewEvent, 'by.display_id', _index.default.get(this.state.previewEvent, 'by.id'));
192
196
  let agent = this.props.store.matchAgent(byid);
@@ -246,7 +246,7 @@ class Event extends _common.Com {
246
246
  let ev = this.props.event.ev;
247
247
  let attachments = _index.default.get(ev, 'data.message.attachments');
248
248
  let hasForm = _index.default.find(attachments, att => att.type === 'form');
249
- if (isEmptyMessage(_index.default.get(ev, 'data.message'))) return null;
249
+ if (_index.default.isEmptyMessage(_index.default.get(ev, 'data.message'))) return null;
250
250
  this.tryLoadOrder(ev);
251
251
  let t = new _index.default.Date(ev.created).toLocaleString();
252
252
  if (_index.default.get(ev, 'by.type') !== 'user') {
@@ -515,8 +515,4 @@ class Event extends _common.Com {
515
515
  return acc.name;
516
516
  }
517
517
  }
518
- exports.default = Event;
519
- function isEmptyMessage(msg) {
520
- if (!msg) return true;
521
- if (!msg.text && !msg.block && !_index.default.size(msg.attachments)) return true;
522
- }
518
+ exports.default = Event;
@@ -190,6 +190,7 @@ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi
190
190
  if (_index.default.size(allconvos) === 0) return null;
191
191
  var $unreadcount = null;
192
192
  let user = this.props.store.matchUser();
193
+ if (!user || !user.id) return null;
193
194
  let unreadcount = 0;
194
195
  _index.default.map(allconvos, convo => {
195
196
  if (convo.id == this.props.cid) return;
@@ -71,7 +71,7 @@ class TextMessage extends _common.Com {
71
71
  }, tags);
72
72
  }
73
73
  renderBlock(block) {
74
- if (isEmptyBlock(block)) return null;
74
+ if (_index.default.isEmptyBlock(block)) return null;
75
75
  let t = new _index.default.Date(_index.default.get(this.props.ev, 'created')).toLocaleString();
76
76
  let byType = _index.default.get(this.props.ev, 'by.type');
77
77
  if (byType !== 'user') byType = 'agent';
@@ -97,9 +97,4 @@ class TextMessage extends _common.Com {
97
97
  }));
98
98
  }
99
99
  }
100
- exports.default = TextMessage;
101
- function isEmptyBlock(block) {
102
- if (!block || !block.type) return true;
103
- let hasContent = _index.default.size(_index.default.filter(_index.default.map(block.content, block => isEmptyBlock(block)), isEmpty => !isEmpty)) > 0;
104
- return !_index.default.trim(block.text) && !hasContent;
105
- }
100
+ exports.default = TextMessage;
@@ -64,7 +64,7 @@ class Widget extends _common.Com {
64
64
  creating: true
65
65
  });
66
66
  let botid = cid.split('_')[0].slice(7);
67
- let oldconvo = this.props.store.matchConvo(this.props.cid);
67
+ let oldconvo = this.props.store.matchConvo(this.props.cid) || {};
68
68
  const {
69
69
  convo,
70
70
  error
@@ -47,6 +47,12 @@ class Main extends _common.Com {
47
47
  this.props.store.onResetCSS(this, () => this.refreshCSS());
48
48
  this.props.store.onConvoEvent(this, ev => this.onConvoEvent(ev));
49
49
  this.props.store.onUpdate(this, _ => this.checkExpand());
50
+ this.props.store.onDestroyed(this, _ => {
51
+ this.setState({
52
+ widgetView: '',
53
+ widgetConvoId: ''
54
+ });
55
+ });
50
56
  await this.refreshCSS();
51
57
  this.setState({
52
58
  cssready: true
@@ -3,6 +3,7 @@
3
3
  var localStorageMemory = {};
4
4
  var cache = {};
5
5
  localStorageMemory.length = 0;
6
+ localStorageMemory.cache = cache;
6
7
  localStorageMemory.getItem = function (key) {
7
8
  if (key in cache) return cache[key];
8
9
  return null;
@@ -41,10 +41,14 @@ class _default {
41
41
  }
42
42
  }
43
43
  clear(table) {
44
+ var keys = [];
44
45
  for (var i = 0; i < this.localStorage.length; i++) {
45
46
  let key = this.localStorage.key(i);
46
47
  if (!key.startsWith(this.schema + '#' + table + '#')) continue;
47
- this.localStorage.removeItem(key);
48
+ keys.push(key);
49
+ }
50
+ for (var i = 0; i < keys.length; i++) {
51
+ this.localStorage.removeItem(keys[i]);
48
52
  }
49
53
  this.allkeys = {};
50
54
  }
@@ -21,6 +21,7 @@ var cookie = require('cookie_js');
21
21
  cookie.defaults.path = '/';
22
22
  cookie.expiresMultiplier = 60 * 60 * 24;
23
23
  cookie.defaults.expires = 3650;
24
+ let memlocalStorage = require('./inmem_localstorage.js');
24
25
  const MAX_CONVO = 20;
25
26
  const page_loaded = _index.default.Date.now();
26
27
  class Store {
@@ -31,6 +32,7 @@ class Store {
31
32
  _defineProperty(this, "_currentViewingProduct", {});
32
33
  _defineProperty(this, "new_visitor", true);
33
34
  _defineProperty(this, "matchUser", () => {
35
+ if (!this.cache) return undefined;
34
36
  this._touchAcc();
35
37
  return this.cache.match('user');
36
38
  });
@@ -39,6 +41,7 @@ class Store {
39
41
  _defineProperty(this, "matchPaymentMethods", () => this.cache.match('payment_methods'));
40
42
  _defineProperty(this, "matchUnread", () => {
41
43
  let user = this.matchUser();
44
+ if (!user || !user.id) return;
42
45
  let allconvos = this.matchConvo('*');
43
46
  let unreadcount = 0;
44
47
  _index.default.map(allconvos, convo => {
@@ -169,6 +172,7 @@ class Store {
169
172
  this.seenQueue.push(id);
170
173
  });
171
174
  _defineProperty(this, "onUpdate", (o, cb) => this.pubsub.on2(o, 'account', cb));
175
+ _defineProperty(this, "onDestroyed", (o, cb) => this.pubsub.on2(o, 'destroy', cb));
172
176
  _defineProperty(this, "onConnection", (o, cb) => this.pubsub.on2(o, 'connection', cb));
173
177
  _defineProperty(this, "onResetCSS", (o, cb) => this.pubsub.on2(o, 'resetCSS', cb));
174
178
  _defineProperty(this, "onHighlight", (o, cb) => this.pubsub.on2(o, 'highlight', cb));
@@ -205,7 +209,6 @@ class Store {
205
209
  this.FileURL = FileURL;
206
210
  this._track_page_view = true;
207
211
  this.device_type = 'desktop';
208
- this.lightConvos = {};
209
212
  if (this.fake) this.api = new _api_fake.default(ApiURL, FileURL);else this.api = new _api.default(ApiURL, FileURL);
210
213
  if (!inmem) {
211
214
  try {
@@ -470,7 +473,12 @@ class Store {
470
473
  }
471
474
  }
472
475
  }
473
- if (this.cookie.get('__sbref', userRef) != userRef) cleanMyLocalStorage();
476
+ if (this.cookie.get('__sbref', userRef) != userRef) {
477
+ cleanMyLocalStorage();
478
+ this.clearBrowserData();
479
+ }
480
+ this.lightConvos = {};
481
+ this.cache = new _kv.default(new _lsdb.default('sbz2023', true), 'kv');
474
482
  this.api.setAuth({
475
483
  accid: accid
476
484
  });
@@ -543,6 +551,7 @@ class Store {
543
551
  _index.default.clearInterval(this._seenInterval);
544
552
  this._seenInterval = _index.default.setInterval(() => {
545
553
  if (this._die) return _index.default.clearInterval(this._seenInterval);
554
+ if (!this.cache) return;
546
555
  this.seenQueue = [...new Set(this.seenQueue)];
547
556
  let user = this.cache.match('user') || {};
548
557
  _index.default.map(this.seenQueue, id => {
@@ -576,7 +585,7 @@ class Store {
576
585
  let user = this.matchUser();
577
586
  if (!old) return;
578
587
  let mem = _index.default.find(old.members, mem => mem.type == 'user' && mem.id == user.id);
579
- mem.seen_at = this.now();
588
+ if (mem) mem.seen_at = this.now();
580
589
  this.kv.put('light_convos', this.lightConvos);
581
590
  this.g_haveSentSeenM[lastmsgsent.id] = true;
582
591
  return;
@@ -1144,7 +1153,7 @@ class Store {
1144
1153
  async loopTime() {
1145
1154
  if (this._die) return;
1146
1155
  let startms = this.now();
1147
- if (!_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
1156
+ if (!this.cache || !_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
1148
1157
  let {
1149
1158
  body: t,
1150
1159
  error
@@ -1181,15 +1190,17 @@ class Store {
1181
1190
  _index.default.each(this.cookie.all(), (v, k) => {
1182
1191
  if ((k || '').startsWith('__sb')) this.cookie.remove(k);
1183
1192
  });
1184
- this.kv.destroy();
1193
+ if (this.kv) this.kv.destroy();
1185
1194
  this.kv = new _kv.default(new _lsdb.default('sbz2023', this.inmem), 'kv');
1186
- this.chain.destroy();
1195
+ if (this.chain) this.chain.destroy();
1187
1196
  this.chain = new _chain.default(new _lsdb.default('cbz2023', true), 'ch');
1197
+ if (this.realtime) this.realtime.stop();
1198
+ if (this.cache) this.cache.destroy();
1199
+ this.pubsub.publish('destroy');
1188
1200
  }
1189
1201
  destroy() {
1190
1202
  this._die = true;
1191
- if (this.kv) this.kv.destroy();
1192
- if (this.chain) this.chain.destroy();
1203
+ this.clearBrowserData();
1193
1204
  _index.default.clearInterval(this._seenInterval);
1194
1205
  if (this.realtime) this.realtime.stop();
1195
1206
  this.readyGate.close();
@@ -1326,6 +1337,7 @@ let cleanLocalStorage = () => {
1326
1337
  for (var key in localStorage) {
1327
1338
  if (key && (key.startsWith('cbz2020') || key.startsWith('sbz2020'))) {
1328
1339
  localStorage.removeItem(key);
1340
+ memlocalStorage.removeItem(key);
1329
1341
  }
1330
1342
  }
1331
1343
  });
@@ -1340,6 +1352,7 @@ let cleanMyLocalStorage = () => {
1340
1352
  for (var key in localStorage) {
1341
1353
  if (key && (key.startsWith('cbz2020') || key.startsWith('sbz2020') || key.startsWith('sbz2022') || key.startsWith('sbz2023'))) {
1342
1354
  localStorage.removeItem(key);
1355
+ memlocalStorage.removeItem(key);
1343
1356
  }
1344
1357
  }
1345
1358
  });
@@ -34,6 +34,8 @@ exports.includes = includes;
34
34
  exports.isBlockEmpty = isBlockEmpty;
35
35
  exports.isConvoSeen = isConvoSeen;
36
36
  exports.isEmail = isEmail;
37
+ exports.isEmptyBlock = isEmptyBlock;
38
+ exports.isEmptyMessage = isEmptyMessage;
37
39
  exports.isNumber = isNumber;
38
40
  exports.isPhone = isPhone;
39
41
  exports.isURL = isURL;
@@ -1291,4 +1293,13 @@ emojis = map(emojis, e => ':' + e + ':');
1291
1293
  function absLink(url) {
1292
1294
  if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
1293
1295
  return url;
1296
+ }
1297
+ function isEmptyBlock(block) {
1298
+ if (!block || !block.type) return true;
1299
+ let hasContent = size(filter(map(block.content, block => isEmptyBlock(block)), isEmpty => !isEmpty)) > 0;
1300
+ return !trim(block.text) && !hasContent;
1301
+ }
1302
+ function isEmptyMessage(msg) {
1303
+ if (!msg) return true;
1304
+ if (!msg.text && isEmptyBlock(msg.block) && !size(msg.attachments)) return true;
1294
1305
  }