@messenger-box/platform-mobile 10.0.3-alpha.7 → 10.0.3-alpha.72

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 (98) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/lib/compute.js +2 -3
  3. package/lib/compute.js.map +1 -1
  4. package/lib/index.js.map +1 -1
  5. package/lib/queries/inboxQueries.js +65 -0
  6. package/lib/queries/inboxQueries.js.map +1 -0
  7. package/lib/routes.json +2 -3
  8. package/lib/screens/inbox/DialogMessages.js +1 -1
  9. package/lib/screens/inbox/DialogMessages.js.map +1 -1
  10. package/lib/screens/inbox/DialogThreadMessages.js +4 -8
  11. package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
  12. package/lib/screens/inbox/DialogThreads.js +57 -12
  13. package/lib/screens/inbox/DialogThreads.js.map +1 -1
  14. package/lib/screens/inbox/Inbox.js +1 -1
  15. package/lib/screens/inbox/Inbox.js.map +1 -1
  16. package/lib/screens/inbox/components/CachedImage/consts.js +1 -1
  17. package/lib/screens/inbox/components/CachedImage/consts.js.map +1 -1
  18. package/lib/screens/inbox/components/CachedImage/index.js +168 -46
  19. package/lib/screens/inbox/components/CachedImage/index.js.map +1 -1
  20. package/lib/screens/inbox/components/DialogItem.js +169 -0
  21. package/lib/screens/inbox/components/DialogItem.js.map +1 -0
  22. package/lib/screens/inbox/components/GiftedChatInboxComponent.js +313 -0
  23. package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
  24. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +147 -31
  25. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
  26. package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js +6 -1
  27. package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
  28. package/lib/screens/inbox/components/SubscriptionHandler.js +24 -0
  29. package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
  30. package/lib/screens/inbox/components/ThreadsViewItem.js +66 -55
  31. package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
  32. package/lib/screens/inbox/config/config.js +2 -2
  33. package/lib/screens/inbox/config/config.js.map +1 -1
  34. package/lib/screens/inbox/containers/ConversationView.js +1111 -434
  35. package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
  36. package/lib/screens/inbox/containers/Dialogs.js +193 -80
  37. package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
  38. package/lib/screens/inbox/containers/ThreadConversationView.js +725 -216
  39. package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
  40. package/lib/screens/inbox/containers/ThreadsView.js +83 -50
  41. package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
  42. package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
  43. package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
  44. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
  45. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
  46. package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
  47. package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
  48. package/package.json +4 -4
  49. package/src/compute.ts +5 -6
  50. package/src/index.ts +2 -0
  51. package/src/navigation/InboxNavigation.tsx +3 -3
  52. package/src/queries/inboxQueries.ts +299 -0
  53. package/src/queries/index.d.ts +2 -0
  54. package/src/queries/index.ts +1 -0
  55. package/src/screens/inbox/DialogMessages.tsx +1 -1
  56. package/src/screens/inbox/DialogThreadMessages.tsx +7 -14
  57. package/src/screens/inbox/DialogThreads.tsx +55 -61
  58. package/src/screens/inbox/Inbox.tsx +1 -1
  59. package/src/screens/inbox/components/Actionsheet.tsx +30 -0
  60. package/src/screens/inbox/components/CachedImage/consts.ts +4 -3
  61. package/src/screens/inbox/components/CachedImage/index.tsx +232 -61
  62. package/src/screens/inbox/components/DialogItem.tsx +306 -0
  63. package/src/screens/inbox/components/DialogsHeader.tsx +6 -13
  64. package/src/screens/inbox/components/DialogsListItem.tsx +262 -198
  65. package/src/screens/inbox/components/ExpandableInput.tsx +460 -0
  66. package/src/screens/inbox/components/ExpandableInputActionSheet.tsx +518 -0
  67. package/src/screens/inbox/components/GiftedChatInboxComponent.tsx +411 -0
  68. package/src/screens/inbox/components/ServiceDialogsListItem.tsx +337 -194
  69. package/src/screens/inbox/components/SlackInput.tsx +23 -0
  70. package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +233 -23
  71. package/src/screens/inbox/components/SlackMessageContainer/SlackMessage.tsx +1 -1
  72. package/src/screens/inbox/components/SmartLoader.tsx +61 -0
  73. package/src/screens/inbox/components/SubscriptionHandler.tsx +41 -0
  74. package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +53 -55
  75. package/src/screens/inbox/components/ThreadsViewItem.tsx +178 -285
  76. package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +145 -0
  77. package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +159 -0
  78. package/src/screens/inbox/config/config.ts +2 -2
  79. package/src/screens/inbox/containers/ConversationView.tsx +1843 -702
  80. package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
  81. package/src/screens/inbox/containers/Dialogs.tsx +402 -204
  82. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +4 -4
  83. package/src/screens/inbox/containers/ThreadConversationView.tsx +1350 -319
  84. package/src/screens/inbox/containers/ThreadsView.tsx +105 -193
  85. package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +20 -0
  86. package/src/screens/inbox/containers/workflow/conversation-xstate.ts +313 -0
  87. package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +196 -0
  88. package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +401 -0
  89. package/src/screens/inbox/hooks/useInboxMessages.ts +34 -0
  90. package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +136 -0
  91. package/src/screens/inbox/index.ts +37 -0
  92. package/src/screens/inbox/machines/threadsMachine.ts +147 -0
  93. package/src/screens/inbox/workflow/dialog-threads-xstate.ts +163 -0
  94. package/tsconfig.json +11 -54
  95. package/lib/screens/inbox/components/DialogsListItem.js +0 -171
  96. package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
  97. package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -171
  98. package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +0 -1
@@ -6,13 +6,14 @@ import { useNavigation, useRoute, useIsFocused, useFocusEffect } from '@react-na
6
6
  import { orderBy, uniqBy, startCase } from 'lodash-es';
7
7
  import {
8
8
  useThreadMessagesQuery,
9
- OnThreadCreatedUpdatedDocument as THREAD_CHAT_ADDED,
10
- useOnThreadCreatedUpdatedSubscription,
11
- } from 'common/lib/generated/generated.js';
9
+ THREAD_CREATED_UPDATED,
10
+ useThreadCreatedUpdatedSubscription,
11
+ } from '../../../queries/inboxQueries';
12
12
  import { userSelector } from '@adminide-stack/user-auth0-client';
13
13
  import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
14
14
  import { ThreadViewItem } from '../components/ThreadsViewItem';
15
15
  import { config } from '../config';
16
+ import { Actions } from '../workflow/dialog-threads-xstate';
16
17
  const { MESSAGES_PER_PAGE } = config;
17
18
 
18
19
  export interface ThreadsViewProps {
@@ -49,27 +50,46 @@ const ThreadsViewComponent = ({
49
50
  const navigation = useNavigation<any>();
50
51
  const isFocused = useIsFocused();
51
52
  const [refreshing, setRefresh] = useState<boolean>(false);
52
- const [threadData, setThreadsData] = useState<any>([]);
53
53
 
54
- // const {
55
- // data,
56
- // loading: threadLoading,
57
- // error,
58
- // refetch,
59
- // subscribeToMore,
60
- // } = useThreadMessagesQuery({
61
- // variables: {
62
- // channelId: channelId?.toString(),
63
- // role: role?.toString(),
64
- // limit: MESSAGES_PER_PAGE,
65
- // repliesLimit2: 5,
66
- // },
67
- // // fetchPolicy: 'cache-and-network',
68
- // });
69
-
70
- // const { data: threadCreatedUpdated } = useOnThreadCreatedUpdatedSubscription({
71
- // variables: { channelId: channelId?.toString() },
72
- // });
54
+ // Use thread subscription for real-time updates
55
+ const { data: threadCreatedUpdated } = useThreadCreatedUpdatedSubscription({
56
+ variables: { channelId: channelId?.toString() },
57
+ });
58
+
59
+ // Subscribe to thread updates
60
+ const subscribeToNewMessages = useCallback(() => {
61
+ return subscribeToMore({
62
+ document: THREAD_CREATED_UPDATED,
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]);
73
93
 
74
94
  useFocusEffect(
75
95
  React.useCallback(() => {
@@ -81,64 +101,25 @@ const ThreadsViewComponent = ({
81
101
  limit: MESSAGES_PER_PAGE,
82
102
  repliesLimit2: 5,
83
103
  });
84
- // .then(({ data }) => {
85
- // if (!data?.threadMessages?.data) {
86
- // return;
87
- // }
88
104
 
89
- // if (data?.threadMessages?.data?.length) {
90
- // const { data: newThreads } = data?.threadMessages;
91
- // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
92
- // }
93
- // });
105
+ // Setup subscription
106
+ const unsubscribe = subscribeToNewMessages();
94
107
 
95
108
  return () => {
96
- // Do something when the screen is unfocused
97
- // Useful for cleanup functions
109
+ // Unsubscribe on cleanup
110
+ if (unsubscribe) unsubscribe();
98
111
  };
99
112
  }, []),
100
113
  );
101
114
 
102
- // React.useEffect(() => {
103
- // if (data?.threadMessages?.data?.length) {
104
- // const { data: newThreads } = data?.threadMessages;
105
- // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
106
- // }
107
- // }, [data]);
108
-
109
- // React.useEffect(() => {
110
- // if (threadCreatedUpdated?.threadCreatedUpdated?.data) {
111
- // const { data: newThreads } = threadCreatedUpdated?.threadCreatedUpdated;
112
-
113
- // setThreadsData((oldThreads: any) => {
114
- // const i = oldThreads.findIndex((el: any) => el.id === newThreads?.id);
115
- // if (i > -1) oldThreads[i] = newThreads; // (2)
116
- // else oldThreads.push(newThreads);
117
- // return oldThreads;
118
- // });
119
- // // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
120
- // }
121
- // }, [threadCreatedUpdated]);
122
-
123
- const setData = React.useCallback((newThreads: any) => {
124
- setThreadsData((oldThreads: any) => {
125
- const i = oldThreads.findIndex((el: any) => el.id === newThreads?.id);
126
- if (i > -1) oldThreads[i] = newThreads; // (2)
127
- else oldThreads.push(newThreads);
128
- return oldThreads;
129
- });
130
- // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, newThreads], ({ id }) => id));
131
- }, []);
132
-
133
- // const threads = React.useMemo(() => {
134
- // if (!threadData?.length) return null;
135
- // return orderBy(threadData, ['updatedAt'], ['desc']) || [];
136
- // //return threadData || [];
137
- // }, [threadData]);
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]);
138
121
 
139
122
  const threads = React.useMemo(() => {
140
- // if (!data?.threadMessages?.data?.length) return null;
141
- // const { data: newThreads } = data?.threadMessages;
142
123
  if (data?.threadMessages?.data?.length == 0) return [];
143
124
  const threadsFiltered = data?.threadMessages?.data
144
125
  ? uniqBy([...data?.threadMessages?.data], ({ id }: any) => id)
@@ -149,7 +130,6 @@ const ThreadsViewComponent = ({
149
130
  const threadReplies = React.useMemo(() => {
150
131
  if (!threads?.length) return null;
151
132
  return threads?.map((t: any) => t?.replies)?.flat(1) || [];
152
- //return threadData || [];
153
133
  }, [threads]);
154
134
 
155
135
  const handleSelectThread = useCallback((id: any, title: any, postParentId: any) => {
@@ -160,153 +140,85 @@ const ThreadsViewComponent = ({
160
140
  postParentId: postParentId,
161
141
  hideTabBar: true,
162
142
  });
163
- // if (params?.channelId) {
164
- // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
165
- // channelId: params?.channelId,
166
- // title: params?.title ?? null,
167
- // postParentId: postParentId,
168
- // hideTabBar: true,
169
- // });
170
- // } else {
171
- // navigation.navigate(config.THREAD_MESSEGE_PATH as any, {
172
- // channelId: id,
173
- // title: title,
174
- // postParentId: postParentId,
175
- // hideTabBar: true,
176
- // });
177
- // }
178
143
  }, []);
179
144
 
180
145
  const handleRefresh = useCallback(() => {
146
+ setRefresh(true);
181
147
  refetch({
182
148
  channelId: channelId?.toString(),
183
149
  role: role?.toString(),
184
150
  limit: MESSAGES_PER_PAGE,
185
151
  repliesLimit2: 5,
152
+ }).finally(() => {
153
+ setRefresh(false);
186
154
  });
187
- // .then(({ data }) => {
188
- // if (!data?.threadMessages?.data) {
189
- // return;
190
- // }
191
-
192
- // if (data?.threadMessages?.data?.length) {
193
- // const { data: newThreads } = data?.threadMessages;
194
- // setThreadsData((oldThreads: any) => uniqBy([...oldThreads, ...newThreads], ({ id }) => id));
195
- // }
196
- // });
197
155
  }, []);
198
156
 
199
157
  const fetchMoreThreads = useCallback(() => {
200
158
  refetch({
201
159
  channelId: channelId?.toString(),
202
160
  role: role?.toString(),
203
- skip: threads?.length,
161
+ limit: MESSAGES_PER_PAGE,
162
+ repliesLimit2: 5,
204
163
  });
205
164
  }, []);
206
165
 
207
- // if (!threadReplies || threadReplies?.length == 0) {
208
- // return (
209
- // <Center w="full" bg={'f8f8f8'} height={'full'}>
210
- // You don't have any message yet!
211
- // </Center>
212
- // );
213
- // }
214
- console.log('threadLoading', threadLoading, ' threads?.length=', threads?.length);
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
+ }
215
176
 
216
177
  return (
217
- <Box
218
- flex={1}
219
- p={'$2'}
220
- pb={'$0'}
221
- $dark-borderColor="$coolGray600"
222
- $dark-backgroundColor="$trueGray700"
223
- $light-backgroundColor="$trueGray50"
224
- >
225
- <FlatList
226
- style={{ flex: 1 }}
227
- data={threads && threads?.length > 0 ? threads : []}
228
- onRefresh={handleRefresh}
229
- refreshing={threadLoading}
230
- contentContainerStyle={{ paddingBottom: 60 }}
231
- ItemSeparatorComponent={() => <Box height="$0.5" backgroundColor="$gray200" />}
232
- renderItem={({ item: thread, index }) => (
233
- <ThreadViewItem
234
- key={index}
235
- onOpen={handleSelectThread}
236
- currentUser={auth}
237
- thread={thread}
238
- role={role}
239
- setData={setData}
240
- />
241
- )}
242
- ListEmptyComponent={() => (
243
- <>
244
- {/* {!threadLoading || threads?.length == 0} */}
245
- {!threadLoading && threads?.length == 0 && (
246
- <Box p={'$5'}>
247
- <Center mt={'$6'}>
248
- <Ionicons name="chatbubbles" size={50} />
249
- <Text>You don't have any message yet!</Text>
250
- </Center>
251
- </Box>
252
- )}
253
- </>
254
- )}
255
- ListFooterComponent={() => (
256
- <>
257
- <SubscriptionHandler
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}
258
195
  channelId={channelId}
259
- subscribeToNewMessages={() =>
260
- subscribeToMore({
261
- document: THREAD_CHAT_ADDED,
262
- variables: {
263
- channelId: channelId?.toString(),
264
- postParentId: null,
265
- },
266
- updateQuery: (prev, { subscriptionData }: any) => {
267
- if (!subscriptionData.data) return prev;
268
- const newPostThreadData: any =
269
- subscriptionData?.data?.threadCreatedUpdated?.data;
270
- const newMessage: any =
271
- subscriptionData?.data?.threadCreatedUpdated?.lastMessage;
272
- const data = prev?.threadMessages?.data?.map((t: any) =>
273
- t.id === newPostThreadData?.id
274
- ? {
275
- ...t,
276
- replies: [newMessage, ...t?.replies],
277
- replyCount: newPostThreadData?.replyCount,
278
- lastReplyAt: newPostThreadData?.lastReplyAt,
279
- updatedAt: newPostThreadData?.updatedAt,
280
- }
281
- : t,
282
- );
283
-
284
- return Object.assign({}, prev, {
285
- threadMessages: {
286
- ...prev?.threadMessages,
287
- // totalCount: prev?.threadMessages?.totalCount + 1,
288
- data: data,
289
- },
290
- });
291
- },
292
- })
293
- }
196
+ channelsDetail={channelsDetail}
294
197
  />
295
- </>
296
- )}
297
- keyExtractor={(item, index) => 'threads-view-key' + index}
298
- onEndReached={fetchMoreThreads}
299
- onEndReachedThreshold={0.1}
300
- />
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} />
301
208
  </Box>
302
209
  );
303
210
  };
304
211
 
212
+ // Component to handle subscription logic
305
213
  const SubscriptionHandler = ({ subscribeToNewMessages, channelId }: IThreadSubscriptionHandlerProps) => {
306
- useEffect(() => subscribeToNewMessages(), [channelId]);
307
- return <></>;
214
+ useEffect(() => {
215
+ const unsubscribe = subscribeToNewMessages();
216
+ return () => {
217
+ if (unsubscribe) unsubscribe();
218
+ };
219
+ }, [channelId]);
220
+
221
+ return null;
308
222
  };
309
223
 
310
224
  export const ThreadsView = ThreadsViewComponent;
311
-
312
- // export const ThreadsView = React.memo(ThreadsViewComponent);
@@ -0,0 +1,20 @@
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
+ };