@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.
- package/compiled_src/chatbox/ChatButton.js +4 -0
- package/compiled_src/chatbox/Event.js +2 -6
- package/compiled_src/chatbox/Header.js +1 -0
- package/compiled_src/chatbox/TextMessage.js +2 -7
- package/compiled_src/chatbox/Widget.js +1 -1
- package/compiled_src/chatbox/main.js +6 -0
- package/compiled_src/store/inmem_localstorage.js +1 -0
- package/compiled_src/store/lsdb.js +5 -1
- package/compiled_src/store/store.js +21 -8
- package/compiled_src/util/common.js +11 -0
- package/dist/198a3089a0c.app.js +1 -0
- package/dist/{198a2601817.chat.html → 198a3089a0c.chat.html} +1 -1
- package/dist/198a3089a0c.chat.js +1 -0
- package/dist/{198a2601817.form.html → 198a3089a0c.form.html} +1 -1
- package/dist/198a3089a0c.form.js +1 -0
- package/dist/{198a2601817.index.html → 198a3089a0c.index.html} +1 -1
- package/dist/{198a2601817.library.html → 198a3089a0c.library.html} +1 -1
- package/dist/198a3089a0c.library.js +1 -0
- package/dist/{198a2601817.preview.html → 198a3089a0c.preview.html} +1 -1
- package/dist/198a3089a0c.preview.js +1 -0
- package/dist/198a3089a0c.webview.js +1 -0
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +13 -11
- package/package.json +1 -1
- package/src/chatbox/ChatButton.js +5 -1
- package/src/chatbox/Event.js +2 -6
- package/src/chatbox/Header.js +1 -0
- package/src/chatbox/TextMessage.js +1 -13
- package/src/chatbox/Widget.js +1 -1
- package/src/chatbox/main.js +6 -0
- package/src/store/inmem_localstorage.js +1 -0
- package/src/store/kv.js +0 -1
- package/src/store/lsdb.js +6 -1
- package/src/store/store.js +21 -9
- package/src/util/common.js +21 -4
- package/tracking.js +45 -0
- package/dist/198a2601817.app.js +0 -1
- package/dist/198a2601817.chat.js +0 -1
- package/dist/198a2601817.form.js +0 -1
- package/dist/198a2601817.library.js +0 -1
- package/dist/198a2601817.preview.js +0 -1
- package/dist/198a2601817.webview.js +0 -1
- /package/dist/{198a2601817.127.js → 198a3089a0c.127.js} +0 -0
- /package/dist/{198a2601817.132.js → 198a3089a0c.132.js} +0 -0
- /package/dist/{198a2601817.185.js → 198a3089a0c.185.js} +0 -0
- /package/dist/{198a2601817.27.js → 198a3089a0c.27.js} +0 -0
- /package/dist/{198a2601817.278.js → 198a3089a0c.278.js} +0 -0
- /package/dist/{198a2601817.339.js → 198a3089a0c.339.js} +0 -0
- /package/dist/{198a2601817.459.js → 198a3089a0c.459.js} +0 -0
- /package/dist/{198a2601817.490.js → 198a3089a0c.490.js} +0 -0
- /package/dist/{198a2601817.74.js → 198a3089a0c.74.js} +0 -0
- /package/dist/{198a2601817.997.js → 198a3089a0c.997.js} +0 -0
package/dist/HASH
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
198a3089a0c
|
package/dist/screenshoot.js
CHANGED
|
@@ -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
|
@@ -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)) || {}
|
package/src/chatbox/Event.js
CHANGED
|
@@ -234,7 +234,8 @@ export default class Event extends Com {
|
|
|
234
234
|
let ev = this.props.event.ev
|
|
235
235
|
let attachments = sb.get(ev, 'data.message.attachments')
|
|
236
236
|
let hasForm = sb.find(attachments, (att) => att.type === 'form')
|
|
237
|
-
if (isEmptyMessage(sb.get(ev, 'data.message'))) return null
|
|
237
|
+
if (sb.isEmptyMessage(sb.get(ev, 'data.message'))) return null
|
|
238
|
+
|
|
238
239
|
this.tryLoadOrder(ev)
|
|
239
240
|
let t = new sb.Date(ev.created).toLocaleString()
|
|
240
241
|
// message of agent
|
|
@@ -468,8 +469,3 @@ export default class Event extends Com {
|
|
|
468
469
|
return acc.name
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
|
-
|
|
472
|
-
function isEmptyMessage(msg) {
|
|
473
|
-
if (!msg) return true
|
|
474
|
-
if (!msg.text && !msg.block && !sb.size(msg.attachments)) return true
|
|
475
|
-
}
|
package/src/chatbox/Header.js
CHANGED
|
@@ -73,7 +73,7 @@ export default class TextMessage extends Com {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
renderBlock(block) {
|
|
76
|
-
if (isEmptyBlock(block)) return null
|
|
76
|
+
if (sb.isEmptyBlock(block)) return null
|
|
77
77
|
let t = new sb.Date(sb.get(this.props.ev, 'created')).toLocaleString()
|
|
78
78
|
let byType = sb.get(this.props.ev, 'by.type')
|
|
79
79
|
if (byType !== 'user') byType = 'agent'
|
|
@@ -94,15 +94,3 @@ export default class TextMessage extends Com {
|
|
|
94
94
|
)
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
98
|
-
function isEmptyBlock(block) {
|
|
99
|
-
if (!block || !block.type) return true
|
|
100
|
-
let hasContent =
|
|
101
|
-
sb.size(
|
|
102
|
-
sb.filter(
|
|
103
|
-
sb.map(block.content, (block) => isEmptyBlock(block)),
|
|
104
|
-
(isEmpty) => !isEmpty,
|
|
105
|
-
),
|
|
106
|
-
) > 0
|
|
107
|
-
return !sb.trim(block.text) && !hasContent
|
|
108
|
-
}
|
package/src/chatbox/Widget.js
CHANGED
|
@@ -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,
|
package/src/chatbox/main.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
}
|
package/src/store/store.js
CHANGED
|
@@ -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
|
-
|
|
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/src/util/common.js
CHANGED
|
@@ -12,7 +12,7 @@ var op = require('./op.js')
|
|
|
12
12
|
* @return Array The HSL representation
|
|
13
13
|
*/
|
|
14
14
|
export function rgbToHsl(r, g, b) {
|
|
15
|
-
;(r /= 255), (g /= 255), (b /= 255)
|
|
15
|
+
;((r /= 255), (g /= 255), (b /= 255))
|
|
16
16
|
|
|
17
17
|
var max = Math.max(r, g, b),
|
|
18
18
|
min = Math.min(r, g, b)
|
|
@@ -721,9 +721,9 @@ export function replaceCssVariable(css, setting) {
|
|
|
721
721
|
'desktop_button.height',
|
|
722
722
|
'desktop_button.margin_x',
|
|
723
723
|
'desktop_button.margin_y',
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
724
|
+
'form_header_font_size',
|
|
725
|
+
'form_desc_font_size',
|
|
726
|
+
'form_input_label_font_size',
|
|
727
727
|
'width',
|
|
728
728
|
'height',
|
|
729
729
|
].includes(path)
|
|
@@ -1548,3 +1548,20 @@ function absLink(url) {
|
|
|
1548
1548
|
if (!url.startsWith('http://') && !url.startsWith('https://') && !url.startsWith('//')) return 'http://' + url
|
|
1549
1549
|
return url
|
|
1550
1550
|
}
|
|
1551
|
+
|
|
1552
|
+
export function isEmptyBlock(block) {
|
|
1553
|
+
if (!block || !block.type) return true
|
|
1554
|
+
let hasContent =
|
|
1555
|
+
size(
|
|
1556
|
+
filter(
|
|
1557
|
+
map(block.content, (block) => isEmptyBlock(block)),
|
|
1558
|
+
(isEmpty) => !isEmpty,
|
|
1559
|
+
),
|
|
1560
|
+
) > 0
|
|
1561
|
+
return !trim(block.text) && !hasContent
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
export function isEmptyMessage(msg) {
|
|
1565
|
+
if (!msg) return true
|
|
1566
|
+
if (!msg.text && isEmptyBlock(msg.block) && !size(msg.attachments)) return true
|
|
1567
|
+
}
|
package/tracking.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// send signal to server when the chatbox is not visible
|
|
2
|
+
|
|
3
|
+
setTimeout(() => {
|
|
4
|
+
var $button = document.querySelector('div.chat-button')
|
|
5
|
+
|
|
6
|
+
let status = ''
|
|
7
|
+
if ($button) {
|
|
8
|
+
var rect = $button.getBoundingClientRect()
|
|
9
|
+
var visible = rect.width > 0 && rect.height > 0
|
|
10
|
+
if (visible) {
|
|
11
|
+
// the chatbox is visible
|
|
12
|
+
return
|
|
13
|
+
} else {
|
|
14
|
+
// the chatbox is not visible
|
|
15
|
+
status = 'hidden'
|
|
16
|
+
}
|
|
17
|
+
} else {
|
|
18
|
+
// the chatbox is not found in DOM
|
|
19
|
+
status = 'not-found'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Collect device and browser info
|
|
23
|
+
var info = {
|
|
24
|
+
status: status,
|
|
25
|
+
href: window.location.href,
|
|
26
|
+
userAgent: navigator.userAgent,
|
|
27
|
+
platform: navigator.platform,
|
|
28
|
+
language: navigator.language,
|
|
29
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Send via XHR
|
|
33
|
+
var xhr = new XMLHttpRequest()
|
|
34
|
+
xhr.open('POST', 'https://api.subiz.com.vn/4.1/chatbox-failed', true)
|
|
35
|
+
xhr.withCredentials = false
|
|
36
|
+
xhr.setRequestHeader('Content-Type', 'text/plain')
|
|
37
|
+
|
|
38
|
+
xhr.onreadystatechange = function () {
|
|
39
|
+
if (xhr.readyState === XMLHttpRequest.DONE) {
|
|
40
|
+
console.log('Server responded with:', xhr.status, xhr.responseText)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
xhr.send(JSON.stringify(info))
|
|
45
|
+
}, 15000)
|