@subiz/widget-v4 4.1.113 → 4.1.114

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 (29) hide show
  1. package/assets/less/message.less +108 -9
  2. package/compiled_src/chatbox/Event.js +94 -2
  3. package/compiled_src/chatbox/Events.js +24 -11
  4. package/compiled_src/chatbox/ImageAttachments.js +1 -1
  5. package/compiled_src/store/store.js +15 -1
  6. package/dist/195ec5442e3.278.js +1 -0
  7. package/dist/{19565267fde.app.js → 195ec5442e3.app.js} +1 -1
  8. package/dist/{19565267fde.index.html → 195ec5442e3.index.html} +1 -1
  9. package/dist/{19565267fde.library.html → 195ec5442e3.library.html} +1 -1
  10. package/dist/{19565267fde.library.js → 195ec5442e3.library.js} +1 -1
  11. package/dist/{19565267fde.preview.html → 195ec5442e3.preview.html} +1 -1
  12. package/dist/{19565267fde.preview.js → 195ec5442e3.preview.js} +1 -1
  13. package/dist/{19565267fde.webview.js → 195ec5442e3.webview.js} +1 -1
  14. package/dist/278.js +1 -1
  15. package/dist/HASH +1 -1
  16. package/package.json +2 -2
  17. package/src/chatbox/Event.js +110 -28
  18. package/src/chatbox/Events.js +27 -13
  19. package/src/chatbox/ImageAttachments.js +1 -1
  20. package/src/store/store.js +16 -1
  21. package/dist/19565267fde.278.js +0 -1
  22. /package/dist/{19565267fde.127.js → 195ec5442e3.127.js} +0 -0
  23. /package/dist/{19565267fde.132.js → 195ec5442e3.132.js} +0 -0
  24. /package/dist/{19565267fde.185.js → 195ec5442e3.185.js} +0 -0
  25. /package/dist/{19565267fde.27.js → 195ec5442e3.27.js} +0 -0
  26. /package/dist/{19565267fde.459.js → 195ec5442e3.459.js} +0 -0
  27. /package/dist/{19565267fde.490.js → 195ec5442e3.490.js} +0 -0
  28. /package/dist/{19565267fde.74.js → 195ec5442e3.74.js} +0 -0
  29. /package/dist/{19565267fde.997.js → 195ec5442e3.997.js} +0 -0
@@ -13,10 +13,10 @@
13
13
  }
14
14
 
15
15
  .mobile .widget-body--events {
16
- display: flex;
17
- flex-direction: column;
18
- justify-content: flex-end;
19
- padding-bottom: 15px;
16
+ display: flex;
17
+ flex-direction: column;
18
+ justify-content: flex-end;
19
+ padding-bottom: 15px;
20
20
  }
21
21
 
22
22
  .widget-body--events-container.widget-body--events-container__error {
@@ -108,12 +108,15 @@
108
108
 
109
109
  .message-text--agent {
110
110
  white-space: pre-wrap;
111
- margin: 5px 0 0;
112
111
  display: inline-block;
113
112
  background-color: @primary-color;
114
113
  .color(@text-color);
115
114
  padding: 10px 14px 10px 14px;
116
115
  }
116
+ .message-agent.message-text--agent {
117
+ max-width: unset;
118
+ margin-top: 0;
119
+ }
117
120
 
118
121
  .message-user__container {
119
122
  display: flex;
@@ -148,13 +151,13 @@
148
151
  }
149
152
 
150
153
  .message-user.message-user-images-container {
151
- width: 85%;
152
- display: flex;
153
- justify-content: flex-end;
154
+ width: 85%;
155
+ display: flex;
156
+ justify-content: flex-end;
154
157
  }
155
158
 
156
159
  .message-user.message-user-audio {
157
- flex: 1;
160
+ flex: 1;
158
161
  }
159
162
 
160
163
  .message-agent {
@@ -741,3 +744,99 @@ a.product_attachment__title {
741
744
  margin-left: 5px;
742
745
  margin-top: -2px;
743
746
  }
747
+
748
+ .agent-convo-event-wrapper {
749
+ max-width: 85%;
750
+ margin-top: 5px;
751
+ }
752
+
753
+ .agent-convo-event-inner {
754
+ width: fit-content;
755
+ position: relative;
756
+ }
757
+
758
+ .message-event-actions {
759
+ position: absolute;
760
+ bottom: -18px;
761
+ left: calc(100% - 40px);
762
+ display: none;
763
+ border: 1px solid #dee2e6;
764
+ background-color: white;
765
+ border-radius: 4px;
766
+ z-index: 10;
767
+ }
768
+
769
+ .agent-convo-event-inner:hover .message-event-actions {
770
+ display: flex;
771
+ }
772
+
773
+ .agent-convo-event-inner.last {
774
+ .message-event-actions {
775
+ display: flex;
776
+ position: unset;
777
+ margin-top: 4px;
778
+ border: none;
779
+ padding: 0;
780
+ }
781
+
782
+ .message-event-action-btn {
783
+ padding: 0;
784
+ .message-event-action-btn-svg {
785
+ width: 24px;
786
+ height: 24px;
787
+ background-position: 2px 2px;
788
+ background-size: 20px 20px;
789
+ }
790
+ }
791
+ }
792
+
793
+ .message-event-action-btn {
794
+ width: 24px;
795
+ height: 24px;
796
+ display: flex;
797
+ align-items: center;
798
+ justify-content: center;
799
+ cursor: pointer;
800
+ padding: 2px;
801
+
802
+ &:hover {
803
+ .message-event-action-btn-svg {
804
+ background-color: #ececec;
805
+ }
806
+ }
807
+
808
+ &.active:hover {
809
+ .message-event-action-btn-svg {
810
+ background-color: #dbfde3;
811
+ }
812
+ }
813
+ }
814
+
815
+ .message-event-action-btn .message-event-action-btn-svg {
816
+ width: 20px;
817
+ height: 20px;
818
+ border-radius: 4px;
819
+ background-position: 2px 2px;
820
+ background-size: 16px 16px;
821
+ background-repeat: no-repeat;
822
+ background-position: center;
823
+ }
824
+
825
+ .message-event-action-btn-svg.like {
826
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNWE2MjY4IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgc3Ryb2tlLXdpZHRoPSIxIj4gPHBhdGggZD0iTTcgMTF2OGExIDEgMCAwIDEgLTEgMWgtMmExIDEgMCAwIDEgLTEgLTF2LTdhMSAxIDAgMCAxIDEgLTFoM2E0IDQgMCAwIDAgNCAtNHYtMWEyIDIgMCAwIDEgNCAwdjVoM2EyIDIgMCAwIDEgMiAybC0xIDVhMiAzIDAgMCAxIC0yIDJoLTdhMyAzIDAgMCAxIC0zIC0zIj48L3BhdGg+IDwvc3ZnPiAK');
827
+ }
828
+ .message-event-action-btn-svg.dislike {
829
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjNWE2MjY4IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgc3Ryb2tlLXdpZHRoPSIxIj4gPHBhdGggZD0iTTcgMTN2LThhMSAxIDAgMCAwIC0xIC0xaC0yYTEgMSAwIDAgMCAtMSAxdjdhMSAxIDAgMCAwIDEgMWgzYTQgNCAwIDAgMSA0IDR2MWEyIDIgMCAwIDAgNCAwdi01aDNhMiAyIDAgMCAwIDIgLTJsLTEgLTVhMiAzIDAgMCAwIC0yIC0yaC03YTMgMyAwIDAgMCAtMyAzIj48L3BhdGg+IDwvc3ZnPiAK');
830
+ }
831
+ .message-event-action-btn:hover .message-event-action-btn-svg.like {
832
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBzdHJva2Utd2lkdGg9IjEiPiA8cGF0aCBkPSJNNyAxMXY4YTEgMSAwIDAgMSAtMSAxaC0yYTEgMSAwIDAgMSAtMSAtMXYtN2ExIDEgMCAwIDEgMSAtMWgzYTQgNCAwIDAgMCA0IC00di0xYTIgMiAwIDAgMSA0IDB2NWgzYTIgMiAwIDAgMSAyIDJsLTEgNWEyIDMgMCAwIDEgLTIgMmgtN2EzIDMgMCAwIDEgLTMgLTMiPjwvcGF0aD4gPC9zdmc+IA==');
833
+ }
834
+ .message-event-action-btn:hover .message-event-action-btn-svg.dislike {
835
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSJjdXJyZW50Q29sb3IiIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2IiBzdHJva2Utd2lkdGg9IjEiPiA8cGF0aCBkPSJNNyAxM3YtOGExIDEgMCAwIDAgLTEgLTFoLTJhMSAxIDAgMCAwIC0xIDF2N2ExIDEgMCAwIDAgMSAxaDNhNCA0IDAgMCAxIDQgNHYxYTIgMiAwIDAgMCA0IDB2LTVoM2EyIDIgMCAwIDAgMiAtMmwtMSAtNWEyIDMgMCAwIDAgLTIgLTJoLTdhMyAzIDAgMCAwIC0zIDMiPjwvcGF0aD4gPC9zdmc+IA==');
836
+ }
837
+ .message-event-action-btn.active .message-event-action-btn-svg.like {
838
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMzRDNzU5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgc3Ryb2tlLXdpZHRoPSIyIj4gPHBhdGggZD0iTTcgMTF2OGExIDEgMCAwIDEgLTEgMWgtMmExIDEgMCAwIDEgLTEgLTF2LTdhMSAxIDAgMCAxIDEgLTFoM2E0IDQgMCAwIDAgNCAtNHYtMWEyIDIgMCAwIDEgNCAwdjVoM2EyIDIgMCAwIDEgMiAybC0xIDVhMiAzIDAgMCAxIC0yIDJoLTdhMyAzIDAgMCAxIC0zIC0zIj48L3BhdGg+IDwvc3ZnPiAK');
839
+ }
840
+ .message-event-action-btn.active .message-event-action-btn-svg.dislike {
841
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMzRDNzU5IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgc3Ryb2tlLXdpZHRoPSIyIj4gPHBhdGggZD0iTTcgMTN2LThhMSAxIDAgMCAwIC0xIC0xaC0yYTEgMSAwIDAgMCAtMSAxdjdhMSAxIDAgMCAwIDEgMWgzYTQgNCAwIDAgMSA0IDR2MWEyIDIgMCAwIDAgNCAwdi01aDNhMiAyIDAgMCAwIDIgLTJsLTEgLTVhMiAzIDAgMCAwIC0yIC0yaC03YTMgMyAwIDAgMCAtMyAzIj48L3BhdGg+IDwvc3ZnPiAK');
842
+ }
@@ -28,7 +28,11 @@ const LoadOrderAttachments = () => Promise.resolve().then(() => _interopRequireW
28
28
  class Event extends _common.Com {
29
29
  constructor(props) {
30
30
  super(props);
31
+ this.props.store.onConvoEvent(this, ev => this.onEvent(ev));
31
32
  this.refForm = (0, _preact.createRef)();
33
+ this.state = {
34
+ pongs: _index.default.get(this.props.event, 'ev.data.message.pongs') || []
35
+ };
32
36
  }
33
37
  render() {
34
38
  var ev = _index.default.get(this.props.event, 'ev', {});
@@ -52,6 +56,24 @@ class Event extends _common.Com {
52
56
  focus() {
53
57
  this.refForm.current && this.refForm.current.focus();
54
58
  }
59
+ onEvent(ev) {
60
+ if (ev.id !== _index.default.get(this.props.event, 'ev.id')) return;
61
+ this.setState({
62
+ pongs: _index.default.get(ev, 'data.message.pongs') || []
63
+ });
64
+ }
65
+ hasLike() {
66
+ let {
67
+ pongs
68
+ } = this.state;
69
+ return !!_index.default.find(pongs, pong => pong.type === 'like');
70
+ }
71
+ hasDislike() {
72
+ let {
73
+ pongs
74
+ } = this.state;
75
+ return !!_index.default.find(pongs, pong => pong.type === 'dislike');
76
+ }
55
77
  chooseQuickReply(reply) {
56
78
  let ev = _index.default.get(this.props.event, 'ev', {});
57
79
  let message = {
@@ -145,10 +167,16 @@ class Event extends _common.Com {
145
167
  if (_index.default.get(ev, 'by.type') !== 'user') {
146
168
  let $sender = null;
147
169
  if (this.props.event.mode === 'lead') $sender = this.renderAgentAvatar(ev);
170
+ let innercls = 'agent-convo-event-inner';
171
+ if (this.props.isLast) innercls += ' last';
148
172
  return (0, _preact.h)("div", {
149
173
  class: "convo-event agent-message",
150
174
  title: t
151
- }, $time, $sender, (0, _preact.h)(_TextMessage.default, {
175
+ }, $time, $sender, (0, _preact.h)("div", {
176
+ class: "agent-convo-event-wrapper"
177
+ }, (0, _preact.h)("div", {
178
+ class: innercls
179
+ }, (0, _preact.h)(_TextMessage.default, {
152
180
  store: this.props.store,
153
181
  ev: ev,
154
182
  onLink: this.props.onLink
@@ -196,7 +224,7 @@ class Event extends _common.Com {
196
224
  store: this.props.store,
197
225
  ev: ev,
198
226
  onSelect: e => this.chooseQuickReply(e)
199
- }));
227
+ }), this.renderReactions())));
200
228
  }
201
229
  if (_index.default.get(ev, 'data.message.idempotency_key') === ev.id && this.props.store.now() - ev.created < 900) {
202
230
  _index.default.setTimeout(() => this.setState({
@@ -269,6 +297,70 @@ class Event extends _common.Com {
269
297
  ev: ev
270
298
  })), $error);
271
299
  }
300
+ async onSendReaction(action) {
301
+ if (this._reacting) return;
302
+ let ev = this.props.event.ev;
303
+ let cid = _index.default.get(ev, 'data.message.conversation_id');
304
+ ev = {
305
+ type: 'message_pong',
306
+ data: {
307
+ message: {
308
+ id: ev.id,
309
+ pongs: [{
310
+ type: action
311
+ }],
312
+ conversion_id: cid
313
+ }
314
+ }
315
+ };
316
+ let {
317
+ pongs
318
+ } = this.state;
319
+ if (action === 'like') {
320
+ pongs = pongs.filter(pong => pong.type !== 'dislike');
321
+ pongs.push({
322
+ type: 'like'
323
+ });
324
+ } else if (action === 'dislike') {
325
+ pongs = pongs.filter(pong => pong.type !== 'like');
326
+ pongs.push({
327
+ type: 'dislike'
328
+ });
329
+ } else if (action === 'remove_like') {
330
+ pongs = pongs.filter(pong => pong.type !== 'like');
331
+ } else if (action === 'remove_dislike') {
332
+ pongs = pongs.filter(pong => pong.type !== 'dislike');
333
+ }
334
+ this.setState({
335
+ pongs
336
+ });
337
+ this._reacting = true;
338
+ let res = await this.props.store.sendReaction(cid, ev);
339
+ this._reacting = false;
340
+ }
341
+ renderReactions() {
342
+ let ev = _index.default.get(this.props.event, 'ev') || {};
343
+ let pongs = _index.default.get(ev, 'data.message.pongs') || [];
344
+ let hasLike = this.hasLike();
345
+ let hasDislike = this.hasDislike();
346
+ let likecls = 'message-event-action-btn';
347
+ if (hasLike) likecls += ' active';
348
+ let dislikecls = 'message-event-action-btn';
349
+ if (hasDislike) dislikecls += ' active';
350
+ return (0, _preact.h)("div", {
351
+ class: "message-event-actions"
352
+ }, (0, _preact.h)("div", {
353
+ class: likecls,
354
+ onClick: () => this.onSendReaction(hasLike ? 'remove_like' : 'like')
355
+ }, (0, _preact.h)("div", {
356
+ class: "message-event-action-btn-svg like"
357
+ })), (0, _preact.h)("div", {
358
+ class: dislikecls,
359
+ onClick: () => this.onSendReaction(hasDislike ? 'remove_dislike' : 'dislike')
360
+ }, (0, _preact.h)("div", {
361
+ class: "message-event-action-btn-svg dislike"
362
+ })));
363
+ }
272
364
  renderUpdateConvo(ev) {
273
365
  var state = _index.default.get(ev, 'data.conversation.state');
274
366
  if (state === 'active') return null;
@@ -52,17 +52,30 @@ class Events extends _common.Com {
52
52
  ev: ev
53
53
  }));
54
54
  processEvents(convo, events);
55
- let $events = _index.default.map(events, ev => (0, _preact.h)(_Event.default, {
56
- chatbox: this.props.chatbox,
57
- onLink: this.props.onLink,
58
- store: this.props.store,
59
- onFormSubmit: this.props.onFormSubmit,
60
- onSend: this.props.onSend,
61
- onPostback: this.props.onPostback,
62
- event: ev,
63
- t: this.props.t,
64
- key: ev.ev.id
65
- }));
55
+ let lastAgentMessageSentId = '';
56
+ for (let i = events.length - 1; i >= 0; i--) {
57
+ let ev = _index.default.get(events, [i, 'ev']) || {};
58
+ let bytype = _index.default.get(ev, 'by.type');
59
+ if (bytype !== 'user' && ev.type === 'message_sent') {
60
+ lastAgentMessageSentId = ev.id;
61
+ break;
62
+ }
63
+ }
64
+ let $events = _index.default.map(events, ev => {
65
+ let isLast = ev.ev.id === lastAgentMessageSentId;
66
+ return (0, _preact.h)(_Event.default, {
67
+ isLast: isLast,
68
+ chatbox: this.props.chatbox,
69
+ onLink: this.props.onLink,
70
+ store: this.props.store,
71
+ onFormSubmit: this.props.onFormSubmit,
72
+ onSend: this.props.onSend,
73
+ onPostback: this.props.onPostback,
74
+ event: ev,
75
+ t: this.props.t,
76
+ key: ev.ev.id
77
+ });
78
+ });
66
79
  let $loading = null;
67
80
  let style = 'opacity: 1 !important';
68
81
  if (this.state.loading || this.props.creating) {
@@ -27,7 +27,7 @@ class ImageAttachment extends _common.Com {
27
27
  const MAX_HEIGHT = 240;
28
28
  const DEFAULT_MAX_WIDTH = 267;
29
29
  let $container = this.containerRef.current;
30
- this.frameWidth = $container ? $container.offsetWidth : DEFAULT_MAX_WIDTH;
30
+ this.frameWidth = $container ? $container.parentNode.parentNode.offsetWidth : DEFAULT_MAX_WIDTH;
31
31
  this.frameHeight = MAX_HEIGHT;
32
32
  this.setState({
33
33
  ready: true
@@ -722,7 +722,17 @@ class Store {
722
722
  var oldev = this.chain.match(cid, msgid);
723
723
  if (!_index.default.get(oldev, 'data.message')) return;
724
724
  var pongs = _index.default.get(oldev, 'data.message.pongs', []);
725
- pongs = pongs.concat(_index.default.get(ev, 'data.message.pongs', []));
725
+ let newpongs = _index.default.get(ev, 'data.message.pongs', []) || [];
726
+ pongs = pongs.concat(newpongs);
727
+ if (newpongs.length === 1) {
728
+ let pongtype = newpongs[0].type;
729
+ if (pongtype === 'like' || pongtype === 'remove_dislike') {
730
+ pongs = pongs.filter(pong => pong.type !== 'dislike');
731
+ }
732
+ if (pongtype === 'dislike' || pongtype === 'remove_like') {
733
+ pongs = pongs.filter(pong => pong.type !== 'like');
734
+ }
735
+ }
726
736
  oldev.data.message.pongs = pongs;
727
737
  _index.default.map(pongs, pong => {
728
738
  if (pong.member_id == user.id && pong.type === 'seen') {
@@ -731,6 +741,7 @@ class Store {
731
741
  }
732
742
  });
733
743
  this.chain.put(cid, oldev.id, _index.default.getMs(oldev.created), oldev);
744
+ this.pubsub.publish('events', oldev);
734
745
  }
735
746
  if (ev.type === 'message_sent') {
736
747
  let idemkey = _index.default.get(ev, 'data.message.idempotency_key');
@@ -782,6 +793,9 @@ class Store {
782
793
  createPostback(cid, postback) {
783
794
  return this.api.createPostback(cid, postback);
784
795
  }
796
+ sendReaction(cid, ev) {
797
+ return this.api.sendConvoEvent(cid, ev);
798
+ }
785
799
  async sendConvoEvent(cid, type, data) {
786
800
  await this.readyGate.entry();
787
801
  var idempotency = _index.default.randomString(36);