@subiz/widget-v4 4.0.91 → 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 (194) 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 +3 -43
  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 +103 -66
  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 +46 -257
  61. package/compiled_src/util/campaign.js +0 -13
  62. package/compiled_src/util/common.js +15 -190
  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 +12 -12
  74. package/src/chatbox/main.js +3 -3
  75. package/src/lib.js +24 -2
  76. package/src/store/api.js +111 -22
  77. package/src/store/api_fake.js +5 -6
  78. package/src/store/store.js +38 -14
  79. package/src/util/common.js +0 -4
  80. package/src/util/index.js +1 -0
  81. package/src/util/mutex.js +27 -0
  82. package/dist/0b82fa7e5c3b07b40a44.png +0 -1
  83. package/dist/0f4af006e38ee8b93633.png +0 -1
  84. package/dist/132.js +0 -6777
  85. package/dist/178.js +0 -573
  86. package/dist/17f00e48d38.132.js +0 -1
  87. package/dist/17f00e48d38.178.js +0 -1
  88. package/dist/17f00e48d38.213.js +0 -1
  89. package/dist/17f00e48d38.335.js +0 -1
  90. package/dist/17f00e48d38.362.js +0 -1
  91. package/dist/17f00e48d38.441.js +0 -1
  92. package/dist/17f00e48d38.605.js +0 -1
  93. package/dist/17f00e48d38.678.js +0 -1
  94. package/dist/17f00e48d38.782.js +0 -1
  95. package/dist/17f00e48d38.app.js +0 -1
  96. package/dist/17f00e48d38.index.html +0 -22
  97. package/dist/17f00e48d38.library.html +0 -22
  98. package/dist/17f00e48d38.library.js +0 -1
  99. package/dist/17f00e48d38.preview.html +0 -759
  100. package/dist/17f00e48d38.preview.js +0 -1
  101. package/dist/17f00e48d38.screenshoot.js +0 -1
  102. package/dist/1ea1c6cd21d25176810c.png +0 -1
  103. package/dist/213.js +0 -3188
  104. package/dist/292d42404e1b03398f61.png +0 -1
  105. package/dist/312d376370831b7bea83.png +0 -1
  106. package/dist/313d1bfc1cf776d1aefe.png +0 -1
  107. package/dist/335.js +0 -411
  108. package/dist/362.js +0 -157
  109. package/dist/441.js +0 -2732
  110. package/dist/4aa58bb7a66bb44975aa.png +0 -1
  111. package/dist/56ce063bc6c81adb7322.png +0 -1
  112. package/dist/605.js +0 -328
  113. package/dist/678.js +0 -157
  114. package/dist/6a411166ef5cc79e0714.png +0 -1
  115. package/dist/6faf403782fefacc1649.png +0 -1
  116. package/dist/782.js +0 -204
  117. package/dist/79dca33c68fab79c067f.png +0 -1
  118. package/dist/82da1578fa84f9debaeb.png +0 -1
  119. package/dist/8b8e0f0824743974b282.png +0 -1
  120. package/dist/8d551390d81e39130a3c.png +0 -1
  121. package/dist/9fc61b9479877ebdb6c7.png +0 -1
  122. package/dist/HASH +0 -1
  123. package/dist/a165d31dcb3dc90f1057.png +0 -1
  124. package/dist/a98d4a5698812c4426b3.png +0 -1
  125. package/dist/assets/img/Facebook.64607ec.png +0 -0
  126. package/dist/assets/img/Zalo.6845707.png +0 -0
  127. package/dist/assets/img/award1a.1a58e10.png +0 -0
  128. package/dist/assets/img/award3a.3b74423.png +0 -0
  129. package/dist/assets/img/award4a.ed6ccd4.png +0 -0
  130. package/dist/assets/img/award5.39eb7ae.png +0 -0
  131. package/dist/assets/img/bubble_default.7d5e4ab.svg +0 -20
  132. package/dist/assets/img/caret.998eb8f.svg +0 -1
  133. package/dist/assets/img/convos_empty.2353007.svg +0 -72
  134. package/dist/assets/img/default.06e6ee0.jpg +0 -0
  135. package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
  136. package/dist/assets/img/done_gray.d7e8203.svg +0 -4
  137. package/dist/assets/img/done_green.b817fd4.svg +0 -4
  138. package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
  139. package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
  140. package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
  141. package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
  142. package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
  143. package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
  144. package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
  145. package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
  146. package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
  147. package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
  148. package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
  149. package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
  150. package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
  151. package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
  152. package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
  153. package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
  154. package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
  155. package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
  156. package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
  157. package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
  158. package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
  159. package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
  160. package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
  161. package/dist/assets/img/empty.29bed2d.svg +0 -23
  162. package/dist/assets/img/empty_1.0b98af0.svg +0 -11
  163. package/dist/assets/img/examplte_logo.f86535f.svg +0 -1
  164. package/dist/assets/img/external-link.90577cc.svg +0 -1
  165. package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
  166. package/dist/assets/img/ghn.070f8e3.svg +0 -17
  167. package/dist/assets/img/ghtk.326eac1.svg +0 -18
  168. package/dist/assets/img/image_default.be0698b.png +0 -0
  169. package/dist/assets/img/info.ebce7ea.svg +0 -1
  170. package/dist/assets/img/loader.37000a7.svg +0 -1
  171. package/dist/assets/img/loading_static.8f403ae.svg +0 -10
  172. package/dist/assets/img/main-service1.d536cc2.png +0 -0
  173. package/dist/assets/img/main-service2.9b99549.png +0 -0
  174. package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
  175. package/dist/assets/img/package.8d37d0f.svg +0 -5
  176. package/dist/assets/img/package_fade.763c001.svg +0 -1
  177. package/dist/assets/img/rating--average.1ea492c.svg +0 -12
  178. package/dist/assets/img/rating--great.e3d712e.svg +0 -16
  179. package/dist/assets/img/rating--poor.2938a25.svg +0 -12
  180. package/dist/assets/img/search.f9705ff.svg +0 -1
  181. package/dist/assets/img/send.6db52a9.svg +0 -3
  182. package/dist/assets/img/shop.f7dc7d8.svg +0 -1
  183. package/dist/assets/img/shop_faded.df7845a.svg +0 -1
  184. package/dist/assets/img/subiz-mono.877e9f5.svg +0 -3
  185. package/dist/assets/img/x.26fdfa3.svg +0 -5
  186. package/dist/c41606bf9d1b604e46d5.png +0 -1
  187. package/dist/ce1f7450ce6c1aacd330.png +0 -1
  188. package/dist/cf8c01e88f4770a6e3e5.png +0 -1
  189. package/dist/dfbcfeab1d5622a737e2.png +0 -1
  190. package/dist/e4893ed8c2f7b8329919.png +0 -1
  191. package/dist/ec2ab4eb4ef73d186186.png +0 -1
  192. package/dist/malicious-app.js +0 -13
  193. package/dist/screenshoot.html +0 -7
  194. package/dist/screenshoot.js +0 -5919
@@ -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,40 +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
- const INTEGRATION_ID = _index.default.getIntegrationId(user.account_id);
655
-
656
546
  let cid = _index.default.convoOfEv(ev);
657
-
658
547
  let convo;
659
-
660
548
  if (cid) {
661
549
  convo = this.matchConvo(cid);
662
-
663
550
  if (!convo || !convo.id) {
664
551
  let {
665
552
  body: apiconvo,
@@ -669,61 +556,45 @@ class Store {
669
556
  convo = apiconvo;
670
557
  }
671
558
  }
672
-
673
559
  if (!convo) return;
674
560
 
675
- let integrationId = _index.default.get(convo, 'integration.id', '');
676
-
677
- if (!integrationId) integrationId = _index.default.get(ev, 'data.message.integration_id', '');
678
- if (!integrationId || integrationId !== INTEGRATION_ID) return;
561
+ let channel = _index.default.get(ev, 'touchpoint.channel', '');
562
+ if (channel && channel != 'subiz') return;
679
563
  this.pubsub.publish('events', ev);
680
564
 
681
565
  if (ev.type === 'conversation_joined') {
682
566
  let members = _index.default.get(ev, 'data.conversation.members', []);
683
-
684
567
  let me = _index.default.find(members, m => m.id === this.kv.match('user').id);
685
-
686
568
  if (me) {
687
569
  await this.chain.reload(cid, (type, anchor, limit) => this.listmessageapi(type, anchor, limit));
688
570
  this.markSync('events' + cid);
689
571
  let {
690
572
  body: apiconvo
691
573
  } = await this.api.getConversation(cid);
692
-
693
574
  if (apiconvo) {
694
575
  convo = apiconvo;
695
-
696
576
  this._setConvo(convo);
697
577
  }
698
-
699
578
  this.pubsub.publish('account');
700
579
  }
701
580
  }
702
-
703
581
  if (ev.type === 'message_sent') {
704
582
  if (_index.default.get(ev, 'by.id') !== user.id) {
705
583
  this.api.markAsReceived(cid, ev.id);
706
584
  }
707
585
  }
708
-
709
586
  if (_index.default.startsWith(ev.type, 'message_') || _index.default.startsWith(ev.type, 'conversation_')) {
710
587
  this.restConvoEvent(ev);
711
-
712
588
  if (ev.type === 'message_sent' && _index.default.get(ev, 'by.id') !== user.id) {
713
589
  sendEventToThirdParty('SUBIZ Chat', 'Received', 'User');
714
590
  }
715
-
716
591
  return;
717
592
  }
718
593
  }
719
-
720
594
  async restConvoEvent(ev) {
721
595
  let user = this.kv.match('user');
722
-
723
596
  let cid = _index.default.convoOfEv(ev);
724
-
725
597
  let convo = this.cache.match('convo_' + cid) || {};
726
-
727
598
  if (ev.type === 'conversation_state_updated') {
728
599
  if (!_index.default.get(convo, 'id')) {
729
600
  let {
@@ -732,68 +603,50 @@ class Store {
732
603
  } = await this.api.getConversation(cid);
733
604
  if (error) return;
734
605
  }
735
-
736
606
  convo = Object.assign(convo, _index.default.get(ev, 'data.conversation'));
737
607
  }
738
-
739
608
  if (ev.type === 'message_pong') {
740
609
  var msgid = _index.default.get(ev, 'data.message.id');
741
-
742
610
  var oldev = this.chain.match(cid, msgid);
743
611
  if (!_index.default.get(oldev, 'data.message')) return;
744
-
745
612
  var pongs = _index.default.get(oldev, 'data.message.pongs', []);
746
-
747
613
  pongs = pongs.concat(_index.default.get(ev, 'data.message.pongs', []));
748
614
  oldev.data.message.pongs = pongs;
749
-
750
615
  _index.default.map(pongs, pong => {
751
616
  if (pong.member_id == user.id && pong.type === 'seen') {
752
617
  let mem = _index.default.find(convo.members, mem => mem.id === user.id);
753
-
754
618
  if (mem) mem.seen_at = pong.created;
755
619
  }
756
620
  });
757
-
758
621
  this.chain.put(cid, oldev.id, _index.default.getMs(oldev.created), oldev);
759
622
  }
760
-
761
623
  if (ev.type === 'message_sent') {
762
624
  let idemkey = _index.default.getMsgField(ev, 'idempotency');
763
-
764
625
  let found = _index.default.find(this.listEvents(cid), oldev => oldev.id === idemkey);
765
-
766
626
  if (found) {
767
627
  this.chain.del(cid, found.id);
768
628
  ev.created = found.created;
769
629
  }
770
-
771
630
  convo.last_message_sent = ev;
772
631
  }
773
632
 
774
633
  if (ev.type !== 'message_pong' && ev.type !== 'conversation_typing') {
775
634
  this.chain.put(cid, ev.id, _index.default.getMs(ev.created), ev);
776
635
  }
777
-
778
636
  this._setConvo(convo);
779
-
780
637
  this.pubsub.publish('account');
781
638
  }
782
-
783
639
  handleFormSubmit(convoKey, ev) {
784
640
  if (ev.type !== 'message_sent') return;
785
641
  let formSubmits = [];
786
642
  let attachments = _index.default.get(ev, 'data.message.attachments') || [];
787
-
788
643
  _index.default.each(attachments, att => {
789
644
  if (!att) return;
790
645
  if (att.type !== 'form_submit') return;
791
646
  formSubmits.push(att.form_submit);
792
647
  });
793
-
794
648
  _index.default.each(formSubmits, submit => {
795
649
  let formev = _index.default.get(this.convoEventM, convoKey + '.' + submit.form_message_id);
796
-
797
650
  if (!formev) return;
798
651
 
799
652
  let forms = _index.default.filter(_index.default.get(formev, 'data.message.attachments'), att => {
@@ -801,10 +654,8 @@ class Store {
801
654
  if (att.type !== 'form' && att.type !== 'ask_info_form') return false;
802
655
  return true;
803
656
  });
804
-
805
657
  _index.default.each(forms, form => {
806
658
  form = form.form;
807
-
808
659
  _index.default.each(form.fields, formfield => {
809
660
  _index.default.each(submit.fields, submitfield => {
810
661
  if (formfield.name !== submitfield.name) return;
@@ -813,17 +664,13 @@ class Store {
813
664
  });
814
665
  });
815
666
  });
816
-
817
667
  if (_index.default.size(forms) > 0) this.pubsub.publish('state.convoEventM', this.convoEventM, convoKey);
818
668
  });
819
669
  }
820
-
821
670
  typing(cid) {
822
671
  if (!cid) return;
823
-
824
672
  this._typing(cid);
825
673
  }
826
-
827
674
  async startConvo(req) {
828
675
  await this.readyGate.entry();
829
676
  this.convoGate.close();
@@ -836,31 +683,23 @@ class Store {
836
683
  if (error) return {
837
684
  error
838
685
  };
839
-
840
686
  this._setConvo(convo);
841
-
842
687
  return {
843
688
  convo
844
689
  };
845
690
  }
846
-
847
691
  fetchOrder(id) {
848
692
  return this.api.getOrder(id);
849
693
  }
850
-
851
694
  lookupOrder(key) {
852
695
  return this.api.lookupOrder(key);
853
696
  }
854
-
855
697
  createPostback(cid, postback) {
856
698
  return this.api.createPostback(cid, postback);
857
699
  }
858
-
859
700
  async sendConvoEvent(cid, type, data) {
860
701
  await this.readyGate.entry();
861
-
862
702
  var idempotency = _index.default.randomString(36);
863
-
864
703
  let user = this.kv.match('user') || {};
865
704
  var event = {
866
705
  id: idempotency,
@@ -873,28 +712,24 @@ class Store {
873
712
  type,
874
713
  created: this.now()
875
714
  };
876
-
877
715
  _index.default.convoToEv(cid, event);
878
-
879
716
  let files = [];
880
-
881
717
  if (type === 'message_sent') {
882
718
  _index.default.setMsgField(event, 'idempotency', idempotency);
883
-
884
719
  event.data.message.conversation_id = cid;
720
+
885
721
  await flow.map(event.data.message.attachments, 2, async (att, i) => {
886
722
  if (att.type !== 'file') return;
887
723
  if (!att._file) return;
888
724
  files.push(att);
889
-
890
725
  if (ImageTypes.includes(att._file.type)) {
891
726
  att.url = await loadImage(att._file);
892
727
  }
893
728
  });
894
729
  }
895
-
896
730
  this.onWs(event);
897
731
  await this.convoGate.entry();
732
+
898
733
  await flow.map(files, 1, async att => {
899
734
  const {
900
735
  url,
@@ -908,17 +743,14 @@ class Store {
908
743
  body: ret,
909
744
  error
910
745
  } = await this.api.sendConvoEvent(cid, event);
911
-
912
746
  if (error) {
913
747
  event._error = error;
914
748
  this.onWs(event);
915
749
  return;
916
750
  }
917
-
918
751
  this.onWs(ret);
919
752
  sendEventToThirdParty('SUBIZ Chat', 'Sent', 'User');
920
753
  let lastMsgSent = this.kv.match('last_msg_sent');
921
-
922
754
  if (!lastMsgSent) {
923
755
  let dataLayer = window.dataLayer || [];
924
756
  dataLayer.push({
@@ -928,52 +760,40 @@ class Store {
928
760
  first_interaction: 1
929
761
  });
930
762
  }
931
-
932
763
  this.kv.put('last_msg_sent', _index.default.Date.now());
933
764
  return ret;
934
765
  }
935
-
936
766
  _setConvo(convo) {
937
767
  let count = 0;
938
- let user = this.kv.match('user');
939
-
940
- const INTEGRATION_ID = _index.default.getIntegrationId(user.account_id);
941
768
 
942
- let integrationId = _index.default.get(convo, 'integration.id', '');
943
-
944
- if (!integrationId || integrationId !== INTEGRATION_ID) return;
769
+ let user = this.kv.match('user');
770
+ let channel = _index.default.get(convo, 'touchpoint.channel', '');
771
+ if (channel && channel != 'subiz') return;
945
772
  let allconvo = {};
946
-
947
773
  _index.default.map(this.cache.all(), (value, key) => {
948
774
  if (key.startsWith('convo_')) {
949
775
  allconvo[key] = value;
950
776
  }
951
777
  });
952
-
953
778
  if (_index.default.size(allconvo) > MAX_CONVO - 2) {
954
779
  allconvo = _index.default.orderBy(_index.default.map(allconvo), 'created', 'desc');
955
-
956
780
  for (var i = MAX_CONVO - 2; i < _index.default.size(allconvo); i++) {
957
781
  let convo = allconvo[i];
958
782
  this.cache.del('convo_' + convo.id);
959
783
  }
960
784
  }
961
-
962
785
  this.markSync(convo.id);
963
786
  this.pubsub.publish('account');
964
787
  this.cache.put('convo_' + convo.id, convo);
965
788
  }
966
-
967
789
  matchLastPluginRun(pluginid) {
968
790
  let log = this.kv.match('plugin_run_logs') || {};
969
791
  return log[pluginid];
970
792
  }
971
-
972
793
  matchLastBotRun(botid) {
973
794
  let log = this.kv.match('bot_run_logs') || {};
974
795
  return log[botid];
975
796
  }
976
-
977
797
  logBotRun(botid) {
978
798
  let log = this.kv.match('bot_run_logs') || {};
979
799
  log[botid] = {
@@ -982,7 +802,6 @@ class Store {
982
802
  };
983
803
  this.kv.put('bot_run_logs', log);
984
804
  }
985
-
986
805
  sendImpression(id) {
987
806
  let user = this.kv.match('user') || {};
988
807
  let log = this.kv.match('plugin_run_logs') || {};
@@ -1000,7 +819,6 @@ class Store {
1000
819
  device: this.device
1001
820
  });
1002
821
  }
1003
-
1004
822
  sendConversion(id, fields, impressionToken) {
1005
823
  let user = this.kv.match('user') || {};
1006
824
  let submission = {
@@ -1022,12 +840,10 @@ class Store {
1022
840
  impression_token: impressionToken
1023
841
  });
1024
842
  }
1025
-
1026
843
  isConverted(id) {
1027
844
  let conv = this.kv.match('conversions') || {};
1028
845
  return conv[id];
1029
846
  }
1030
-
1031
847
  async listmessageapi(type, anchor, limit) {
1032
848
  let convoid = type;
1033
849
  let {
@@ -1045,23 +861,19 @@ class Store {
1045
861
  value: event
1046
862
  };
1047
863
  });
1048
- let user = this.kv.match('user') || {};
1049
864
 
865
+ let user = this.kv.match('user') || {};
1050
866
  for (let i = 0; i < events.length; i++) {
1051
867
  let ev = events[i].value;
1052
868
  if (ev.type !== 'message_sent') continue;
1053
869
  if (_index.default.get(ev, 'by.id') === user.id) continue;
1054
-
1055
870
  let pongbyme = _index.default.find(_index.default.get(ev, 'data.message.pongs'), p => p.member_id === user.id);
1056
-
1057
871
  if (pongbyme) break;
1058
872
  this.api.markAsReceived(convoid, ev.id);
1059
873
  break;
1060
874
  }
1061
-
1062
875
  return [events, anchor];
1063
876
  }
1064
-
1065
877
  async loopTime() {
1066
878
  let startms = _index.default.Date.now();
1067
879
 
@@ -1073,22 +885,17 @@ class Store {
1073
885
  if (error) return setTimeout(() => this.loopTime(), 30000);
1074
886
  var latences = Math.abs(_index.default.Date.now() - startms) / 2;
1075
887
  var serverMs = new _index.default.Date(t).getTime() + latences;
1076
-
1077
888
  var localMs = _index.default.Date.now();
1078
-
1079
889
  this.timeDiff = Math.floor(serverMs - localMs);
1080
890
  setTimeout(() => this.loopTime(), 240000);
1081
891
  }
1082
-
1083
892
  replaceFileUrl(src) {
1084
893
  if (!src) return '';
1085
894
  if (_index.default.startsWith(src, '/')) return src;
1086
895
  if (_index.default.startsWith(src, 'data:')) return src;
1087
-
1088
896
  if (!_index.default.startsWith(src, 'http://') && !_index.default.startsWith(src, 'https://') && !_index.default.startsWith(src, '//')) {
1089
897
  src = _index.default.trim(this.FileURL, '/') + '/' + _index.default.trimStart(src, '/');
1090
898
  }
1091
-
1092
899
  src = src.replace('https://file-subiz.com/', this.FileURL);
1093
900
  src = src.replace('http://file-subiz.com/', this.FileURL);
1094
901
  src = src.replace('https://file-v4.subiz.com/', this.FileURL);
@@ -1103,33 +910,26 @@ class Store {
1103
910
  src = src.replace('http://file.mysubiz.com/', this.FileURL);
1104
911
  return src;
1105
912
  }
1106
-
1107
913
  clearBrowserData() {
1108
914
  _index.default.each(this.cookie.all(), (v, k) => {
1109
915
  if ((k || '').startsWith('__sb')) this.cookie.remove(k);
1110
916
  });
1111
-
1112
917
  this.kv.destroy();
1113
918
  this.kv = new _storage.default.kv(new _storage.default.lsdb('sbz2020', this.inmem), 'kv');
1114
919
  this.chain.destroy();
1115
920
  this.chain = new _storage.default.chain(new _storage.default.lsdb('cbz2020', true), 'ch');
1116
921
  }
1117
-
1118
922
  destroy() {
1119
923
  this._die = true;
1120
924
  this.clearBrowserData();
1121
925
  if (this.realtime) this.realtime.stop();
1122
926
  this.readyGate.close();
1123
927
  }
1124
-
1125
928
  }
1126
-
1127
929
  exports.default = Store;
1128
-
1129
930
  function loadImage(file) {
1130
931
  return new Promise(rs => {
1131
932
  var reader = new window.FileReader();
1132
-
1133
933
  reader.onload = e => {
1134
934
  rs(e.target.result);
1135
935
  };
@@ -1137,13 +937,13 @@ function loadImage(file) {
1137
937
  reader.readAsDataURL(file);
1138
938
  });
1139
939
  }
1140
-
1141
940
  const ImageTypes = ['image/gif', 'image/jpeg', 'image/png', 'image/svg+xml'];
1142
-
1143
941
  function onVisibilityChange(cb) {
1144
942
  var hidden = 'hidden';
1145
- 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;
1146
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;
1147
947
  function onchange(evt) {
1148
948
  var v = 'visible';
1149
949
  var h = 'hidden';
@@ -1163,26 +963,20 @@ function onVisibilityChange(cb) {
1163
963
  type: document[hidden] ? 'blur' : 'focus'
1164
964
  });
1165
965
  }
1166
-
1167
966
  const inmemCookie = {
1168
967
  data: {},
1169
-
1170
968
  get(k, def) {
1171
969
  return this.data[k] || def;
1172
970
  },
1173
-
1174
971
  set(k, v) {
1175
972
  return this.data[k] = k;
1176
973
  },
1177
-
1178
974
  all() {
1179
975
  return this.data;
1180
976
  },
1181
-
1182
977
  remove(k) {
1183
978
  delete this.data[k];
1184
979
  }
1185
-
1186
980
  };
1187
981
 
1188
982
  function getGaClientId() {
@@ -1208,7 +1002,6 @@ function getGaTrackingIds() {
1208
1002
  });
1209
1003
  return trackingIds;
1210
1004
  }
1211
-
1212
1005
  function sendToFBPixel(category, action, label) {
1213
1006
  if (!window.fbq) return;
1214
1007
  window.fbq('trackCustom', category, {
@@ -1216,13 +1009,11 @@ function sendToFBPixel(category, action, label) {
1216
1009
  label: label
1217
1010
  });
1218
1011
  }
1219
-
1220
1012
  function sendToGA(category, action, label) {
1221
1013
  if (window.gtag) window.gtag('event', category, {
1222
1014
  Action: action,
1223
1015
  Label: label
1224
1016
  });
1225
-
1226
1017
  if (window.ga && window.ga.getAll) {
1227
1018
  const allTrackers = window.ga.getAll() || [];
1228
1019
  allTrackers.forEach(function (tracker) {
@@ -1231,7 +1022,6 @@ function sendToGA(category, action, label) {
1231
1022
  });
1232
1023
  }
1233
1024
  }
1234
-
1235
1025
  function sendEventToThirdParty(category, action, label) {
1236
1026
  document.dispatchEvent(new CustomEvent('subiz', {
1237
1027
  detail: {
@@ -1253,5 +1043,4 @@ function sendEventToThirdParty(category, action, label) {
1253
1043
  let mobileCheck = function (a) {
1254
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));
1255
1045
  }(navigator.userAgent || navigator.vendor || window.opera);
1256
-
1257
1046
  let tabletCheck = /(ipad|tablet|(android(?!.*mobile))|(windows(?!.*phone)(.*touch))|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP))))/.test(navigator.userAgent);