Skip to content

fix(notifications): ensure notification tap always opens target email - #67

Open
arnauda-gh wants to merge 2 commits into
bulwarkmail:mainfrom
arnauda-gh:fix/notification-open-target-email
Open

arnauda-gh wants to merge 2 commits into
bulwarkmail:mainfrom
arnauda-gh:fix/notification-open-target-email

Conversation

@arnauda-gh

Copy link
Copy Markdown
Contributor

Summary

Fixes an issue where tapping a notification sometimes opened the wrong email (specifically the newest email received in the inbox rather than the email from the notification).

Root Causes

  1. Paging over open folder instead of single page: When navigateToNotificationTap navigated to EmailThread, it did not pass emailIds: [payload.emailId]. If the target email was present in the cached folder list (e.g. Inbox) and a newer email had arrived in the meantime, viewerPages returned the entire folder list with the newly arrived email at index 0 and the target email at index > 0.
  2. FlatList initialScrollIndex failure on Android: Because initialNumToRender was set to 1 and no onScrollToIndexFailed handler was configured, FlatList on Android failed to scroll to initialScrollIndex before the initial layout pass completed, getting stuck at scroll offset 0 (which rendered the newly arrived email at index 0). Touching or scrolling then caused onMomentumScrollEnd to reassign activeEmailId to the newly arrived email.
  3. Intent filter coalescing: BulwarkFcmModule.kt created notification intents without a unique data URI, which under FLAG_ACTIVITY_SINGLE_TOP could cause Android to deliver stale/reused intent extras when MainActivity was already alive.
  4. Premature group summary creation: BulwarkFcmModule.kt posted a group summary even when there was only 1 notification active. Tapping a collapsed notification group triggered the summary's PendingIntent (which had no emailId), taking the user to the inbox instead of the tapped email.

Solution

  1. In App.tsx: Pass emailIds: [payload.emailId] in navigateToNotificationTap so the viewer mounts as a dedicated single-page view for the tapped email, as intended by viewerPages.
  2. In src/screens/EmailThreadScreen.tsx: Set initialNumToRender={Math.max(initialIndexRef.current + 1, 1)} and implement onScrollToIndexFailed on the pager FlatList to prevent the pager from ever getting stuck at index 0 when navigating to an index > 0.
  3. In android/app/src/main/java/com/anonymous/bulwarkmobile/BulwarkFcmModule.kt:
    • Attach unique data = Uri.parse("bulwark-notification://$notificationId") (and for group summaries) so Android's intent filter matcher treats each notification intent as unique.
    • Only post group summaries when children.size >= 2, and cancel any existing summary when fewer than 2 child notifications remain.
  4. Added unit test in src/lib/__tests__/viewer-pages.test.ts.

!! AI WARNING !! : This PR was generated and created by AI. It has been tested on my own use case and seems to work. However have a deep look about the generated code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant