@webitel/ui-chats 26.12.2 → 26.12.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/ui-chats",
3
- "version": "26.12.2",
3
+ "version": "26.12.4",
4
4
  "description": "Reusable Webitel Frontend Code for Chats UI",
5
5
  "workspaces": [
6
6
  "../../",
@@ -197,8 +197,8 @@ function handlePlayerInitialize(player: object) {
197
197
  white-space: pre-line;
198
198
  padding: var(--spacing-xs);
199
199
  border-radius: var(--border-radius);
200
- background: var(--primary-light-color);
201
- color: var(--primary-on-color);
200
+ background: var(--p-primary-highlight-color);
201
+ color: var(--p-primary-on-highlight-color);
202
202
  place-self: flex-start;
203
203
  }
204
204
 
@@ -0,0 +1,118 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { isInternalThread, isOutgoingMessage } from '../isOutgoingMessage';
4
+ import { bot, client, colleague, message, operator, thread } from './fixtures';
5
+
6
+ const internalThread = thread({
7
+ members: [
8
+ operator,
9
+ colleague,
10
+ bot,
11
+ ],
12
+ });
13
+
14
+ describe('isInternalThread', () => {
15
+ it('is a thread with no client', () => {
16
+ expect(isInternalThread(internalThread)).toBe(true);
17
+ });
18
+
19
+ it('is not a thread with a client', () => {
20
+ expect(isInternalThread(thread())).toBe(false);
21
+ });
22
+
23
+ it('is not a thread whose members are not known', () => {
24
+ expect(
25
+ isInternalThread(
26
+ thread({
27
+ members: [],
28
+ }),
29
+ ),
30
+ ).toBe(false);
31
+ expect(
32
+ isInternalThread(
33
+ thread({
34
+ members: undefined,
35
+ }),
36
+ ),
37
+ ).toBe(false);
38
+ });
39
+ });
40
+
41
+ describe('isOutgoingMessage', () => {
42
+ describe('with a client in the thread', () => {
43
+ const withClient = thread({
44
+ members: [
45
+ operator,
46
+ colleague,
47
+ bot,
48
+ client,
49
+ ],
50
+ });
51
+
52
+ it.each([
53
+ [
54
+ 'the operator',
55
+ operator,
56
+ ],
57
+ [
58
+ 'a colleague',
59
+ colleague,
60
+ ],
61
+ [
62
+ 'a bot',
63
+ bot,
64
+ ],
65
+ ])('puts %s on the operator’s side', (_who, sender) => {
66
+ expect(
67
+ isOutgoingMessage({
68
+ message: message({
69
+ sender,
70
+ }),
71
+ thread: withClient,
72
+ selfMemberId: operator.id,
73
+ }),
74
+ ).toBe(true);
75
+ });
76
+
77
+ it('puts the client on the other side', () => {
78
+ expect(
79
+ isOutgoingMessage({
80
+ message: message({
81
+ sender: client,
82
+ }),
83
+ thread: withClient,
84
+ selfMemberId: operator.id,
85
+ }),
86
+ ).toBe(false);
87
+ });
88
+ });
89
+
90
+ describe('between colleagues', () => {
91
+ it('puts only the operator on the operator’s side', () => {
92
+ const outgoing = (sender: typeof operator) =>
93
+ isOutgoingMessage({
94
+ message: message({
95
+ sender,
96
+ }),
97
+ thread: internalThread,
98
+ selfMemberId: operator.id,
99
+ });
100
+
101
+ expect(outgoing(operator)).toBe(true);
102
+ expect(outgoing(colleague)).toBe(false);
103
+ expect(outgoing(bot)).toBe(false);
104
+ });
105
+
106
+ it('puts nobody on it while the operator’s member is unknown', () => {
107
+ expect(
108
+ isOutgoingMessage({
109
+ message: message({
110
+ sender: operator,
111
+ }),
112
+ thread: internalThread,
113
+ selfMemberId: '',
114
+ }),
115
+ ).toBe(false);
116
+ });
117
+ });
118
+ });
@@ -0,0 +1,33 @@
1
+ import type { MessageModel, ThreadModel } from '../types';
2
+ import { isContactCentreSide } from './isContactCentreSide';
3
+ import { isSelfMessage } from './isSelfMessage';
4
+
5
+ /**
6
+ * A thread with no client in it: every member is an operator or a bot, as in
7
+ * a chat between colleagues. A thread whose members are not known is not
8
+ * taken for one.
9
+ */
10
+ export const isInternalThread = (thread: ThreadModel): boolean => {
11
+ const members = thread.members ?? [];
12
+
13
+ return members.length > 0 && members.every(isContactCentreSide);
14
+ };
15
+
16
+ /**
17
+ * Which side of the history a message sits on. With a client in the thread,
18
+ * everyone who speaks for the contact centre (operators, bots) shares the
19
+ * operator's side against the client. Between colleagues there is no such
20
+ * opposition, so only the operator using the UI sits on it.
21
+ */
22
+ export const isOutgoingMessage = ({
23
+ message,
24
+ thread,
25
+ selfMemberId,
26
+ }: {
27
+ message: MessageModel;
28
+ thread: ThreadModel;
29
+ selfMemberId: string;
30
+ }): boolean =>
31
+ isInternalThread(thread)
32
+ ? isSelfMessage(message, thread, selfMemberId)
33
+ : isContactCentreSide(message.sender);
@@ -2,7 +2,9 @@ import { flushPromises } from '@vue/test-utils';
2
2
  import { describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  import {
5
+ bot,
5
6
  client,
7
+ colleague,
6
8
  message,
7
9
  operator,
8
10
  thread,
@@ -86,6 +88,33 @@ describe('ChatHistory', () => {
86
88
  expect(rows[1].classes()).toContain('chat-message--outgoing');
87
89
  });
88
90
 
91
+ it('puts only the operator on the outgoing side between colleagues', () => {
92
+ const wrapper = setup({
93
+ thread: thread({
94
+ members: [
95
+ operator,
96
+ colleague,
97
+ bot,
98
+ ],
99
+ }),
100
+ messages: [
101
+ message({
102
+ sender: colleague,
103
+ }),
104
+ message({
105
+ sender: bot,
106
+ }),
107
+ message({
108
+ sender: operator,
109
+ }),
110
+ ],
111
+ });
112
+ const rows = wrapper.findAll('.chat-message');
113
+ expect(rows[0].classes()).not.toContain('chat-message--outgoing');
114
+ expect(rows[1].classes()).not.toContain('chat-message--outgoing');
115
+ expect(rows[2].classes()).toContain('chat-message--outgoing');
116
+ });
117
+
89
118
  it('shows ticks only on the operator’s own messages', () => {
90
119
  const wrapper = setup({
91
120
  messages: [
@@ -59,7 +59,7 @@ import { useChatsV2I18n } from '../../../locale/useChatsV2I18n';
59
59
  import { hasAttachments } from '../../../scripts/attachments';
60
60
  import { formatMessageTime } from '../../../scripts/formatDate';
61
61
  import { getMessageStatus } from '../../../scripts/getMessageStatus';
62
- import { isContactCentreSide } from '../../../scripts/isContactCentreSide';
62
+ import { isOutgoingMessage } from '../../../scripts/isOutgoingMessage';
63
63
  import { participantName } from '../../../scripts/resolveSystemNotice';
64
64
  import { toTimestamp } from '../../../scripts/toTimestamp';
65
65
  import type {
@@ -80,7 +80,13 @@ const props = defineProps<{
80
80
 
81
81
  const { t } = useChatsV2I18n();
82
82
 
83
- const isOutgoing = computed(() => isContactCentreSide(props.message.sender));
83
+ const isOutgoing = computed(() =>
84
+ isOutgoingMessage({
85
+ message: props.message,
86
+ thread: props.thread,
87
+ selfMemberId: props.selfMemberId,
88
+ }),
89
+ );
84
90
 
85
91
  const authorName = computed(() => participantName(props.message.sender));
86
92