Skip to content

Commit 5b04f58

Browse files
committed
UserAvatarWithPresence [nfc]: Finish migration to UserId-based interface
By unexporting the old UserAvatarWithPresence and giving its name to UserAvatarWithPresenceById.
1 parent b31750c commit 5b04f58

File tree

6 files changed

+23
-51
lines changed

6 files changed

+23
-51
lines changed

src/common/UserAvatarWithPresence.js

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { UserId } from '../types';
66
import { createStyleSheet } from '../styles';
77
import UserAvatar from './UserAvatar';
88
import PresenceStatusIndicator from './PresenceStatusIndicator';
9-
import { AvatarURL } from '../utils/avatar';
109
import { tryGetUserForId } from '../users/userSelectors';
1110
import { useSelector } from '../react-redux';
1211

@@ -19,57 +18,21 @@ const styles = createStyleSheet({
1918
});
2019

2120
type Props = $ReadOnly<{|
22-
avatarUrl: AvatarURL,
21+
userId: UserId,
2322
size: number,
2423
onPress?: () => void,
25-
email: string,
2624
isMuted?: boolean,
2725
|}>;
2826

2927
/**
3028
* A user avatar with a PresenceStatusIndicator in the corner.
3129
*
32-
* Prefer `UserAvatarWithPresenceById` over this component: it does the same
33-
* thing but avoids an email in the component's interface. Once all callers
34-
* have migrated to that version, it'll replace this one.
35-
*
36-
* @prop [avatarUrl]
37-
* @prop [email] - Sender's / user's email address, for the presence dot.
38-
* @prop [size] - Sets width and height in logical pixels.
39-
* @prop [onPress] - Event fired on pressing the component.
40-
*/
41-
export default function UserAvatarWithPresence(props: Props): Node {
42-
const { avatarUrl, email, isMuted, size, onPress } = props;
43-
44-
return (
45-
<UserAvatar avatarUrl={avatarUrl} size={size} isMuted={isMuted} onPress={onPress}>
46-
<PresenceStatusIndicator
47-
style={styles.status}
48-
email={email}
49-
hideIfOffline
50-
useOpaqueBackground
51-
/>
52-
</UserAvatar>
53-
);
54-
}
55-
56-
/**
57-
* A user avatar with a PresenceStatusIndicator in the corner.
58-
*
59-
* Use this in preference to the default export `UserAvatarWithPresence`.
60-
* We're migrating from that one to this in order to avoid using emails.
61-
*
6230
* @prop [userId]
6331
* @prop [size]
6432
* @prop [onPress]
6533
*/
66-
export function UserAvatarWithPresenceById(
67-
props: $ReadOnly<{|
68-
...$Diff<Props, {| avatarUrl: mixed, email: mixed |}>,
69-
userId: UserId,
70-
|}>,
71-
): Node {
72-
const { userId, ...restProps } = props;
34+
export default function UserAvatarWithPresence(props: Props): Node {
35+
const { userId, isMuted, size, onPress } = props;
7336

7437
const user = useSelector(state => tryGetUserForId(state, userId));
7538
if (!user) {
@@ -79,5 +42,14 @@ export function UserAvatarWithPresenceById(
7942
return null;
8043
}
8144

82-
return <UserAvatarWithPresence {...restProps} avatarUrl={user.avatar_url} email={user.email} />;
45+
return (
46+
<UserAvatar avatarUrl={user.avatar_url} size={size} isMuted={isMuted} onPress={onPress}>
47+
<PresenceStatusIndicator
48+
style={styles.status}
49+
email={user.email}
50+
hideIfOffline
51+
useOpaqueBackground
52+
/>
53+
</UserAvatar>
54+
);
8355
}

src/lightbox/LightboxHeader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SafeAreaView } from 'react-native-safe-area-context';
66

77
import { shortTime, humanDate } from '../utils/date';
88
import { createStyleSheet } from '../styles';
9-
import { UserAvatarWithPresenceById } from '../common/UserAvatarWithPresence';
9+
import UserAvatarWithPresence from '../common/UserAvatarWithPresence';
1010
import { Icon } from '../common/Icons';
1111
import { OfflineNoticePlaceholder } from '../boot/OfflineNoticeProvider';
1212
import type { UserId } from '../api/idTypes';
@@ -63,7 +63,7 @@ export default function LightboxHeader(props: Props): Node {
6363
<SafeAreaView mode="padding" edges={['top']}>
6464
<OfflineNoticePlaceholder />
6565
<SafeAreaView mode="padding" edges={['right', 'left']} style={styles.contentArea}>
66-
<UserAvatarWithPresenceById size={36} userId={senderId} />
66+
<UserAvatarWithPresence size={36} userId={senderId} />
6767
<View style={styles.text}>
6868
<Text style={styles.name} numberOfLines={1}>
6969
{senderName}

src/title/TitleGroup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useSelector } from '../react-redux';
88
import { getMutedUsers, getOwnUserId } from '../selectors';
99
import { pmUiRecipientsFromKeyRecipients, type PmKeyRecipients } from '../utils/recipient';
1010
import styles, { createStyleSheet } from '../styles';
11-
import { UserAvatarWithPresenceById } from '../common/UserAvatarWithPresence';
11+
import UserAvatarWithPresence from '../common/UserAvatarWithPresence';
1212
import { useNavigation } from '../react-navigation';
1313

1414
type Props = $ReadOnly<{|
@@ -32,7 +32,7 @@ export default function TitleGroup(props: Props): Node {
3232
<View style={styles.navWrapper}>
3333
{userIds.map(userId => (
3434
<View key={userId} style={componentStyles.titleAvatar}>
35-
<UserAvatarWithPresenceById
35+
<UserAvatarWithPresence
3636
onPress={() => {
3737
navigation.push('account-details', { userId });
3838
}}

src/title/TitlePrivate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import styles, { createStyleSheet } from '../styles';
99
import { useSelector } from '../react-redux';
1010
import Touchable from '../common/Touchable';
1111
import ViewPlaceholder from '../common/ViewPlaceholder';
12-
import { UserAvatarWithPresenceById } from '../common/UserAvatarWithPresence';
12+
import UserAvatarWithPresence from '../common/UserAvatarWithPresence';
1313
import ActivityText from './ActivityText';
1414
import { tryGetUserForId } from '../users/userSelectors';
1515
import { useNavigation } from '../react-navigation';
@@ -44,7 +44,7 @@ export default function TitlePrivate(props: Props): Node {
4444
style={componentStyles.outer}
4545
>
4646
<View style={componentStyles.inner}>
47-
<UserAvatarWithPresenceById size={32} userId={user.user_id} />
47+
<UserAvatarWithPresence size={32} userId={user.user_id} />
4848
<ViewPlaceholder width={8} />
4949
<View style={componentStyles.textWrapper}>
5050
<Text style={[styles.navTitle, { color }]} numberOfLines={1} ellipsizeMode="tail">

src/user-picker/AvatarItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Animated, Easing, View } from 'react-native';
55
import type AnimatedValue from 'react-native/Libraries/Animated/nodes/AnimatedValue';
66

77
import type { UserId, UserOrBot } from '../types';
8-
import { UserAvatarWithPresenceById } from '../common/UserAvatarWithPresence';
8+
import UserAvatarWithPresence from '../common/UserAvatarWithPresence';
99
import ComponentWithOverlay from '../common/ComponentWithOverlay';
1010
import ZulipText from '../common/ZulipText';
1111
import Touchable from '../common/Touchable';
@@ -77,7 +77,7 @@ export default class AvatarItem extends PureComponent<Props> {
7777
overlayPosition="bottom-right"
7878
overlay={<IconCancel color="gray" size={20} />}
7979
>
80-
<UserAvatarWithPresenceById key={user.user_id} size={50} userId={user.user_id} />
80+
<UserAvatarWithPresence key={user.user_id} size={50} userId={user.user_id} />
8181
</ComponentWithOverlay>
8282
</Touchable>
8383
<View style={styles.textFrame}>

src/users/UserItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { UserId } from '../types';
88
import ZulipText from '../common/ZulipText';
99
import Touchable from '../common/Touchable';
1010
import UnreadCount from '../common/UnreadCount';
11-
import { UserAvatarWithPresenceById } from '../common/UserAvatarWithPresence';
11+
import UserAvatarWithPresence from '../common/UserAvatarWithPresence';
1212
import globalStyles, { createStyleSheet, BRAND_COLOR } from '../styles';
1313
import { useSelector } from '../react-redux';
1414
import { getUserForId } from './userSelectors';
@@ -96,7 +96,7 @@ export function UserItemRaw<
9696
return (
9797
<Touchable onPress={onPress && handlePress}>
9898
<View style={[styles.wrapper, isSelected && styles.selectedRow]}>
99-
<UserAvatarWithPresenceById
99+
<UserAvatarWithPresence
100100
// At size medium, keep just big enough for a 48px touch target.
101101
size={size === 'large' ? 48 : 32}
102102
userId={user.user_id}

0 commit comments

Comments
 (0)