@messenger-box/platform-mobile 10.0.3-alpha.16 → 10.0.3-alpha.162

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 (95) hide show
  1. package/CHANGELOG.md +248 -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/module.js.map +1 -1
  6. package/lib/queries/inboxQueries.js +65 -0
  7. package/lib/queries/inboxQueries.js.map +1 -0
  8. package/lib/routes.json +13 -1
  9. package/lib/screens/inbox/DialogMessages.js +5 -3
  10. package/lib/screens/inbox/DialogMessages.js.map +1 -1
  11. package/lib/screens/inbox/DialogThreadMessages.js +3 -7
  12. package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
  13. package/lib/screens/inbox/DialogThreads.js +57 -18
  14. package/lib/screens/inbox/DialogThreads.js.map +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/ImageViewerModal.js.map +1 -1
  25. package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js +197 -0
  26. package/lib/screens/inbox/components/SlackMessageContainer/PaymentMessage.js.map +1 -0
  27. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +141 -31
  28. package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
  29. package/lib/screens/inbox/components/SlackMessageContainer/SlackMessage.js.map +1 -1
  30. package/lib/screens/inbox/components/SubscriptionHandler.js +24 -0
  31. package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
  32. package/lib/screens/inbox/components/ThreadsViewItem.js +66 -44
  33. package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
  34. package/lib/screens/inbox/config/config.js +2 -2
  35. package/lib/screens/inbox/config/config.js.map +1 -1
  36. package/lib/screens/inbox/containers/ConversationView.js +1205 -432
  37. package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
  38. package/lib/screens/inbox/containers/Dialogs.js +193 -80
  39. package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
  40. package/lib/screens/inbox/containers/ThreadConversationView.js +724 -207
  41. package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
  42. package/lib/screens/inbox/containers/ThreadsView.js +83 -50
  43. package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
  44. package/lib/screens/inbox/hooks/useInboxMessages.js +31 -0
  45. package/lib/screens/inbox/hooks/useInboxMessages.js.map +1 -0
  46. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
  47. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
  48. package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
  49. package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
  50. package/package.json +5 -5
  51. package/src/index.ts +2 -0
  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 +2 -1
  56. package/src/screens/inbox/DialogThreadMessages.tsx +3 -11
  57. package/src/screens/inbox/DialogThreads.tsx +53 -60
  58. package/src/screens/inbox/components/Actionsheet.tsx +30 -0
  59. package/src/screens/inbox/components/CachedImage/consts.ts +4 -3
  60. package/src/screens/inbox/components/CachedImage/index.tsx +232 -61
  61. package/src/screens/inbox/components/DialogItem.tsx +306 -0
  62. package/src/screens/inbox/components/DialogsListItem.tsx +230 -170
  63. package/src/screens/inbox/components/ExpandableInput.tsx +460 -0
  64. package/src/screens/inbox/components/ExpandableInputActionSheet.tsx +518 -0
  65. package/src/screens/inbox/components/GiftedChatInboxComponent.tsx +411 -0
  66. package/src/screens/inbox/components/ServiceDialogsListItem.tsx +330 -171
  67. package/src/screens/inbox/components/SlackInput.tsx +23 -0
  68. package/src/screens/inbox/components/SlackMessageContainer/PaymentMessage.tsx +199 -0
  69. package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +233 -23
  70. package/src/screens/inbox/components/SmartLoader.tsx +61 -0
  71. package/src/screens/inbox/components/SubscriptionHandler.tsx +41 -0
  72. package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +41 -24
  73. package/src/screens/inbox/components/ThreadsViewItem.tsx +177 -265
  74. package/src/screens/inbox/components/workflow/dialogs-list-item-xstate.ts +145 -0
  75. package/src/screens/inbox/components/workflow/service-dialogs-list-item-xstate.ts +159 -0
  76. package/src/screens/inbox/config/config.ts +2 -2
  77. package/src/screens/inbox/containers/ConversationView.tsx +2004 -698
  78. package/src/screens/inbox/containers/ConversationView.tsx.bk +1467 -0
  79. package/src/screens/inbox/containers/Dialogs.tsx +402 -196
  80. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +2 -2
  81. package/src/screens/inbox/containers/ThreadConversationView.tsx +1337 -301
  82. package/src/screens/inbox/containers/ThreadsView.tsx +105 -186
  83. package/src/screens/inbox/containers/workflow/apollo/handleResult.ts +20 -0
  84. package/src/screens/inbox/containers/workflow/conversation-xstate.ts +313 -0
  85. package/src/screens/inbox/containers/workflow/dialogs-xstate.ts +196 -0
  86. package/src/screens/inbox/containers/workflow/thread-conversation-xstate.ts +401 -0
  87. package/src/screens/inbox/hooks/useInboxMessages.ts +34 -0
  88. package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +136 -0
  89. package/src/screens/inbox/index.ts +37 -0
  90. package/src/screens/inbox/machines/threadsMachine.ts +147 -0
  91. package/src/screens/inbox/workflow/dialog-threads-xstate.ts +163 -0
  92. package/lib/screens/inbox/components/DialogsListItem.js +0 -175
  93. package/lib/screens/inbox/components/DialogsListItem.js.map +0 -1
  94. package/lib/screens/inbox/components/ServiceDialogsListItem.js +0 -165
  95. 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/graphql';
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,146 +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 className="flex-1 p-2 pb-0 bg-gray-100 dark:border-gray-600 dark:bg-gray-700">
218
- <FlatList
219
- style={{ flex: 1 }}
220
- data={threads && threads?.length > 0 ? threads : []}
221
- onRefresh={handleRefresh}
222
- refreshing={threadLoading}
223
- contentContainerStyle={{ paddingBottom: 60 }}
224
- ItemSeparatorComponent={() => <Box className="h-0.5 bg-gray-200" />}
225
- renderItem={({ item: thread, index }) => (
226
- <ThreadViewItem
227
- key={index}
228
- onOpen={handleSelectThread}
229
- currentUser={auth}
230
- thread={thread}
231
- role={role}
232
- setData={setData}
233
- />
234
- )}
235
- ListEmptyComponent={() => (
236
- <>
237
- {/* {!threadLoading || threads?.length == 0} */}
238
- {!threadLoading && threads?.length == 0 && (
239
- <Box className="p-5">
240
- <Center className="mt-6">
241
- <Ionicons name="chatbubbles" size={50} />
242
- <Text>You don't have any message yet!</Text>
243
- </Center>
244
- </Box>
245
- )}
246
- </>
247
- )}
248
- ListFooterComponent={() => (
249
- <>
250
- <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}
251
195
  channelId={channelId}
252
- subscribeToNewMessages={() =>
253
- subscribeToMore({
254
- document: THREAD_CHAT_ADDED,
255
- variables: {
256
- channelId: channelId?.toString(),
257
- postParentId: null,
258
- },
259
- updateQuery: (prev, { subscriptionData }: any) => {
260
- if (!subscriptionData.data) return prev;
261
- const newPostThreadData: any =
262
- subscriptionData?.data?.threadCreatedUpdated?.data;
263
- const newMessage: any =
264
- subscriptionData?.data?.threadCreatedUpdated?.lastMessage;
265
- const data = prev?.threadMessages?.data?.map((t: any) =>
266
- t.id === newPostThreadData?.id
267
- ? {
268
- ...t,
269
- replies: [newMessage, ...t?.replies],
270
- replyCount: newPostThreadData?.replyCount,
271
- lastReplyAt: newPostThreadData?.lastReplyAt,
272
- updatedAt: newPostThreadData?.updatedAt,
273
- }
274
- : t,
275
- );
276
-
277
- return Object.assign({}, prev, {
278
- threadMessages: {
279
- ...prev?.threadMessages,
280
- // totalCount: prev?.threadMessages?.totalCount + 1,
281
- data: data,
282
- },
283
- });
284
- },
285
- })
286
- }
196
+ channelsDetail={channelsDetail}
287
197
  />
288
- </>
289
- )}
290
- keyExtractor={(item, index) => 'threads-view-key' + index}
291
- onEndReached={fetchMoreThreads}
292
- onEndReachedThreshold={0.1}
293
- />
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} />
294
208
  </Box>
295
209
  );
296
210
  };
297
211
 
212
+ // Component to handle subscription logic
298
213
  const SubscriptionHandler = ({ subscribeToNewMessages, channelId }: IThreadSubscriptionHandlerProps) => {
299
- useEffect(() => subscribeToNewMessages(), [channelId]);
300
- return <></>;
214
+ useEffect(() => {
215
+ const unsubscribe = subscribeToNewMessages();
216
+ return () => {
217
+ if (unsubscribe) unsubscribe();
218
+ };
219
+ }, [channelId]);
220
+
221
+ return null;
301
222
  };
302
223
 
303
224
  export const ThreadsView = ThreadsViewComponent;
304
-
305
- // 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
+ };