@messenger-box/platform-mobile 10.0.3-alpha.23 → 10.0.3-alpha.232
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/lib/components/messages-container-ui/BuildModeView.js +428 -0
- package/lib/components/messages-container-ui/BuildModeView.js.map +1 -0
- package/lib/components/messages-container-ui/MessagesContainerUI.js +55 -0
- package/lib/components/messages-container-ui/MessagesContainerUI.js.map +1 -0
- package/lib/components/messages-container-ui/PlanModeView.js +336 -0
- package/lib/components/messages-container-ui/PlanModeView.js.map +1 -0
- package/lib/compute.js +2 -3
- package/lib/compute.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/module.js.map +1 -1
- package/lib/queries/inboxQueries.js +62 -0
- package/lib/queries/inboxQueries.js.map +1 -0
- package/lib/routes.json +2 -3
- package/lib/screens/inbox/DialogMessages.js +8 -3
- package/lib/screens/inbox/DialogMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreadMessages.js +6 -11
- package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreads.js +9 -11
- package/lib/screens/inbox/DialogThreads.js.map +1 -1
- package/lib/screens/inbox/Inbox.js.map +1 -1
- package/lib/screens/inbox/components/CachedImage/consts.js +1 -1
- package/lib/screens/inbox/components/CachedImage/consts.js.map +1 -1
- package/lib/screens/inbox/components/CachedImage/index.js +125 -96
- package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
- package/lib/screens/inbox/components/DialogItem.js +160 -0
- package/lib/screens/inbox/components/DialogItem.js.map +1 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js +315 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js +3 -1
- package/lib/screens/inbox/components/SlackMessageContainer/ImageViewerModal.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js +194 -0
- package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js.map +1 -0
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +149 -36
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js +4 -5
- package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
- package/lib/screens/inbox/components/SubscriptionHandler.js +22 -0
- package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
- package/lib/screens/inbox/components/ThreadsViewItem.js +2 -4
- package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
- package/lib/screens/inbox/config/config.js +4 -2
- package/lib/screens/inbox/config/config.js.map +1 -1
- package/lib/screens/inbox/containers/ConversationView.js +1093 -1090
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +130 -577
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +864 -1408
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadsView.js +9 -15
- package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
- package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
- package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +1 -1
- package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -1
- package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -1
- package/package.json +10 -8
- package/CHANGELOG.md +0 -172
- package/jest.config.js +0 -24
- package/lib/screens/inbox/components/DialogsListItem.js +0 -548
- package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -489
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +0 -1
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js +0 -175
- package/lib/screens/inbox/components/workflow/dialogs-list-item-xstate.js.map +0 -1
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js +0 -191
- package/lib/screens/inbox/components/workflow/service-dialogs-list-item-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js +0 -380
- package/lib/screens/inbox/containers/workflow/conversation-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js +0 -211
- package/lib/screens/inbox/containers/workflow/dialogs-xstate.js.map +0 -1
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js +0 -438
- package/lib/screens/inbox/containers/workflow/thread-conversation-xstate.js.map +0 -1
- package/rollup.config.mjs +0 -45
- package/src/components/index.ts +0 -0
- package/src/compute.ts +0 -63
- package/src/index.ts +0 -7
- package/src/module.ts +0 -10
- package/src/navigation/InboxNavigation.tsx +0 -102
- package/src/navigation/index.ts +0 -1
- package/src/screens/inbox/DialogMessages.tsx +0 -21
- package/src/screens/inbox/DialogThreadMessages.tsx +0 -97
- package/src/screens/inbox/DialogThreads.tsx +0 -125
- package/src/screens/inbox/Inbox.tsx +0 -17
- package/src/screens/inbox/components/CachedImage/consts.ts +0 -6
- package/src/screens/inbox/components/CachedImage/index.tsx +0 -223
- package/src/screens/inbox/components/DialogsHeader.tsx +0 -30
- package/src/screens/inbox/components/DialogsListItem.tsx +0 -819
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +0 -679
- package/src/screens/inbox/components/SlackMessageContainer/ImageViewerModal.tsx +0 -113
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +0 -313
- package/src/screens/inbox/components/SlackMessageContainer/SlackMessage.tsx +0 -145
- package/src/screens/inbox/components/SlackMessageContainer/index.ts +0 -3
- package/src/screens/inbox/components/SmartLoader.tsx +0 -61
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +0 -301
- package/src/screens/inbox/components/ThreadsViewItem.tsx +0 -233
- package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +0 -145
- package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +0 -159
- package/src/screens/inbox/config/config.ts +0 -15
- package/src/screens/inbox/config/index.ts +0 -1
- package/src/screens/inbox/containers/ConversationView.tsx +0 -1784
- package/src/screens/inbox/containers/Dialogs.tsx +0 -829
- package/src/screens/inbox/containers/SupportServiceDialogs.tsx +0 -119
- package/src/screens/inbox/containers/ThreadConversationView.tsx +0 -2295
- package/src/screens/inbox/containers/ThreadsView.tsx +0 -224
- package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +0 -20
- package/src/screens/inbox/containers/workflow/conversation-xstate.ts +0 -313
- package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +0 -196
- package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +0 -401
- package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +0 -136
- package/src/screens/inbox/index.ts +0 -37
- package/src/screens/inbox/machines/threadsMachine.ts +0 -147
- package/src/screens/inbox/workflow/dialog-threads-xstate.ts +0 -163
- package/src/screens/index.ts +0 -4
- package/tsconfig.json +0 -13
- package/webpack.config.js +0 -58
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useMemo, useEffect, useState } from 'react';
|
|
2
|
-
import { FlatList, Box, Heading, Input, Text, Icon, Center, Spinner, Button } from '@admin-layout/gluestack-ui-mobile';
|
|
3
|
-
import { Ionicons } from '@expo/vector-icons';
|
|
4
|
-
import { useSelector, useDispatch } from 'react-redux';
|
|
5
|
-
import { useNavigation, useRoute, useIsFocused, useFocusEffect } from '@react-navigation/native';
|
|
6
|
-
import { orderBy, uniqBy, startCase } from 'lodash-es';
|
|
7
|
-
import {
|
|
8
|
-
useThreadMessagesQuery,
|
|
9
|
-
OnThreadCreatedUpdatedDocument as THREAD_CHAT_ADDED,
|
|
10
|
-
useOnThreadCreatedUpdatedSubscription,
|
|
11
|
-
} from 'common/graphql';
|
|
12
|
-
import { userSelector } from '@adminide-stack/user-auth0-client';
|
|
13
|
-
import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
|
|
14
|
-
import { ThreadViewItem } from '../components/ThreadsViewItem';
|
|
15
|
-
import { config } from '../config';
|
|
16
|
-
import { Actions } from '../workflow/dialog-threads-xstate';
|
|
17
|
-
const { MESSAGES_PER_PAGE } = config;
|
|
18
|
-
|
|
19
|
-
export interface ThreadsViewProps {
|
|
20
|
-
data: any;
|
|
21
|
-
loading: boolean;
|
|
22
|
-
refetch: any;
|
|
23
|
-
subscribeToMore: any;
|
|
24
|
-
error: any;
|
|
25
|
-
channelId?: string;
|
|
26
|
-
role?: string;
|
|
27
|
-
channelsDetail?: any;
|
|
28
|
-
refetchChannelDetail: (id: any) => Promise<any>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface IThreadSubscriptionHandlerProps {
|
|
32
|
-
subscribeToNewMessages: () => any;
|
|
33
|
-
channelId: string | undefined;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const ThreadsViewComponent = ({
|
|
37
|
-
data,
|
|
38
|
-
loading: threadLoading,
|
|
39
|
-
refetch,
|
|
40
|
-
subscribeToMore,
|
|
41
|
-
error,
|
|
42
|
-
channelId,
|
|
43
|
-
role,
|
|
44
|
-
channelsDetail,
|
|
45
|
-
refetchChannelDetail,
|
|
46
|
-
}: ThreadsViewProps) => {
|
|
47
|
-
const { params } = useRoute<any>();
|
|
48
|
-
const auth = useSelector(userSelector);
|
|
49
|
-
const dispatch = useDispatch();
|
|
50
|
-
const navigation = useNavigation<any>();
|
|
51
|
-
const isFocused = useIsFocused();
|
|
52
|
-
const [refreshing, setRefresh] = useState<boolean>(false);
|
|
53
|
-
|
|
54
|
-
// Use thread subscription for real-time updates
|
|
55
|
-
const { data: threadCreatedUpdated } = useOnThreadCreatedUpdatedSubscription({
|
|
56
|
-
variables: { channelId: channelId?.toString() },
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Subscribe to thread updates
|
|
60
|
-
const subscribeToNewMessages = useCallback(() => {
|
|
61
|
-
return subscribeToMore({
|
|
62
|
-
document: THREAD_CHAT_ADDED,
|
|
63
|
-
variables: { channelId: channelId?.toString() },
|
|
64
|
-
updateQuery: (prev: any, { subscriptionData }: any) => {
|
|
65
|
-
if (!subscriptionData.data) return prev;
|
|
66
|
-
|
|
67
|
-
const newThread = subscriptionData.data.threadCreatedUpdated.data;
|
|
68
|
-
if (!newThread) return prev;
|
|
69
|
-
|
|
70
|
-
const threads = prev.threadMessages.data || [];
|
|
71
|
-
const index = threads.findIndex((t: any) => t.id === newThread.id);
|
|
72
|
-
|
|
73
|
-
let updatedThreads;
|
|
74
|
-
if (index > -1) {
|
|
75
|
-
// Update existing thread
|
|
76
|
-
updatedThreads = [...threads];
|
|
77
|
-
updatedThreads[index] = newThread;
|
|
78
|
-
} else {
|
|
79
|
-
// Add new thread
|
|
80
|
-
updatedThreads = [newThread, ...threads];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
...prev,
|
|
85
|
-
threadMessages: {
|
|
86
|
-
...prev.threadMessages,
|
|
87
|
-
data: uniqBy(updatedThreads, 'id'),
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
}, [channelId, subscribeToMore]);
|
|
93
|
-
|
|
94
|
-
useFocusEffect(
|
|
95
|
-
React.useCallback(() => {
|
|
96
|
-
// Do something when the screen is focused
|
|
97
|
-
navigation?.setOptions({ title: params?.title ?? 'Thread' });
|
|
98
|
-
refetch({
|
|
99
|
-
channelId: channelId?.toString(),
|
|
100
|
-
role: role?.toString(),
|
|
101
|
-
limit: MESSAGES_PER_PAGE,
|
|
102
|
-
repliesLimit2: 5,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Setup subscription
|
|
106
|
-
const unsubscribe = subscribeToNewMessages();
|
|
107
|
-
|
|
108
|
-
return () => {
|
|
109
|
-
// Unsubscribe on cleanup
|
|
110
|
-
if (unsubscribe) unsubscribe();
|
|
111
|
-
};
|
|
112
|
-
}, []),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
// Effect for thread updates from subscription
|
|
116
|
-
React.useEffect(() => {
|
|
117
|
-
if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
|
|
118
|
-
// The subscription handler will handle updates
|
|
119
|
-
}
|
|
120
|
-
}, [threadCreatedUpdated]);
|
|
121
|
-
|
|
122
|
-
const threads = React.useMemo(() => {
|
|
123
|
-
if (data?.threadMessages?.data?.length == 0) return [];
|
|
124
|
-
const threadsFiltered = data?.threadMessages?.data
|
|
125
|
-
? uniqBy([...data?.threadMessages?.data], ({ id }: any) => id)
|
|
126
|
-
: [];
|
|
127
|
-
return orderBy(threadsFiltered, ['updatedAt'], ['desc']) || [];
|
|
128
|
-
}, [data]);
|
|
129
|
-
|
|
130
|
-
const threadReplies = React.useMemo(() => {
|
|
131
|
-
if (!threads?.length) return null;
|
|
132
|
-
return threads?.map((t: any) => t?.replies)?.flat(1) || [];
|
|
133
|
-
}, [threads]);
|
|
134
|
-
|
|
135
|
-
const handleSelectThread = useCallback((id: any, title: any, postParentId: any) => {
|
|
136
|
-
navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
|
|
137
|
-
channelId: id,
|
|
138
|
-
role: role?.toString(),
|
|
139
|
-
title: title,
|
|
140
|
-
postParentId: postParentId,
|
|
141
|
-
hideTabBar: true,
|
|
142
|
-
});
|
|
143
|
-
}, []);
|
|
144
|
-
|
|
145
|
-
const handleRefresh = useCallback(() => {
|
|
146
|
-
setRefresh(true);
|
|
147
|
-
refetch({
|
|
148
|
-
channelId: channelId?.toString(),
|
|
149
|
-
role: role?.toString(),
|
|
150
|
-
limit: MESSAGES_PER_PAGE,
|
|
151
|
-
repliesLimit2: 5,
|
|
152
|
-
}).finally(() => {
|
|
153
|
-
setRefresh(false);
|
|
154
|
-
});
|
|
155
|
-
}, []);
|
|
156
|
-
|
|
157
|
-
const fetchMoreThreads = useCallback(() => {
|
|
158
|
-
refetch({
|
|
159
|
-
channelId: channelId?.toString(),
|
|
160
|
-
role: role?.toString(),
|
|
161
|
-
limit: MESSAGES_PER_PAGE,
|
|
162
|
-
repliesLimit2: 5,
|
|
163
|
-
});
|
|
164
|
-
}, []);
|
|
165
|
-
|
|
166
|
-
if (error) {
|
|
167
|
-
return (
|
|
168
|
-
<Box style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
169
|
-
<Text>Error loading threads. {error.message}</Text>
|
|
170
|
-
<Button onPress={handleRefresh} style={{ marginTop: 4 }}>
|
|
171
|
-
<Text>Try Again</Text>
|
|
172
|
-
</Button>
|
|
173
|
-
</Box>
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
<Box style={{ flex: 1 }}>
|
|
179
|
-
{threadLoading && !threads?.length ? (
|
|
180
|
-
<Center style={{ flex: 1 }}>
|
|
181
|
-
<Spinner size="large" />
|
|
182
|
-
</Center>
|
|
183
|
-
) : threads?.length === 0 ? (
|
|
184
|
-
<Box style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
|
185
|
-
<Text>No threads found</Text>
|
|
186
|
-
</Box>
|
|
187
|
-
) : (
|
|
188
|
-
<FlatList
|
|
189
|
-
data={threads}
|
|
190
|
-
keyExtractor={(item) => item.id.toString()}
|
|
191
|
-
renderItem={({ item }) => (
|
|
192
|
-
<ThreadViewItem
|
|
193
|
-
{...item}
|
|
194
|
-
onPress={handleSelectThread}
|
|
195
|
-
channelId={channelId}
|
|
196
|
-
channelsDetail={channelsDetail}
|
|
197
|
-
/>
|
|
198
|
-
)}
|
|
199
|
-
refreshing={refreshing}
|
|
200
|
-
onRefresh={handleRefresh}
|
|
201
|
-
onEndReached={fetchMoreThreads}
|
|
202
|
-
onEndReachedThreshold={0.5}
|
|
203
|
-
contentContainerStyle={{ padding: 16 }}
|
|
204
|
-
ItemSeparatorComponent={() => <Box style={{ height: 3 }} />}
|
|
205
|
-
/>
|
|
206
|
-
)}
|
|
207
|
-
<SubscriptionHandler subscribeToNewMessages={subscribeToNewMessages} channelId={channelId} />
|
|
208
|
-
</Box>
|
|
209
|
-
);
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
// Component to handle subscription logic
|
|
213
|
-
const SubscriptionHandler = ({ subscribeToNewMessages, channelId }: IThreadSubscriptionHandlerProps) => {
|
|
214
|
-
useEffect(() => {
|
|
215
|
-
const unsubscribe = subscribeToNewMessages();
|
|
216
|
-
return () => {
|
|
217
|
-
if (unsubscribe) unsubscribe();
|
|
218
|
-
};
|
|
219
|
-
}, [channelId]);
|
|
220
|
-
|
|
221
|
-
return null;
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
export const ThreadsView = ThreadsViewComponent;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ApolloError, FetchResult, SingleExecutionResult } from '@apollo/client';
|
|
2
|
-
|
|
3
|
-
// Accept any promise-like object with a data field
|
|
4
|
-
export const newHandleMutationResult = async (
|
|
5
|
-
promise: Promise<any>,
|
|
6
|
-
transformer: (result: any) => any,
|
|
7
|
-
): Promise<any> => {
|
|
8
|
-
try {
|
|
9
|
-
const result = await promise;
|
|
10
|
-
if (result.errors) {
|
|
11
|
-
throw result.errors;
|
|
12
|
-
}
|
|
13
|
-
if (!result.data) {
|
|
14
|
-
throw new Error('No data returned from query');
|
|
15
|
-
}
|
|
16
|
-
return transformer(result.data);
|
|
17
|
-
} catch (error: any) {
|
|
18
|
-
throw error;
|
|
19
|
-
}
|
|
20
|
-
};
|
|
@@ -1,313 +0,0 @@
|
|
|
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
|
-
SEND_MESSAGE = 'SEND_MESSAGE',
|
|
8
|
-
SEND_MESSAGE_WITH_FILE = 'SEND_MESSAGE_WITH_FILE',
|
|
9
|
-
SET_CHANNEL_MESSAGES = 'SET_CHANNEL_MESSAGES',
|
|
10
|
-
CLEAR_MESSAGES = 'CLEAR_MESSAGES',
|
|
11
|
-
FETCH_MORE_MESSAGES = 'FETCH_MORE_MESSAGES',
|
|
12
|
-
SUBSCRIBE_TO_MESSAGES = 'SUBSCRIBE_TO_MESSAGES',
|
|
13
|
-
CREATE_DIRECT_CHANNEL = 'CREATE_DIRECT_CHANNEL',
|
|
14
|
-
START_LOADING = 'START_LOADING',
|
|
15
|
-
STOP_LOADING = 'STOP_LOADING',
|
|
16
|
-
SET_IMAGE = 'SET_IMAGE',
|
|
17
|
-
CLEAR_IMAGE = 'CLEAR_IMAGE',
|
|
18
|
-
SET_MESSAGE_TEXT = 'SET_MESSAGE_TEXT',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const enum BaseState {
|
|
22
|
-
Idle = 'idle',
|
|
23
|
-
Error = 'error',
|
|
24
|
-
Loading = 'loading',
|
|
25
|
-
Done = 'done',
|
|
26
|
-
FetchChannels = 'fetchChannels',
|
|
27
|
-
FetchMessages = 'fetchMessages',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const enum MainState {
|
|
31
|
-
SendMessage = 'sendMessage',
|
|
32
|
-
SendMessageWithFile = 'sendMessageWithFile',
|
|
33
|
-
FetchMoreMessages = 'fetchMoreMessages',
|
|
34
|
-
CreateDirectChannel = 'createDirectChannel',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const conversationXstate = setup({
|
|
38
|
-
types: {
|
|
39
|
-
context: {} as {
|
|
40
|
-
channelId: string | null;
|
|
41
|
-
channelMessages: any[];
|
|
42
|
-
totalCount: number;
|
|
43
|
-
skip: number;
|
|
44
|
-
loading: boolean;
|
|
45
|
-
loadingOldMessages: boolean;
|
|
46
|
-
error: string | null;
|
|
47
|
-
selectedImage: string;
|
|
48
|
-
files: any[];
|
|
49
|
-
images: any[];
|
|
50
|
-
messageText: string;
|
|
51
|
-
imageLoading: boolean;
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
actions: {
|
|
55
|
-
errorState: assign(({ context, event }) => {
|
|
56
|
-
return {
|
|
57
|
-
...context,
|
|
58
|
-
error: event.data?.message || 'An error occurred',
|
|
59
|
-
loading: false,
|
|
60
|
-
loadingOldMessages: false,
|
|
61
|
-
imageLoading: false,
|
|
62
|
-
};
|
|
63
|
-
}),
|
|
64
|
-
setInitialContext: assign(({ context, event }) => {
|
|
65
|
-
return merge({
|
|
66
|
-
...context,
|
|
67
|
-
channelId: event.data?.channelId || null,
|
|
68
|
-
loading: false,
|
|
69
|
-
});
|
|
70
|
-
}),
|
|
71
|
-
setChannelMessages: assign(({ context, event }) => {
|
|
72
|
-
return {
|
|
73
|
-
...context,
|
|
74
|
-
channelMessages: event.data?.messages || [],
|
|
75
|
-
totalCount: event.data?.totalCount || 0,
|
|
76
|
-
loading: false,
|
|
77
|
-
};
|
|
78
|
-
}),
|
|
79
|
-
addChannelMessages: assign(({ context, event }) => {
|
|
80
|
-
const messages = event.data?.messages || [];
|
|
81
|
-
return {
|
|
82
|
-
...context,
|
|
83
|
-
channelMessages: [...context.channelMessages, ...messages],
|
|
84
|
-
loadingOldMessages: false,
|
|
85
|
-
};
|
|
86
|
-
}),
|
|
87
|
-
addNewMessage: assign(({ context, event }) => {
|
|
88
|
-
const message = event.data?.message;
|
|
89
|
-
if (!message) return context;
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
...context,
|
|
93
|
-
channelMessages: [...context.channelMessages, message],
|
|
94
|
-
totalCount: context.totalCount + 1,
|
|
95
|
-
loading: false,
|
|
96
|
-
};
|
|
97
|
-
}),
|
|
98
|
-
updateSkip: assign(({ context, event }) => {
|
|
99
|
-
return {
|
|
100
|
-
...context,
|
|
101
|
-
skip: context.channelMessages.length,
|
|
102
|
-
loadingOldMessages: true,
|
|
103
|
-
};
|
|
104
|
-
}),
|
|
105
|
-
clearMessages: assign(({ context }) => {
|
|
106
|
-
return {
|
|
107
|
-
...context,
|
|
108
|
-
channelMessages: [],
|
|
109
|
-
totalCount: 0,
|
|
110
|
-
skip: 0,
|
|
111
|
-
};
|
|
112
|
-
}),
|
|
113
|
-
setChannelId: assign(({ context, event }) => {
|
|
114
|
-
return {
|
|
115
|
-
...context,
|
|
116
|
-
channelId: event.data?.channelId || null,
|
|
117
|
-
};
|
|
118
|
-
}),
|
|
119
|
-
startLoading: assign(({ context }) => {
|
|
120
|
-
return {
|
|
121
|
-
...context,
|
|
122
|
-
loading: true,
|
|
123
|
-
};
|
|
124
|
-
}),
|
|
125
|
-
stopLoading: assign(({ context }) => {
|
|
126
|
-
return {
|
|
127
|
-
...context,
|
|
128
|
-
loading: false,
|
|
129
|
-
};
|
|
130
|
-
}),
|
|
131
|
-
startImageLoading: assign(({ context }) => {
|
|
132
|
-
return {
|
|
133
|
-
...context,
|
|
134
|
-
imageLoading: true,
|
|
135
|
-
};
|
|
136
|
-
}),
|
|
137
|
-
stopImageLoading: assign(({ context }) => {
|
|
138
|
-
return {
|
|
139
|
-
...context,
|
|
140
|
-
imageLoading: false,
|
|
141
|
-
};
|
|
142
|
-
}),
|
|
143
|
-
setSelectedImage: assign(({ context, event }) => {
|
|
144
|
-
return {
|
|
145
|
-
...context,
|
|
146
|
-
selectedImage: event.data?.image || '',
|
|
147
|
-
files: event.data?.files || context.files,
|
|
148
|
-
images: event.data?.images || context.images,
|
|
149
|
-
imageLoading: false,
|
|
150
|
-
};
|
|
151
|
-
}),
|
|
152
|
-
clearImageData: assign(({ context }) => {
|
|
153
|
-
return {
|
|
154
|
-
...context,
|
|
155
|
-
selectedImage: '',
|
|
156
|
-
files: [],
|
|
157
|
-
images: [],
|
|
158
|
-
};
|
|
159
|
-
}),
|
|
160
|
-
setMessageText: assign(({ context, event }) => {
|
|
161
|
-
return {
|
|
162
|
-
...context,
|
|
163
|
-
messageText: event.data?.messageText || '',
|
|
164
|
-
};
|
|
165
|
-
}),
|
|
166
|
-
},
|
|
167
|
-
guards: {
|
|
168
|
-
hasMoreMessages: ({ context }) => {
|
|
169
|
-
return context.totalCount > context.channelMessages.length;
|
|
170
|
-
},
|
|
171
|
-
},
|
|
172
|
-
}).createMachine({
|
|
173
|
-
id: 'conversation-view',
|
|
174
|
-
initial: BaseState.Idle,
|
|
175
|
-
context: {
|
|
176
|
-
channelId: null,
|
|
177
|
-
channelMessages: [],
|
|
178
|
-
totalCount: 0,
|
|
179
|
-
skip: 0,
|
|
180
|
-
loading: false,
|
|
181
|
-
loadingOldMessages: false,
|
|
182
|
-
error: null,
|
|
183
|
-
selectedImage: '',
|
|
184
|
-
files: [],
|
|
185
|
-
images: [],
|
|
186
|
-
messageText: '',
|
|
187
|
-
imageLoading: false,
|
|
188
|
-
},
|
|
189
|
-
states: {
|
|
190
|
-
[BaseState.Idle]: {
|
|
191
|
-
on: {
|
|
192
|
-
[Actions.INITIAL_CONTEXT]: {
|
|
193
|
-
target: BaseState.FetchMessages,
|
|
194
|
-
actions: ['setInitialContext'],
|
|
195
|
-
},
|
|
196
|
-
[Actions.SEND_MESSAGE]: {
|
|
197
|
-
target: MainState.SendMessage,
|
|
198
|
-
actions: ['startLoading'],
|
|
199
|
-
},
|
|
200
|
-
[Actions.SEND_MESSAGE_WITH_FILE]: {
|
|
201
|
-
target: MainState.SendMessageWithFile,
|
|
202
|
-
actions: ['startLoading'],
|
|
203
|
-
},
|
|
204
|
-
[Actions.FETCH_MORE_MESSAGES]: {
|
|
205
|
-
target: MainState.FetchMoreMessages,
|
|
206
|
-
actions: ['updateSkip'],
|
|
207
|
-
guard: 'hasMoreMessages',
|
|
208
|
-
},
|
|
209
|
-
[Actions.CLEAR_MESSAGES]: {
|
|
210
|
-
target: BaseState.Idle,
|
|
211
|
-
actions: ['clearMessages'],
|
|
212
|
-
},
|
|
213
|
-
[Actions.CREATE_DIRECT_CHANNEL]: {
|
|
214
|
-
target: MainState.CreateDirectChannel,
|
|
215
|
-
actions: ['startLoading'],
|
|
216
|
-
},
|
|
217
|
-
[Actions.START_LOADING]: {
|
|
218
|
-
target: BaseState.Idle,
|
|
219
|
-
actions: ['startLoading'],
|
|
220
|
-
},
|
|
221
|
-
[Actions.STOP_LOADING]: {
|
|
222
|
-
target: BaseState.Idle,
|
|
223
|
-
actions: ['stopLoading'],
|
|
224
|
-
},
|
|
225
|
-
[Actions.SET_IMAGE]: {
|
|
226
|
-
target: BaseState.Idle,
|
|
227
|
-
actions: ['setSelectedImage'],
|
|
228
|
-
},
|
|
229
|
-
[Actions.CLEAR_IMAGE]: {
|
|
230
|
-
target: BaseState.Idle,
|
|
231
|
-
actions: ['clearImageData'],
|
|
232
|
-
},
|
|
233
|
-
[Actions.SET_MESSAGE_TEXT]: {
|
|
234
|
-
target: BaseState.Idle,
|
|
235
|
-
actions: ['setMessageText'],
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
},
|
|
239
|
-
[BaseState.Error]: {
|
|
240
|
-
entry: ['errorState'],
|
|
241
|
-
on: {
|
|
242
|
-
[Actions.ERROR_HANDLED]: {
|
|
243
|
-
target: BaseState.Idle,
|
|
244
|
-
},
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
[BaseState.FetchMessages]: {
|
|
248
|
-
invoke: {
|
|
249
|
-
src: 'fetchMessages',
|
|
250
|
-
input: ({ context, event }) => ({ context, event }),
|
|
251
|
-
onDone: {
|
|
252
|
-
target: BaseState.Idle,
|
|
253
|
-
actions: ['setChannelMessages'],
|
|
254
|
-
},
|
|
255
|
-
onError: {
|
|
256
|
-
target: BaseState.Error,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
[MainState.SendMessage]: {
|
|
261
|
-
invoke: {
|
|
262
|
-
src: 'sendMessage',
|
|
263
|
-
input: ({ context, event }) => ({ context, event }),
|
|
264
|
-
onDone: {
|
|
265
|
-
target: BaseState.Idle,
|
|
266
|
-
actions: ['addNewMessage', 'stopLoading'],
|
|
267
|
-
},
|
|
268
|
-
onError: {
|
|
269
|
-
target: BaseState.Error,
|
|
270
|
-
},
|
|
271
|
-
},
|
|
272
|
-
},
|
|
273
|
-
[MainState.SendMessageWithFile]: {
|
|
274
|
-
invoke: {
|
|
275
|
-
src: 'sendMessageWithFile',
|
|
276
|
-
input: ({ context, event }) => ({ context, event }),
|
|
277
|
-
onDone: {
|
|
278
|
-
target: BaseState.Idle,
|
|
279
|
-
actions: ['addNewMessage', 'clearImageData', 'stopLoading'],
|
|
280
|
-
},
|
|
281
|
-
onError: {
|
|
282
|
-
target: BaseState.Error,
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
[MainState.FetchMoreMessages]: {
|
|
287
|
-
invoke: {
|
|
288
|
-
src: 'fetchMoreMessages',
|
|
289
|
-
input: ({ context, event }) => ({ context, event }),
|
|
290
|
-
onDone: {
|
|
291
|
-
target: BaseState.Idle,
|
|
292
|
-
actions: ['addChannelMessages'],
|
|
293
|
-
},
|
|
294
|
-
onError: {
|
|
295
|
-
target: BaseState.Error,
|
|
296
|
-
},
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
[MainState.CreateDirectChannel]: {
|
|
300
|
-
invoke: {
|
|
301
|
-
src: 'createDirectChannel',
|
|
302
|
-
input: ({ context, event }) => ({ context, event }),
|
|
303
|
-
onDone: {
|
|
304
|
-
target: BaseState.Idle,
|
|
305
|
-
actions: ['setChannelId', 'stopLoading'],
|
|
306
|
-
},
|
|
307
|
-
onError: {
|
|
308
|
-
target: BaseState.Error,
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
} as any);
|