Skip to content

Commit 79090fd

Browse files
committed
autocomplete: Fix crash in showing avatar for pseudo-users.
Fixes: #4422
1 parent 2e48c1e commit 79090fd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/common/UserAvatarWithPresence.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createStyleSheet } from '../styles';
66
import UserAvatar from './UserAvatar';
77
import PresenceStatusIndicator from './PresenceStatusIndicator';
88
import { AvatarURL } from '../utils/avatar';
9-
import { getUserForId } from '../users/userSelectors';
9+
import { tryGetUserForId } from '../users/userSelectors';
1010
import { useSelector } from '../react-redux';
1111

1212
const styles = createStyleSheet({
@@ -70,6 +70,14 @@ export function UserAvatarWithPresenceById(
7070
|}>,
7171
) {
7272
const { userId, ...restProps } = props;
73-
const user = useSelector(state => getUserForId(state, userId));
73+
74+
const user = useSelector(state => tryGetUserForId(state, userId));
75+
if (!user) {
76+
// This condition really does happen, because UserItem can be passed a fake
77+
// pseudo-user by PeopleAutocomplete, to represent `@all` or `@everyone`.
78+
// TODO eliminate that, and use plain `getUserForId` here.
79+
return null;
80+
}
81+
7482
return <UserAvatarWithPresence {...restProps} avatarUrl={user.avatar_url} email={user.email} />;
7583
}

0 commit comments

Comments
 (0)