@messenger-box/platform-mobile 10.0.3-alpha.40 → 10.0.3-alpha.46
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/compute.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/queries/inboxQueries.js +77 -0
- package/lib/queries/inboxQueries.js.map +1 -0
- package/lib/routes.json +2 -3
- package/lib/screens/inbox/DialogThreadMessages.js +3 -7
- package/lib/screens/inbox/DialogThreadMessages.js.map +1 -1
- package/lib/screens/inbox/DialogThreads.js +3 -7
- package/lib/screens/inbox/DialogThreads.js.map +1 -1
- package/lib/screens/inbox/components/DialogsListItem.js +47 -46
- package/lib/screens/inbox/components/DialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js +313 -0
- package/lib/screens/inbox/components/GiftedChatInboxComponent.js.map +1 -0
- package/lib/screens/inbox/components/ServiceDialogsListItem.js +72 -57
- package/lib/screens/inbox/components/ServiceDialogsListItem.js.map +1 -1
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js +115 -14
- package/lib/screens/inbox/components/SlackMessageContainer/SlackBubble.js.map +1 -1
- package/lib/screens/inbox/components/SubscriptionHandler.js +24 -0
- package/lib/screens/inbox/components/SubscriptionHandler.js.map +1 -0
- package/lib/screens/inbox/containers/ConversationView.js +640 -493
- package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/Dialogs.js +100 -181
- package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadConversationView.js +659 -245
- package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
- package/lib/screens/inbox/containers/ThreadsView.js +3 -3
- 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/package.json +4 -4
- package/src/index.ts +2 -0
- package/src/queries/inboxQueries.ts +298 -0
- package/src/queries/index.d.ts +2 -0
- package/src/queries/index.ts +1 -0
- package/src/screens/inbox/DialogThreadMessages.tsx +3 -11
- package/src/screens/inbox/DialogThreads.tsx +3 -7
- package/src/screens/inbox/components/Actionsheet.tsx +30 -0
- package/src/screens/inbox/components/DialogsListItem.tsx +89 -148
- package/src/screens/inbox/components/ExpandableInput.tsx +460 -0
- package/src/screens/inbox/components/ExpandableInputActionSheet.tsx +518 -0
- package/src/screens/inbox/components/GiftedChatInboxComponent.tsx +411 -0
- package/src/screens/inbox/components/ServiceDialogsListItem.tsx +202 -221
- package/src/screens/inbox/components/SlackInput.tsx +23 -0
- package/src/screens/inbox/components/SlackMessageContainer/SlackBubble.tsx +216 -30
- package/src/screens/inbox/components/SubscriptionHandler.tsx +41 -0
- package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +6 -7
- package/src/screens/inbox/containers/ConversationView.tsx +1109 -669
- package/src/screens/inbox/containers/Dialogs.tsx +198 -342
- package/src/screens/inbox/containers/SupportServiceDialogs.tsx +2 -2
- package/src/screens/inbox/containers/ThreadConversationView.tsx +1141 -402
- package/src/screens/inbox/containers/ThreadsView.tsx +5 -5
- package/src/screens/inbox/hooks/useInboxMessages.ts +34 -0
- package/src/screens/inbox/machines/threadsMachine.ts +2 -2
|
@@ -16,14 +16,15 @@ import { format, isToday, isYesterday } from 'date-fns';
|
|
|
16
16
|
import { useFocusEffect } from '@react-navigation/native';
|
|
17
17
|
import { IChannel, IUserAccount } from 'common';
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
THREAD_CREATED_UPDATED,
|
|
20
|
+
CHAT_MESSAGE_ADDED,
|
|
21
21
|
useThreadMessagesQuery,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} from '
|
|
22
|
+
useThreadCreatedUpdatedSubscription,
|
|
23
|
+
useThreadChatMessageAddedSubscription,
|
|
24
|
+
} from '../../../queries/inboxQueries';
|
|
25
25
|
import { startCase } from 'lodash-es';
|
|
26
26
|
import colors from 'tailwindcss/colors';
|
|
27
|
+
import { SubscriptionHandler } from './SubscriptionHandler';
|
|
27
28
|
|
|
28
29
|
// Helper function to safely create a Date object
|
|
29
30
|
const safeDate = (dateValue) => {
|
|
@@ -65,6 +66,7 @@ export interface IDialogListItemProps {
|
|
|
65
66
|
onOpen: (id: any, title: any, postParentId?: any) => void;
|
|
66
67
|
refreshing: boolean;
|
|
67
68
|
role: any;
|
|
69
|
+
visible?: boolean;
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
// Helper function to compute the last message from a list of messages
|
|
@@ -121,7 +123,23 @@ const computeLastMessage = (threadMessages) => {
|
|
|
121
123
|
};
|
|
122
124
|
|
|
123
125
|
const ServiceChannelWithLastMessage = React.memo(
|
|
124
|
-
({
|
|
126
|
+
({
|
|
127
|
+
channel,
|
|
128
|
+
lastMessage,
|
|
129
|
+
subscribeToNewMessages,
|
|
130
|
+
subscribeToChatMessages,
|
|
131
|
+
subscribeToMore,
|
|
132
|
+
postParentId,
|
|
133
|
+
servicePostParentId,
|
|
134
|
+
}: {
|
|
135
|
+
channel: any;
|
|
136
|
+
lastMessage: any;
|
|
137
|
+
subscribeToNewMessages: () => void;
|
|
138
|
+
subscribeToChatMessages: () => void;
|
|
139
|
+
subscribeToMore: any;
|
|
140
|
+
postParentId: any;
|
|
141
|
+
servicePostParentId: any;
|
|
142
|
+
}) => {
|
|
125
143
|
React.useEffect(() => {
|
|
126
144
|
console.log(`Setting up subscriptions for channel ${channel?.id}`);
|
|
127
145
|
// Subscribe and store the unsubscribe functions
|
|
@@ -197,20 +215,40 @@ const ServiceChannelWithLastMessage = React.memo(
|
|
|
197
215
|
}
|
|
198
216
|
|
|
199
217
|
return (
|
|
200
|
-
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
<
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
218
|
+
<>
|
|
219
|
+
<SubscriptionHandler
|
|
220
|
+
subscribeToMore={subscribeToMore}
|
|
221
|
+
document={THREAD_CREATED_UPDATED}
|
|
222
|
+
variables={{
|
|
223
|
+
channelId: channel?.id?.toString(),
|
|
224
|
+
postParentId: postParentId || servicePostParentId || null,
|
|
225
|
+
}}
|
|
226
|
+
updateQuery={undefined} // Provide custom updateQuery if needed
|
|
227
|
+
/>
|
|
228
|
+
<SubscriptionHandler
|
|
229
|
+
subscribeToMore={subscribeToMore}
|
|
230
|
+
document={CHAT_MESSAGE_ADDED}
|
|
231
|
+
variables={{
|
|
232
|
+
channelId: channel?.id?.toString(),
|
|
233
|
+
postParentId: postParentId || servicePostParentId || null,
|
|
234
|
+
}}
|
|
235
|
+
updateQuery={undefined} // Provide custom updateQuery if needed
|
|
236
|
+
/>
|
|
237
|
+
<HStack space={'sm'} className="flex-1 justify-between">
|
|
238
|
+
<Box className="flex-[0.8]">
|
|
239
|
+
<Text color={colors.gray[600]} className="text-base text-wrap flex-wrap font-semibold">
|
|
240
|
+
{title}
|
|
241
|
+
</Text>
|
|
242
|
+
<Text color={colors.gray[600]} numberOfLines={1}>
|
|
243
|
+
{displayMessage}
|
|
244
|
+
</Text>
|
|
245
|
+
</Box>
|
|
246
|
+
|
|
247
|
+
<Box className="flex-[0.2]">
|
|
248
|
+
<Text color={colors.gray[500]}>{lastMessage ? createdAtText(lastMessage?.createdAt) : ''}</Text>
|
|
249
|
+
</Box>
|
|
250
|
+
</HStack>
|
|
251
|
+
</>
|
|
214
252
|
);
|
|
215
253
|
},
|
|
216
254
|
);
|
|
@@ -228,12 +266,15 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
228
266
|
onOpen,
|
|
229
267
|
refreshing,
|
|
230
268
|
role,
|
|
269
|
+
visible = true,
|
|
231
270
|
}) {
|
|
232
|
-
// Create a ref to track if component is mounted
|
|
233
271
|
const isMountedRef = useRef(true);
|
|
234
272
|
const [subscriptionsTimestamp, setSubscriptionsTimestamp] = useState(Date.now());
|
|
235
273
|
|
|
236
|
-
//
|
|
274
|
+
// Only run queries/subscriptions if visible
|
|
275
|
+
const shouldQuery = !!channel?.id && visible;
|
|
276
|
+
|
|
277
|
+
// Query for thread messages (minimal fields if possible)
|
|
237
278
|
const {
|
|
238
279
|
data: threadMessagesData,
|
|
239
280
|
loading: threadMessageLoading,
|
|
@@ -246,31 +287,31 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
246
287
|
role,
|
|
247
288
|
limit: 2,
|
|
248
289
|
},
|
|
290
|
+
skip: !shouldQuery, // Only run if visible
|
|
249
291
|
fetchPolicy: 'cache-and-network',
|
|
250
292
|
onCompleted: (data) => {
|
|
251
|
-
|
|
252
|
-
`Completed thread messages query for channel ${channel?.id}:`,
|
|
253
|
-
data?.threadMessages?.data?.length ? 'Has messages' : 'No messages',
|
|
254
|
-
);
|
|
293
|
+
if (!shouldQuery) return;
|
|
255
294
|
},
|
|
256
295
|
onError: (error) => {
|
|
296
|
+
if (!shouldQuery) return;
|
|
257
297
|
console.error(`Error fetching thread messages for channel ${channel?.id}:`, error);
|
|
258
298
|
},
|
|
259
299
|
});
|
|
260
300
|
|
|
261
301
|
// Extract threadMessages data for easier access
|
|
262
|
-
const threadMessages = threadMessagesData?.threadMessages?.data || [];
|
|
302
|
+
const threadMessages = useMemo(() => threadMessagesData?.threadMessages?.data || [], [threadMessagesData]);
|
|
263
303
|
|
|
264
304
|
// Calculate lastMessage directly from threadMessages
|
|
265
305
|
const lastMessage = useMemo(() => {
|
|
306
|
+
if (!shouldQuery) return null;
|
|
266
307
|
return computeLastMessage(threadMessages);
|
|
267
|
-
}, [threadMessages]);
|
|
308
|
+
}, [shouldQuery, threadMessages]);
|
|
268
309
|
|
|
269
310
|
// Calculate servicePostParentId based on lastMessage
|
|
270
311
|
const servicePostParentId = useMemo(() => {
|
|
271
|
-
if (!lastMessage) return null;
|
|
312
|
+
if (!shouldQuery || !lastMessage) return null;
|
|
272
313
|
return lastMessage?.parentId ? lastMessage?.parentId : lastMessage?.id;
|
|
273
|
-
}, [lastMessage]);
|
|
314
|
+
}, [shouldQuery, lastMessage]);
|
|
274
315
|
|
|
275
316
|
// Handle component unmount
|
|
276
317
|
React.useEffect(() => {
|
|
@@ -280,7 +321,7 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
280
321
|
}, []);
|
|
281
322
|
|
|
282
323
|
const creatorAndMembersId = useMemo(() => {
|
|
283
|
-
if (!channel?.members) return null;
|
|
324
|
+
if (!shouldQuery || !channel?.members) return null;
|
|
284
325
|
const membersIds: any =
|
|
285
326
|
channel?.members
|
|
286
327
|
?.filter((m: any) => m !== null && m?.user?.id !== currentUser?.id)
|
|
@@ -288,24 +329,20 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
288
329
|
const creatorId: any = channel?.creator?.id;
|
|
289
330
|
const mergedIds: any = [].concat(membersIds, creatorId) ?? [];
|
|
290
331
|
return mergedIds?.filter((m: any, pos: any) => mergedIds?.indexOf(m) === pos) ?? [];
|
|
291
|
-
}, [channel, currentUser]);
|
|
332
|
+
}, [shouldQuery, channel, currentUser]);
|
|
292
333
|
|
|
293
334
|
const postParentId = useMemo(() => {
|
|
294
|
-
if (!creatorAndMembersId?.length) return null;
|
|
295
|
-
|
|
335
|
+
if (!shouldQuery || !creatorAndMembersId?.length) return null;
|
|
296
336
|
return creatorAndMembersId?.length && creatorAndMembersId?.includes(currentUser?.id)
|
|
297
337
|
? null
|
|
298
338
|
: lastMessage?.parentId
|
|
299
339
|
? lastMessage?.parentId
|
|
300
340
|
: lastMessage?.id ?? 0;
|
|
301
|
-
}, [creatorAndMembersId, lastMessage, currentUser]);
|
|
341
|
+
}, [shouldQuery, creatorAndMembersId, lastMessage, currentUser]);
|
|
302
342
|
|
|
303
343
|
// Function to force refresh the component state
|
|
304
344
|
const refreshThreadState = useCallback(() => {
|
|
305
|
-
if (channel?.id && isMountedRef.current) {
|
|
306
|
-
console.log('Forcing thread state refresh for channel:', channel?.id);
|
|
307
|
-
|
|
308
|
-
// Refetch messages from server
|
|
345
|
+
if (shouldQuery && channel?.id && isMountedRef.current) {
|
|
309
346
|
refetchThreadMessages({
|
|
310
347
|
channelId: channel?.id?.toString(),
|
|
311
348
|
role,
|
|
@@ -314,23 +351,15 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
314
351
|
console.error('Error refreshing thread state:', err);
|
|
315
352
|
});
|
|
316
353
|
}
|
|
317
|
-
}, [channel?.id, refetchThreadMessages,
|
|
354
|
+
}, [shouldQuery, channel?.id, refetchThreadMessages, role]);
|
|
318
355
|
|
|
319
356
|
// Reset subscriptions when the component gains focus
|
|
320
357
|
useFocusEffect(
|
|
321
358
|
React.useCallback(() => {
|
|
322
|
-
|
|
359
|
+
if (!shouldQuery || !channel?.id) return;
|
|
323
360
|
setSubscriptionsTimestamp(Date.now());
|
|
324
|
-
|
|
325
|
-
// Existing focus effect logic...
|
|
326
|
-
if (!channel?.id) return;
|
|
327
|
-
|
|
328
|
-
console.log('ServiceDialogsListItem focused for channel:', channel?.id);
|
|
329
|
-
|
|
330
|
-
// Use a direct refetch with network-only policy to force fresh data
|
|
331
361
|
const fetchFreshData = async () => {
|
|
332
362
|
try {
|
|
333
|
-
// Force a network-only fetch
|
|
334
363
|
await refetchThreadMessages({
|
|
335
364
|
channelId: channel?.id?.toString(),
|
|
336
365
|
role,
|
|
@@ -340,14 +369,9 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
340
369
|
console.error('Error refetching thread messages on focus:', error);
|
|
341
370
|
}
|
|
342
371
|
};
|
|
343
|
-
|
|
344
|
-
// Execute fetch
|
|
345
372
|
fetchFreshData();
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
// Cleanup function when unfocused
|
|
349
|
-
};
|
|
350
|
-
}, [refreshing, channel?.id, refetchThreadMessages, role]),
|
|
373
|
+
return () => {};
|
|
374
|
+
}, [shouldQuery, refreshing, channel?.id, refetchThreadMessages, role]),
|
|
351
375
|
);
|
|
352
376
|
|
|
353
377
|
return (
|
|
@@ -380,174 +404,131 @@ export const ServiceDialogsListItemComponent: React.FC<IDialogListItemProps> = f
|
|
|
380
404
|
channel={channel}
|
|
381
405
|
lastMessage={lastMessage}
|
|
382
406
|
subscribeToNewMessages={() =>
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
threadMessages: {
|
|
443
|
-
...prev?.threadMessages,
|
|
444
|
-
totalCount:
|
|
445
|
-
newPostThreadData?.totalCount ??
|
|
446
|
-
prev?.threadMessages?.totalCount ??
|
|
447
|
-
0,
|
|
448
|
-
data: updatedThreads,
|
|
449
|
-
},
|
|
450
|
-
};
|
|
451
|
-
} catch (error) {
|
|
452
|
-
console.error(
|
|
453
|
-
`Error processing subscription data for channel ${channel?.id}:`,
|
|
454
|
-
error,
|
|
455
|
-
);
|
|
456
|
-
return prev;
|
|
457
|
-
}
|
|
458
|
-
},
|
|
459
|
-
onError: (error) => {
|
|
460
|
-
console.error(`Thread subscription error for channel ${channel?.id}:`, error);
|
|
461
|
-
},
|
|
462
|
-
})
|
|
407
|
+
shouldQuery
|
|
408
|
+
? subscribeToMore({
|
|
409
|
+
document: THREAD_CREATED_UPDATED,
|
|
410
|
+
variables: {
|
|
411
|
+
channelId: channel?.id?.toString(),
|
|
412
|
+
postParentId: postParentId || servicePostParentId || null,
|
|
413
|
+
},
|
|
414
|
+
updateQuery: (prev, { subscriptionData }: any) => {
|
|
415
|
+
if (!subscriptionData?.data) {
|
|
416
|
+
return prev;
|
|
417
|
+
}
|
|
418
|
+
try {
|
|
419
|
+
const newPostThreadData: any =
|
|
420
|
+
subscriptionData?.data?.threadCreatedUpdated?.data;
|
|
421
|
+
const newMessage: any =
|
|
422
|
+
subscriptionData?.data?.threadCreatedUpdated?.lastMessage;
|
|
423
|
+
if (!newPostThreadData || !newMessage) {
|
|
424
|
+
return prev;
|
|
425
|
+
}
|
|
426
|
+
const prevThreads = prev?.threadMessages?.data || [];
|
|
427
|
+
const threadExists = prevThreads.some(
|
|
428
|
+
(t: any) => t.id === newPostThreadData?.id,
|
|
429
|
+
);
|
|
430
|
+
let updatedThreads;
|
|
431
|
+
if (threadExists) {
|
|
432
|
+
updatedThreads = prevThreads.map((t: any) =>
|
|
433
|
+
t.id === newPostThreadData?.id
|
|
434
|
+
? {
|
|
435
|
+
...t,
|
|
436
|
+
replies: [...(t?.replies || []), newMessage],
|
|
437
|
+
replyCount: newPostThreadData?.replyCount,
|
|
438
|
+
lastReplyAt: newPostThreadData?.lastReplyAt,
|
|
439
|
+
updatedAt: newPostThreadData?.updatedAt,
|
|
440
|
+
}
|
|
441
|
+
: t,
|
|
442
|
+
);
|
|
443
|
+
} else {
|
|
444
|
+
updatedThreads = [...prevThreads, newPostThreadData];
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
...prev,
|
|
448
|
+
threadMessages: {
|
|
449
|
+
...prev?.threadMessages,
|
|
450
|
+
totalCount:
|
|
451
|
+
newPostThreadData?.totalCount ??
|
|
452
|
+
prev?.threadMessages?.totalCount ??
|
|
453
|
+
0,
|
|
454
|
+
data: updatedThreads,
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
} catch (error) {
|
|
458
|
+
return prev;
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
onError: (error) => {
|
|
462
|
+
console.error(`Thread subscription error for channel ${channel?.id}:`, error);
|
|
463
|
+
},
|
|
464
|
+
})
|
|
465
|
+
: undefined
|
|
463
466
|
}
|
|
464
467
|
subscribeToChatMessages={() =>
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
thread.lastReplyAt = newMessage.createdAt;
|
|
527
|
-
thread.updatedAt = newMessage.createdAt;
|
|
528
|
-
|
|
529
|
-
updatedThreads[threadIndex] = thread;
|
|
530
|
-
|
|
531
|
-
return {
|
|
532
|
-
...prev,
|
|
533
|
-
threadMessages: {
|
|
534
|
-
...prev?.threadMessages,
|
|
535
|
-
data: updatedThreads,
|
|
536
|
-
},
|
|
537
|
-
};
|
|
538
|
-
} catch (error) {
|
|
539
|
-
console.error(
|
|
540
|
-
`Error processing chat message subscription for channel ${channel?.id}:`,
|
|
541
|
-
error,
|
|
542
|
-
);
|
|
543
|
-
return prev;
|
|
544
|
-
}
|
|
545
|
-
},
|
|
546
|
-
onError: (error) => {
|
|
547
|
-
console.error(`Chat message subscription error for channel ${channel?.id}:`, error);
|
|
548
|
-
},
|
|
549
|
-
})
|
|
468
|
+
shouldQuery
|
|
469
|
+
? subscribeToMore({
|
|
470
|
+
document: CHAT_MESSAGE_ADDED,
|
|
471
|
+
variables: {
|
|
472
|
+
channelId: channel?.id?.toString(),
|
|
473
|
+
postParentId: postParentId || servicePostParentId || null,
|
|
474
|
+
},
|
|
475
|
+
updateQuery: (prev, { subscriptionData }: any) => {
|
|
476
|
+
if (!subscriptionData?.data) {
|
|
477
|
+
return prev;
|
|
478
|
+
}
|
|
479
|
+
try {
|
|
480
|
+
const newMessage = subscriptionData?.data?.chatMessageAdded;
|
|
481
|
+
if (!newMessage) {
|
|
482
|
+
return prev;
|
|
483
|
+
}
|
|
484
|
+
const prevThreads = prev?.threadMessages?.data || [];
|
|
485
|
+
const threadIndex = prevThreads.findIndex((t: any) => {
|
|
486
|
+
if (newMessage.parentId && t.post?.id === newMessage.parentId) {
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
if (
|
|
490
|
+
t.replies &&
|
|
491
|
+
t.replies.some((r: any) => r.id === newMessage.parentId)
|
|
492
|
+
) {
|
|
493
|
+
return true;
|
|
494
|
+
}
|
|
495
|
+
return false;
|
|
496
|
+
});
|
|
497
|
+
if (threadIndex === -1) {
|
|
498
|
+
return prev;
|
|
499
|
+
}
|
|
500
|
+
const updatedThreads = [...prevThreads];
|
|
501
|
+
const thread = { ...updatedThreads[threadIndex] };
|
|
502
|
+
thread.replies = [...(thread.replies || []), newMessage];
|
|
503
|
+
const currentReplyCount =
|
|
504
|
+
typeof thread.replyCount === 'number' ? thread.replyCount : 0;
|
|
505
|
+
thread.replyCount = currentReplyCount + 1;
|
|
506
|
+
thread.lastReplyAt = newMessage.createdAt;
|
|
507
|
+
thread.updatedAt = newMessage.createdAt;
|
|
508
|
+
updatedThreads[threadIndex] = thread;
|
|
509
|
+
return {
|
|
510
|
+
...prev,
|
|
511
|
+
threadMessages: {
|
|
512
|
+
...prev?.threadMessages,
|
|
513
|
+
data: updatedThreads,
|
|
514
|
+
},
|
|
515
|
+
};
|
|
516
|
+
} catch (error) {
|
|
517
|
+
return prev;
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
onError: (error) => {
|
|
521
|
+
console.error(
|
|
522
|
+
`Chat message subscription error for channel ${channel?.id}:`,
|
|
523
|
+
error,
|
|
524
|
+
);
|
|
525
|
+
},
|
|
526
|
+
})
|
|
527
|
+
: undefined
|
|
550
528
|
}
|
|
529
|
+
subscribeToMore={subscribeToMore}
|
|
530
|
+
postParentId={postParentId}
|
|
531
|
+
servicePostParentId={servicePostParentId}
|
|
551
532
|
/>
|
|
552
533
|
</Box>
|
|
553
534
|
</HStack>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TextInput, TextInputProps } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export const SlackInput = React.forwardRef<TextInput, TextInputProps>((props, ref) => {
|
|
5
|
+
return (
|
|
6
|
+
<TextInput
|
|
7
|
+
ref={ref}
|
|
8
|
+
{...props}
|
|
9
|
+
style={[
|
|
10
|
+
{
|
|
11
|
+
flex: 1,
|
|
12
|
+
fontSize: 16,
|
|
13
|
+
padding: 10,
|
|
14
|
+
borderRadius: 8,
|
|
15
|
+
backgroundColor: '#f8f8f8',
|
|
16
|
+
borderColor: '#e0e0e0',
|
|
17
|
+
borderWidth: 1,
|
|
18
|
+
},
|
|
19
|
+
props.style,
|
|
20
|
+
]}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
});
|