From 6b686ab3f81691831a11d6a56629bfac4dc4e767 Mon Sep 17 00:00:00 2001 From: Mattermost Build Date: Wed, 12 Jul 2023 17:31:29 +0300 Subject: [PATCH] fix: crash when reactor is missing (#7448) (#7449) (cherry picked from commit 40254fba96acf6fd835fa3002aa4d2a9295166f5) Co-authored-by: Elias Nahum --- app/components/user_item/user_item.tsx | 21 +++++++++++-------- .../reactors_list/reactor/reactor.tsx | 17 ++++++++++++--- app/utils/user/index.ts | 4 ++++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/components/user_item/user_item.tsx b/app/components/user_item/user_item.tsx index 6af46a5cac4..84325d96ba6 100644 --- a/app/components/user_item/user_item.tsx +++ b/app/components/user_item/user_item.tsx @@ -13,13 +13,13 @@ import {useTheme} from '@context/theme'; import {nonBreakingString} from '@utils/strings'; import {makeStyleSheetFromTheme, changeOpacity} from '@utils/theme'; import {typography} from '@utils/typography'; -import {displayUsername, getUserCustomStatus, isBot, isCustomStatusExpired, isGuest, isShared} from '@utils/user'; +import {displayUsername, getUserCustomStatus, isBot, isCustomStatusExpired, isDeactivated, isGuest, isShared} from '@utils/user'; import type UserModel from '@typings/database/models/servers/user'; type AtMentionItemProps = { FooterComponent?: ReactNode; - user: UserProfile | UserModel; + user?: UserProfile | UserModel; containerStyle?: StyleProp; currentUserId: string; includeMargin?: boolean; @@ -115,13 +115,12 @@ const UserItem = ({ const bot = user ? isBot(user) : false; const guest = user ? isGuest(user.roles) : false; const shared = user ? isShared(user) : false; + const deactivated = user ? isDeactivated(user) : false; const isCurrentUser = currentUserId === user?.id; const customStatus = getUserCustomStatus(user); const customStatusExpired = isCustomStatusExpired(user); - const deleteAt = 'deleteAt' in user ? user.deleteAt : user.delete_at; - let displayName = displayUsername(user, locale, teammateNameDisplay); const showTeammateDisplay = displayName !== user?.username; if (isCurrentUser) { @@ -142,11 +141,15 @@ const UserItem = ({ }, [disabled, padding, includeMargin]); const onPress = useCallback(() => { - onUserPress?.(user); + if (user) { + onUserPress?.(user); + } }, [user, onUserPress]); const onLongPress = useCallback(() => { - onUserLongPress?.(user); + if (user) { + onUserLongPress?.(user); + } }, [user, onUserLongPress]); return ( @@ -175,15 +178,15 @@ const UserItem = ({ testID={`${userItemTestId}.display_name`} > {nonBreakingString(displayName)} - {Boolean(showTeammateDisplay) && ( + {Boolean(showTeammateDisplay) && Boolean(user?.username) && ( - {nonBreakingString(` @${user!.username}`)} + {nonBreakingString(` @${user?.username}`)} )} - {Boolean(deleteAt) && ( + {deactivated && ( { +const Reactor = ({channelId, location, reaction, user}: Props) => { const intl = useIntl(); const theme = useTheme(); + const serverUrl = useServerUrl(); const openUserProfile = async () => { if (user) { await dismissBottomSheet(Screens.REACTIONS); @@ -34,6 +39,12 @@ const Reactor = ({channelId, location, user}: Props) => { } }; + useEffect(() => { + if (!user) { + fetchUsersByIds(serverUrl, [reaction.userId]); + } + }, []); + return ( = 0; i--) {