@subiz/widget-v4 4.1.156 → 4.1.157

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 (31) hide show
  1. package/compiled_src/chatbox/ChatButton.js +1 -1
  2. package/compiled_src/store/kv.js +0 -2
  3. package/compiled_src/store/store.js +1 -1
  4. package/dist/{1986e37f014.app.js → 19888eff7f5.app.js} +1 -1
  5. package/dist/{1986e37f014.chat.html → 19888eff7f5.chat.html} +1 -1
  6. package/dist/{1986e37f014.chat.js → 19888eff7f5.chat.js} +1 -1
  7. package/dist/{1986e37f014.form.html → 19888eff7f5.form.html} +1 -1
  8. package/dist/{1986e37f014.form.js → 19888eff7f5.form.js} +1 -1
  9. package/dist/{1986e37f014.index.html → 19888eff7f5.index.html} +1 -1
  10. package/dist/{1986e37f014.library.html → 19888eff7f5.library.html} +1 -1
  11. package/dist/{1986e37f014.library.js → 19888eff7f5.library.js} +1 -1
  12. package/dist/{1986e37f014.preview.html → 19888eff7f5.preview.html} +1 -1
  13. package/dist/19888eff7f5.preview.js +1 -0
  14. package/dist/{1986e37f014.webview.js → 19888eff7f5.webview.js} +1 -1
  15. package/dist/HASH +1 -1
  16. package/dist/screenshoot.js +174 -33
  17. package/package.json +1 -1
  18. package/src/chatbox/ChatButton.js +1 -1
  19. package/src/store/kv.js +11 -14
  20. package/src/store/store.js +1 -1
  21. package/dist/1986e37f014.preview.js +0 -1
  22. /package/dist/{1986e37f014.127.js → 19888eff7f5.127.js} +0 -0
  23. /package/dist/{1986e37f014.132.js → 19888eff7f5.132.js} +0 -0
  24. /package/dist/{1986e37f014.185.js → 19888eff7f5.185.js} +0 -0
  25. /package/dist/{1986e37f014.27.js → 19888eff7f5.27.js} +0 -0
  26. /package/dist/{1986e37f014.278.js → 19888eff7f5.278.js} +0 -0
  27. /package/dist/{1986e37f014.339.js → 19888eff7f5.339.js} +0 -0
  28. /package/dist/{1986e37f014.459.js → 19888eff7f5.459.js} +0 -0
  29. /package/dist/{1986e37f014.490.js → 19888eff7f5.490.js} +0 -0
  30. /package/dist/{1986e37f014.74.js → 19888eff7f5.74.js} +0 -0
  31. /package/dist/{1986e37f014.997.js → 19888eff7f5.997.js} +0 -0
package/dist/HASH CHANGED
@@ -1 +1 @@
1
- 1986e37f014
1
+ 19888eff7f5
@@ -4854,12 +4854,15 @@ class Store {
4854
4854
  if (!id) return;
4855
4855
  if (id === '*') {
4856
4856
  this._touchAcc();
4857
- return util/* default */.A.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
4857
+ return util/* default */.A.filter(this.cache.all(), (value, k) => k.startsWith('convo_')).concat(util/* default */.A.map(this.lightConvos));
4858
4858
  }
4859
+ if (id.startsWith('cslight')) return this.lightConvos[id];
4859
4860
  if (!this.isInsync(id)) this.fetchConvo(id);
4860
4861
  return this.cache.match('convo_' + id);
4861
4862
  });
4862
4863
  store_defineProperty(this, "fetchConvo", async cid => {
4864
+ if (!cid) return;
4865
+ if (cid.startsWith('cslight')) return;
4863
4866
  if (this._die) return dieErr;
4864
4867
  await this.readyGate.entry();
4865
4868
  await this.reconnectGate.entry(undefined, true);
@@ -4878,9 +4881,12 @@ class Store {
4878
4881
  store_defineProperty(this, "outofmsgM", {});
4879
4882
  store_defineProperty(this, "listEvents", id => {
4880
4883
  if (!id || id === '*' || typeof id !== 'string') return;
4884
+ if (id.startsWith('cslight')) return util/* default */.A.get(this.lightConvos, [id, 'events'], []);
4881
4885
  return this.chain.listM(id);
4882
4886
  });
4883
4887
  store_defineProperty(this, "fetchMoreEvents", async convoid => {
4888
+ if (!convoid) return;
4889
+ if (convoid.startsWith('cslight')) return [[], ''];
4884
4890
  if (!this.isInsync('events' + convoid)) {
4885
4891
  await this.readyGate.entry();
4886
4892
  await this.reconnectGate.entry(undefined, true);
@@ -4992,6 +4998,7 @@ class Store {
4992
4998
  this.FileURL = FileURL;
4993
4999
  this._track_page_view = true;
4994
5000
  this.device_type = 'desktop';
5001
+ this.lightConvos = {};
4995
5002
  if (this.fake) this.api = new api_fake(ApiURL, FileURL);else this.api = new api(ApiURL, FileURL);
4996
5003
  if (!inmem) {
4997
5004
  try {
@@ -5012,9 +5019,9 @@ class Store {
5012
5019
  this.chain = new Chain(new lsdb('cbz2023', true), 'ch');
5013
5020
  this.getLocaleContent = this.api.getLocaleContent;
5014
5021
  this.g_haveSentSeenM = {};
5015
- this.last_focused = util/* default */.A.Date.now();
5022
+ this.last_focused = this.now();
5016
5023
  window.addEventListener('blur', () => {
5017
- this.last_focused = util/* default */.A.Date.now();
5024
+ this.last_focused = this.now();
5018
5025
  this.sendPresence();
5019
5026
  });
5020
5027
  window.addEventListener('focus', () => {
@@ -5036,7 +5043,7 @@ class Store {
5036
5043
  this._presenceInterval2 = util/* default */.A.setInterval(() => {
5037
5044
  if (this._die) return util/* default */.A.clearInterval(this._presenceInterval2);
5038
5045
  if (this.browserVisibility === 'visible' && document.hasFocus()) return;
5039
- if (this.last_focused && util/* default */.A.Date.now() - this.last_focused > 30 * 60000) {
5046
+ if (this.last_focused && this.now() - this.last_focused > 30 * 60000) {
5040
5047
  return;
5041
5048
  }
5042
5049
  this.sendPresence();
@@ -5263,6 +5270,7 @@ class Store {
5263
5270
  await this.reconnectWs(accid, user.id);
5264
5271
  this.reconnect();
5265
5272
  });
5273
+ this.lightConvos = this.kv.match('light_convos') || {};
5266
5274
  this.seenLoop();
5267
5275
  await this.reconnect({
5268
5276
  user: user
@@ -5321,9 +5329,8 @@ class Store {
5321
5329
  if (!lastmsgsent) return;
5322
5330
  if (this.g_haveSentSeenM[lastmsgsent.id]) return;
5323
5331
  if (lastmsgsent.id === lastmsgsent.data.message.idempotency_key) return;
5324
- this.api.markAsSeen(id, lastmsgsent.id);
5325
5332
  this.pubsub.publish('events', {
5326
- created: util/* default */.A.Date.now(),
5333
+ created: this.now(),
5327
5334
  type: 'message_pong',
5328
5335
  by: {
5329
5336
  type: 'user'
@@ -5334,14 +5341,25 @@ class Store {
5334
5341
  id: '*',
5335
5342
  pongs: [{
5336
5343
  type: 'seen',
5337
- created: util/* default */.A.Date.now()
5344
+ created: this.now()
5338
5345
  }]
5339
5346
  }
5340
5347
  }
5341
5348
  });
5349
+ if (id.startsWith('cslight')) {
5350
+ let old = this.lightConvos[id];
5351
+ let user = this.matchUser();
5352
+ if (!old) return;
5353
+ let mem = util/* default */.A.find(old.members, mem => mem.type == 'user' && mem.id == user.id);
5354
+ mem.seen_at = this.now();
5355
+ this.kv.put('light_convos', this.lightConvos);
5356
+ this.g_haveSentSeenM[lastmsgsent.id] = true;
5357
+ return;
5358
+ }
5359
+ this.api.markAsSeen(id, lastmsgsent.id);
5342
5360
  let convo = this.cache.match('convo_' + id) || {};
5343
5361
  let mem = util/* default */.A.find(convo.members, m => m.id === user.id);
5344
- if (mem) mem.seen_at = util/* default */.A.Date.now();
5362
+ if (mem) mem.seen_at = this.now();
5345
5363
  this._setConvo(convo);
5346
5364
  this.g_haveSentSeenM[lastmsgsent.id] = true;
5347
5365
  });
@@ -5502,7 +5520,7 @@ class Store {
5502
5520
  let cid = util/* default */.A.convoOfEv(ev);
5503
5521
  let convo;
5504
5522
  let alreadyFetched = false;
5505
- if (cid) {
5523
+ if (cid && !cid.startsWith('cslight')) {
5506
5524
  convo = this.cache.match('convo_' + cid);
5507
5525
  if (!convo || !convo.id) {
5508
5526
  let {
@@ -5515,6 +5533,15 @@ class Store {
5515
5533
  this._setConvo(convo);
5516
5534
  }
5517
5535
  }
5536
+ if (cid.startsWith('cslight')) {
5537
+ convo = this.lightConvos[cid];
5538
+ if (!convo) return;
5539
+ convo.events.push(ev);
5540
+ convo.last_message_sent = ev;
5541
+ this.kv.put('light_convos', this.lightConvos);
5542
+ this.pubsub.publish('events', ev);
5543
+ return;
5544
+ }
5518
5545
  if (!convo) return;
5519
5546
  this.pubsub.publish('events', ev);
5520
5547
  if (ev.type === 'conversation_joined') {
@@ -5611,8 +5638,65 @@ class Store {
5611
5638
  }
5612
5639
  typing(cid) {
5613
5640
  if (!cid) return;
5641
+ if (cid.startsWith('cslight')) return;
5614
5642
  this._typing(cid);
5615
5643
  }
5644
+ deleteLightConvo(id) {
5645
+ delete this.lightConvos[id];
5646
+ this.kv.put('light_convos', this.lightConvos);
5647
+ }
5648
+ startLightConvo(botid, message, locale) {
5649
+ let convoid = 'cslight' + botid + '_' + this.now();
5650
+ let user = this.cache.match('user') || {};
5651
+ let old = this.lightConvos[convoid];
5652
+ if (old) return {
5653
+ convo: old
5654
+ };
5655
+ let now = this.now();
5656
+ let ev = {};
5657
+ ev.created = now;
5658
+ ev.event_time = now;
5659
+ ev.id = 'evfake' + now;
5660
+ ev.type = 'message_sent';
5661
+ ev.by = {
5662
+ id: botid,
5663
+ type: 'bot'
5664
+ };
5665
+ ev.data = {
5666
+ message: message
5667
+ };
5668
+ ev.data.message.conversation_id = convoid;
5669
+ let newconvo = {
5670
+ id: convoid,
5671
+ locale: locale,
5672
+ initial_by: botid,
5673
+ created: now,
5674
+ actived: now,
5675
+ last_message_sent: ev,
5676
+ members: [{
5677
+ type: 'user',
5678
+ id: user.id
5679
+ }, {
5680
+ type: 'bot',
5681
+ id: botid,
5682
+ membership: 'active'
5683
+ }],
5684
+ state: 'active',
5685
+ touchpoint: {
5686
+ id: convoid,
5687
+ channel: 'subiz',
5688
+ source: 'web'
5689
+ },
5690
+ traffic_source: 'direct',
5691
+ events: [ev]
5692
+ };
5693
+ this.pubsub.publish('events', ev);
5694
+ this.lightConvos[convoid] = newconvo;
5695
+ this.kv.put('light_convos', this.lightConvos);
5696
+ return {
5697
+ convo: newconvo
5698
+ };
5699
+ }
5616
5700
  async startConvo(req) {
5617
5701
  if (!req) req = {};
5618
5702
  await this.readyGate.entry();
@@ -5638,9 +5722,11 @@ class Store {
5638
5722
  return this.api.lookupOrder(key);
5639
5723
  }
5640
5724
  createPostback(cid, postback) {
5725
+ if (cid && cid.startsWith('cslight')) return;
5641
5726
  return this.api.createPostback(cid, postback);
5642
5727
  }
5643
5728
  sendReaction(cid, ev) {
5729
+ if (cid && cid.startsWith('cslight')) return;
5644
5730
  return this.api.sendConvoEvent(cid, ev);
5645
5731
  }
5646
5732
  async sendConvoEvent(cid, type, data) {
@@ -5694,6 +5780,7 @@ class Store {
5694
5780
  att.url = url;
5695
5781
  });
5696
5782
  if (event._error) return this.onWs(event);
5783
+ if (cid && cid.startsWith('cslight')) return;
5697
5784
  let {
5698
5785
  body: ret,
5699
5786
  error
@@ -5715,7 +5802,7 @@ class Store {
5715
5802
  first_interaction: 1
5716
5803
  });
5717
5804
  }
5718
- this.kv.put('last_msg_sent', util/* default */.A.Date.now());
5805
+ this.kv.put('last_msg_sent', this.now());
5719
5806
  return ret;
5720
5807
  }
5721
5808
  _setConvo(convo) {
@@ -5800,6 +5887,7 @@ class Store {
5800
5887
  }
5801
5888
  async listmessageapi(type, anchor, limit) {
5802
5889
  let convoid = type;
5890
+ if (convoid && convoid.startsWith('cslight')) return [fakeevents, '', undefined, true];
5803
5891
  let {
5804
5892
  body: events,
5805
5893
  code,
@@ -5833,16 +5921,16 @@ class Store {
5833
5921
  }
5834
5922
  async loopTime() {
5835
5923
  if (this._die) return;
5836
- let startms = util/* default */.A.Date.now();
5924
+ let startms = this.now();
5837
5925
  if (!util/* default */.A.get(this.cache.match('user'), 'id')) return util/* default */.A.setTimeout(() => this.loopTime(), 240000);
5838
5926
  let {
5839
5927
  body: t,
5840
5928
  error
5841
5929
  } = await this.api.time();
5842
5930
  if (error) return util/* default */.A.setTimeout(() => this.loopTime(), 30000);
5843
- var latences = Math.abs(util/* default */.A.Date.now() - startms) / 2;
5931
+ var latences = Math.abs(this.now() - startms) / 2;
5844
5932
  var serverMs = new util/* default */.A.Date(t).getTime() + latences;
5845
- var localMs = util/* default */.A.Date.now();
5933
+ var localMs = this.now();
5846
5934
  this.timeDiff = Math.floor(serverMs - localMs);
5847
5935
  util/* default */.A.setTimeout(() => this.loopTime(), 240000);
5848
5936
  }
@@ -6088,7 +6176,7 @@ class ChatButton extends common/* Com */.Mw {
6088
6176
  this.props.store.onConvoEvent(this, ev => {
6089
6177
  if (util/* default */.A.get(ev, 'type') !== 'message_sent') return;
6090
6178
  let bytype = util/* default */.A.get(ev, 'by.type');
6091
- if (bytype !== 'system' && bytype !== 'agent') return;
6179
+ if (bytype !== 'system' && bytype !== 'agent' && bytype !== 'bot') return;
6092
6180
  let isquickreplies = false;
6093
6181
  util/* default */.A.map(util/* default */.A.get(ev, 'data.message.attachments', []), att => {
6094
6182
  if (!att) return;
@@ -6157,18 +6245,23 @@ class ChatButton extends common/* Com */.Mw {
6157
6245
  displayPreview: false
6158
6246
  });
6159
6247
  }
6160
- ShowGreeting() {
6161
- if (this.props.store.isMobile()) {
6162
- let accid = util/* default */.A.get(this.props.plugin, 'chatbox.account_id', {});
6163
- if (accid === 'acqjeefqeaoiagyfprap') return;
6164
- }
6165
- let greeting = util/* default */.A.get(this.props.plugin, 'chatbox.greeting', {});
6166
- let agentM = this.props.store.matchAgent('*');
6167
- let byid = greeting.agent_id;
6168
- if (!byid) byid = randomAgent(agentM).id;
6169
- let text = this.props.t.i18n(util/* default */.A.get(greeting, 'greeting', {})) || greeting.message;
6170
- this.setState({
6171
- previewEvent: {
6248
+ pickBestGreeting() {
6249
+ let convoM = this.props.store.matchConvo('*');
6250
+ let unseenConvo = util/* default */.A.filter(convoM, convo => {
6251
+ let seen = util/* default */.A.isConvoSeen(convo, this.props.store.matchUser().id);
6252
+ return !seen;
6253
+ }).sort((a, b) => util/* default */.A.get(b, 'last_message_sent.created', 0) - util/* default */.A.get(a, 'last_message_sent.created', 0));
6254
+ if (util/* default */.A.size(unseenConvo) == 0) {
6255
+ if (this.props.store.isMobile()) {
6256
+ let accid = util/* default */.A.get(this.props.plugin, 'chatbox.account_id', {});
6257
+ if (accid === 'acqjeefqeaoiagyfprap') return;
6258
+ }
6259
+ let greeting = util/* default */.A.get(this.props.plugin, 'chatbox.greeting', {});
6260
+ let agentM = this.props.store.matchAgent('*');
6261
+ let byid = greeting.agent_id;
6262
+ if (!byid) byid = randomAgent(agentM).id;
6263
+ let text = this.props.t.i18n(util/* default */.A.get(greeting, 'greeting', {})) || greeting.message;
6264
+ return {
6172
6265
  by: {
6173
6266
  id: byid,
6174
6267
  type: 'agent'
@@ -6179,7 +6272,13 @@ class ChatButton extends common/* Com */.Mw {
6179
6272
  format: 'plaintext'
6180
6273
  }
6181
6274
  }
6182
- },
6275
+ };
6276
+ }
6277
+ return unseenConvo[0].last_message_sent;
6278
+ }
6279
+ ShowGreeting() {
6280
+ this.setState({
6281
+ previewEvent: this.pickBestGreeting(),
6183
6282
  displayPreview: true
6184
6283
  });
6185
6284
  }
@@ -6539,6 +6638,7 @@ function AgentsAvatar(props) {
6539
6638
  }
6540
6639
  if (agents.length === 1) {
6541
6640
  var agent = agents[0];
6641
+ let avatarurl = agent.avatar_url || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582);
6542
6642
  var groupClass = mode === 'primary' ? 'group-avatar--agent-middle' : 'group-avatar--agent-left';
6543
6643
  return (0,preact_module.h)("div", {
6544
6644
  class: `group-avatar group-avatar--${mode}`
@@ -6551,7 +6651,7 @@ function AgentsAvatar(props) {
6551
6651
  height: 35,
6552
6652
  class: `avatar ${groupClass}`,
6553
6653
  alt: "agent avatar",
6554
- src: props.store.replaceFileUrl(agent.avatar_url) || __webpack_require__(2538)
6654
+ src: avatarurl
6555
6655
  })));
6556
6656
  }
6557
6657
  if (agents.length === 2) {
@@ -6568,7 +6668,7 @@ function AgentsAvatar(props) {
6568
6668
  height: 35,
6569
6669
  alt: "agent avatar left",
6570
6670
  class: "avatar group-avatar--agent-left",
6571
- src: props.store.replaceFileUrl(leftAgent.avatar_url) || __webpack_require__(2538)
6671
+ src: props.store.replaceFileUrl(leftAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
6572
6672
  })), (0,preact_module.h)("div", {
6573
6673
  class: "d-inline-block pos-relative",
6574
6674
  "data-tooltip": rightAgent.fullname || acc.name,
@@ -6578,7 +6678,7 @@ function AgentsAvatar(props) {
6578
6678
  width: 35,
6579
6679
  height: 35,
6580
6680
  class: "avatar group-avatar--agent-right",
6581
- src: props.store.replaceFileUrl(rightAgent.avatar_url) || __webpack_require__(2538)
6681
+ src: props.store.replaceFileUrl(rightAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
6582
6682
  })));
6583
6683
  }
6584
6684
  let leftAgent = agents[0];
@@ -6595,7 +6695,7 @@ function AgentsAvatar(props) {
6595
6695
  height: 35,
6596
6696
  alt: "agent avatar left",
6597
6697
  class: "avatar group-avatar--agent-left",
6598
- src: props.store.replaceFileUrl(leftAgent.avatar_url) || __webpack_require__(2538)
6698
+ src: props.store.replaceFileUrl(leftAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
6599
6699
  })), (0,preact_module.h)("div", {
6600
6700
  class: "d-inline-block pos-relative",
6601
6701
  "data-tooltip": middleAgent.fullname || acc.name,
@@ -6605,7 +6705,7 @@ function AgentsAvatar(props) {
6605
6705
  width: 35,
6606
6706
  height: 35,
6607
6707
  class: "avatar group-avatar--agent-middle",
6608
- src: props.store.replaceFileUrl(middleAgent.avatar_url) || __webpack_require__(2538)
6708
+ src: props.store.replaceFileUrl(middleAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
6609
6709
  })), (0,preact_module.h)("div", {
6610
6710
  class: "d-inline-block pos-relative",
6611
6711
  "data-tooltip": rightAgent.fullname || acc.name,
@@ -6615,7 +6715,7 @@ function AgentsAvatar(props) {
6615
6715
  height: 35,
6616
6716
  alt: "agent avatar right",
6617
6717
  class: "avatar group-avatar--agent-right",
6618
- src: props.store.replaceFileUrl(rightAgent.avatar_url) || __webpack_require__(2538)
6718
+ src: props.store.replaceFileUrl(rightAgent.avatar_url) || props.store.replaceFileUrl(acc.logo_url) || __webpack_require__(3582)
6619
6719
  })));
6620
6720
  }
6621
6721
  ;// ./src/chatbox/Header.js
@@ -9802,6 +9902,47 @@ class Widget extends common/* Com */.Mw {
9802
9902
  return;
9803
9903
  }
9804
9904
  let text = message.text;
9905
+ if (this.props.cid && this.props.cid.startsWith('cslight')) {
9906
+ let cid = this.props.cid;
9907
+ this._creating = (this._creating || 0) + 1;
9908
+ let _creating = this._creating;
9909
+ this.setState({
9910
+ creating: true
9911
+ });
9912
+ let botid = cid.split('_')[0].slice(7);
9913
+ const {
9914
+ convo,
9915
+ error
9916
+ } = await this.props.store.startConvo({
9917
+ locale: this.props.t.locale(),
9918
+ message: text,
9919
+ members: [{
9920
+ type: 'bot',
9921
+ id: botid
9922
+ }],
9923
+ initial_by: this.props.store.matchUser().id
9924
+ });
9925
+ if (_creating != this._creating) return;
9926
+ if (error) {
9927
+ this.setState({
9928
+ creating: false
9929
+ });
9930
+ return;
9931
+ }
9932
+ this.props.store.deleteLightConvo(cid);
9933
+ await this.props.store.sendConvoEvent(convo.id, 'message_sent', {
9934
+ message
9935
+ });
9936
+ if (_creating != this._creating) return;
9937
+ this.props.onGo({
9938
+ view: 'chat',
9939
+ cid: convo.id
9940
+ });
9941
+ this.setState({
9942
+ creating: false
9943
+ });
9944
+ return;
9945
+ }
9805
9946
  if (!this.props.cid) {
9806
9947
  this._creating = (this._creating || 0) + 1;
9807
9948
  let _creating = this._creating;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.1.156",
3
+ "version": "4.1.157",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -208,7 +208,7 @@ export default class ChatButton extends Com {
208
208
  if (!agent) agent = this.props.store.matchAgent('*')[byid] || {}
209
209
  agent = sb.cloneDeep(agent)
210
210
  agent.fullname = agent.fullname || sb.get(account, 'name') || this.props.t('agent')
211
- agent.avatar_url = agent.avatar_url || defaultAvatar
211
+ agent.avatar_url = agent.avatar_url || account.logo_url || require('../../assets/img/image_default.png')
212
212
  let position = sb.get(accountSetting, 'desktop_button.position') || 'right'
213
213
  if (this.props.store.isMobile()) {
214
214
  position = sb.get(accountSetting, 'mobile_button.position') || position
package/src/store/kv.js CHANGED
@@ -1,7 +1,7 @@
1
1
  let KvMaxSize = 500
2
2
  // A key-value database with a cache layer
3
3
  export default class {
4
- constructor (db, schema) {
4
+ constructor(db, schema) {
5
5
  this.name = schema
6
6
  schema += '_kv'
7
7
  this.dead = false
@@ -12,23 +12,22 @@ export default class {
12
12
  this.init()
13
13
  }
14
14
 
15
- refreshCache () {
15
+ refreshCache() {
16
16
  if (this.dead) return
17
17
  let inmemItemM = {}
18
18
  let allitems = this.db.all('items')
19
- allitems.forEach(function(item) {
19
+ allitems.forEach(function (item) {
20
20
  inmemItemM[item.key] = item.value
21
21
  })
22
22
  this.cache = inmemItemM
23
23
  }
24
24
 
25
- init () {
25
+ init() {
26
26
  if (this.initialized) return
27
27
  let inmemItemM = {}
28
28
 
29
- console.time('KV' + this.name)
30
29
  let allitems = this.db.all('items')
31
- allitems.forEach(function(item) {
30
+ allitems.forEach(function (item) {
32
31
  inmemItemM[item.key] = item.value
33
32
  })
34
33
  this.cache = inmemItemM
@@ -51,20 +50,18 @@ export default class {
51
50
  }
52
51
 
53
52
  this.db.removes('items', [removekeys])
54
-
55
53
  }
56
54
 
57
55
  this.initialized = true
58
- console.timeEnd('KV' + this.name)
59
56
  }
60
57
 
61
- all () {
58
+ all() {
62
59
  if (this.dead) return []
63
60
  if (!this.initialized) return []
64
61
  return this.cache
65
62
  }
66
63
 
67
- match (key) {
64
+ match(key) {
68
65
  if (this.dead || !this.initialized) return
69
66
  if (!key) return
70
67
  return this.cache[key]
@@ -74,24 +71,24 @@ export default class {
74
71
  // put('1', {id: '1', name: 'thanh'})
75
72
  // put({id: '1', name: 'thanh'}, 'id')
76
73
  // put([{id: '1', name: 'thanh'},{id: '2', name: 'van'}], 'id')
77
- put (key, value) {
74
+ put(key, value) {
78
75
  if (!key) return
79
76
  if (this.dead) return []
80
77
  if (!this.initialized) throw new Error('uninitialized')
81
78
  // if multiple key
82
79
  this.cache[key] = value
83
- this.db.put('items', key, { key, value })
80
+ this.db.put('items', key, {key, value})
84
81
  }
85
82
 
86
83
  // delete an record in a schema
87
- del (key) {
84
+ del(key) {
88
85
  if (this.dead) return
89
86
  if (!this.initialized) throw new Error('uninitialized')
90
87
  delete this.cache[key]
91
88
  this.db.removes('items', [key])
92
89
  }
93
90
 
94
- destroy () {
91
+ destroy() {
95
92
  // clear all data
96
93
  this.db.clear('items')
97
94
 
@@ -1032,9 +1032,9 @@ export default class Store {
1032
1032
  traffic_source: 'direct',
1033
1033
  events: [ev],
1034
1034
  }
1035
- this.pubsub.publish('events', ev)
1036
1035
  this.lightConvos[convoid] = newconvo
1037
1036
  this.kv.put('light_convos', this.lightConvos)
1037
+ this.pubsub.publish('events', ev)
1038
1038
  return {convo: newconvo}
1039
1039
  }
1040
1040