@subiz/widget-v4 4.1.163 → 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 (46) hide show
  1. package/compiled_src/chatbox/ChatButton.js +4 -0
  2. package/compiled_src/chatbox/Header.js +1 -0
  3. package/compiled_src/chatbox/Widget.js +1 -1
  4. package/compiled_src/chatbox/main.js +6 -0
  5. package/compiled_src/store/inmem_localstorage.js +1 -0
  6. package/compiled_src/store/lsdb.js +5 -1
  7. package/compiled_src/store/store.js +21 -8
  8. package/dist/198a3089a0c.app.js +1 -0
  9. package/dist/{198a2dde018.chat.html → 198a3089a0c.chat.html} +1 -1
  10. package/dist/198a3089a0c.chat.js +1 -0
  11. package/dist/{198a2dde018.form.html → 198a3089a0c.form.html} +1 -1
  12. package/dist/198a3089a0c.form.js +1 -0
  13. package/dist/{198a2dde018.index.html → 198a3089a0c.index.html} +1 -1
  14. package/dist/{198a2dde018.library.html → 198a3089a0c.library.html} +1 -1
  15. package/dist/198a3089a0c.library.js +1 -0
  16. package/dist/{198a2dde018.preview.html → 198a3089a0c.preview.html} +1 -1
  17. package/dist/198a3089a0c.preview.js +1 -0
  18. package/dist/198a3089a0c.webview.js +1 -0
  19. package/dist/HASH +1 -1
  20. package/dist/screenshoot.js +13 -11
  21. package/package.json +1 -1
  22. package/src/chatbox/ChatButton.js +5 -1
  23. package/src/chatbox/Header.js +1 -0
  24. package/src/chatbox/Widget.js +1 -1
  25. package/src/chatbox/main.js +6 -0
  26. package/src/store/inmem_localstorage.js +1 -0
  27. package/src/store/kv.js +0 -1
  28. package/src/store/lsdb.js +6 -1
  29. package/src/store/store.js +21 -9
  30. package/tracking.js +2 -1
  31. package/dist/198a2dde018.app.js +0 -1
  32. package/dist/198a2dde018.chat.js +0 -1
  33. package/dist/198a2dde018.form.js +0 -1
  34. package/dist/198a2dde018.library.js +0 -1
  35. package/dist/198a2dde018.preview.js +0 -1
  36. package/dist/198a2dde018.webview.js +0 -1
  37. /package/dist/{198a2dde018.127.js → 198a3089a0c.127.js} +0 -0
  38. /package/dist/{198a2dde018.132.js → 198a3089a0c.132.js} +0 -0
  39. /package/dist/{198a2dde018.185.js → 198a3089a0c.185.js} +0 -0
  40. /package/dist/{198a2dde018.27.js → 198a3089a0c.27.js} +0 -0
  41. /package/dist/{198a2dde018.278.js → 198a3089a0c.278.js} +0 -0
  42. /package/dist/{198a2dde018.339.js → 198a3089a0c.339.js} +0 -0
  43. /package/dist/{198a2dde018.459.js → 198a3089a0c.459.js} +0 -0
  44. /package/dist/{198a2dde018.490.js → 198a3089a0c.490.js} +0 -0
  45. /package/dist/{198a2dde018.74.js → 198a3089a0c.74.js} +0 -0
  46. /package/dist/{198a2dde018.997.js → 198a3089a0c.997.js} +0 -0
package/dist/HASH CHANGED
@@ -1 +1 @@
1
- 198a2dde018
1
+ 198a3089a0c
@@ -2216,6 +2216,8 @@ __webpack_require__.r(__webpack_exports__);
2216
2216
  /* harmony export */ isBlockEmpty: () => (/* binding */ isBlockEmpty),
2217
2217
  /* harmony export */ isConvoSeen: () => (/* binding */ isConvoSeen),
2218
2218
  /* harmony export */ isEmail: () => (/* binding */ isEmail),
2219
+ /* harmony export */ isEmptyBlock: () => (/* binding */ isEmptyBlock),
2220
+ /* harmony export */ isEmptyMessage: () => (/* binding */ isEmptyMessage),
2219
2221
  /* harmony export */ isNumber: () => (/* binding */ isNumber),
2220
2222
  /* harmony export */ isPhone: () => (/* binding */ isPhone),
2221
2223
  /* harmony export */ isURL: () => (/* binding */ isURL),
@@ -3475,6 +3477,15 @@ function absLink(url) {
3475
3477
  if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url;
3476
3478
  return url;
3477
3479
  }
3480
+ function isEmptyBlock(block) {
3481
+ if (!block || !block.type) return true;
3482
+ let hasContent = size(filter(map(block.content, block => isEmptyBlock(block)), isEmpty => !isEmpty)) > 0;
3483
+ return !trim(block.text) && !hasContent;
3484
+ }
3485
+ function isEmptyMessage(msg) {
3486
+ if (!msg) return true;
3487
+ if (!msg.text && isEmptyBlock(msg.block) && !size(msg.attachments)) return true;
3488
+ }
3478
3489
 
3479
3490
  /***/ })
3480
3491
 
@@ -8548,7 +8559,7 @@ class TextMessage extends common/* Com */.Mw {
8548
8559
  }, tags);
8549
8560
  }
8550
8561
  renderBlock(block) {
8551
- if (isEmptyBlock(block)) return null;
8562
+ if (util/* default */.A.isEmptyBlock(block)) return null;
8552
8563
  let t = new util/* default */.A.Date(util/* default */.A.get(this.props.ev, 'created')).toLocaleString();
8553
8564
  let byType = util/* default */.A.get(this.props.ev, 'by.type');
8554
8565
  if (byType !== 'user') byType = 'agent';
@@ -8574,11 +8585,6 @@ class TextMessage extends common/* Com */.Mw {
8574
8585
  }));
8575
8586
  }
8576
8587
  }
8577
- function isEmptyBlock(block) {
8578
- if (!block || !block.type) return true;
8579
- let hasContent = util/* default */.A.size(util/* default */.A.filter(util/* default */.A.map(block.content, block => isEmptyBlock(block)), isEmpty => !isEmpty)) > 0;
8580
- return !util/* default */.A.trim(block.text) && !hasContent;
8581
- }
8582
8588
  ;// ./src/chatbox/InfoMessage.js
8583
8589
 
8584
8590
  function getRateLang(rating) {
@@ -8855,7 +8861,7 @@ class Event extends common/* Com */.Mw {
8855
8861
  let ev = this.props.event.ev;
8856
8862
  let attachments = util/* default */.A.get(ev, 'data.message.attachments');
8857
8863
  let hasForm = util/* default */.A.find(attachments, att => att.type === 'form');
8858
- if (isEmptyMessage(util/* default */.A.get(ev, 'data.message'))) return null;
8864
+ if (util/* default */.A.isEmptyMessage(util/* default */.A.get(ev, 'data.message'))) return null;
8859
8865
  this.tryLoadOrder(ev);
8860
8866
  let t = new util/* default */.A.Date(ev.created).toLocaleString();
8861
8867
  if (util/* default */.A.get(ev, 'by.type') !== 'user') {
@@ -9124,10 +9130,6 @@ class Event extends common/* Com */.Mw {
9124
9130
  return acc.name;
9125
9131
  }
9126
9132
  }
9127
- function isEmptyMessage(msg) {
9128
- if (!msg) return true;
9129
- if (!msg.text && !msg.block && !util/* default */.A.size(msg.attachments)) return true;
9130
- }
9131
9133
  ;// ./src/chatbox/Events.js
9132
9134
 
9133
9135
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.163",
3
+ "version": "4.1.165",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -171,6 +171,10 @@ export default class ChatButton extends Com {
171
171
  // if lastview is list, make sure we have at least one convo or fallback
172
172
  // to preview click
173
173
  if (lastview.view !== 'list' || sb.size(this.props.store.matchConvo('*')) > 0) {
174
+ if (lastview.view == 'chat' && !sb.get(lastview, 'opts.cid')) {
175
+ // dont have last view => equal preview click
176
+ return this.onPreviewClick()
177
+ }
174
178
  return this.props.onClick && this.props.onClick(Object.assign({}, lastview.opts, {view: lastview.view})) // last view
175
179
  }
176
180
  }
@@ -181,7 +185,6 @@ export default class ChatButton extends Com {
181
185
 
182
186
  onPreviewClick(e) {
183
187
  let cid = sb.convoOfEv(this.state.previewEvent)
184
-
185
188
  if (!cid) {
186
189
  let convos = sb.map(this.props.store.matchConvo('*'))
187
190
  let convo = sb.find(convos, (convo) => !sb.isConvoSeen(convo, this.props.store.matchUser().id))
@@ -200,6 +203,7 @@ export default class ChatButton extends Com {
200
203
 
201
204
  renderPreview() {
202
205
  let account = this.props.store.matchAccount()
206
+ if (!account) return null
203
207
  let accountSetting = this.props.plugin.chatbox
204
208
  let byid = sb.get(this.state.previewEvent, 'by.display_id', sb.get(this.state.previewEvent, 'by.id'))
205
209
  // let agent = sb.cloneDeep(this.props.store.matchAgent(byid)) || {}
@@ -209,6 +209,7 @@ Vui lòng hỏi chúng tôi bất cứ điều gì hoặc chia sẻ phản hồi
209
209
 
210
210
  var $unreadcount = null
211
211
  let user = this.props.store.matchUser()
212
+ if (!user || !user.id) return null
212
213
 
213
214
  let unreadcount = 0
214
215
  sb.map(allconvos, (convo) => {
@@ -783,7 +783,7 @@ export default class Widget extends Com {
783
783
  let _creating = this._creating
784
784
  this.setState({creating: true})
785
785
  let botid = cid.split('_')[0].slice(7) // 6 = len(cslight)
786
- let oldconvo = this.props.store.matchConvo(this.props.cid)
786
+ let oldconvo = this.props.store.matchConvo(this.props.cid) || {}
787
787
  const {convo, error} = await this.props.store.startConvo({
788
788
  locale: this.props.t.locale(),
789
789
  message: text,
@@ -52,6 +52,12 @@ export default class Main extends Com {
52
52
  this.props.store.onResetCSS(this, () => this.refreshCSS())
53
53
  this.props.store.onConvoEvent(this, (ev) => this.onConvoEvent(ev))
54
54
  this.props.store.onUpdate(this, (_) => this.checkExpand())
55
+ this.props.store.onDestroyed(this, (_) => {
56
+ this.setState({
57
+ widgetView: '',
58
+ widgetConvoId: '',
59
+ })
60
+ })
55
61
  await this.refreshCSS()
56
62
  this.setState({cssready: true})
57
63
 
@@ -3,6 +3,7 @@ var localStorageMemory = {}
3
3
  var cache = {}
4
4
 
5
5
  localStorageMemory.length = 0
6
+ localStorageMemory.cache = cache
6
7
 
7
8
  localStorageMemory.getItem = function (key) {
8
9
  if (key in cache) return cache[key]
package/src/store/kv.js CHANGED
@@ -31,7 +31,6 @@ export default class {
31
31
  inmemItemM[item.key] = item.value
32
32
  })
33
33
  this.cache = inmemItemM
34
-
35
34
  // If the cache is full. Randomly remove half of the cache. credit to thanos
36
35
  // this is so simple since we don't need to keep track of last modified time
37
36
  // for each key. Implementing a LRU cache won't add much value.
package/src/store/lsdb.js CHANGED
@@ -44,10 +44,15 @@ export default class {
44
44
  }
45
45
 
46
46
  clear(table) {
47
+ var keys = []
47
48
  for (var i = 0; i < this.localStorage.length; i++) {
48
49
  let key = this.localStorage.key(i)
49
50
  if (!key.startsWith(this.schema + '#' + table + '#')) continue
50
- this.localStorage.removeItem(key)
51
+ keys.push(key)
52
+ }
53
+
54
+ for (var i = 0; i < keys.length; i++) {
55
+ this.localStorage.removeItem(keys[i])
51
56
  }
52
57
  this.allkeys = {}
53
58
  }
@@ -11,7 +11,7 @@ var cookie = require('cookie_js')
11
11
  cookie.defaults.path = '/'
12
12
  cookie.expiresMultiplier = 60 * 60 * 24 // days
13
13
  cookie.defaults.expires = 3650 // 10 year
14
-
14
+ let memlocalStorage = require('./inmem_localstorage.js')
15
15
  const MAX_CONVO = 20
16
16
  const page_loaded = sb.Date.now()
17
17
 
@@ -35,7 +35,6 @@ export default class Store {
35
35
  this.FileURL = FileURL
36
36
  this._track_page_view = true
37
37
  this.device_type = 'desktop'
38
- this.lightConvos = {} // convo that have not been created, for faking bot conversation
39
38
  if (this.fake) this.api = new APIFake(ApiURL, FileURL)
40
39
  else this.api = new API(ApiURL, FileURL)
41
40
 
@@ -331,6 +330,7 @@ export default class Store {
331
330
 
332
331
  // must ensure only call this function after init is done
333
332
  matchUser = () => {
333
+ if (!this.cache) return undefined
334
334
  this._touchAcc()
335
335
  return this.cache.match('user')
336
336
  }
@@ -342,6 +342,7 @@ export default class Store {
342
342
 
343
343
  matchUnread = () => {
344
344
  let user = this.matchUser()
345
+ if (!user || !user.id) return // not init
345
346
  let allconvos = this.matchConvo('*')
346
347
  let unreadcount = 0
347
348
  sb.map(allconvos, (convo) => {
@@ -538,8 +539,13 @@ export default class Store {
538
539
  }
539
540
  }
540
541
  }
542
+ if (this.cookie.get('__sbref', userRef) != userRef) {
543
+ cleanMyLocalStorage()
544
+ this.clearBrowserData()
545
+ }
546
+ this.lightConvos = {} // convo that have not been created, for faking bot conversation
547
+ this.cache = new KV(new LSDB('sbz2023', true), 'kv')
541
548
 
542
- if (this.cookie.get('__sbref', userRef) != userRef) cleanMyLocalStorage()
543
549
  this.api.setAuth({accid: accid})
544
550
  // set cookie forever
545
551
  if (userRef) this.cookie.set('__sbref', userRef)
@@ -611,6 +617,7 @@ export default class Store {
611
617
  sb.clearInterval(this._seenInterval)
612
618
  this._seenInterval = sb.setInterval(() => {
613
619
  if (this._die) return sb.clearInterval(this._seenInterval)
620
+ if (!this.cache) return // not init
614
621
  // deduplicate
615
622
  this.seenQueue = [...new Set(this.seenQueue)]
616
623
  let user = this.cache.match('user') || {}
@@ -647,7 +654,7 @@ export default class Store {
647
654
  let user = this.matchUser()
648
655
  if (!old) return
649
656
  let mem = sb.find(old.members, (mem) => mem.type == 'user' && mem.id == user.id)
650
- mem.seen_at = this.now()
657
+ if (mem) mem.seen_at = this.now()
651
658
  this.kv.put('light_convos', this.lightConvos)
652
659
  this.g_haveSentSeenM[lastmsgsent.id] = true
653
660
  return
@@ -1196,6 +1203,7 @@ export default class Store {
1196
1203
  }
1197
1204
 
1198
1205
  onUpdate = (o, cb) => this.pubsub.on2(o, 'account', cb)
1206
+ onDestroyed = (o, cb) => this.pubsub.on2(o, 'destroy', cb)
1199
1207
  onConnection = (o, cb) => this.pubsub.on2(o, 'connection', cb)
1200
1208
  onResetCSS = (o, cb) => this.pubsub.on2(o, 'resetCSS', cb)
1201
1209
  onHighlight = (o, cb) => this.pubsub.on2(o, 'highlight', cb)
@@ -1310,7 +1318,7 @@ export default class Store {
1310
1318
  let startms = this.now()
1311
1319
 
1312
1320
  // store not init
1313
- if (!sb.get(this.cache.match('user'), 'id')) return sb.setTimeout(() => this.loopTime(), 240000)
1321
+ if (!this.cache || !sb.get(this.cache.match('user'), 'id')) return sb.setTimeout(() => this.loopTime(), 240000)
1314
1322
 
1315
1323
  let {body: t, error} = await this.api.time()
1316
1324
  if (error) return sb.setTimeout(() => this.loopTime(), 30000)
@@ -1352,16 +1360,18 @@ export default class Store {
1352
1360
  sb.each(this.cookie.all(), (v, k) => {
1353
1361
  if ((k || '').startsWith('__sb')) this.cookie.remove(k)
1354
1362
  })
1355
- this.kv.destroy()
1363
+ if (this.kv) this.kv.destroy()
1356
1364
  this.kv = new KV(new LSDB('sbz2023', this.inmem), 'kv')
1357
- this.chain.destroy()
1365
+ if (this.chain) this.chain.destroy()
1358
1366
  this.chain = new Chain(new LSDB('cbz2023', true), 'ch')
1367
+ if (this.realtime) this.realtime.stop()
1368
+ if (this.cache) this.cache.destroy()
1369
+ this.pubsub.publish('destroy')
1359
1370
  }
1360
1371
 
1361
1372
  destroy() {
1362
1373
  this._die = true
1363
- if (this.kv) this.kv.destroy()
1364
- if (this.chain) this.chain.destroy()
1374
+ this.clearBrowserData()
1365
1375
  sb.clearInterval(this._seenInterval)
1366
1376
  if (this.realtime) this.realtime.stop()
1367
1377
  this.readyGate.close()
@@ -1511,6 +1521,7 @@ let cleanLocalStorage = () => {
1511
1521
  for (var key in localStorage) {
1512
1522
  if (key && (key.startsWith('cbz2020') || key.startsWith('sbz2020'))) {
1513
1523
  localStorage.removeItem(key)
1524
+ memlocalStorage.removeItem(key)
1514
1525
  }
1515
1526
  }
1516
1527
  })
@@ -1532,6 +1543,7 @@ let cleanMyLocalStorage = () => {
1532
1543
  key.startsWith('sbz2023'))
1533
1544
  ) {
1534
1545
  localStorage.removeItem(key)
1546
+ memlocalStorage.removeItem(key)
1535
1547
  }
1536
1548
  }
1537
1549
  })
package/tracking.js CHANGED
@@ -22,6 +22,7 @@ setTimeout(() => {
22
22
  // Collect device and browser info
23
23
  var info = {
24
24
  status: status,
25
+ href: window.location.href,
25
26
  userAgent: navigator.userAgent,
26
27
  platform: navigator.platform,
27
28
  language: navigator.language,
@@ -41,4 +42,4 @@ setTimeout(() => {
41
42
  }
42
43
 
43
44
  xhr.send(JSON.stringify(info))
44
- }, 10000)
45
+ }, 15000)