-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ml/fix deeplink to groupchat #1395
Changes from 5 commits
24975c4
8f6ba7c
cfa6299
0a0fa5b
956242a
b02e0fb
c9c012b
e6dc449
2ebf4f0
807aff5
6d4539e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
import * as Notifications from "expo-notifications"; | ||
import { | ||
navigate, | ||
navigateToTopic, | ||
setTopicToNavigateTo, | ||
} from "@utils/navigation"; | ||
import { navigate, navigateToTopic } from "@utils/navigation"; | ||
import { getTopicFromV3Id } from "@utils/groupUtils/groupId"; | ||
import { useAccountsStore } from "@data/store/accountsStore"; | ||
import type { ConversationId, ConversationTopic } from "@xmtp/react-native-sdk"; | ||
import { fetchPersistedConversationListQuery } from "@/queries/useConversationListQuery"; | ||
import { resetNotifications } from "./resetNotifications"; | ||
import logger from "@/utils/logger"; | ||
import { getXmtpClient } from "@/utils/xmtpRN/sync"; | ||
import { ConverseXmtpClientType } from "@/utils/xmtpRN/client"; | ||
import { waitForXmtpClientHydration } from "@/data/store/appStore"; | ||
import logger from "@utils/logger"; | ||
|
||
export const onInteractWithNotification = async ( | ||
event: Notifications.NotificationResponse | ||
) => { | ||
logger.debug("[onInteractWithNotification]"); | ||
// todo(lustig): zod verification of external payloads such as those from | ||
// notifications, deep links, etc | ||
let notificationData = event.notification.request.content.data; | ||
// Android returns the data in the body as a string | ||
if ( | ||
|
@@ -58,40 +55,13 @@ export const onInteractWithNotification = async ( | |
| undefined; | ||
|
||
if (conversationTopic) { | ||
// todo(lustig): zod verification of external payloads such as those from | ||
// notifications, deep links, etc | ||
await waitForXmtpClientHydration(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out all the crap I was doing before in the previous diff uh was done in client hydration so it's not needed here |
||
const account: string = | ||
notificationData["account"] || useAccountsStore.getState().currentAccount; | ||
|
||
// Fetch the conversation list to ensure we have the latest conversation list | ||
// before navigating to the conversation | ||
try { | ||
await fetchPersistedConversationListQuery({ account }); | ||
} catch (e) { | ||
logger.error( | ||
`[onInteractWithNotification] Error fetching conversation list from network` | ||
); | ||
if ( | ||
`${e}`.includes("storage error: Pool needs to reconnect before use") | ||
) { | ||
logger.info( | ||
`[onInteractWithNotification] Reconnecting XMTP client for account ${account}` | ||
); | ||
const client = (await getXmtpClient(account)) as ConverseXmtpClientType; | ||
await client.reconnectLocalDatabase(); | ||
logger.info( | ||
`[onInteractWithNotification] XMTP client reconnected for account ${account}` | ||
); | ||
logger.info( | ||
`[onInteractWithNotification] Fetching conversation list from network for account ${account}` | ||
); | ||
await fetchPersistedConversationListQuery({ account }); | ||
} | ||
} | ||
useAccountsStore.getState().setCurrentAccount(account, false); | ||
|
||
navigateToTopic(conversationTopic as ConversationTopic); | ||
setTopicToNavigateTo(undefined); | ||
resetNotifications(); | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,11 @@ | |
import { useAddressBookStateHandler } from "../utils/addressBook"; | ||
import { useAutoConnectExternalWallet } from "../utils/evm/external"; | ||
import { usePrivyAccessToken } from "../utils/evm/privy"; | ||
import { converseNavigations } from "../utils/navigation"; | ||
import { | ||
converseNavigations, | ||
converseNavigatorRef, | ||
setConverseNavigatorRef, | ||
} from "../utils/navigation"; | ||
import { ConversationScreenConfig } from "../features/conversation/conversation.nav"; | ||
import { GroupScreenConfig } from "./Navigation/GroupNav"; | ||
import { | ||
|
@@ -39,6 +43,7 @@ | |
getConverseStateFromPath, | ||
} from "./Navigation/navHelpers"; | ||
import { JoinGroupScreenConfig } from "@/features/GroupInvites/joinGroup/JoinGroupNavigation"; | ||
import logger from "@/utils/logger"; | ||
|
||
const prefix = Linking.createURL("/"); | ||
|
||
|
@@ -84,9 +89,10 @@ | |
theme={navigationTheme} | ||
linking={linking} | ||
ref={(r) => { | ||
if (r) { | ||
converseNavigations["main"] = r; | ||
} | ||
logger.info( | ||
`[Main] Setting navigation ref to ${r ? "not null" : "null"}` | ||
); | ||
setConverseNavigatorRef(r); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We only have one navigation ref now that we are no longer supporting different layouts and stuff so I did some refactoring to reflect that |
||
}} | ||
onUnhandledAction={() => { | ||
// Since we're handling multiple navigators, | ||
|
@@ -105,9 +111,7 @@ | |
const NavigationContent = () => { | ||
const authStatus = useAuthStatus(); | ||
|
||
const { splashScreenHidden } = useAppStore( | ||
useSelect(["notificationsPermissionStatus", "splashScreenHidden"]) | ||
); | ||
const { splashScreenHidden } = useAppStore(useSelect(["splashScreenHidden"])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused |
||
|
||
// Uncomment to test design system components | ||
// return ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you doing this vs creating a subscription to the store instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I thought about that too. But It would look something like that no? Which isn't cleaner IMO or even much more performant. Maybe we keep what Michael have for now which is good enough IMO.
And we'll probably have to refactor stuff anyway later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you guys are right I like this better. It would also resolve sooner (rather than waiting for the 100ms window to elapse)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's a loom with this change: https://www.loom.com/share/d1967df857fb4d1984cbdce195ff7739 (explaining the reason for the wait(1)