@messenger-box/platform-mobile 10.0.3-alpha.19 → 10.0.3-alpha.22
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/CHANGELOG.md +8 -0
- package/lib/screens/inbox/components/CachedImage/index.js +0 -19
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogsListItem.js +423 -50
- package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +375 -51
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js +175 -0
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js.map +1 -0
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js +191 -0
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js.map +1 -0
- package/lib/screens/inbox/containers/Dialogs.js +536 -66
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +95 -23
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +211 -0
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +1 -0
- package/package.json +2 -2
- package/src/screens/inbox/components/CachedImage/index.tsx +9 -9
- package/src/screens/inbox/components/DialogsListItem.tsx +624 -107
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +506 -114
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +35 -17
- package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +145 -0
- package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +159 -0
- package/src/screens/inbox/containers/Dialogs.tsx +711 -169
- package/src/screens/inbox/containers/ThreadConversationView.tsx +151 -35
|
@@ -29,10 +29,23 @@ import colors from 'tailwindcss/colors';
|
|
|
29
29
|
|
|
30
30
|
const createdAtText = (value: string) => {
|
|
31
31
|
if (!value) return '';
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
// Validate the date before processing
|
|
35
|
+
const timestamp = new Date(value).getTime();
|
|
36
|
+
if (isNaN(timestamp)) {
|
|
37
|
+
console.warn(`Invalid date value in createdAtText: ${value}`);
|
|
38
|
+
return 'Unknown date';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let date = new Date(value);
|
|
42
|
+
if (isToday(date)) return 'Today';
|
|
43
|
+
if (isYesterday(date)) return 'Yesterday';
|
|
44
|
+
return format(date, 'MMM dd, yyyy');
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(`Error processing date in createdAtText: ${value}`, error);
|
|
47
|
+
return 'Unknown date';
|
|
48
|
+
}
|
|
36
49
|
};
|
|
37
50
|
|
|
38
51
|
export interface IDialogListChannel extends IChannel {
|
|
@@ -250,6 +263,23 @@ export const SupportServiceDialogsListItemComponent: React.FC<IDialogListItemPro
|
|
|
250
263
|
|
|
251
264
|
const ServiceChannelWithLastMessage = React.memo(({ channel, lastMessage, subscribeToNewMessages }: any) => {
|
|
252
265
|
React.useEffect(() => subscribeToNewMessages(), []);
|
|
266
|
+
|
|
267
|
+
// Define message display text
|
|
268
|
+
let displayMessage = 'No messages yet';
|
|
269
|
+
|
|
270
|
+
if (lastMessage) {
|
|
271
|
+
// Check for file attachments
|
|
272
|
+
const hasFileAttachments = lastMessage.files?.data?.length > 0;
|
|
273
|
+
|
|
274
|
+
if (hasFileAttachments) {
|
|
275
|
+
displayMessage = '📎 File attachment';
|
|
276
|
+
} else if (lastMessage.message && lastMessage.message.trim() !== '') {
|
|
277
|
+
displayMessage = lastMessage.message;
|
|
278
|
+
} else {
|
|
279
|
+
displayMessage = '(Empty message)';
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
253
283
|
return (
|
|
254
284
|
<HStack space={'sm'} className="flex-1 justify-center items-center">
|
|
255
285
|
<Box className="flex-[0.8]">
|
|
@@ -257,23 +287,11 @@ const ServiceChannelWithLastMessage = React.memo(({ channel, lastMessage, subscr
|
|
|
257
287
|
{channel?.title}
|
|
258
288
|
</Text>
|
|
259
289
|
<Text color={colors.gray[600]} numberOfLines={1}>
|
|
260
|
-
{
|
|
261
|
-
? lastMessageCreatorAndMembers?.message ?? ''
|
|
262
|
-
: lastMessage?.message ?? ''} */}
|
|
263
|
-
{lastMessage?.message ?? ''}
|
|
290
|
+
{displayMessage}
|
|
264
291
|
</Text>
|
|
265
292
|
</Box>
|
|
266
293
|
|
|
267
294
|
<Box className="flex-[0.2]">
|
|
268
|
-
{/* {creatorAndMembersId?.length && creatorAndMembersId?.includes(currentUser?.id) ? (
|
|
269
|
-
<Text color="gray.500">
|
|
270
|
-
{lastMessageCreatorAndMembers
|
|
271
|
-
? createdAtText(lastMessageCreatorAndMembers?.createdAt)
|
|
272
|
-
: ''}
|
|
273
|
-
</Text>
|
|
274
|
-
) : (
|
|
275
|
-
<Text color="gray.500">{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
276
|
-
)} */}
|
|
277
295
|
<Text color={colors.gray[500]}>{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
278
296
|
</Box>
|
|
279
297
|
</HStack>
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { assign, setup } from 'xstate';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
export const enum Actions {
|
|
5
|
+
INITIAL_CONTEXT = 'INITIAL_CONTEXT',
|
|
6
|
+
ERROR_HANDLED = 'ERROR_HANDLED',
|
|
7
|
+
FETCH_MESSAGES = 'FETCH_MESSAGES',
|
|
8
|
+
UPDATE_MESSAGES = 'UPDATE_MESSAGES',
|
|
9
|
+
SUBSCRIBE_TO_MESSAGES = 'SUBSCRIBE_TO_MESSAGES',
|
|
10
|
+
SET_TITLE = 'SET_TITLE',
|
|
11
|
+
START_LOADING = 'START_LOADING',
|
|
12
|
+
STOP_LOADING = 'STOP_LOADING',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const enum BaseState {
|
|
16
|
+
Idle = 'idle',
|
|
17
|
+
Error = 'error',
|
|
18
|
+
FetchingMessages = 'fetchingMessages',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const dialogsListItemXstate = setup({
|
|
22
|
+
types: {
|
|
23
|
+
context: {} as {
|
|
24
|
+
channelId: string | null;
|
|
25
|
+
currentUser: any;
|
|
26
|
+
messages: any[];
|
|
27
|
+
loading: boolean;
|
|
28
|
+
error: string | null;
|
|
29
|
+
title: string;
|
|
30
|
+
channelMembers: any[];
|
|
31
|
+
lastMessage: any;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
actions: {
|
|
35
|
+
errorState: assign(({ context, event }) => {
|
|
36
|
+
return {
|
|
37
|
+
...context,
|
|
38
|
+
error: event.data?.message || 'An error occurred',
|
|
39
|
+
loading: false,
|
|
40
|
+
};
|
|
41
|
+
}),
|
|
42
|
+
setInitialContext: assign(({ context, event }) => {
|
|
43
|
+
return merge({
|
|
44
|
+
...context,
|
|
45
|
+
channelId: event.data?.channelId || null,
|
|
46
|
+
currentUser: event.data?.currentUser || null,
|
|
47
|
+
loading: true,
|
|
48
|
+
});
|
|
49
|
+
}),
|
|
50
|
+
setMessages: assign(({ context, event }) => {
|
|
51
|
+
return {
|
|
52
|
+
...context,
|
|
53
|
+
messages: event.data?.messages || [],
|
|
54
|
+
loading: false,
|
|
55
|
+
};
|
|
56
|
+
}),
|
|
57
|
+
updateMessages: assign(({ context, event }) => {
|
|
58
|
+
const newMessage = event.data?.message;
|
|
59
|
+
if (!newMessage) return context;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
...context,
|
|
63
|
+
messages: [...context.messages, newMessage],
|
|
64
|
+
};
|
|
65
|
+
}),
|
|
66
|
+
setTitle: assign(({ context, event }) => {
|
|
67
|
+
return {
|
|
68
|
+
...context,
|
|
69
|
+
title: event.data?.title || '',
|
|
70
|
+
};
|
|
71
|
+
}),
|
|
72
|
+
startLoading: assign(({ context }) => {
|
|
73
|
+
return {
|
|
74
|
+
...context,
|
|
75
|
+
loading: true,
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
stopLoading: assign(({ context }) => {
|
|
79
|
+
return {
|
|
80
|
+
...context,
|
|
81
|
+
loading: false,
|
|
82
|
+
};
|
|
83
|
+
}),
|
|
84
|
+
},
|
|
85
|
+
}).createMachine({
|
|
86
|
+
id: 'dialogs-list-item',
|
|
87
|
+
initial: BaseState.Idle,
|
|
88
|
+
context: {
|
|
89
|
+
channelId: null,
|
|
90
|
+
currentUser: null,
|
|
91
|
+
messages: [],
|
|
92
|
+
loading: false,
|
|
93
|
+
error: null,
|
|
94
|
+
title: '',
|
|
95
|
+
channelMembers: [],
|
|
96
|
+
lastMessage: null,
|
|
97
|
+
},
|
|
98
|
+
states: {
|
|
99
|
+
[BaseState.Idle]: {
|
|
100
|
+
on: {
|
|
101
|
+
[Actions.INITIAL_CONTEXT]: {
|
|
102
|
+
target: BaseState.FetchingMessages,
|
|
103
|
+
actions: ['setInitialContext'],
|
|
104
|
+
},
|
|
105
|
+
[Actions.UPDATE_MESSAGES]: {
|
|
106
|
+
target: BaseState.Idle,
|
|
107
|
+
actions: ['updateMessages'],
|
|
108
|
+
},
|
|
109
|
+
[Actions.SET_TITLE]: {
|
|
110
|
+
target: BaseState.Idle,
|
|
111
|
+
actions: ['setTitle'],
|
|
112
|
+
},
|
|
113
|
+
[Actions.START_LOADING]: {
|
|
114
|
+
target: BaseState.Idle,
|
|
115
|
+
actions: ['startLoading'],
|
|
116
|
+
},
|
|
117
|
+
[Actions.STOP_LOADING]: {
|
|
118
|
+
target: BaseState.Idle,
|
|
119
|
+
actions: ['stopLoading'],
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
[BaseState.Error]: {
|
|
124
|
+
entry: ['errorState'],
|
|
125
|
+
on: {
|
|
126
|
+
[Actions.ERROR_HANDLED]: {
|
|
127
|
+
target: BaseState.Idle,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
[BaseState.FetchingMessages]: {
|
|
132
|
+
invoke: {
|
|
133
|
+
src: 'fetchMessages',
|
|
134
|
+
input: ({ context, event }) => ({ context, event }),
|
|
135
|
+
onDone: {
|
|
136
|
+
target: BaseState.Idle,
|
|
137
|
+
actions: ['setMessages'],
|
|
138
|
+
},
|
|
139
|
+
onError: {
|
|
140
|
+
target: BaseState.Error,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
} as any);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { assign, setup } from 'xstate';
|
|
2
|
+
import { merge } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
export const enum Actions {
|
|
5
|
+
INITIAL_CONTEXT = 'INITIAL_CONTEXT',
|
|
6
|
+
ERROR_HANDLED = 'ERROR_HANDLED',
|
|
7
|
+
FETCH_THREAD_MESSAGES = 'FETCH_THREAD_MESSAGES',
|
|
8
|
+
UPDATE_THREAD_MESSAGES = 'UPDATE_THREAD_MESSAGES',
|
|
9
|
+
SUBSCRIBE_TO_THREAD_MESSAGES = 'SUBSCRIBE_TO_THREAD_MESSAGES',
|
|
10
|
+
SET_TITLE = 'SET_TITLE',
|
|
11
|
+
START_LOADING = 'START_LOADING',
|
|
12
|
+
STOP_LOADING = 'STOP_LOADING',
|
|
13
|
+
SET_SERVICE_POST_PARENT_ID = 'SET_SERVICE_POST_PARENT_ID',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const enum BaseState {
|
|
17
|
+
Idle = 'idle',
|
|
18
|
+
Error = 'error',
|
|
19
|
+
FetchingThreadMessages = 'fetchingThreadMessages',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const serviceDialogsListItemXstate = setup({
|
|
23
|
+
types: {
|
|
24
|
+
context: {} as {
|
|
25
|
+
channelId: string | null;
|
|
26
|
+
currentUser: any;
|
|
27
|
+
threadMessages: any[];
|
|
28
|
+
loading: boolean;
|
|
29
|
+
error: string | null;
|
|
30
|
+
title: string;
|
|
31
|
+
role: string;
|
|
32
|
+
servicePostParentId: string | null;
|
|
33
|
+
lastMessage: any;
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
actions: {
|
|
37
|
+
errorState: assign(({ context, event }) => {
|
|
38
|
+
return {
|
|
39
|
+
...context,
|
|
40
|
+
error: event.data?.message || 'An error occurred',
|
|
41
|
+
loading: false,
|
|
42
|
+
};
|
|
43
|
+
}),
|
|
44
|
+
setInitialContext: assign(({ context, event }) => {
|
|
45
|
+
return merge({
|
|
46
|
+
...context,
|
|
47
|
+
channelId: event.data?.channelId || null,
|
|
48
|
+
currentUser: event.data?.currentUser || null,
|
|
49
|
+
role: event.data?.role || null,
|
|
50
|
+
loading: true,
|
|
51
|
+
});
|
|
52
|
+
}),
|
|
53
|
+
setThreadMessages: assign(({ context, event }) => {
|
|
54
|
+
return {
|
|
55
|
+
...context,
|
|
56
|
+
threadMessages: event.data?.threadMessages || [],
|
|
57
|
+
loading: false,
|
|
58
|
+
};
|
|
59
|
+
}),
|
|
60
|
+
updateThreadMessages: assign(({ context, event }) => {
|
|
61
|
+
const newThreadMessage = event.data?.message;
|
|
62
|
+
if (!newThreadMessage) return context;
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
...context,
|
|
66
|
+
threadMessages: [...context.threadMessages, newThreadMessage],
|
|
67
|
+
};
|
|
68
|
+
}),
|
|
69
|
+
setTitle: assign(({ context, event }) => {
|
|
70
|
+
return {
|
|
71
|
+
...context,
|
|
72
|
+
title: event.data?.title || '',
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
setServicePostParentId: assign(({ context, event }) => {
|
|
76
|
+
return {
|
|
77
|
+
...context,
|
|
78
|
+
servicePostParentId: event.data?.servicePostParentId || null,
|
|
79
|
+
};
|
|
80
|
+
}),
|
|
81
|
+
startLoading: assign(({ context }) => {
|
|
82
|
+
return {
|
|
83
|
+
...context,
|
|
84
|
+
loading: true,
|
|
85
|
+
};
|
|
86
|
+
}),
|
|
87
|
+
stopLoading: assign(({ context }) => {
|
|
88
|
+
return {
|
|
89
|
+
...context,
|
|
90
|
+
loading: false,
|
|
91
|
+
};
|
|
92
|
+
}),
|
|
93
|
+
},
|
|
94
|
+
}).createMachine({
|
|
95
|
+
id: 'service-dialogs-list-item',
|
|
96
|
+
initial: BaseState.Idle,
|
|
97
|
+
context: {
|
|
98
|
+
channelId: null,
|
|
99
|
+
currentUser: null,
|
|
100
|
+
threadMessages: [],
|
|
101
|
+
loading: false,
|
|
102
|
+
error: null,
|
|
103
|
+
title: '',
|
|
104
|
+
role: '',
|
|
105
|
+
servicePostParentId: null,
|
|
106
|
+
lastMessage: null,
|
|
107
|
+
},
|
|
108
|
+
states: {
|
|
109
|
+
[BaseState.Idle]: {
|
|
110
|
+
on: {
|
|
111
|
+
[Actions.INITIAL_CONTEXT]: {
|
|
112
|
+
target: BaseState.FetchingThreadMessages,
|
|
113
|
+
actions: ['setInitialContext'],
|
|
114
|
+
},
|
|
115
|
+
[Actions.UPDATE_THREAD_MESSAGES]: {
|
|
116
|
+
target: BaseState.Idle,
|
|
117
|
+
actions: ['updateThreadMessages'],
|
|
118
|
+
},
|
|
119
|
+
[Actions.SET_TITLE]: {
|
|
120
|
+
target: BaseState.Idle,
|
|
121
|
+
actions: ['setTitle'],
|
|
122
|
+
},
|
|
123
|
+
[Actions.SET_SERVICE_POST_PARENT_ID]: {
|
|
124
|
+
target: BaseState.Idle,
|
|
125
|
+
actions: ['setServicePostParentId'],
|
|
126
|
+
},
|
|
127
|
+
[Actions.START_LOADING]: {
|
|
128
|
+
target: BaseState.Idle,
|
|
129
|
+
actions: ['startLoading'],
|
|
130
|
+
},
|
|
131
|
+
[Actions.STOP_LOADING]: {
|
|
132
|
+
target: BaseState.Idle,
|
|
133
|
+
actions: ['stopLoading'],
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
[BaseState.Error]: {
|
|
138
|
+
entry: ['errorState'],
|
|
139
|
+
on: {
|
|
140
|
+
[Actions.ERROR_HANDLED]: {
|
|
141
|
+
target: BaseState.Idle,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
[BaseState.FetchingThreadMessages]: {
|
|
146
|
+
invoke: {
|
|
147
|
+
src: 'fetchThreadMessages',
|
|
148
|
+
input: ({ context, event }) => ({ context, event }),
|
|
149
|
+
onDone: {
|
|
150
|
+
target: BaseState.Idle,
|
|
151
|
+
actions: ['setThreadMessages'],
|
|
152
|
+
},
|
|
153
|
+
onError: {
|
|
154
|
+
target: BaseState.Error,
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
} as any);
|