@subiz/widget-v4 4.1.163 → 4.1.166
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 -0
- package/compiled_src/chatbox/Header.js +1 -0
- 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 +39 -38
- package/dist/198a3614cdc.app.js +1 -0
- package/dist/{198a2dde018.chat.html → 198a3614cdc.chat.html} +1 -1
- package/dist/198a3614cdc.chat.js +1 -0
- package/dist/{198a2dde018.form.html → 198a3614cdc.form.html} +1 -1
- package/dist/198a3614cdc.form.js +1 -0
- package/dist/{198a2dde018.index.html → 198a3614cdc.index.html} +1 -1
- package/dist/{198a2dde018.library.html → 198a3614cdc.library.html} +1 -1
- package/dist/198a3614cdc.library.js +1 -0
- package/dist/{198a2dde018.preview.html → 198a3614cdc.preview.html} +1 -1
- package/dist/198a3614cdc.preview.js +1 -0
- package/dist/198a3614cdc.webview.js +1 -0
- package/dist/HASH +1 -1
- package/dist/screenshoot.js +52 -21
- package/inject.html +11 -2
- package/package.json +1 -1
- package/src/chatbox/ChatButton.js +5 -1
- package/src/chatbox/Event.js +2 -1
- package/src/chatbox/Header.js +1 -0
- package/src/chatbox/Widget.js +1 -1
- package/src/chatbox/main.js +6 -0
- package/src/lib.js +0 -1
- 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 +43 -40
- package/tracking.js +2 -1
- package/dist/198a2dde018.app.js +0 -1
- package/dist/198a2dde018.chat.js +0 -1
- package/dist/198a2dde018.form.js +0 -1
- package/dist/198a2dde018.library.js +0 -1
- package/dist/198a2dde018.preview.js +0 -1
- package/dist/198a2dde018.webview.js +0 -1
- /package/dist/{198a2dde018.127.js → 198a3614cdc.127.js} +0 -0
- /package/dist/{198a2dde018.132.js → 198a3614cdc.132.js} +0 -0
- /package/dist/{198a2dde018.185.js → 198a3614cdc.185.js} +0 -0
- /package/dist/{198a2dde018.27.js → 198a3614cdc.27.js} +0 -0
- /package/dist/{198a2dde018.278.js → 198a3614cdc.278.js} +0 -0
- /package/dist/{198a2dde018.339.js → 198a3614cdc.339.js} +0 -0
- /package/dist/{198a2dde018.459.js → 198a3614cdc.459.js} +0 -0
- /package/dist/{198a2dde018.490.js → 198a3614cdc.490.js} +0 -0
- /package/dist/{198a2dde018.74.js → 198a3614cdc.74.js} +0 -0
- /package/dist/{198a2dde018.997.js → 198a3614cdc.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);
|
|
@@ -462,6 +462,8 @@ class Event extends _common.Com {
|
|
|
462
462
|
renderAIDevNote() {
|
|
463
463
|
if (!this.props.isLast) return null;
|
|
464
464
|
if (!this.props.store.isAIDevMode()) return null;
|
|
465
|
+
let cid = _index.default.get(this.props.event.ev, 'data.message.conversation_id', '');
|
|
466
|
+
if (cid.startsWith('cslight')) return null;
|
|
465
467
|
let ev = _index.default.get(this.props.event, 'ev') || {};
|
|
466
468
|
let pongs = _index.default.get(ev, 'data.message.pongs') || [];
|
|
467
469
|
let hasLike = this.hasLike();
|
|
@@ -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;
|
|
@@ -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
|
|
@@ -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
|
-
|
|
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 {
|
|
@@ -280,6 +283,7 @@ class Store {
|
|
|
280
283
|
});
|
|
281
284
|
}
|
|
282
285
|
}, 2000);
|
|
286
|
+
this.loopCheckConnectionStatus();
|
|
283
287
|
}
|
|
284
288
|
async loopCheckConnectionStatus() {
|
|
285
289
|
while (true) {
|
|
@@ -438,8 +442,6 @@ class Store {
|
|
|
438
442
|
if (!this.isInsync('account')) this.reconnect();
|
|
439
443
|
}
|
|
440
444
|
async init(accid, mask, userRef, options) {
|
|
441
|
-
this.readyGate.close();
|
|
442
|
-
accid = (accid || '').trim();
|
|
443
445
|
this.g_sync = {};
|
|
444
446
|
if (!options || !options.use_subdomain_cookie) {
|
|
445
447
|
if (window && window.location && window.location.hostname) {
|
|
@@ -470,68 +472,62 @@ class Store {
|
|
|
470
472
|
}
|
|
471
473
|
}
|
|
472
474
|
}
|
|
473
|
-
if (this.cookie.get('__sbref', userRef) != userRef)
|
|
475
|
+
if (this.cookie.get('__sbref', userRef) != userRef) {
|
|
476
|
+
cleanMyLocalStorage();
|
|
477
|
+
this.clearBrowserData();
|
|
478
|
+
}
|
|
474
479
|
this.api.setAuth({
|
|
475
480
|
accid: accid
|
|
476
481
|
});
|
|
477
482
|
if (userRef) this.cookie.set('__sbref', userRef);
|
|
478
|
-
|
|
483
|
+
return this._initResource(accid, {
|
|
479
484
|
accid: accid,
|
|
480
485
|
mask: mask,
|
|
481
486
|
ref: userRef
|
|
487
|
+
}, {
|
|
488
|
+
account_id: accid,
|
|
489
|
+
user_ref: userRef,
|
|
490
|
+
user_mask: mask
|
|
482
491
|
});
|
|
492
|
+
}
|
|
493
|
+
async _initResource(accid, auth, realtimep) {
|
|
494
|
+
this.g_sync = {};
|
|
495
|
+
let user = await this.api.setAuth(auth);
|
|
483
496
|
if (user.error) {
|
|
484
497
|
console.error(user);
|
|
485
498
|
return user;
|
|
486
499
|
}
|
|
500
|
+
this.readyGate.close();
|
|
501
|
+
accid = (accid || '').trim();
|
|
502
|
+
this.lightConvos = this.kv.match('light_convos') || {};
|
|
503
|
+
this.cache = new _kv.default(new _lsdb.default('sbz2023', true), 'kv');
|
|
487
504
|
if (this.realtime) this.realtime.stop();
|
|
488
|
-
if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL,
|
|
489
|
-
account_id: accid,
|
|
490
|
-
user_ref: userRef,
|
|
491
|
-
user_mask: mask
|
|
492
|
-
}, xhrsend);
|
|
505
|
+
if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, realtimep, xhrsend);
|
|
493
506
|
this.realtime.onEvent(this.onWs.bind(this));
|
|
494
507
|
this.realtime.onInterrupted(async () => {
|
|
495
508
|
await this.reconnectWs(accid, user.id);
|
|
496
509
|
this.reconnect();
|
|
497
510
|
});
|
|
498
|
-
this.lightConvos = this.kv.match('light_convos') || {};
|
|
499
511
|
this.seenLoop();
|
|
500
512
|
await this.reconnect({
|
|
501
513
|
user: user
|
|
502
514
|
});
|
|
503
515
|
this.readyGate.open();
|
|
504
516
|
this.reconnectWs(accid, user.id);
|
|
505
|
-
this.loopCheckConnectionStatus();
|
|
506
517
|
return user;
|
|
507
518
|
}
|
|
508
519
|
async login(accid, user_id, tokenGenerator) {
|
|
509
520
|
if (this._die) return dieErr;
|
|
510
|
-
|
|
521
|
+
cleanMyLocalStorage();
|
|
522
|
+
this.clearBrowserData();
|
|
523
|
+
this.new_visitor = false;
|
|
524
|
+
return this._initResource(accid, {
|
|
511
525
|
accid: accid,
|
|
512
526
|
profile_id: user_id,
|
|
513
527
|
tokenGenerator: tokenGenerator
|
|
514
|
-
}
|
|
515
|
-
if (user.error) return user;
|
|
516
|
-
this.clearBrowserData();
|
|
517
|
-
this.readyGate.close();
|
|
518
|
-
accid = (accid || '').trim();
|
|
519
|
-
this.g_sync = {};
|
|
520
|
-
this.new_visitor = false;
|
|
521
|
-
if (this.realtime) this.realtime.stop();
|
|
522
|
-
if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, {
|
|
528
|
+
}, {
|
|
523
529
|
getAccessToken: () => this.api.token_generator()
|
|
524
530
|
});
|
|
525
|
-
this.realtime.onEvent(this.onWs.bind(this));
|
|
526
|
-
this.realtime.onInterrupted(async () => {
|
|
527
|
-
await this.reconnectWs(accid, user.id);
|
|
528
|
-
this.reconnect();
|
|
529
|
-
});
|
|
530
|
-
this.seenLoop();
|
|
531
|
-
await this.reconnect();
|
|
532
|
-
this.readyGate.open();
|
|
533
|
-
this.reconnectWs(accid, user.id);
|
|
534
|
-
return user;
|
|
535
531
|
}
|
|
536
532
|
logout(userRef) {
|
|
537
533
|
return this.api.setAuth({
|
|
@@ -543,6 +539,7 @@ class Store {
|
|
|
543
539
|
_index.default.clearInterval(this._seenInterval);
|
|
544
540
|
this._seenInterval = _index.default.setInterval(() => {
|
|
545
541
|
if (this._die) return _index.default.clearInterval(this._seenInterval);
|
|
542
|
+
if (!this.cache) return;
|
|
546
543
|
this.seenQueue = [...new Set(this.seenQueue)];
|
|
547
544
|
let user = this.cache.match('user') || {};
|
|
548
545
|
_index.default.map(this.seenQueue, id => {
|
|
@@ -576,7 +573,7 @@ class Store {
|
|
|
576
573
|
let user = this.matchUser();
|
|
577
574
|
if (!old) return;
|
|
578
575
|
let mem = _index.default.find(old.members, mem => mem.type == 'user' && mem.id == user.id);
|
|
579
|
-
mem.seen_at = this.now();
|
|
576
|
+
if (mem) mem.seen_at = this.now();
|
|
580
577
|
this.kv.put('light_convos', this.lightConvos);
|
|
581
578
|
this.g_haveSentSeenM[lastmsgsent.id] = true;
|
|
582
579
|
return;
|
|
@@ -1144,7 +1141,7 @@ class Store {
|
|
|
1144
1141
|
async loopTime() {
|
|
1145
1142
|
if (this._die) return;
|
|
1146
1143
|
let startms = this.now();
|
|
1147
|
-
if (!_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
|
|
1144
|
+
if (!this.cache || !_index.default.get(this.cache.match('user'), 'id')) return _index.default.setTimeout(() => this.loopTime(), 240000);
|
|
1148
1145
|
let {
|
|
1149
1146
|
body: t,
|
|
1150
1147
|
error
|
|
@@ -1181,15 +1178,17 @@ class Store {
|
|
|
1181
1178
|
_index.default.each(this.cookie.all(), (v, k) => {
|
|
1182
1179
|
if ((k || '').startsWith('__sb')) this.cookie.remove(k);
|
|
1183
1180
|
});
|
|
1184
|
-
this.kv.destroy();
|
|
1181
|
+
if (this.kv) this.kv.destroy();
|
|
1185
1182
|
this.kv = new _kv.default(new _lsdb.default('sbz2023', this.inmem), 'kv');
|
|
1186
|
-
this.chain.destroy();
|
|
1183
|
+
if (this.chain) this.chain.destroy();
|
|
1187
1184
|
this.chain = new _chain.default(new _lsdb.default('cbz2023', true), 'ch');
|
|
1185
|
+
if (this.realtime) this.realtime.stop();
|
|
1186
|
+
if (this.cache) this.cache.destroy();
|
|
1187
|
+
this.pubsub.publish('destroy');
|
|
1188
1188
|
}
|
|
1189
1189
|
destroy() {
|
|
1190
1190
|
this._die = true;
|
|
1191
|
-
|
|
1192
|
-
if (this.chain) this.chain.destroy();
|
|
1191
|
+
this.clearBrowserData();
|
|
1193
1192
|
_index.default.clearInterval(this._seenInterval);
|
|
1194
1193
|
if (this.realtime) this.realtime.stop();
|
|
1195
1194
|
this.readyGate.close();
|
|
@@ -1326,6 +1325,7 @@ let cleanLocalStorage = () => {
|
|
|
1326
1325
|
for (var key in localStorage) {
|
|
1327
1326
|
if (key && (key.startsWith('cbz2020') || key.startsWith('sbz2020'))) {
|
|
1328
1327
|
localStorage.removeItem(key);
|
|
1328
|
+
memlocalStorage.removeItem(key);
|
|
1329
1329
|
}
|
|
1330
1330
|
}
|
|
1331
1331
|
});
|
|
@@ -1340,6 +1340,7 @@ let cleanMyLocalStorage = () => {
|
|
|
1340
1340
|
for (var key in localStorage) {
|
|
1341
1341
|
if (key && (key.startsWith('cbz2020') || key.startsWith('sbz2020') || key.startsWith('sbz2022') || key.startsWith('sbz2023'))) {
|
|
1342
1342
|
localStorage.removeItem(key);
|
|
1343
|
+
memlocalStorage.removeItem(key);
|
|
1343
1344
|
}
|
|
1344
1345
|
}
|
|
1345
1346
|
});
|