@subiz/widget-v4 4.1.209 → 4.1.211

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 (137) hide show
  1. package/README.md +21 -2
  2. package/assets/less/chatbox.less +9 -0
  3. package/assets/less/form.less +10 -0
  4. package/assets/less/message.less +114 -13
  5. package/assets/less/widget.less +21 -16
  6. package/compiled_src/call/css.js +1 -1
  7. package/compiled_src/chatbox/Buttons.js +7 -4
  8. package/compiled_src/chatbox/ChatButton.js +115 -29
  9. package/compiled_src/chatbox/Event.js +37 -5
  10. package/compiled_src/chatbox/Events.js +348 -129
  11. package/compiled_src/chatbox/FormAttachment.js +1 -1
  12. package/compiled_src/chatbox/Header.js +6 -2
  13. package/compiled_src/chatbox/InfoMessage.js +1 -1
  14. package/compiled_src/chatbox/MessageInput.js +24 -9
  15. package/compiled_src/chatbox/OrderAttachments.js +13 -13
  16. package/compiled_src/chatbox/QuoteMessage.js +3 -2
  17. package/compiled_src/chatbox/TextMessage.js +22 -18
  18. package/compiled_src/chatbox/Widget.js +200 -129
  19. package/compiled_src/chatbox/block.js +39 -29
  20. package/compiled_src/chatbox/conversation-history.js +44 -0
  21. package/compiled_src/chatbox/event-layout.js +59 -0
  22. package/compiled_src/chatbox/greeting.js +32 -0
  23. package/compiled_src/common.js +13 -9
  24. package/compiled_src/form/css.js +1 -1
  25. package/compiled_src/lib.js +22 -32
  26. package/compiled_src/notif/css.js +1 -1
  27. package/compiled_src/plugin.js +11 -18
  28. package/compiled_src/popup/css.js +1 -1
  29. package/compiled_src/popup/popup.js +1 -1
  30. package/compiled_src/store/api.js +0 -2
  31. package/compiled_src/store/api_fake.js +1 -1
  32. package/compiled_src/store/attachments.js +28 -0
  33. package/compiled_src/store/chain.js +24 -10
  34. package/compiled_src/store/kv.js +9 -13
  35. package/compiled_src/store/lsdb.js +1 -1
  36. package/compiled_src/store/store.js +356 -117
  37. package/compiled_src/util/common.js +48 -41
  38. package/compiled_src/util/event.js +15 -0
  39. package/compiled_src/util/pubsub.js +28 -13
  40. package/compiled_src/util/url.js +18 -0
  41. package/dist/.HASH +1 -0
  42. package/dist/127.js +13 -13
  43. package/dist/132.js +1 -1
  44. package/dist/1a0ddc53cbb.127.js +1 -0
  45. package/dist/{1a08405c848.132.js → 1a0ddc53cbb.132.js} +1 -1
  46. package/dist/{1a08405c848.27.js → 1a0ddc53cbb.27.js} +1 -1
  47. package/dist/1a0ddc53cbb.278.js +1 -0
  48. package/dist/{1a08405c848.339.js → 1a0ddc53cbb.339.js} +1 -1
  49. package/dist/1a0ddc53cbb.459.js +1 -0
  50. package/dist/1a0ddc53cbb.app.js +1 -0
  51. package/dist/1a0ddc53cbb.chat.html +1 -0
  52. package/dist/1a0ddc53cbb.chat.js +1 -0
  53. package/dist/1a0ddc53cbb.form.html +1 -0
  54. package/dist/1a0ddc53cbb.form.js +1 -0
  55. package/dist/1a0ddc53cbb.index.html +72 -0
  56. package/dist/1a0ddc53cbb.library.html +72 -0
  57. package/dist/1a0ddc53cbb.library.js +1 -0
  58. package/dist/1a0ddc53cbb.preview.html +759 -0
  59. package/dist/1a0ddc53cbb.preview.js +1 -0
  60. package/dist/1a0ddc53cbb.webview.js +1 -0
  61. package/dist/27.js +4 -4
  62. package/dist/459.js +4 -4
  63. package/dist/screenshoot.js +1523 -654
  64. package/package.json +10 -3
  65. package/src/call/css.js +1 -1
  66. package/src/chatbox/Buttons.js +5 -4
  67. package/src/chatbox/ChatButton.js +120 -39
  68. package/src/chatbox/Event.js +38 -5
  69. package/src/chatbox/Events.js +306 -134
  70. package/src/chatbox/FormAttachment.js +1 -1
  71. package/src/chatbox/Header.js +4 -4
  72. package/src/chatbox/InfoMessage.js +1 -1
  73. package/src/chatbox/MessageInput.js +15 -10
  74. package/src/chatbox/OrderAttachments.js +13 -13
  75. package/src/chatbox/QuoteMessage.js +3 -2
  76. package/src/chatbox/TextMessage.js +21 -20
  77. package/src/chatbox/Widget.js +150 -150
  78. package/src/chatbox/block.js +29 -27
  79. package/src/chatbox/conversation-history.js +37 -0
  80. package/src/chatbox/event-layout.js +72 -0
  81. package/src/chatbox/greeting.js +13 -0
  82. package/src/common.js +15 -9
  83. package/src/form/css.js +1 -1
  84. package/src/lib.js +22 -35
  85. package/src/notif/css.js +1 -1
  86. package/src/plugin.js +11 -13
  87. package/src/popup/css.js +1 -1
  88. package/src/popup/popup.js +1 -1
  89. package/src/store/api.js +0 -2
  90. package/src/store/api_fake.js +1 -1
  91. package/src/store/attachments.js +21 -0
  92. package/src/store/chain.js +25 -12
  93. package/src/store/kv.js +10 -19
  94. package/src/store/lsdb.js +1 -1
  95. package/src/store/store.js +313 -130
  96. package/src/util/common.js +48 -43
  97. package/src/util/event.js +7 -0
  98. package/src/util/pubsub.js +27 -8
  99. package/src/util/url.js +14 -0
  100. package/test.cjs +59 -0
  101. package/webpack.prod.js +3 -0
  102. package/assets/less/contact.less +0 -126
  103. package/compiled_src/util/common.test.js +0 -414
  104. package/compiled_src/util/event.test.js +0 -38
  105. package/compiled_src/util/extractor.test.js +0 -299
  106. package/compiled_src/util/extractor.test2.js +0 -61
  107. package/compiled_src/util/gate.test.js +0 -18
  108. package/compiled_src/util/pubsub.test.js +0 -35
  109. package/dist/1a08405c848.127.js +0 -1
  110. package/dist/1a08405c848.278.js +0 -1
  111. package/dist/1a08405c848.459.js +0 -1
  112. package/dist/1a08405c848.74.js +0 -1
  113. package/dist/1a08405c848.997.js +0 -1
  114. package/dist/1a08405c848.app.js +0 -1
  115. package/dist/1a08405c848.chat.html +0 -1
  116. package/dist/1a08405c848.chat.js +0 -1
  117. package/dist/1a08405c848.form.html +0 -1
  118. package/dist/1a08405c848.form.js +0 -1
  119. package/dist/1a08405c848.index.html +0 -1
  120. package/dist/1a08405c848.library.html +0 -1
  121. package/dist/1a08405c848.library.js +0 -1
  122. package/dist/1a08405c848.preview.html +0 -1
  123. package/dist/1a08405c848.preview.js +0 -1
  124. package/dist/1a08405c848.webview.js +0 -1
  125. package/dist/74.js +0 -376
  126. package/dist/997.js +0 -37
  127. package/dist/HASH +0 -1
  128. package/src/contact/contact.js +0 -400
  129. package/src/contact/css.js +0 -1
  130. package/src/util/common.test.js +0 -301
  131. package/src/util/event.test.js +0 -31
  132. package/src/util/extractor.test.js +0 -240
  133. package/src/util/extractor.test2.js +0 -56
  134. package/src/util/gate.test.js +0 -20
  135. package/src/util/pubsub.test.js +0 -37
  136. /package/dist/{1a08405c848.185.js → 1a0ddc53cbb.185.js} +0 -0
  137. /package/dist/{1a08405c848.490.js → 1a0ddc53cbb.490.js} +0 -0
@@ -1,400 +0,0 @@
1
- import sb from '../util/index.js'
2
- import {render, h, createRef} from 'preact'
3
- import {Com} from '../common.js'
4
- // var Color = require('color')
5
- // import {Loader} from '@googlemaps/js-api-loader'
6
-
7
- let CSS = (() => import(/*webpackChunkName: "contact-css" */ './css.js'))()
8
-
9
- // props: ['mobile', 'plugin', 'frame', 'select'],
10
- export default class Contact extends Com {
11
- state = {
12
- map: false,
13
- map_loading: false,
14
- map_initialized: false,
15
- }
16
-
17
- constructor(props) {
18
- super(props)
19
-
20
- this.showMap = this.showMap.bind(this)
21
- this.hideMap = this.hideMap.bind(this)
22
- }
23
-
24
- async initMap() {
25
- if (this.map_initialized) return
26
- this.setState({map_initialized: true, map_loading: true})
27
- await new Loader({apiKey: 'YOUR_API_KEY', version: 'weekly'}).load()
28
- this.gmap = new google.maps.Map(document.getElementById('map'))
29
- this.setState({map_loading: false})
30
- }
31
-
32
- js2css(js, onlyProps) {
33
- return sb.js2css(js, onlyProps, {
34
- '@font_size': this.props.plugin.popup.font_size,
35
- '@font_family': this.props.plugin.popup.font_family,
36
- '@text_color': this.props.plugin.popup.text_color,
37
- '@primary_color': this.props.plugin.popup.primary_color,
38
- '@background': this.props.plugin.popup.background,
39
- '@spacer0': spacer / 2 + 'px',
40
- '@spacer': spacer + 'px',
41
- '@spacer2': spacer * 2 + 'px',
42
- '@spacer3': spacer * 3 + 'px',
43
- })
44
- }
45
-
46
- renderMapButton(button) {
47
- let icon = (
48
- <svg
49
- width="20px"
50
- aria-hidden="true"
51
- focusable="false"
52
- data-prefix="fas"
53
- data-icon="map-marker-alt"
54
- role="img"
55
- xmlns="http://www.w3.org/2000/svg"
56
- viewBox="0 0 384 512"
57
- class="svg-inline--fa fa-map-marker-alt fa-w-12 fa-3x">
58
- <path
59
- fill="red"
60
- d="M172.268 501.67C26.97 291.031 0 269.413 0 192 0 85.961 85.961 0 192 0s192 85.961 192 192c0 77.413-26.97 99.031-172.268 309.67-9.535 13.774-29.93 13.773-39.464 0zM192 272c44.183 0 80-35.817 80-80s-35.817-80-80-80-80 35.817-80 80 35.817 80 80 80z"
61
- class=""></path>
62
- </svg>
63
- )
64
-
65
- return (
66
- <div class="contact_button" onClick={this.showMap}>
67
- {this.renderMapModal(button)}
68
- {icon}
69
- </div>
70
- )
71
- }
72
-
73
- async setMap(lat, lng) {
74
- console.log('HEE')
75
- await this.initMap()
76
- console.log('HEE22')
77
- window.gmap = this.gmap
78
- this.gmap.map.setCenter(new google.maps.LatLng(lat, lng))
79
- }
80
-
81
- renderMapModal(button) {
82
- let cls = 'map_modal'
83
- if (this.state.map) cls += ' map_modal__show'
84
- else cls += ' map_modal__hide'
85
-
86
- let overlaycls = 'overlay'
87
- if (!this.state.map) overlaycls += ' overlay__hidden'
88
-
89
- let $locations = sb.map(button.map.locations, loc => {
90
- return (
91
- <div class="map_location" onClick={e => this.setMap(loc.latitude, loc.longitude)}>
92
- <div>{loc.name}</div>
93
- <div>{loc.latitude}</div>
94
- <div>{loc.longitude}</div>
95
- </div>
96
- )
97
- })
98
-
99
- $locations.unshift(<div class="map_title">{button.map.title}</div>)
100
-
101
- let $map = (
102
- <div id="map" style="height: 100%; width: 100%">
103
- {' '}
104
- </div>
105
- )
106
- return (
107
- <div class={overlaycls} onClick={this.hideMap}>
108
- <div class={cls} onClick={e => e.stopPropagation()}>
109
- <div class="map_body">
110
- <div class="map_locations">{$locations}</div>
111
- {$map}
112
-
113
- <div class="mapouter">
114
- <div class="gmap_canvas">
115
- <iframe
116
- width="300"
117
- height="400"
118
- id="gmap_canvas"
119
- src="https://maps.google.com/maps?q=2880%20Broadway,%20New%20York&t=&z=13&ie=UTF8&iwloc=&output=embed"
120
- frameborder="0"
121
- scrolling="no"
122
- marginheight="0"
123
- marginwidth="0"></iframe>
124
- </div>
125
- </div>
126
- </div>
127
- </div>
128
- </div>
129
- )
130
- }
131
-
132
- hideMap(e) {
133
- e.stopPropagation()
134
- this.setState({map: false})
135
- }
136
-
137
- showMap() {
138
- this.setState({map: true})
139
- }
140
-
141
- renderZaloButton(button) {
142
- let icon = (
143
- <svg
144
- width="20px "
145
- aria-hidden="true"
146
- focusable="false"
147
- data-prefix="fab"
148
- data-icon="facebook-f"
149
- role="img"
150
- xmlns="http://www.w3.org/2000/svg"
151
- viewBox="0 0 320 512"
152
- class="svg-inline--fa fa-facebook-f fa-w-10 fa-5x">
153
- <path
154
- fill="currentColor"
155
- d="M279.14 288l14.22-92.66h-88.91v-60.13c0-25.35 12.42-50.06 52.24-50.06h40.42V6.26S260.43 0 225.36 0c-73.22 0-121.08 44.38-121.08 124.72v70.62H22.89V288h81.39v224h100.17V288z"
156
- class=""></path>
157
- </svg>
158
- )
159
- return <div class="contact_button">{icon}</div>
160
- }
161
-
162
- renderFacebookButton(button) {
163
- let icon = (
164
- <svg
165
- width="20px "
166
- aria-hidden="true"
167
- focusable="false"
168
- data-prefix="fab"
169
- data-icon="facebook-f"
170
- role="img"
171
- xmlns="http://www.w3.org/2000/svg"
172
- viewBox="0 0 320 512"
173
- class="svg-inline--fa fa-facebook-f fa-w-10 fa-5x">
174
- <path
175
- fill="currentColor"
176
- d="M279.14 288l14.22-92.66h-88.91v-60.13c0-25.35 12.42-50.06 52.24-50.06h40.42V6.26S260.43 0 225.36 0c-73.22 0-121.08 44.38-121.08 124.72v70.62H22.89V288h81.39v224h100.17V288z"
177
- class=""></path>
178
- </svg>
179
- )
180
- return <div class="contact_button">{icon}</div>
181
- }
182
-
183
- renderChatButton() {
184
- return <div>Chat</div>
185
- }
186
-
187
- renderCallButton() {
188
- let icon = (
189
- <svg
190
- width="20px"
191
- aria-hidden="true"
192
- focusable="false"
193
- data-prefix="fas"
194
- data-icon="phone"
195
- role="img"
196
- xmlns="http://www.w3.org/2000/svg"
197
- viewBox="0 0 512 512"
198
- class="svg-inline--fa fa-phone fa-w-16 fa-7x">
199
- <path
200
- fill="currentColor"
201
- d="M493.4 24.6l-104-24c-11.3-2.6-22.9 3.3-27.5 13.9l-48 112c-4.2 9.8-1.4 21.3 6.9 28l60.6 49.6c-36 76.7-98.9 140.5-177.2 177.2l-49.6-60.6c-6.8-8.3-18.2-11.1-28-6.9l-112 48C3.9 366.5-2 378.1.6 389.4l24 104C27.1 504.2 36.7 512 48 512c256.1 0 464-207.5 464-464 0-11.2-7.7-20.9-18.6-23.4z"
202
- class=""></path>
203
- </svg>
204
- )
205
-
206
- return <div>{icon}</div>
207
- }
208
-
209
- // default render for component
210
- renderButtons(buttons) {
211
- if (sb.size(buttons) === 0) return null
212
-
213
- return sb.map(buttons, button => {
214
- if (button.type === 'map') return this.renderMapButton(button)
215
- if (button.type === 'zalo') return this.renderZaloButton(button)
216
- if (button.type === 'facebook') return this.renderFacebookButton(button)
217
- if (button.type === 'call') return this.renderCallButton(button)
218
- if (button.type === 'chat') return this.renderChatButton(button)
219
- return null
220
- })
221
- }
222
-
223
- renderByLayoutSideByStandard() {
224
- let $buttons = this.renderButtons(this.props.plugin.contact.buttons)
225
- return <div>{$buttons}</div>
226
- }
227
-
228
- renderLineComponent(com) {
229
- let style = Object.assign({}, com.style, this.props.mobile ? com.mobile_style : {})
230
- return <div style={this.js2css(style)}></div>
231
- }
232
-
233
- renderTextComponent(com) {
234
- let style = Object.assign({}, com.style, this.props.mobile ? com.mobile_style : {})
235
- return (
236
- <div class="text" style={this.js2css(style)} dangerouslySetInnerHTML={{__html: sb.get(com, 'text.html')}}></div>
237
- )
238
- }
239
-
240
- async refreshCSS() {
241
- let css = (await CSS).default.default.toString()
242
-
243
- var outcss = replaceCssVariable(css, this.props.plugin.popup)
244
- sb.setCss(this.props.plugin.id, this.$cssStyleDiv, outcss)
245
- this.setState({cssready: true})
246
- }
247
-
248
- componentDidMount() {
249
- this.$cssStyleDiv = document.createElement('style')
250
- document.head.appendChild(this.$cssStyleDiv)
251
- this.$cssStyleDiv.type = 'text/css'
252
- this.$cssStyleDiv.id = 'subiz-style-for-' + this.props.plugin.id
253
-
254
- this.refreshCSS()
255
- let pluginstringify = JSON.stringify(this.props.plugin)
256
- this.setState({pluginjson: pluginstringify})
257
- }
258
-
259
- render() {
260
- if (!this.state.cssready) return null
261
- let pluginstringify = JSON.stringify(this.props.plugin)
262
-
263
- if (this.state.pluginjson !== pluginstringify) {
264
- this.refreshCSS()
265
- sb.setTimeout(() => this.setState({pluginjson: pluginstringify}))
266
- }
267
-
268
- if (this.state.close) return null
269
-
270
- let containercss = ''
271
- let bodycss = ''
272
-
273
- let layout = sb.get(this.props.plugin, 'contact.layout', 'standard')
274
-
275
- let $body = null
276
- if (layout === 'standard' || !layout) {
277
- $body = this.renderByLayoutSideByStandard()
278
- }
279
-
280
- if (layout === 'footer') {
281
- $body = this.renderByLayoutFooter(sb.get(this.props.plugin, `popup.pages.${this.state.pageIndex}`))
282
- }
283
-
284
- if (layout === 'mini') {
285
- $body = this.renderByLayoutMini(sb.get(this.props.plugin, `popup.pages.${this.state.pageIndex}`))
286
- }
287
-
288
- if (layout === 'docked') {
289
- $body = this.renderByLayoutDocked(sb.get(this.props.plugin, `popup.pages.${this.state.pageIndex}`))
290
- }
291
-
292
- let left, right, bottom, top, transform
293
- let position = sb.get(this.props.plugin, 'contact.position', 'bottom-left')
294
-
295
- if (position === 'center-left') {
296
- left = '0'
297
- top = '50%'
298
- transform = 'translateY(-50%)'
299
- } else if (position === 'top-left') {
300
- left = '0'
301
- top = '20px'
302
- } else if (position === 'bottom-right') {
303
- right = '0'
304
- bottom = '20px'
305
- } else if (position === 'center-right') {
306
- right = '0'
307
- top = '50%'
308
- transform = 'translateY(-50%)'
309
- } else if (position === 'top-right') {
310
- right = '0'
311
- top = '20px'
312
- } else {
313
- // default bottom left
314
- left = '0'
315
- bottom = '20px'
316
- }
317
-
318
- return (
319
- <div
320
- style={sb.js2css({
321
- position: 'absolute',
322
- left,
323
- right,
324
- bottom,
325
- top,
326
- transform,
327
- display: 'flex',
328
- align_items: 'center',
329
- justify_content: 'center',
330
- overflow: 'hidden',
331
- })}
332
- onClick={e => e.stopPropagation()}>
333
- {$body}
334
- </div>
335
- )
336
- }
337
- }
338
-
339
- function isEmpty(value) {
340
- return value === undefined || value === null || value === ''
341
- }
342
-
343
- async function runCampaign(byTrigger) {
344
- // only run once per pageview (except for area clicked)
345
- if (ran && byTrigger !== 'area_clicked') return
346
- ran = true
347
-
348
- pageIndex = 0
349
- let page = sb.get(camp, `pages.${pageIndex}`) || {}
350
-
351
- // show page
352
- showPage(page)
353
-
354
- triggerType = byTrigger
355
- let {body: impression} = await store.sendImpression(camp.id, byTrigger)
356
- impressionToken = sb.get(impression, 'impression_token') || ''
357
- }
358
-
359
- function eq(a, b) {
360
- return JSON.stringify(a) === JSON.stringify(b)
361
- }
362
-
363
- export function replaceCssVariable(css, setting) {
364
- // tokenize
365
- var tokens = [css]
366
-
367
- // popup
368
- tokens = sb.tokenize(tokens, "'@font_family'")
369
- tokens = sb.tokenize(tokens, "'@font_size'")
370
- tokens = sb.tokenize(tokens, "'@text_color'")
371
- tokens = sb.tokenize(tokens, "'@primary_color'")
372
- tokens = sb.tokenize(tokens, "'@background'")
373
- tokens = sb.tokenize(tokens, "'@spacer'")
374
- tokens = sb.tokenize(tokens, "'@spacer0'")
375
- tokens = sb.tokenize(tokens, "'@spacer2'")
376
- tokens = sb.tokenize(tokens, "'@spacer3'")
377
-
378
- var ret = []
379
- for (var i = 0; i < tokens.length; i++) {
380
- var item = tokens[i]
381
- if (typeof item === 'string') {
382
- ret.push(item)
383
- continue
384
- }
385
-
386
- // remove @''
387
- var path = item.type.substr(2, item.type.length - 3)
388
- var val = sb.get(setting, path) || sb.get(DEFVAL, path) || ''
389
- ret.push(val)
390
- }
391
-
392
- return ret.join('')
393
- }
394
-
395
- export const DEFVAL = {
396
- font_size: '16px',
397
- font_family: 'roboto',
398
- text_color: '#333',
399
- primary_color: '#333',
400
- }
@@ -1 +0,0 @@
1
- export default require('css-loader!less-loader!../../assets/less/contact.less')
@@ -1,301 +0,0 @@
1
- import {createRequire} from 'module'
2
- const require = createRequire(import.meta.url)
3
- global.require = require
4
- global.XMLHttpRequest = {
5
- prototype: {
6
- open: function () {},
7
- },
8
- }
9
- global.document = {
10
- JSON: JSON,
11
- // document.documentElement.appendChild
12
- // f.contentDocument.createElement
13
- body: {
14
- appendChild: function () {},
15
- },
16
- documentElement: {
17
- appendChild: function () {},
18
- },
19
- createElement: function () {
20
- return {
21
- contentWindow: global,
22
- contentDocument: global.document,
23
- style: {display: false},
24
- }
25
- },
26
- }
27
- const test = require('tape')
28
- const util = require('./common.js')
29
-
30
- test('util.checkUrlCondition', (t) => {
31
- var tcs = [
32
- {
33
- name: 'minvoice',
34
- cond: {
35
- key: 'url',
36
- urls: ['qlhd.minvoice.com.vn'],
37
- exclude_urls: ['minvoice.com.vn', 'minvoice.net', 'hdt.minvoice.com.vn'],
38
- },
39
- href: 'https://qlhd.minvoice.com.vn/#/login',
40
- pass: true,
41
- },
42
- ]
43
-
44
- tcs.map((tc) => {
45
- // if (tc.desc !== 'multiple attachemnts') return
46
- var out = util.checkUrlCondition(tc.cond, tc.href)
47
- t.equal(out, tc.pass)
48
- })
49
- t.end()
50
- })
51
-
52
- test('util.randomString', (t) => {
53
- t.equal(10, util.randomString(10).length)
54
- t.equal(11, util.randomString(11).length)
55
- t.equal(12, util.randomString(12).length)
56
- t.end()
57
- })
58
-
59
- test('replaceCssVariable mobile height', (t) => {
60
- let css = "height: '@mobile_height';"
61
- t.equal(util.replaceCssVariable(css, {}), 'height: 100%;', 'defaults to full mobile height')
62
- t.equal(util.replaceCssVariable(css, {mobile_height: '50%'}), 'height: 50%;', 'uses configured mobile height')
63
- t.end()
64
- })
65
-
66
- test('convert message event first msg send', (t) => {
67
- var events = [
68
- {by: {id: 1}, type: 'message_sent', created: 1100},
69
- {by: {id: 1}, type: 'message_sent', created: 1200},
70
- {by: {id: 1}, type: 'message_sent', created: 1300},
71
- ]
72
-
73
- var expect = [
74
- {by: {id: 1}, type: 'message_sent', created: 1100, mode: 'lead', show_time: true},
75
- {by: {id: 1}, type: 'message_sent', created: 1200, mode: 'follow', show_time: false},
76
- {by: {id: 1}, type: 'message_sent', created: 1300, mode: 'follow', show_time: false},
77
- ]
78
-
79
- util.convertMessageEvent(events, 0)
80
- util.convertMessageEvent(events, 1)
81
- util.convertMessageEvent(events, 2)
82
-
83
- t.equal(JSON.stringify(events), JSON.stringify(expect))
84
- t.end()
85
- })
86
-
87
- test('convert message event message tag', (t) => {
88
- var events = [
89
- {type: 'conversation_state_updated'},
90
- {type: 'conversation_tagged'},
91
- {type: 'conversation_tagged'},
92
- {type: 'conversation_tagged'},
93
- {type: 'conversation_state_updated'},
94
- ]
95
-
96
- var expect = [
97
- {type: 'conversation_state_updated'},
98
- {type: 'conversation_tagged', mode: 'hide'},
99
- {type: 'conversation_tagged', mode: 'hide'},
100
- {type: 'conversation_tagged', mode: 'combine'},
101
- {type: 'conversation_state_updated'},
102
- ]
103
-
104
- events.map((_, i) => util.convertMessageEvent(events, i))
105
-
106
- t.equal(JSON.stringify(events), JSON.stringify(expect))
107
-
108
- var events = [{type: 'conversation_tagged'}, {type: 'conversation_tagged'}, {type: 'conversation_tagged'}]
109
-
110
- var expect = [
111
- {type: 'conversation_tagged', mode: 'hide'},
112
- {type: 'conversation_tagged', mode: 'hide'},
113
- {type: 'conversation_tagged', mode: 'combine'},
114
- ]
115
-
116
- events.map((_, i) => util.convertMessageEvent(events, i))
117
-
118
- t.end()
119
- })
120
-
121
- test('convert message event message tag, msg_sent mixup', (t) => {
122
- var events = [
123
- {type: 'conversation_state_updated'},
124
- {type: 'conversation_tagged'},
125
- {by: {id: 1}, type: 'message_sent'},
126
- {by: {id: 2}, type: 'message_sent'},
127
- {type: 'conversation_tagged'},
128
- {type: 'conversation_tagged'},
129
- {type: 'conversation_state_updated'},
130
- ]
131
-
132
- var expect = [
133
- {type: 'conversation_state_updated'},
134
- {type: 'conversation_tagged', mode: 'combine'},
135
- {by: {id: 1}, type: 'message_sent', mode: 'lead', show_time: false},
136
- {by: {id: 2}, type: 'message_sent', mode: 'lead', show_time: false},
137
- {type: 'conversation_tagged', mode: 'hide'},
138
- {type: 'conversation_tagged', mode: 'combine'},
139
- {type: 'conversation_state_updated'},
140
- ]
141
-
142
- events.map((_, i) => util.convertMessageEvent(events, i))
143
-
144
- t.equal(JSON.stringify(events), JSON.stringify(expect))
145
- t.end()
146
- })
147
-
148
- test('test insert message', (t) => {
149
- var events = [
150
- {type: 'conversation_state_updated'},
151
- {id: 1, type: 'conversation_tagged'},
152
- {by: {id: 1}, type: 'message_sent'},
153
- {by: {id: 2}, type: 'message_sent'},
154
- {type: 'conversation_tagged'},
155
- {type: 'conversation_tagged'},
156
- {type: 'conversation_state_updated'},
157
- ]
158
-
159
- events.map((_, i) => util.convertMessageEvent(events, i))
160
-
161
- events.splice(2, 0, {id: 2, type: 'conversation_tagged'})
162
- util.convertUpdatedOrDeletedMessageEvent(events, 2)
163
- var expect = [
164
- {type: 'conversation_state_updated'},
165
- {id: 1, type: 'conversation_tagged', mode: 'hide'},
166
- {id: 2, type: 'conversation_tagged', mode: 'combine'},
167
- {by: {id: 1}, type: 'message_sent', mode: 'lead', show_time: false},
168
- {by: {id: 2}, type: 'message_sent', mode: 'lead', show_time: false},
169
- {type: 'conversation_tagged', mode: 'hide'},
170
- {type: 'conversation_tagged', mode: 'combine'},
171
- {type: 'conversation_state_updated'},
172
- ]
173
-
174
- t.equal(JSON.stringify(events), JSON.stringify(expect))
175
- t.end()
176
- })
177
-
178
- test('mapizeDeep a map', (t) => {
179
- var topicM = {
180
- 0: {
181
- topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxnairroppcktrg',
182
- read: false,
183
- updated: 1570586074000,
184
- },
185
- 1: {
186
- topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxmkozwryrgjvag',
187
- read: false,
188
- updated: 1570551305000,
189
- },
190
- 2: {
191
- topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlvkqgspihkfzsnm',
192
- read: false,
193
- updated: 1570289320000,
194
- },
195
- }
196
-
197
- var out = util.mapizeDeep(topicM, 'topic')
198
- topicM['0'].topic = 't3'
199
- t.deepEqual(out, {
200
- 'account.acqcsmrppbftadjzxnvo.conversation.csqlxnairroppcktrg': {
201
- topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxnairroppcktrg',
202
- read: false,
203
- updated: 1570586074000,
204
- },
205
- 'account.acqcsmrppbftadjzxnvo.conversation.csqlxmkozwryrgjvag': {
206
- topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlxmkozwryrgjvag',
207
- read: false,
208
- updated: 1570551305000,
209
- },
210
- 'account.acqcsmrppbftadjzxnvo.conversation.csqlvkqgspihkfzsnm': {
211
- topic: 'account.acqcsmrppbftadjzxnvo.conversation.csqlvkqgspihkfzsnm',
212
- read: false,
213
- updated: 1570289320000,
214
- },
215
- })
216
- t.end()
217
- })
218
-
219
- test('mapize a map', (t) => {
220
- var topicM = {
221
- 0: {topic: 't1', updated: 157},
222
- 1: {topic: 't2', updated: 158},
223
- }
224
-
225
- var out = util.mapize(topicM, 'topic')
226
- t.deepEqual(out, {t1: {topic: 't1', updated: 157}, t2: {topic: 't2', updated: 158}})
227
- t.end()
228
- })
229
-
230
- test('mapize', (t) => {
231
- var arr = [
232
- {id: 0, value: 0},
233
- {id: 1, value: 1},
234
- {id: 2, value: 2},
235
- {id: 3, value: 3},
236
- {id: 4, value: 4},
237
- ]
238
- var m = util.mapize(arr, 'id')
239
- for (var i = 0; i < arr.length; i++) {
240
- t.equal(m[i], arr[i])
241
- }
242
- t.end()
243
- })
244
-
245
- test('convo id from topic', (t) => {
246
- t.equal('csqldpucwamyuaetjf', util.convoIdFromTopic('account.acqcsmrppbftadjzxnvo.conversation.csqldpucwamyuaetjf'))
247
- t.end()
248
- })
249
-
250
- test('user of convo', (t) => {
251
- var convo = {
252
- id: 'csqlmhetrpccwprnms',
253
- account_id: 'acqcsmrppbftadjzxnvo',
254
- created: 1568970100964184000,
255
- members: [
256
- {
257
- type: 'bot',
258
- id: 'agqhgvgtbwhsbolwtp',
259
- name: 'Automation bot',
260
- membership: 'active',
261
- },
262
- {
263
- type: 'user',
264
- id: 'usqlmfpdhxmajzggsjosw',
265
- name: '',
266
- membership: 'active',
267
- },
268
- {
269
- type: 'agent',
270
- id: 'agqcsmrppbfqstjwen',
271
- name: 'Thành',
272
- membership: 'active',
273
- },
274
- {
275
- type: 'user',
276
- id: 'usqlmfpdhxmajzgasdf',
277
- name: '',
278
- membership: 'active',
279
- },
280
- {
281
- type: 'agent',
282
- id: 'agqczwdrggvdnlbuom',
283
- name: 'THanh',
284
- membership: 'observer',
285
- },
286
- ],
287
- ended: 1569004072969908700,
288
- state: 'ended',
289
- accepted: 1568970101938098700,
290
- actived: 1568974069989570300,
291
- response_sec: 0,
292
- first_message: 'sdfg',
293
- subject: 'sdfg',
294
- }
295
-
296
- var users = util.usersOfConvo(convo)
297
- t.equal(users.length, 2)
298
- t.equal(users[0], 'usqlmfpdhxmajzggsjosw')
299
- t.equal(users[1], 'usqlmfpdhxmajzgasdf')
300
- t.end()
301
- })