[🐴] Handle deleted accounts, restructure ChatListItem (#4114)

* Handle deleted accounts, restructure ChatListItem

* Remove triggerOpacity option

* account for handle change in screen reader

* simplify the check

---------

Co-authored-by: Hailey <me@haileyok.com>
zio/stable
Eric Bailey 2024-05-20 16:16:29 -05:00 committed by GitHub
parent becf373edb
commit 31a716d256
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 202 additions and 166 deletions

View File

@ -18,7 +18,7 @@ import {
import {useMuteConvo} from '#/state/queries/messages/mute-conversation' import {useMuteConvo} from '#/state/queries/messages/mute-conversation'
import {useProfileBlockMutationQueue} from '#/state/queries/profile' import {useProfileBlockMutationQueue} from '#/state/queries/profile'
import * as Toast from '#/view/com/util/Toast' import * as Toast from '#/view/com/util/Toast'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme, ViewStyleProp} from '#/alf'
import {BlockedByListDialog} from '#/components/dms/BlockedByListDialog' import {BlockedByListDialog} from '#/components/dms/BlockedByListDialog'
import {LeaveConvoPrompt} from '#/components/dms/LeaveConvoPrompt' import {LeaveConvoPrompt} from '#/components/dms/LeaveConvoPrompt'
import {ReportConversationPrompt} from '#/components/dms/ReportConversationPrompt' import {ReportConversationPrompt} from '#/components/dms/ReportConversationPrompt'
@ -41,8 +41,8 @@ let ConvoMenu = ({
currentScreen, currentScreen,
showMarkAsRead, showMarkAsRead,
hideTrigger, hideTrigger,
triggerOpacity,
blockInfo, blockInfo,
style,
}: { }: {
convo: ChatBskyConvoDefs.ConvoView convo: ChatBskyConvoDefs.ConvoView
profile: Shadow<AppBskyActorDefs.ProfileViewBasic> profile: Shadow<AppBskyActorDefs.ProfileViewBasic>
@ -50,11 +50,11 @@ let ConvoMenu = ({
currentScreen: 'list' | 'conversation' currentScreen: 'list' | 'conversation'
showMarkAsRead?: boolean showMarkAsRead?: boolean
hideTrigger?: boolean hideTrigger?: boolean
triggerOpacity?: number
blockInfo: { blockInfo: {
listBlocks: ModerationCause[] listBlocks: ModerationCause[]
userBlock?: ModerationCause userBlock?: ModerationCause
} }
style?: ViewStyleProp['style']
}): React.ReactNode => { }): React.ReactNode => {
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const {_} = useLingui() const {_} = useLingui()
@ -66,6 +66,7 @@ let ConvoMenu = ({
const {listBlocks, userBlock} = blockInfo const {listBlocks, userBlock} = blockInfo
const isBlocking = userBlock || !!listBlocks.length const isBlocking = userBlock || !!listBlocks.length
const isDeletedAccount = profile.handle === 'missing.invalid'
const {data: convo} = useConvoQuery(initialConvo) const {data: convo} = useConvoQuery(initialConvo)
@ -105,7 +106,7 @@ let ConvoMenu = ({
<> <>
<Menu.Root control={control}> <Menu.Root control={control}>
{!hideTrigger && ( {!hideTrigger && (
<View style={{opacity: triggerOpacity}}> <View style={[style]}>
<Menu.Trigger label={_(msg`Chat settings`)}> <Menu.Trigger label={_(msg`Chat settings`)}>
{({props, state}) => ( {({props, state}) => (
<Pressable <Pressable
@ -128,6 +129,19 @@ let ConvoMenu = ({
</Menu.Trigger> </Menu.Trigger>
</View> </View>
)} )}
{isDeletedAccount ? (
<Menu.Outer>
<Menu.Item
label={_(msg`Leave conversation`)}
onPress={leaveConvoControl.open}>
<Menu.ItemText>
<Trans>Leave conversation</Trans>
</Menu.ItemText>
<Menu.ItemIcon icon={ArrowBoxLeft} />
</Menu.Item>
</Menu.Outer>
) : (
<Menu.Outer> <Menu.Outer>
<Menu.Group> <Menu.Group>
{showMarkAsRead && ( {showMarkAsRead && (
@ -198,6 +212,7 @@ let ConvoMenu = ({
</Menu.Item> </Menu.Item>
</Menu.Group> </Menu.Group>
</Menu.Outer> </Menu.Outer>
)}
</Menu.Root> </Menu.Root>
<LeaveConvoPrompt <LeaveConvoPrompt

View File

@ -8,9 +8,7 @@ import {
} from '@atproto/api' } from '@atproto/api'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from '#/lib/routes/types'
import {isNative} from '#/platform/detection' import {isNative} from '#/platform/detection'
import {useProfileShadow} from '#/state/cache/profile-shadow' import {useProfileShadow} from '#/state/cache/profile-shadow'
import {useModerationOpts} from '#/state/preferences/moderation-opts' import {useModerationOpts} from '#/state/preferences/moderation-opts'
@ -19,9 +17,9 @@ import {sanitizeDisplayName} from 'lib/strings/display-names'
import {TimeElapsed} from '#/view/com/util/TimeElapsed' import {TimeElapsed} from '#/view/com/util/TimeElapsed'
import {UserAvatar} from '#/view/com/util/UserAvatar' import {UserAvatar} from '#/view/com/util/UserAvatar'
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf' import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
import {Button} from '#/components/Button'
import {ConvoMenu} from '#/components/dms/ConvoMenu' import {ConvoMenu} from '#/components/dms/ConvoMenu'
import {Bell2Off_Filled_Corner0_Rounded as BellStroke} from '#/components/icons/Bell2' import {Bell2Off_Filled_Corner0_Rounded as BellStroke} from '#/components/icons/Bell2'
import {Link} from '#/components/Link'
import {useMenuControl} from '#/components/Menu' import {useMenuControl} from '#/components/Menu'
import {Text} from '#/components/Typography' import {Text} from '#/components/Typography'
@ -91,6 +89,8 @@ function ChatListItemReady({
moderation.ui('displayName'), moderation.ui('displayName'),
) )
const isDimStyle = convo.muted || moderation.blocked || isDeletedAccount
let lastMessage = _(msg`No messages yet`) let lastMessage = _(msg`No messages yet`)
let lastMessageSentAt: string | null = null let lastMessageSentAt: string | null = null
if (ChatBskyConvoDefs.isMessageView(convo.lastMessage)) { if (ChatBskyConvoDefs.isMessageView(convo.lastMessage)) {
@ -102,10 +102,9 @@ function ChatListItemReady({
lastMessageSentAt = convo.lastMessage.sentAt lastMessageSentAt = convo.lastMessage.sentAt
} }
if (ChatBskyConvoDefs.isDeletedMessageView(convo.lastMessage)) { if (ChatBskyConvoDefs.isDeletedMessageView(convo.lastMessage)) {
lastMessage = _(msg`Message deleted`) lastMessage = _(msg`Conversation deleted`)
} }
const navigation = useNavigation<NavigationProp>()
const [showActions, setShowActions] = useState(false) const [showActions, setShowActions] = useState(false)
const onMouseEnter = useCallback(() => { const onMouseEnter = useCallback(() => {
@ -121,12 +120,6 @@ function ChatListItemReady({
setShowActions(true) setShowActions(true)
}, []) }, [])
const onPress = useCallback(() => {
navigation.push('MessagesConversation', {
conversation: convo.id,
})
}, [convo.id, navigation])
const onLongPress = useCallback(() => { const onLongPress = useCallback(() => {
menuControl.open() menuControl.open()
}, [menuControl]) }, [menuControl])
@ -137,13 +130,16 @@ function ChatListItemReady({
onMouseEnter={onMouseEnter} onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave} onMouseLeave={onMouseLeave}
onFocus={onFocus} onFocus={onFocus}
onBlur={onMouseLeave}> onBlur={onMouseLeave}
<Button style={[a.relative]}>
onPress={onPress} <Link
style={[a.flex_1]} to={`/messages/${convo.id}`}
onLongPress={isNative ? onLongPress : undefined} label={displayName}
label={profile.displayName || profile.handle} accessibilityHint={
accessibilityHint={_(msg`Go to conversation with ${profile.handle}`)} !isDeletedAccount
? _(msg`Go to conversation with ${profile.handle}`)
: undefined
}
accessibilityActions={ accessibilityActions={
isNative isNative
? [ ? [
@ -152,16 +148,33 @@ function ChatListItemReady({
] ]
: undefined : undefined
} }
onAccessibilityAction={onLongPress}> onAccessibilityAction={onLongPress}
onPress={
isDeletedAccount
? e => {
e.preventDefault()
return false
}
: undefined
}
style={[
web({
cursor: isDeletedAccount ? 'default' : 'pointer',
}),
]}
onLongPress={isNative ? menuControl.open : undefined}>
{({hovered, pressed, focused}) => ( {({hovered, pressed, focused}) => (
<View <View
style={[ style={[
a.flex_row, a.flex_row,
isDeletedAccount ? a.align_center : a.align_start,
a.flex_1, a.flex_1,
a.px_lg, a.px_lg,
a.py_md, a.py_md,
a.gap_md, a.gap_md,
(hovered || pressed || focused) && t.atoms.bg_contrast_25, (hovered || pressed || focused) &&
!isDeletedAccount &&
t.atoms.bg_contrast_25,
t.atoms.border_contrast_low, t.atoms.border_contrast_low,
]}> ]}>
<UserAvatar <UserAvatar
@ -169,20 +182,20 @@ function ChatListItemReady({
size={52} size={52}
moderation={moderation.ui('avatar')} moderation={moderation.ui('avatar')}
/> />
<View style={[a.flex_1, a.flex_row, a.align_center]}>
<View style={[a.flex_1]}> <View style={[a.flex_1, a.justify_center]}>
<View <View style={[a.w_full, a.flex_row, a.align_end, a.pb_2xs]}>
style={[
a.flex_1,
a.flex_row,
a.align_end,
a.pb_2xs,
web([{marginTop: -2}]),
]}>
<Text <Text
numberOfLines={1} numberOfLines={1}
style={[{maxWidth: '85%'}, web([a.leading_normal])]}> style={[{maxWidth: '85%'}, web([a.leading_normal])]}>
<Text style={[a.text_md, t.atoms.text, a.font_bold]}> <Text
style={[
a.text_md,
t.atoms.text,
a.font_bold,
{lineHeight: 21},
isDimStyle && t.atoms.text_contrast_medium,
]}>
{displayName} {displayName}
</Text> </Text>
</Text> </Text>
@ -192,7 +205,7 @@ function ChatListItemReady({
<Text <Text
style={[ style={[
a.text_sm, a.text_sm,
web([a.leading_normal, {whiteSpace: 'pre'}]), {lineHeight: 21},
t.atoms.text_contrast_medium, t.atoms.text_contrast_medium,
]}> ]}>
{' '} {' '}
@ -205,18 +218,19 @@ function ChatListItemReady({
<Text <Text
style={[ style={[
a.text_sm, a.text_sm,
web([a.leading_normal, {whiteSpace: 'pre'}]), {lineHeight: 21},
t.atoms.text_contrast_medium, t.atoms.text_contrast_medium,
]}> ]}>
{' '} {' '}
&middot;{' '} &middot;{' '}
<BellStroke <BellStroke
size="xs" size="xs"
style={t.atoms.text_contrast_medium} style={[t.atoms.text_contrast_medium]}
/> />
</Text> </Text>
)} )}
</View> </View>
{!isDeletedAccount && ( {!isDeletedAccount && (
<Text <Text
numberOfLines={1} numberOfLines={1}
@ -224,6 +238,7 @@ function ChatListItemReady({
@{profile.handle} @{profile.handle}
</Text> </Text>
)} )}
<Text <Text
numberOfLines={2} numberOfLines={2}
style={[ style={[
@ -232,20 +247,18 @@ function ChatListItemReady({
convo.unreadCount > 0 convo.unreadCount > 0
? a.font_bold ? a.font_bold
: t.atoms.text_contrast_high, : t.atoms.text_contrast_high,
(convo.muted || moderation.blocked) && isDimStyle && t.atoms.text_contrast_medium,
t.atoms.text_contrast_medium,
]}> ]}>
{lastMessage} {lastMessage}
</Text> </Text>
</View>
{convo.unreadCount > 0 && ( {convo.unreadCount > 0 && (
<View <View
style={[ style={[
a.absolute, a.absolute,
a.rounded_full, a.rounded_full,
{ {
backgroundColor: backgroundColor: isDimStyle
convo.muted || moderation.blocked
? t.palette.contrast_200 ? t.palette.contrast_200
: t.palette.primary_500, : t.palette.primary_500,
height: 7, height: 7,
@ -263,6 +276,11 @@ function ChatListItemReady({
]} ]}
/> />
)} )}
</View>
</View>
)}
</Link>
<ConvoMenu <ConvoMenu
convo={convo} convo={convo}
profile={profile} profile={profile}
@ -270,15 +288,18 @@ function ChatListItemReady({
currentScreen="list" currentScreen="list"
showMarkAsRead={convo.unreadCount > 0} showMarkAsRead={convo.unreadCount > 0}
hideTrigger={isNative} hideTrigger={isNative}
triggerOpacity={
!gtMobile || showActions || menuControl.isOpen ? 1 : 0
}
blockInfo={blockInfo} blockInfo={blockInfo}
style={[
a.absolute,
a.h_full,
a.self_end,
a.justify_center,
{
right: a.px_lg.paddingRight,
opacity: !gtMobile || showActions || menuControl.isOpen ? 1 : 0,
},
]}
/> />
</View> </View>
</View>
)}
</Button>
</View>
) )
} }