@messenger-box/platform-mobile 10.0.3-alpha.22 → 10.0.3-alpha.23

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 (29) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/screens/inbox/DialogThreads.js +52 -12
  3. package/lib/screens/inbox/DialogThreads.js.map +1 -1
  4. package/lib/screens/inbox/components/ThreadsViewItem.js +66 -44
  5. package/lib/screens/inbox/components/ThreadsViewItem.js.map +1 -1
  6. package/lib/screens/inbox/containers/ConversationView.js +36 -34
  7. package/lib/screens/inbox/containers/ConversationView.js.map +1 -1
  8. package/lib/screens/inbox/containers/Dialogs.js +82 -37
  9. package/lib/screens/inbox/containers/Dialogs.js.map +1 -1
  10. package/lib/screens/inbox/containers/ThreadConversationView.js +282 -219
  11. package/lib/screens/inbox/containers/ThreadConversationView.js.map +1 -1
  12. package/lib/screens/inbox/containers/ThreadsView.js +83 -50
  13. package/lib/screens/inbox/containers/ThreadsView.js.map +1 -1
  14. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js +108 -0
  15. package/lib/screens/inbox/hooks/useSafeDialogThreadsMachine.js.map +1 -0
  16. package/lib/screens/inbox/workflow/dialog-threads-xstate.js +151 -0
  17. package/lib/screens/inbox/workflow/dialog-threads-xstate.js.map +1 -0
  18. package/package.json +2 -2
  19. package/src/screens/inbox/DialogThreads.tsx +49 -53
  20. package/src/screens/inbox/components/SmartLoader.tsx +61 -0
  21. package/src/screens/inbox/components/ThreadsViewItem.tsx +177 -265
  22. package/src/screens/inbox/containers/ConversationView.tsx +32 -30
  23. package/src/screens/inbox/containers/Dialogs.tsx +57 -22
  24. package/src/screens/inbox/containers/ThreadConversationView.tsx +467 -484
  25. package/src/screens/inbox/containers/ThreadsView.tsx +102 -183
  26. package/src/screens/inbox/hooks/useSafeDialogThreadsMachine.ts +136 -0
  27. package/src/screens/inbox/index.ts +37 -0
  28. package/src/screens/inbox/machines/threadsMachine.ts +147 -0
  29. package/src/screens/inbox/workflow/dialog-threads-xstate.ts +163 -0
@@ -362,7 +362,8 @@ const DialogsComponent = (props: InboxProps) => {
362
362
  // Calculate skip based on page number (pagination)
363
363
  const skipCount = (pageNum - 1) * 15;
364
364
 
365
- const { data } = await getChannelsRefetch({
365
+ // Add timeout to prevent hanging requests
366
+ const fetchPromise = getChannelsRefetch({
366
367
  role: channelRole,
367
368
  criteria: channelFilters,
368
369
  supportServices: supportServices ? true : false,
@@ -373,14 +374,43 @@ const DialogsComponent = (props: InboxProps) => {
373
374
  skip: skipCount,
374
375
  });
375
376
 
377
+ // Set a timeout to abort long-running requests
378
+ const timeoutPromise = new Promise((_, reject) =>
379
+ setTimeout(() => reject(new Error('Request timeout')), 8000),
380
+ );
381
+
382
+ // Race the fetch against the timeout
383
+ const result = (await Promise.race([fetchPromise, timeoutPromise])) as any;
384
+ const data = result?.data || {};
385
+
376
386
  const allChannels = [...(data?.supportServiceChannels ?? []), ...(data?.channelsByUser ?? [])];
387
+
388
+ // Optimize filtering by using more efficient approach
377
389
  const filteredChannels =
378
- allChannels?.filter((c) =>
379
- c.members.some(
380
- (u) => u !== null && u?.user?.id != auth?.id && u.user.__typename == 'UserAccount',
381
- ),
382
- ) ?? [];
383
- const sortedChannels = (filteredChannels && orderBy(filteredChannels, ['updatedAt'], ['desc'])) || [];
390
+ allChannels?.filter((c) => {
391
+ if (!c || !c.members) return false;
392
+
393
+ // Early return pattern for better performance
394
+ for (const member of c.members) {
395
+ if (
396
+ member &&
397
+ member.user &&
398
+ member.user.id !== auth?.id &&
399
+ member.user.__typename === 'UserAccount'
400
+ ) {
401
+ return true;
402
+ }
403
+ }
404
+ return false;
405
+ }) ?? [];
406
+
407
+ // Use more efficient sorting
408
+ const sortedChannels =
409
+ filteredChannels.sort((a, b) => {
410
+ const dateA = new Date(a.updatedAt);
411
+ const dateB = new Date(b.updatedAt);
412
+ return dateB.getTime() - dateA.getTime();
413
+ }) || [];
384
414
 
385
415
  console.log(`📊 Processed channels: ${sortedChannels.length} (page: ${pageNum}, skip: ${skipCount})`);
386
416
 
@@ -393,12 +423,11 @@ const DialogsComponent = (props: InboxProps) => {
393
423
  } else {
394
424
  safeSend({
395
425
  type: Actions.FETCH_CHANNELS,
396
- data: { channels: sortedChannels },
426
+ data: { channels: sortedChannels, stopLoading: true },
397
427
  });
398
428
  }
399
429
 
400
- // Immediately stop loading state instead of waiting
401
- safeSend({ type: Actions.STOP_LOADING });
430
+ // No need for another stop loading call as we included stopLoading: true above
402
431
  }
403
432
  } catch (error) {
404
433
  console.error('Error fetching channels:', error);
@@ -413,8 +442,7 @@ const DialogsComponent = (props: InboxProps) => {
413
442
  [getChannelsRefetch, channelRole, channelFilters, supportServices, auth?.id, safeSend],
414
443
  );
415
444
 
416
- // Add a safety timeout to ensure loading state is eventually cleared
417
- // even if the fetchChannelsDirectly function fails to complete
445
+ // Optimize safety timeout to use a shorter duration
418
446
  useEffect(() => {
419
447
  if (loading) {
420
448
  const safetyTimeout = setTimeout(() => {
@@ -422,7 +450,7 @@ const DialogsComponent = (props: InboxProps) => {
422
450
  if (isMountedRef.current) {
423
451
  safeSend({ type: Actions.STOP_LOADING });
424
452
  }
425
- }, 5000); // 5 seconds safety timeout
453
+ }, 3000); // Reduced from 5000 to 3000 ms
426
454
 
427
455
  return () => clearTimeout(safetyTimeout);
428
456
  }
@@ -697,9 +725,12 @@ const DialogsComponent = (props: InboxProps) => {
697
725
  contentContainerStyle={{ minHeight: '100%' }}
698
726
  ItemSeparatorComponent={() => <Box className="h-0.5 bg-gray-200" />}
699
727
  renderItem={({ item: channel }) => {
728
+ // Use memoized key for better list performance
729
+ const key = `${channel.type === RoomType.Service ? 'service' : 'direct'}-${channel.id}`;
730
+
700
731
  return channel?.type === RoomType.Service ? (
701
732
  <ServiceDialogsListItem
702
- key={`service-${channel.id}`}
733
+ key={key}
703
734
  onOpen={handleSelectServiceChannel}
704
735
  currentUser={auth}
705
736
  channel={channel}
@@ -709,12 +740,12 @@ const DialogsComponent = (props: InboxProps) => {
709
740
  />
710
741
  ) : (
711
742
  <DialogsListItem
712
- key={`direct-${channel.id}`}
743
+ key={key}
713
744
  onOpen={handleSelectChannel}
714
745
  currentUser={auth}
715
746
  channel={channel}
716
747
  selectedChannelId={selectedChannelId}
717
- forceRefresh={true}
748
+ forceRefresh={false} // Change to false to avoid unnecessary refreshes
718
749
  />
719
750
  );
720
751
  }}
@@ -726,12 +757,17 @@ const DialogsComponent = (props: InboxProps) => {
726
757
  ) : null
727
758
  }
728
759
  onEndReached={handleLoadMore}
729
- onEndReachedThreshold={0.3}
730
- initialNumToRender={10}
731
- maxToRenderPerBatch={10}
732
- windowSize={10}
760
+ onEndReachedThreshold={0.5} // Increased from 0.3 for earlier loading
761
+ initialNumToRender={5} // Reduced from 10 for faster initial render
762
+ maxToRenderPerBatch={5} // Reduced from 10 for smoother rendering
763
+ windowSize={5} // Reduced from 10 to maintain fewer items in memory
733
764
  removeClippedSubviews={true}
734
- updateCellsBatchingPeriod={50}
765
+ updateCellsBatchingPeriod={100} // Increased from 50 to batch updates better
766
+ getItemLayout={(data, index) =>
767
+ // Pre-calculate item dimensions for more efficient rendering
768
+ ({ length: 80, offset: 80 * index, index })
769
+ }
770
+ keyExtractor={(item) => `channel-${item.id}`}
735
771
  ListEmptyComponent={() => {
736
772
  console.log('Rendering ListEmptyComponent', { loading, refreshing, stateValue: state.value });
737
773
 
@@ -785,7 +821,6 @@ const DialogsComponent = (props: InboxProps) => {
785
821
  </Box>
786
822
  );
787
823
  }}
788
- keyExtractor={(item) => `channel-${item.id}`}
789
824
  />
790
825
  </Box>
791
826
  );