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>zio/stable
parent
42723dfaf6
commit
6325eff938
|
@ -91,7 +91,10 @@ export const ProfileScreen = withAuthRequired(
|
||||||
const onPressCompose = React.useCallback(() => {
|
const onPressCompose = React.useCallback(() => {
|
||||||
track('ProfileScreen:PressCompose')
|
track('ProfileScreen:PressCompose')
|
||||||
const mention =
|
const mention =
|
||||||
uiState.profile.handle === store.me.handle ? '' : uiState.profile.handle
|
uiState.profile.handle === store.me.handle ||
|
||||||
|
uiState.profile.handle === 'handle.invalid'
|
||||||
|
? undefined
|
||||||
|
: uiState.profile.handle
|
||||||
store.shell.openComposer({mention})
|
store.shell.openComposer({mention})
|
||||||
}, [store, track, uiState])
|
}, [store, track, uiState])
|
||||||
const onSelectView = React.useCallback(
|
const onSelectView = React.useCallback(
|
||||||
|
|
|
@ -185,20 +185,33 @@ function ComposeBtn() {
|
||||||
const {getState} = useNavigation()
|
const {getState} = useNavigation()
|
||||||
const {isTablet} = useWebMediaQueries()
|
const {isTablet} = useWebMediaQueries()
|
||||||
|
|
||||||
const getProfileHandle = () => {
|
const getProfileHandle = async () => {
|
||||||
const {routes} = getState()
|
const {routes} = getState()
|
||||||
const currentRoute = routes[routes.length - 1]
|
const currentRoute = routes[routes.length - 1]
|
||||||
|
|
||||||
if (currentRoute.name === 'Profile') {
|
if (currentRoute.name === 'Profile') {
|
||||||
const {name: handle} =
|
let handle: string | undefined = (
|
||||||
currentRoute.params as CommonNavigatorParams['Profile']
|
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 handle
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const onPressCompose = () =>
|
const onPressCompose = async () =>
|
||||||
store.shell.openComposer({mention: getProfileHandle()})
|
store.shell.openComposer({mention: await getProfileHandle()})
|
||||||
|
|
||||||
if (isTablet) {
|
if (isTablet) {
|
||||||
return null
|
return null
|
||||||
|
|
Loading…
Reference in New Issue