about summary refs log tree commit diff
path: root/src/view/shell/desktop/LeftNav.tsx
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2023-09-27 11:06:33 -0500
committerGitHub <noreply@github.com>2023-09-27 09:06:33 -0700
commit6325eff938495b88a3808aef3c772e9fe93d5550 (patch)
tree71b0fbc6d53976145f578a5beb04341b566e29b2 /src/view/shell/desktop/LeftNav.tsx
parent42723dfaf6fa9287053a76b6c7ddd4570ead8418 (diff)
downloadvoidsky-6325eff938495b88a3808aef3c772e9fe93d5550.tar.zst
Improvements to auto-mentioning users from their profiles (#1556)
* Don't automatically mention users with invalid handles

* don't mention when using did urls

* resolve profile from cache

* a little clearer

---------

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
Diffstat (limited to 'src/view/shell/desktop/LeftNav.tsx')
-rw-r--r--src/view/shell/desktop/LeftNav.tsx23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx
index b19d5e8ab..fb3d66462 100644
--- a/src/view/shell/desktop/LeftNav.tsx
+++ b/src/view/shell/desktop/LeftNav.tsx
@@ -185,20 +185,33 @@ function ComposeBtn() {
   const {getState} = useNavigation()
   const {isTablet} = useWebMediaQueries()
 
-  const getProfileHandle = () => {
+  const getProfileHandle = async () => {
     const {routes} = getState()
     const currentRoute = routes[routes.length - 1]
+
     if (currentRoute.name === 'Profile') {
-      const {name: handle} =
+      let handle: string | undefined = (
         currentRoute.params as CommonNavigatorParams['Profile']
-      if (handle === store.me.handle) return undefined
+      ).name
+
+      if (handle.startsWith('did:')) {
+        const cached = await store.profiles.cache.get(handle)
+        const profile = cached ? cached.data : undefined
+        // if we can't resolve handle, set to undefined
+        handle = profile?.handle || undefined
+      }
+
+      if (!handle || handle === store.me.handle || handle === 'handle.invalid')
+        return undefined
+
       return handle
     }
+
     return undefined
   }
 
-  const onPressCompose = () =>
-    store.shell.openComposer({mention: getProfileHandle()})
+  const onPressCompose = async () =>
+    store.shell.openComposer({mention: await getProfileHandle()})
 
   if (isTablet) {
     return null