@subiz/widget-v4 4.0.92 → 4.0.93

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 (169) hide show
  1. package/compiled_src/bot.js +0 -11
  2. package/compiled_src/call/call.js +0 -61
  3. package/compiled_src/call/css.js +0 -2
  4. package/compiled_src/chatbox/AgentsAvatar.js +0 -16
  5. package/compiled_src/chatbox/AudioAttachments.js +0 -14
  6. package/compiled_src/chatbox/ButtonAttachments.js +1 -14
  7. package/compiled_src/chatbox/Buttons.js +0 -13
  8. package/compiled_src/chatbox/ChatButton.js +1 -78
  9. package/compiled_src/chatbox/DropdownSelect.js +3 -44
  10. package/compiled_src/chatbox/Emoji.js +0 -7
  11. package/compiled_src/chatbox/Event.js +0 -59
  12. package/compiled_src/chatbox/Events.js +4 -44
  13. package/compiled_src/chatbox/FileAttachments.js +0 -14
  14. package/compiled_src/chatbox/FormAttachment.js +1 -52
  15. package/compiled_src/chatbox/FormAttachments.js +0 -14
  16. package/compiled_src/chatbox/FormSubmitAttachments.js +0 -11
  17. package/compiled_src/chatbox/GenericTemplateAttachments.js +1 -20
  18. package/compiled_src/chatbox/Header.js +1 -46
  19. package/compiled_src/chatbox/ImageAttachments.js +0 -16
  20. package/compiled_src/chatbox/InfoMessage.js +0 -13
  21. package/compiled_src/chatbox/ListField.js +0 -16
  22. package/compiled_src/chatbox/MessageInput.js +1 -47
  23. package/compiled_src/chatbox/Order.js +0 -35
  24. package/compiled_src/chatbox/OrderAttachments.js +1 -23
  25. package/compiled_src/chatbox/PoweredBy.js +0 -7
  26. package/compiled_src/chatbox/ProductAttachments.js +0 -19
  27. package/compiled_src/chatbox/QuickReplies.js +0 -18
  28. package/compiled_src/chatbox/Rating.js +0 -37
  29. package/compiled_src/chatbox/ShadowDomRoot.js +0 -9
  30. package/compiled_src/chatbox/TextMessage.js +0 -64
  31. package/compiled_src/chatbox/Typing.js +0 -15
  32. package/compiled_src/chatbox/VideoAttachments.js +0 -14
  33. package/compiled_src/chatbox/Widget.js +6 -167
  34. package/compiled_src/chatbox/css.js +0 -2
  35. package/compiled_src/chatbox/dragscroll.js +1 -5
  36. package/compiled_src/chatbox/main.js +1 -40
  37. package/compiled_src/chatbox/releaseAnimation.js +0 -11
  38. package/compiled_src/chatbox/spinner.js +0 -10
  39. package/compiled_src/chatbox/time.js +0 -22
  40. package/compiled_src/chatbox/touchscroll.js +0 -7
  41. package/compiled_src/common.js +0 -22
  42. package/compiled_src/contact/contact.js +2 -52
  43. package/compiled_src/contact/css.js +0 -2
  44. package/compiled_src/lib.js +19 -46
  45. package/compiled_src/notif/css.js +0 -2
  46. package/compiled_src/notif/notif.js +0 -63
  47. package/compiled_src/order/address_picker.js +4 -38
  48. package/compiled_src/order/icon.js +0 -16
  49. package/compiled_src/order/index.js +1 -34
  50. package/compiled_src/order/order.js +2 -156
  51. package/compiled_src/plugin.js +1 -77
  52. package/compiled_src/popup/countdown.js +2 -33
  53. package/compiled_src/popup/css.js +0 -2
  54. package/compiled_src/popup/popup.js +2 -165
  55. package/compiled_src/popup/tick.core.commonjs.js +72 -222
  56. package/compiled_src/popup/tick.view.flip.commonjs.js +23 -31
  57. package/compiled_src/store/api.js +99 -65
  58. package/compiled_src/store/api_fake.js +3 -39
  59. package/compiled_src/store/realtime_fake.js +0 -6
  60. package/compiled_src/store/store.js +42 -248
  61. package/compiled_src/util/campaign.js +0 -13
  62. package/compiled_src/util/common.js +15 -185
  63. package/compiled_src/util/common.test.js +0 -4
  64. package/compiled_src/util/extractor.js +1 -21
  65. package/compiled_src/util/extractor.test.js +0 -3
  66. package/compiled_src/util/gate.js +0 -7
  67. package/compiled_src/util/gate.test.js +1 -2
  68. package/compiled_src/util/index.js +1 -7
  69. package/compiled_src/util/mutex.js +31 -0
  70. package/compiled_src/util/op.js +1 -14
  71. package/compiled_src/util/pubsub.js +0 -6
  72. package/compiled_src/util/pubsub.test.js +0 -2
  73. package/package.json +11 -11
  74. package/src/lib.js +24 -2
  75. package/src/store/api.js +110 -21
  76. package/src/store/api_fake.js +5 -6
  77. package/src/store/store.js +31 -5
  78. package/src/util/index.js +1 -0
  79. package/src/util/mutex.js +27 -0
  80. package/dist/132.js +0 -7092
  81. package/dist/178.js +0 -406
  82. package/dist/18364d15f37.132.js +0 -1
  83. package/dist/18364d15f37.178.js +0 -1
  84. package/dist/18364d15f37.213.js +0 -1
  85. package/dist/18364d15f37.335.js +0 -1
  86. package/dist/18364d15f37.362.js +0 -1
  87. package/dist/18364d15f37.441.js +0 -1
  88. package/dist/18364d15f37.605.js +0 -1
  89. package/dist/18364d15f37.678.js +0 -1
  90. package/dist/18364d15f37.782.js +0 -1
  91. package/dist/18364d15f37.app.js +0 -1
  92. package/dist/18364d15f37.index.html +0 -26
  93. package/dist/18364d15f37.library.html +0 -26
  94. package/dist/18364d15f37.library.js +0 -1
  95. package/dist/18364d15f37.preview.html +0 -759
  96. package/dist/18364d15f37.preview.js +0 -1
  97. package/dist/18364d15f37.screenshoot.js +0 -1
  98. package/dist/213.js +0 -3215
  99. package/dist/335.js +0 -411
  100. package/dist/362.js +0 -107
  101. package/dist/441.js +0 -2834
  102. package/dist/605.js +0 -328
  103. package/dist/678.js +0 -107
  104. package/dist/782.js +0 -107
  105. package/dist/HASH +0 -1
  106. package/dist/assets/img/Facebook.64607ec.png +0 -0
  107. package/dist/assets/img/Zalo.6845707.png +0 -0
  108. package/dist/assets/img/award1a.1a58e10.png +0 -0
  109. package/dist/assets/img/award3a.3b74423.png +0 -0
  110. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  111. package/dist/assets/img/award5.39eb7ae.png +0 -0
  112. package/dist/assets/img/bubble_default.7d5e4ab.svg +0 -20
  113. package/dist/assets/img/caret.998eb8f.svg +0 -1
  114. package/dist/assets/img/convos_empty.2353007.svg +0 -72
  115. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  116. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  117. package/dist/assets/img/done_gray.d7e8203.svg +0 -4
  118. package/dist/assets/img/done_green.b817fd4.svg +0 -4
  119. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  120. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  121. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  122. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  123. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  124. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  125. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  126. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  127. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  128. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  129. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  130. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  131. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  132. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  133. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  134. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  135. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  136. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  137. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  138. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  139. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  140. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  141. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  142. package/dist/assets/img/empty.29bed2d.svg +0 -23
  143. package/dist/assets/img/empty_1.0b98af0.svg +0 -11
  144. package/dist/assets/img/examplte_logo.f86535f.svg +0 -1
  145. package/dist/assets/img/external-link.90577cc.svg +0 -1
  146. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  147. package/dist/assets/img/ghn.070f8e3.svg +0 -17
  148. package/dist/assets/img/ghtk.326eac1.svg +0 -18
  149. package/dist/assets/img/image_default.be0698b.png +0 -0
  150. package/dist/assets/img/info.ebce7ea.svg +0 -1
  151. package/dist/assets/img/loader.37000a7.svg +0 -1
  152. package/dist/assets/img/loading_static.8f403ae.svg +0 -10
  153. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  154. package/dist/assets/img/main-service2.9b99549.png +0 -0
  155. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  156. package/dist/assets/img/package.8d37d0f.svg +0 -5
  157. package/dist/assets/img/package_fade.763c001.svg +0 -1
  158. package/dist/assets/img/rating--average.1ea492c.svg +0 -12
  159. package/dist/assets/img/rating--great.e3d712e.svg +0 -16
  160. package/dist/assets/img/rating--poor.2938a25.svg +0 -12
  161. package/dist/assets/img/search.f9705ff.svg +0 -1
  162. package/dist/assets/img/send.6db52a9.svg +0 -3
  163. package/dist/assets/img/shop.f7dc7d8.svg +0 -1
  164. package/dist/assets/img/shop_faded.df7845a.svg +0 -1
  165. package/dist/assets/img/subiz-mono.877e9f5.svg +0 -3
  166. package/dist/assets/img/x.26fdfa3.svg +0 -5
  167. package/dist/malicious-app.js +0 -13
  168. package/dist/screenshoot.html +0 -7
  169. package/dist/screenshoot.js +0 -5953
@@ -4,99 +4,69 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _index = _interopRequireDefault(require("../util/index.js"));
9
-
10
8
  var _storage = _interopRequireDefault(require("@subiz/storage"));
11
-
12
9
  var _api = _interopRequireDefault(require("./api.js"));
13
-
14
10
  var _api_fake = _interopRequireDefault(require("./api_fake.js"));
15
-
16
11
  var _realtime_fake = _interopRequireDefault(require("./realtime_fake.js"));
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
-
22
14
  var flow = require('@subiz/flow');
23
-
24
15
  var Realtime = require('@subiz/wsclient/index.js');
25
-
26
16
  var cookie = require('cookie_js');
27
-
28
17
  cookie.defaults.path = '/';
29
18
  cookie.expiresMultiplier = 60 * 60 * 24;
30
19
  cookie.defaults.expires = 3650;
31
- const MAX_CONVO = 20;
32
20
 
21
+ const MAX_CONVO = 20;
33
22
  const page_loaded = _index.default.Date.now();
34
23
 
35
24
  class Store {
36
- constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi, agenttoken) {
25
+ constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi) {
37
26
  _defineProperty(this, "inmem", false);
38
-
39
27
  _defineProperty(this, "cookie", cookie);
40
-
41
28
  _defineProperty(this, "_currentViewingProduct", {});
42
-
43
29
  _defineProperty(this, "new_visitor", true);
44
-
45
30
  _defineProperty(this, "matchUser", () => {
46
31
  this._touchAcc();
47
-
48
32
  return this.kv.match('user');
49
33
  });
50
-
51
34
  _defineProperty(this, "suggest_addresses", keyword => this.api.suggest_address(keyword));
52
-
53
35
  _defineProperty(this, "matchAccount", () => this.cache.match('account'));
54
-
55
36
  _defineProperty(this, "matchPaymentMethods", () => this.cache.match('payment_methods'));
56
-
57
37
  _defineProperty(this, "matchUnread", () => {
58
38
  let user = this.matchUser();
59
39
  let allconvos = this.matchConvo('*');
60
40
  let unreadcount = 0;
61
-
62
41
  _index.default.map(allconvos, convo => {
63
42
  if (!_index.default.isConvoSeen(convo, user.id)) unreadcount++;
64
43
  });
65
-
66
44
  return unreadcount;
67
45
  });
68
-
69
46
  _defineProperty(this, "matchPlugin", () => {
70
47
  if (_index.default.size(this.forcePlugins) > 0) return _index.default.cloneDeep(this.forcePlugins);
71
48
  return _index.default.cloneDeep(this.cache.match('plugin')) || {};
72
49
  });
73
-
74
50
  _defineProperty(this, "device", {});
75
-
76
51
  _defineProperty(this, "browserVisibility", 'visible');
77
-
78
52
  _defineProperty(this, "matchAgent", id => {
79
53
  let agentM = this.cache.match('agent') || {};
80
54
  if (id === '*') return agentM;
81
55
  return agentM[id];
82
56
  });
83
-
84
57
  _defineProperty(this, "matchConvo", id => {
85
58
  if (!id) return;
86
-
87
59
  if (id === '*') {
88
60
  this._touchAcc();
89
-
90
61
  return _index.default.filter(this.cache.all(), (value, k) => k.startsWith('convo_'));
91
62
  }
92
-
93
63
  if (!this.isInsync(id)) this.fetchConvo(id);
94
64
  return this.cache.match('convo_' + id);
95
65
  });
96
-
97
66
  _defineProperty(this, "fetchConvo", async cid => {
98
67
  await this.readyGate.entry();
99
68
  await this.reconnectGate.entry(undefined, true);
69
+
100
70
  if (this.isInsync(cid)) return this.reconnectGate.open();
101
71
  this.markSync(cid);
102
72
  let {
@@ -106,18 +76,12 @@ class Store {
106
76
  if (convo && !error) this._setConvo(convo);
107
77
  return this.reconnectGate.open();
108
78
  });
109
-
110
79
  _defineProperty(this, "list_provinces", () => this.api.list_provinces());
111
-
112
80
  _defineProperty(this, "list_districts", p => this.api.list_districts(p));
113
-
114
81
  _defineProperty(this, "list_wards", p => this.api.list_wards(p));
115
-
116
82
  _defineProperty(this, "list_provices", void 0);
117
-
118
83
  _defineProperty(this, "listEvents", id => {
119
84
  if (!id || id === '*' || typeof id !== 'string') return;
120
-
121
85
  if (!this.isInsync('events' + id)) {
122
86
  setTimeout(async () => {
123
87
  await this.readyGate.entry();
@@ -129,10 +93,8 @@ class Store {
129
93
  return this.reconnectGate.open();
130
94
  }, 10);
131
95
  }
132
-
133
96
  return this.chain.listM(id);
134
97
  });
135
-
136
98
  _defineProperty(this, "fetchMoreEvents", async convoid => {
137
99
  let {
138
100
  error
@@ -142,76 +104,49 @@ class Store {
142
104
  error
143
105
  };
144
106
  });
145
-
146
107
  _defineProperty(this, "matchLocation", () => this.cache.match('location') || {});
147
-
148
108
  _defineProperty(this, "matchBot", () => this.cache.match('bot') || {});
149
-
150
109
  _defineProperty(this, "readyGate", new _index.default.Gate());
151
-
152
110
  _defineProperty(this, "convoGate", new _index.default.Gate(true));
153
-
154
111
  _defineProperty(this, "reconnectGate", new _index.default.Gate(true));
155
-
156
112
  _defineProperty(this, "matchLastview", () => this.kv.match('lastview') || {});
157
-
158
113
  _defineProperty(this, "matchIsOpen", () => !!this.kv.match('isopen'));
159
-
160
114
  _defineProperty(this, "matchHasManuallyClosed", () => !!this.kv.match('hasManuallyClosed'));
161
-
162
115
  _defineProperty(this, "matchClosePreviewAt", () => this.kv.match('close_preview_at') || 0);
163
-
164
116
  _defineProperty(this, "sendPresence", _index.default.throttle(async () => {
165
117
  await this.readyGate.entry();
166
118
  if (!_index.default.get(this.kv.match('user'), 'id')) return;
167
119
  if (_index.default.isUserBanned(this.kv.match('user'))) return;
168
120
  return this.api.sendPresence(this.device, this.browserVisibility === 'visible' && document.hasFocus(), this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
169
121
  }, 1000));
170
-
171
122
  _defineProperty(this, "now", () => _index.default.Date.now() + this.timeDiff);
172
-
173
123
  _defineProperty(this, "seenQueue", []);
174
-
175
124
  _defineProperty(this, "matchTrafficSource", () => this.kv.match('traffic_source'));
176
-
177
125
  _defineProperty(this, "_typing", _index.default.throttle(convoid => this.api.sendTyping(convoid), 3000, {
178
126
  trailing: false
179
127
  }));
180
-
181
128
  _defineProperty(this, "onConvoEvent", (o, cb) => this.pubsub.on2(o, 'events', cb));
182
-
183
129
  _defineProperty(this, "seenConvo", id => {
184
130
  if (!id || id === 'create') return;
185
131
  this.seenQueue.push(id);
186
132
  });
187
-
188
133
  _defineProperty(this, "onUpdate", (o, cb) => this.pubsub.on2(o, 'account', cb));
189
-
190
134
  _defineProperty(this, "onResetCSS", (o, cb) => this.pubsub.on2(o, 'resetCSS', cb));
191
-
192
135
  _defineProperty(this, "onHighlight", (o, cb) => this.pubsub.on2(o, 'highlight', cb));
193
-
194
136
  _defineProperty(this, "setHasManuallyClosed", () => this.kv.put('hasManuallyClosed', true));
195
-
196
137
  _defineProperty(this, "setIsOpen", isopen => {
197
138
  let lastisopen = this.kv.match('isopen');
198
139
  this.kv.put('isopen', isopen);
199
-
200
140
  if (!lastisopen && isopen) {
201
141
  sendEventToThirdParty('SUBIZ Chat', 'Opened', 'Subiz Windows');
202
142
  }
203
143
  });
204
-
205
144
  _defineProperty(this, "closePreview", () => this.kv.put('close_preview_at', new _index.default.Date().getTime()));
206
-
207
145
  _defineProperty(this, "setLastview", (view, opts) => this.kv.put('lastview', {
208
146
  view,
209
147
  opts
210
148
  }));
211
-
212
149
  _defineProperty(this, "timeDiff", 0);
213
-
214
- this.agent_token = agenttoken;
215
150
  this.g_sync = {};
216
151
  this.forceDevice = null;
217
152
  this.forcePlugins = {};
@@ -221,22 +156,23 @@ class Store {
221
156
  this.fake = fakeapi;
222
157
  this.FileURL = FileURL;
223
158
  if (this.fake) this.api = new _api_fake.default(ApiURL, FileURL);else this.api = new _api.default(ApiURL, FileURL);
224
-
225
159
  if (inmem) {
226
160
  this.inmem = inmem;
227
161
  this.cookie = inmemCookie;
228
162
  }
229
-
230
163
  this.pubsub = new _index.default.Pubsub();
231
164
  this.kv = new _storage.default.kv(new _storage.default.lsdb('sbz2020', this.inmem), 'kv');
232
165
  this.cache = new _storage.default.kv(new _storage.default.lsdb('sbz2020', true), 'kv');
233
166
  this.chain = new _storage.default.chain(new _storage.default.lsdb('cbz2020', true), 'ch');
234
167
  this.getLocaleContent = this.api.getLocaleContent;
168
+
235
169
  this.g_haveSentSeenM = {};
236
170
  window.addEventListener('blur', () => this.sendPresence());
237
171
  window.addEventListener('focus', () => this.sendPresence());
172
+
238
173
  setInterval(() => this.browserVisibility === 'visible' && document.hasFocus() && this.sendPresence(), 20000);
239
174
  setInterval(() => (this.browserVisibility !== 'visible' || document.hasFocus()) && this.sendPresence(), 60000);
175
+
240
176
  onVisibilityChange(val => {
241
177
  this.browserVisibility = val;
242
178
  this.sendPresence();
@@ -251,8 +187,8 @@ class Store {
251
187
  if (!dev.ga_tracking_ids || !dev.ga_client_id) return;
252
188
  clearInterval(_gaInterval);
253
189
  this.device = dev;
254
- let ga_client_id = dev.ga_client_id;
255
190
 
191
+ let ga_client_id = dev.ga_client_id;
256
192
  if (ga_client_id !== _index.default.getUserAttr(user, 'ga_client_id', 'text')) {
257
193
  this.setUser({
258
194
  attributes: [{
@@ -264,13 +200,11 @@ class Store {
264
200
  }
265
201
  }, 2000);
266
202
  }
267
-
268
203
  linkProduct(p) {
269
204
  if (!p) {
270
205
  this._currentViewingProduct = {};
271
206
  return;
272
207
  }
273
-
274
208
  if (p.id) this._currentViewingProduct.id = (p.id + '').trim();
275
209
  if (p.source_id) this._currentViewingProduct.source_id = (p.source_id + '').trim();
276
210
  if (p.sku) this._currentViewingProduct.sku = (p.sku + '').trim();
@@ -279,36 +213,29 @@ class Store {
279
213
  getLinkedProduct() {
280
214
  return _index.default.cloneDeep(this._currentViewingProduct);
281
215
  }
282
-
283
216
  isInsync(key) {
284
217
  return _index.default.Date.now() - (this.g_sync[key] || 0) < 600000;
285
218
  }
286
-
287
219
  async fetchShippingAddresses() {
288
220
  let out = await this.api.fetchShippingAddresses();
289
221
  if (out.error) return null;
290
222
  this.cache.put('shipping_address', out.body.shipping_addresses);
291
223
  }
292
-
293
224
  matchShippingAddresses() {
294
225
  return this.cache.match('shipping_address');
295
226
  }
296
-
297
227
  updateOrder(order) {
298
228
  return this.api.updateOrder(order);
299
229
  }
300
-
301
230
  createShippingAddress(addr) {
302
231
  return this.api.createShippingAddress(addr);
303
232
  }
304
-
305
233
  async overrideAcc(acc) {
306
234
  this.forceAcc = _index.default.cloneDeep(acc);
307
235
  await this.readyGate.entry();
308
236
  this.disconnect('account');
309
237
  this.reconnect();
310
238
  }
311
-
312
239
  async overrideChatbox(chatbox) {
313
240
  this.forceChatbox = chatbox;
314
241
  await this.readyGate.entry();
@@ -316,7 +243,6 @@ class Store {
316
243
  await this.reconnect();
317
244
  setTimeout(this.pubsub.publish('resetCSS'), 10);
318
245
  }
319
-
320
246
  getDeviceInfo() {
321
247
  let device = {
322
248
  user_agent: window.navigator.userAgent,
@@ -335,28 +261,22 @@ class Store {
335
261
  if (ga_tracking_ids.length > 0) device.ga_tracking_ids = ga_tracking_ids;
336
262
  return device;
337
263
  }
338
-
339
264
  highlight(pluginid, ref) {
340
265
  this.pubsub.publish('highlight', pluginid, ref);
341
266
  }
342
-
343
267
  overrideDeviceType(type) {
344
268
  this.forceDevice = type;
345
269
  this.pubsub.publish('account');
346
270
  }
347
-
348
271
  isMobile() {
349
272
  return this.forceDevice === 'mobile' || mobileCheck;
350
273
  }
351
-
352
274
  isTablet() {
353
275
  return this.forceDevice === 'tablet' || tabletCheck;
354
276
  }
355
-
356
277
  isDesktop() {
357
278
  return this.forceDevice === 'desktop' || !this.isMobile() && !this.isTable();
358
279
  }
359
-
360
280
  disconnect(key) {
361
281
  this.g_sync[key] = 0;
362
282
  }
@@ -364,24 +284,19 @@ class Store {
364
284
  pageLoaded() {
365
285
  return page_loaded;
366
286
  }
367
-
368
287
  overridePlugin(plugins) {
369
288
  if (!Array.isArray(plugins)) throw 'plugins must be be an array';
370
289
  let pluginM = {};
371
-
372
290
  _index.default.map(plugins, function (plugin) {
373
291
  pluginM[plugin.id] = plugin;
374
292
  });
375
-
376
293
  this.forcePlugins = pluginM;
377
294
  this.pubsub.publish('account');
378
295
  this.pubsub.publish('resetCSS');
379
296
  }
380
-
381
297
  markSync(key) {
382
298
  this.g_sync[key] = _index.default.Date.now();
383
299
  }
384
-
385
300
  async _touchAcc() {
386
301
  if (this.isInsync('account')) return;
387
302
  await this.readyGate.entry();
@@ -395,28 +310,23 @@ class Store {
395
310
  accid: accid
396
311
  });
397
312
  this.g_sync = {};
398
-
399
313
  if (!mask) {
400
314
  try {
401
315
  mask = this.cookie.get('__sbmask', '');
402
316
  } catch (e) {}
403
317
  }
404
-
405
318
  let localstorageMask = this.kv.match('mask');
406
319
  if (!mask && localstorageMask) mask = localstorageMask;
320
+
407
321
  if (mask && localstorageMask && mask !== localstorageMask) this.clearBrowserData();
408
- if (this.agent_token) mask = await this.api.createAgentUser(this.agent_token);
409
322
  var userId = '';
410
-
411
323
  if (mask) {
412
324
  let parts = mask.split('@');
413
-
414
325
  if (parts[0] != accid) {
415
326
  mask = '';
416
327
  this.clearBrowserData();
417
328
  } else userId = parts[1];
418
329
  }
419
-
420
330
  if (!mask) {
421
331
  let user = await this.api.createUser(accid);
422
332
  this.new_visitor = true;
@@ -445,55 +355,72 @@ class Store {
445
355
  this.reconnectWs(accid, userId);
446
356
  return mask;
447
357
  }
358
+ async login(accid, user_id, tokenGenerator) {
359
+ let user = await this.api.setTokenGenerator(accid, user_id, tokenGenerator);
360
+ if (user.error) return user;
361
+ this.clearBrowserData();
362
+ this.readyGate.close();
363
+ accid = (accid || '').trim();
364
+ this.g_sync = {};
365
+ this.new_visitor = false;
448
366
 
367
+ if (this.realtime) this.realtime.stop();
368
+ if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, {
369
+ getAccessToken: () => this.api.token_generator()
370
+ });
371
+ this.realtime.onEvent(this.onWs.bind(this));
372
+ this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id));
373
+ this.seenLoop();
374
+ await this.reconnect();
375
+ this.readyGate.open();
376
+ this.reconnectWs(accid, user.id);
377
+ return user;
378
+ }
379
+ logout(user_id) {
380
+ this.api.setTokenGenerator(undefined, undefined, undefined);
381
+ }
449
382
  seenLoop() {
450
383
  this.seenQueue = [];
451
384
  clearInterval(this._seenInterval);
452
385
  this._seenInterval = setInterval(() => {
453
386
  this.seenQueue = [...new Set(this.seenQueue)];
454
387
  let user = this.kv.match('user') || {};
455
-
456
388
  _index.default.map(this.seenQueue, id => {
457
389
  var events = this.listEvents(id);
458
390
  if (!events) return;
459
391
  if (_index.default.size(events) === 0) return;
392
+
460
393
  events = _index.default.filter(events, ev => ev.type === 'message_sent');
461
394
  var lastmsgsent = events[_index.default.size(events) - 1];
462
395
  if (!lastmsgsent) return;
463
396
  if (this.g_haveSentSeenM[lastmsgsent.id]) return;
397
+
464
398
  if (lastmsgsent.id === _index.default.getMsgField(lastmsgsent, 'idempotency')) return;
399
+
465
400
  this.api.markAsSeen(id, lastmsgsent.id);
466
401
  let convo = this.cache.match('convo_' + id) || {};
467
-
468
402
  let mem = _index.default.find(convo.members, m => m.id === user.id);
469
-
470
403
  mem.seen_at = Date.now();
471
-
472
404
  this._setConvo(convo);
473
-
474
405
  this.g_haveSentSeenM[lastmsgsent.id] = true;
475
406
  });
476
-
477
407
  this.seenQueue = [];
478
408
  }, 1000);
479
409
  }
480
-
481
410
  async reconnectWs(accid, userid) {
482
411
  await this.realtime.subscribe([`conversation_state_updated.account.${accid}.user.${userid}`, `conversation_joined.account.${accid}.user.${userid}`, `conversation_typing.account.${accid}.user.${userid}`, `message_sent.account.${accid}.user.${userid}`, `conversation_pending.account.${accid}.user.${userid}`, `user_info_updated.account.${accid}.user.${userid}`, `message_pong.account.${accid}.user.${userid}`, `conversation_rating_requested.account.${accid}.user.${userid}`, `conversation_rated.account.${accid}.user.${userid}`]);
483
412
  await this.readyGate.entry();
484
413
  this.disconnect('account');
485
414
  return this.reconnect();
486
415
  }
487
-
488
416
  async reconnect() {
489
417
  if (this._die) return;
418
+
490
419
  await this.reconnectGate.entry(undefined, true);
491
420
  if (this.isInsync('account')) return this.reconnectGate.open();
492
421
  this.markSync('account');
493
422
  let outs = await Promise.all([this.api.getUser(), this.api.getAccountSetting(), this.api.getIsOnline()]);
494
-
495
423
  let error = _index.default.find(outs, out => out.error);
496
-
497
424
  if (error) return console.error(error);
498
425
  let set = Object.assign(outs[1].body, outs[2].body);
499
426
  set.user = outs[0].body;
@@ -501,31 +428,24 @@ class Store {
501
428
  let convob = await this.api.listConversations();
502
429
  error = convob.error;
503
430
  let body = convob.body;
504
-
505
431
  if (!error) {
506
432
  let convos = _index.default.get(body, 'conversations', []);
507
-
508
433
  _index.default.map(this.cache.all(), (value, k) => {
509
434
  if (k.startsWith('convo_')) {
510
435
  if (this.now() - _index.default.getMs(_index.default.get(value, 'actived')) > 1209600000) this.cache.del(k);
511
436
  }
512
437
  });
513
-
514
438
  _index.default.map(convos, convo => this._setConvo(convo));
515
439
  }
516
-
517
440
  return this.reconnectGate.open();
518
441
  }
519
442
 
520
443
  async setUser(user) {
521
444
  if (!user) return;
522
445
  await this.readyGate.entry();
523
-
524
446
  this._setUser(user);
525
-
526
447
  return this.api.updateUser(user);
527
448
  }
528
-
529
449
  _setUser(user) {
530
450
  user = _index.default.cloneDeep(user);
531
451
  let olduser = this.kv.match('user') || {};
@@ -539,7 +459,6 @@ class Store {
539
459
  return oldattr.key !== newattr.key;
540
460
  });
541
461
  });
542
-
543
462
  olduser.attributes = olduser.attributes || [];
544
463
  olduser.attributes = olduser.attributes.concat(user.attributes);
545
464
  olduser.account_id = accid;
@@ -547,28 +466,22 @@ class Store {
547
466
  this.kv.put('user', olduser);
548
467
  this.pubsub.publish('account');
549
468
  }
550
-
551
469
  async setSetting(setting) {
552
470
  if (!setting) return;
553
471
  await this.readyGate.entry();
554
472
  return this._setSetting(setting);
555
473
  }
556
-
557
474
  async _setSetting(setting) {
558
475
  setting = _index.default.cloneDeep(setting) || {};
559
476
  setting.account = Object.assign({}, setting.account, this.forceAcc);
560
-
561
477
  if (!setting.account.logo_url) {
562
478
  setting.account.logo_url = 'https://file-subiz.com/fiqpezhkmeyesdscyetk-default_logo.jpg';
563
479
  }
564
-
565
480
  if (setting.user) {
566
481
  setting.user.account_id = setting.account.id;
567
482
  delete setting.user.session;
568
-
569
483
  this._setUser(setting.user);
570
484
  }
571
-
572
485
  if (setting.account) {
573
486
  setting.account.is_online = setting.is_online;
574
487
  setting.account.is_in_business_hour = setting.is_in_business_hour;
@@ -577,48 +490,36 @@ class Store {
577
490
  }
578
491
 
579
492
  let location = _index.default.get(setting, 'location', []);
580
-
581
493
  this.cache.put('location', location);
582
494
 
583
495
  let bots = _index.default.get(setting, 'bots', []);
584
-
585
496
  let botM = {};
586
-
587
497
  _index.default.map(bots, bot => {
588
498
  botM[bot.id] = bot;
589
499
  });
590
-
591
500
  this.cache.put('bot', botM);
592
501
 
593
502
  let plugins = _index.default.get(setting, 'plugins', []);
594
-
595
503
  let pluginM = {};
596
-
597
504
  _index.default.map(plugins, plugin => {
598
505
  if (plugin.type === 'chatbox') {
599
506
  plugin = _index.default.merge(plugin, this.forceChatbox);
600
507
  }
601
-
602
508
  pluginM[plugin.id] = plugin;
603
509
  });
604
-
605
510
  this.cache.put('plugin', pluginM);
606
511
 
607
512
  var agents = _index.default.get(setting, 'agents', []);
608
-
609
513
  if (_index.default.size(agents) > 0) {
610
514
  let agentM = {};
611
515
  this.api.setAgentId(agents[0].id);
612
-
613
516
  _index.default.map(agents, agent => {
614
517
  agentM[agent.id] = agent;
615
518
  });
616
-
617
519
  this.cache.put('agent', agentM);
618
520
  }
619
521
 
620
522
  let pms = _index.default.get(setting, 'payment_methods', []);
621
-
622
523
  this.cache.put('payment_methods', pms);
623
524
  this.pubsub.publish('account');
624
525
  }
@@ -626,38 +527,26 @@ class Store {
626
527
  async track() {
627
528
  let user = this.kv.match('user') || {};
628
529
  let out = await this.api.sendContentView(this.device, location.href, document.title, this._currentViewingProduct.id, this._currentViewingProduct.source_id, this._currentViewingProduct.sku);
629
-
630
530
  let traffic_source = _index.default.get(out, 'body.by.device.source', '');
631
-
632
531
  if (traffic_source) this.kv.put('traffic_source', traffic_source);
633
532
  this.sendPresence();
634
533
  }
635
-
636
534
  async onWs(ev) {
637
535
  if (!ev || !ev.type) return;
638
536
  ev.created = _index.default.getMs(ev.created);
639
-
640
537
  if (ev.type === 'user_info_updated') {
641
538
  let user = _index.default.cloneDeep(this.kv.match('user'));
642
-
643
539
  let attrs = _index.default.get(ev, 'data.user.attributes') || [];
644
-
645
540
  _index.default.map(attrs, attr => _index.default.setUserAttr(user, attr));
646
-
647
541
  this._setUser(user);
648
-
649
542
  return;
650
543
  }
651
544
 
652
545
  let user = this.kv.match('user') || {};
653
-
654
546
  let cid = _index.default.convoOfEv(ev);
655
-
656
547
  let convo;
657
-
658
548
  if (cid) {
659
549
  convo = this.matchConvo(cid);
660
-
661
550
  if (!convo || !convo.id) {
662
551
  let {
663
552
  body: apiconvo,
@@ -667,60 +556,45 @@ class Store {
667
556
  convo = apiconvo;
668
557
  }
669
558
  }
670
-
671
559
  if (!convo) return;
672
560
 
673
561
  let channel = _index.default.get(ev, 'touchpoint.channel', '');
674
-
675
562
  if (channel && channel != 'subiz') return;
676
563
  this.pubsub.publish('events', ev);
677
564
 
678
565
  if (ev.type === 'conversation_joined') {
679
566
  let members = _index.default.get(ev, 'data.conversation.members', []);
680
-
681
567
  let me = _index.default.find(members, m => m.id === this.kv.match('user').id);
682
-
683
568
  if (me) {
684
569
  await this.chain.reload(cid, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
685
570
  this.markSync('events' + cid);
686
571
  let {
687
572
  body: apiconvo
688
573
  } = await this.api.getConversation(cid);
689
-
690
574
  if (apiconvo) {
691
575
  convo = apiconvo;
692
-
693
576
  this._setConvo(convo);
694
577
  }
695
-
696
578
  this.pubsub.publish('account');
697
579
  }
698
580
  }
699
-
700
581
  if (ev.type === 'message_sent') {
701
582
  if (_index.default.get(ev, 'by.id') !== user.id) {
702
583
  this.api.markAsReceived(cid, ev.id);
703
584
  }
704
585
  }
705
-
706
586
  if (_index.default.startsWith(ev.type, 'message_') || _index.default.startsWith(ev.type, 'conversation_')) {
707
587
  this.restConvoEvent(ev);
708
-
709
588
  if (ev.type === 'message_sent' && _index.default.get(ev, 'by.id') !== user.id) {
710
589
  sendEventToThirdParty('SUBIZ Chat', 'Received', 'User');
711
590
  }
712
-
713
591
  return;
714
592
  }
715
593
  }
716
-
717
594
  async restConvoEvent(ev) {
718
595
  let user = this.kv.match('user');
719
-
720
596
  let cid = _index.default.convoOfEv(ev);
721
-
722
597
  let convo = this.cache.match('convo_' + cid) || {};
723
-
724
598
  if (ev.type === 'conversation_state_updated') {
725
599
  if (!_index.default.get(convo, 'id')) {
726
600
  let {
@@ -729,68 +603,50 @@ class Store {
729
603
  } = await this.api.getConversation(cid);
730
604
  if (error) return;
731
605
  }
732
-
733
606
  convo = Object.assign(convo, _index.default.get(ev, 'data.conversation'));
734
607
  }
735
-
736
608
  if (ev.type === 'message_pong') {
737
609
  var msgid = _index.default.get(ev, 'data.message.id');
738
-
739
610
  var oldev = this.chain.match(cid, msgid);
740
611
  if (!_index.default.get(oldev, 'data.message')) return;
741
-
742
612
  var pongs = _index.default.get(oldev, 'data.message.pongs', []);
743
-
744
613
  pongs = pongs.concat(_index.default.get(ev, 'data.message.pongs', []));
745
614
  oldev.data.message.pongs = pongs;
746
-
747
615
  _index.default.map(pongs, pong => {
748
616
  if (pong.member_id == user.id && pong.type === 'seen') {
749
617
  let mem = _index.default.find(convo.members, mem => mem.id === user.id);
750
-
751
618
  if (mem) mem.seen_at = pong.created;
752
619
  }
753
620
  });
754
-
755
621
  this.chain.put(cid, oldev.id, _index.default.getMs(oldev.created), oldev);
756
622
  }
757
-
758
623
  if (ev.type === 'message_sent') {
759
624
  let idemkey = _index.default.getMsgField(ev, 'idempotency');
760
-
761
625
  let found = _index.default.find(this.listEvents(cid), oldev => oldev.id === idemkey);
762
-
763
626
  if (found) {
764
627
  this.chain.del(cid, found.id);
765
628
  ev.created = found.created;
766
629
  }
767
-
768
630
  convo.last_message_sent = ev;
769
631
  }
770
632
 
771
633
  if (ev.type !== 'message_pong' && ev.type !== 'conversation_typing') {
772
634
  this.chain.put(cid, ev.id, _index.default.getMs(ev.created), ev);
773
635
  }
774
-
775
636
  this._setConvo(convo);
776
-
777
637
  this.pubsub.publish('account');
778
638
  }
779
-
780
639
  handleFormSubmit(convoKey, ev) {
781
640
  if (ev.type !== 'message_sent') return;
782
641
  let formSubmits = [];
783
642
  let attachments = _index.default.get(ev, 'data.message.attachments') || [];
784
-
785
643
  _index.default.each(attachments, att => {
786
644
  if (!att) return;
787
645
  if (att.type !== 'form_submit') return;
788
646
  formSubmits.push(att.form_submit);
789
647
  });
790
-
791
648
  _index.default.each(formSubmits, submit => {
792
649
  let formev = _index.default.get(this.convoEventM, convoKey + '.' + submit.form_message_id);
793
-
794
650
  if (!formev) return;
795
651
 
796
652
  let forms = _index.default.filter(_index.default.get(formev, 'data.message.attachments'), att => {
@@ -798,10 +654,8 @@ class Store {
798
654
  if (att.type !== 'form' && att.type !== 'ask_info_form') return false;
799
655
  return true;
800
656
  });
801
-
802
657
  _index.default.each(forms, form => {
803
658
  form = form.form;
804
-
805
659
  _index.default.each(form.fields, formfield => {
806
660
  _index.default.each(submit.fields, submitfield => {
807
661
  if (formfield.name !== submitfield.name) return;
@@ -810,17 +664,13 @@ class Store {
810
664
  });
811
665
  });
812
666
  });
813
-
814
667
  if (_index.default.size(forms) > 0) this.pubsub.publish('state.convoEventM', this.convoEventM, convoKey);
815
668
  });
816
669
  }
817
-
818
670
  typing(cid) {
819
671
  if (!cid) return;
820
-
821
672
  this._typing(cid);
822
673
  }
823
-
824
674
  async startConvo(req) {
825
675
  await this.readyGate.entry();
826
676
  this.convoGate.close();
@@ -833,31 +683,23 @@ class Store {
833
683
  if (error) return {
834
684
  error
835
685
  };
836
-
837
686
  this._setConvo(convo);
838
-
839
687
  return {
840
688
  convo
841
689
  };
842
690
  }
843
-
844
691
  fetchOrder(id) {
845
692
  return this.api.getOrder(id);
846
693
  }
847
-
848
694
  lookupOrder(key) {
849
695
  return this.api.lookupOrder(key);
850
696
  }
851
-
852
697
  createPostback(cid, postback) {
853
698
  return this.api.createPostback(cid, postback);
854
699
  }
855
-
856
700
  async sendConvoEvent(cid, type, data) {
857
701
  await this.readyGate.entry();
858
-
859
702
  var idempotency = _index.default.randomString(36);
860
-
861
703
  let user = this.kv.match('user') || {};
862
704
  var event = {
863
705
  id: idempotency,
@@ -870,28 +712,24 @@ class Store {
870
712
  type,
871
713
  created: this.now()
872
714
  };
873
-
874
715
  _index.default.convoToEv(cid, event);
875
-
876
716
  let files = [];
877
-
878
717
  if (type === 'message_sent') {
879
718
  _index.default.setMsgField(event, 'idempotency', idempotency);
880
-
881
719
  event.data.message.conversation_id = cid;
720
+
882
721
  await flow.map(event.data.message.attachments, 2, async (att, i) => {
883
722
  if (att.type !== 'file') return;
884
723
  if (!att._file) return;
885
724
  files.push(att);
886
-
887
725
  if (ImageTypes.includes(att._file.type)) {
888
726
  att.url = await loadImage(att._file);
889
727
  }
890
728
  });
891
729
  }
892
-
893
730
  this.onWs(event);
894
731
  await this.convoGate.entry();
732
+
895
733
  await flow.map(files, 1, async att => {
896
734
  const {
897
735
  url,
@@ -905,17 +743,14 @@ class Store {
905
743
  body: ret,
906
744
  error
907
745
  } = await this.api.sendConvoEvent(cid, event);
908
-
909
746
  if (error) {
910
747
  event._error = error;
911
748
  this.onWs(event);
912
749
  return;
913
750
  }
914
-
915
751
  this.onWs(ret);
916
752
  sendEventToThirdParty('SUBIZ Chat', 'Sent', 'User');
917
753
  let lastMsgSent = this.kv.match('last_msg_sent');
918
-
919
754
  if (!lastMsgSent) {
920
755
  let dataLayer = window.dataLayer || [];
921
756
  dataLayer.push({
@@ -925,50 +760,40 @@ class Store {
925
760
  first_interaction: 1
926
761
  });
927
762
  }
928
-
929
763
  this.kv.put('last_msg_sent', _index.default.Date.now());
930
764
  return ret;
931
765
  }
932
-
933
766
  _setConvo(convo) {
934
767
  let count = 0;
935
- let user = this.kv.match('user');
936
768
 
769
+ let user = this.kv.match('user');
937
770
  let channel = _index.default.get(convo, 'touchpoint.channel', '');
938
-
939
771
  if (channel && channel != 'subiz') return;
940
772
  let allconvo = {};
941
-
942
773
  _index.default.map(this.cache.all(), (value, key) => {
943
774
  if (key.startsWith('convo_')) {
944
775
  allconvo[key] = value;
945
776
  }
946
777
  });
947
-
948
778
  if (_index.default.size(allconvo) > MAX_CONVO - 2) {
949
779
  allconvo = _index.default.orderBy(_index.default.map(allconvo), 'created', 'desc');
950
-
951
780
  for (var i = MAX_CONVO - 2; i < _index.default.size(allconvo); i++) {
952
781
  let convo = allconvo[i];
953
782
  this.cache.del('convo_' + convo.id);
954
783
  }
955
784
  }
956
-
957
785
  this.markSync(convo.id);
958
786
  this.pubsub.publish('account');
959
787
  this.cache.put('convo_' + convo.id, convo);
960
788
  }
961
-
962
789
  matchLastPluginRun(pluginid) {
963
790
  let log = this.kv.match('plugin_run_logs') || {};
964
791
  return log[pluginid];
965
792
  }
966
-
967
793
  matchLastBotRun(botid) {
968
794
  let log = this.kv.match('bot_run_logs') || {};
969
795
  return log[botid];
970
796
  }
971
-
972
797
  logBotRun(botid) {
973
798
  let log = this.kv.match('bot_run_logs') || {};
974
799
  log[botid] = {
@@ -977,7 +802,6 @@ class Store {
977
802
  };
978
803
  this.kv.put('bot_run_logs', log);
979
804
  }
980
-
981
805
  sendImpression(id) {
982
806
  let user = this.kv.match('user') || {};
983
807
  let log = this.kv.match('plugin_run_logs') || {};
@@ -995,7 +819,6 @@ class Store {
995
819
  device: this.device
996
820
  });
997
821
  }
998
-
999
822
  sendConversion(id, fields, impressionToken) {
1000
823
  let user = this.kv.match('user') || {};
1001
824
  let submission = {
@@ -1017,12 +840,10 @@ class Store {
1017
840
  impression_token: impressionToken
1018
841
  });
1019
842
  }
1020
-
1021
843
  isConverted(id) {
1022
844
  let conv = this.kv.match('conversions') || {};
1023
845
  return conv[id];
1024
846
  }
1025
-
1026
847
  async listmessageapi(type, anchor, limit) {
1027
848
  let convoid = type;
1028
849
  let {
@@ -1040,23 +861,19 @@ class Store {
1040
861
  value: event
1041
862
  };
1042
863
  });
1043
- let user = this.kv.match('user') || {};
1044
864
 
865
+ let user = this.kv.match('user') || {};
1045
866
  for (let i = 0; i < events.length; i++) {
1046
867
  let ev = events[i].value;
1047
868
  if (ev.type !== 'message_sent') continue;
1048
869
  if (_index.default.get(ev, 'by.id') === user.id) continue;
1049
-
1050
870
  let pongbyme = _index.default.find(_index.default.get(ev, 'data.message.pongs'), p => p.member_id === user.id);
1051
-
1052
871
  if (pongbyme) break;
1053
872
  this.api.markAsReceived(convoid, ev.id);
1054
873
  break;
1055
874
  }
1056
-
1057
875
  return [events, anchor];
1058
876
  }
1059
-
1060
877
  async loopTime() {
1061
878
  let startms = _index.default.Date.now();
1062
879
 
@@ -1068,22 +885,17 @@ class Store {
1068
885
  if (error) return setTimeout(() => this.loopTime(), 30000);
1069
886
  var latences = Math.abs(_index.default.Date.now() - startms) / 2;
1070
887
  var serverMs = new _index.default.Date(t).getTime() + latences;
1071
-
1072
888
  var localMs = _index.default.Date.now();
1073
-
1074
889
  this.timeDiff = Math.floor(serverMs - localMs);
1075
890
  setTimeout(() => this.loopTime(), 240000);
1076
891
  }
1077
-
1078
892
  replaceFileUrl(src) {
1079
893
  if (!src) return '';
1080
894
  if (_index.default.startsWith(src, '/')) return src;
1081
895
  if (_index.default.startsWith(src, 'data:')) return src;
1082
-
1083
896
  if (!_index.default.startsWith(src, 'http://') && !_index.default.startsWith(src, 'https://') && !_index.default.startsWith(src, '//')) {
1084
897
  src = _index.default.trim(this.FileURL, '/') + '/' + _index.default.trimStart(src, '/');
1085
898
  }
1086
-
1087
899
  src = src.replace('https://file-subiz.com/', this.FileURL);
1088
900
  src = src.replace('http://file-subiz.com/', this.FileURL);
1089
901
  src = src.replace('https://file-v4.subiz.com/', this.FileURL);
@@ -1098,33 +910,26 @@ class Store {
1098
910
  src = src.replace('http://file.mysubiz.com/', this.FileURL);
1099
911
  return src;
1100
912
  }
1101
-
1102
913
  clearBrowserData() {
1103
914
  _index.default.each(this.cookie.all(), (v, k) => {
1104
915
  if ((k || '').startsWith('__sb')) this.cookie.remove(k);
1105
916
  });
1106
-
1107
917
  this.kv.destroy();
1108
918
  this.kv = new _storage.default.kv(new _storage.default.lsdb('sbz2020', this.inmem), 'kv');
1109
919
  this.chain.destroy();
1110
920
  this.chain = new _storage.default.chain(new _storage.default.lsdb('cbz2020', true), 'ch');
1111
921
  }
1112
-
1113
922
  destroy() {
1114
923
  this._die = true;
1115
924
  this.clearBrowserData();
1116
925
  if (this.realtime) this.realtime.stop();
1117
926
  this.readyGate.close();
1118
927
  }
1119
-
1120
928
  }
1121
-
1122
929
  exports.default = Store;
1123
-
1124
930
  function loadImage(file) {
1125
931
  return new Promise(rs => {
1126
932
  var reader = new window.FileReader();
1127
-
1128
933
  reader.onload = e => {
1129
934
  rs(e.target.result);
1130
935
  };
@@ -1132,13 +937,13 @@ function loadImage(file) {
1132
937
  reader.readAsDataURL(file);
1133
938
  });
1134
939
  }
1135
-
1136
940
  const ImageTypes = ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'];
1137
-
1138
941
  function onVisibilityChange(cb) {
1139
942
  var hidden = 'hidden';
1140
- if (hidden in document) document.addEventListener('visibilitychange', onchange);else if ((hidden = 'mozHidden') in document) document.addEventListener('mozvisibilitychange', onchange);else if ((hidden = 'webkitHidden') in document) document.addEventListener('webkitvisibilitychange', onchange);else if ((hidden = 'msHidden') in document) document.addEventListener('msvisibilitychange', onchange);else if ('onfocusin' in document) document.onfocusin = document.onfocusout = onchange;else window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange;
1141
943
 
944
+ if (hidden in document) document.addEventListener('visibilitychange', onchange);else if ((hidden = 'mozHidden') in document) document.addEventListener('mozvisibilitychange', onchange);else if ((hidden = 'webkitHidden') in document) document.addEventListener('webkitvisibilitychange', onchange);else if ((hidden = 'msHidden') in document) document.addEventListener('msvisibilitychange', onchange);
945
+ else if ('onfocusin' in document) document.onfocusin = document.onfocusout = onchange;
946
+ else window.onpageshow = window.onpagehide = window.onfocus = window.onblur = onchange;
1142
947
  function onchange(evt) {
1143
948
  var v = 'visible';
1144
949
  var h = 'hidden';
@@ -1158,26 +963,20 @@ function onVisibilityChange(cb) {
1158
963
  type: document[hidden] ? 'blur' : 'focus'
1159
964
  });
1160
965
  }
1161
-
1162
966
  const inmemCookie = {
1163
967
  data: {},
1164
-
1165
968
  get(k, def) {
1166
969
  return this.data[k] || def;
1167
970
  },
1168
-
1169
971
  set(k, v) {
1170
972
  return this.data[k] = k;
1171
973
  },
1172
-
1173
974
  all() {
1174
975
  return this.data;
1175
976
  },
1176
-
1177
977
  remove(k) {
1178
978
  delete this.data[k];
1179
979
  }
1180
-
1181
980
  };
1182
981
 
1183
982
  function getGaClientId() {
@@ -1203,7 +1002,6 @@ function getGaTrackingIds() {
1203
1002
  });
1204
1003
  return trackingIds;
1205
1004
  }
1206
-
1207
1005
  function sendToFBPixel(category, action, label) {
1208
1006
  if (!window.fbq) return;
1209
1007
  window.fbq('trackCustom', category, {
@@ -1211,13 +1009,11 @@ function sendToFBPixel(category, action, label) {
1211
1009
  label: label
1212
1010
  });
1213
1011
  }
1214
-
1215
1012
  function sendToGA(category, action, label) {
1216
1013
  if (window.gtag) window.gtag('event', category, {
1217
1014
  Action: action,
1218
1015
  Label: label
1219
1016
  });
1220
-
1221
1017
  if (window.ga && window.ga.getAll) {
1222
1018
  const allTrackers = window.ga.getAll() || [];
1223
1019
  allTrackers.forEach(function (tracker) {
@@ -1226,7 +1022,6 @@ function sendToGA(category, action, label) {
1226
1022
  });
1227
1023
  }
1228
1024
  }
1229
-
1230
1025
  function sendEventToThirdParty(category, action, label) {
1231
1026
  document.dispatchEvent(new CustomEvent('subiz', {
1232
1027
  detail: {
@@ -1248,5 +1043,4 @@ function sendEventToThirdParty(category, action, label) {
1248
1043
  let mobileCheck = function (a) {
1249
1044
  return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4));
1250
1045
  }(navigator.userAgent || navigator.vendor || window.opera);
1251
-
1252
1046
  let tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(navigator.userAgent);