Skip to content

Commit

Permalink
user [nfc]: Handle name fallback to message within getFullNameText an…
Browse files Browse the repository at this point in the history
…d friends
  • Loading branch information
gnprice authored and chrisbobbe committed Jan 5, 2024
1 parent 0c29df4 commit eb3fb95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
18 changes: 9 additions & 9 deletions src/lightbox/LightboxHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export default function LightboxHeader(props: Props): Node {
<SafeAreaView mode="padding" edges={['right', 'left']} style={styles.contentArea}>
<UserAvatarWithPresence size={36} userId={senderId} />
<View style={styles.text}>
{sender != null ? (
<ZulipTextIntl
style={styles.name}
numberOfLines={1}
text={getFullNameReactText({ user: sender, enableGuestUserIndicator })}
/>
) : (
<ZulipText style={styles.name} numberOfLines={1} text={message.sender_full_name} />
)}
<ZulipTextIntl
style={styles.name}
numberOfLines={1}
text={getFullNameReactText({
user: sender,
enableGuestUserIndicator,
fallback: message.sender_full_name,
})}
/>
<ZulipText style={styles.subheader} numberOfLines={1}>
{subheader}
</ZulipText>
Expand Down
26 changes: 16 additions & 10 deletions src/users/userSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ export function getDisplayEmailForUser(realm: RealmState, user: UserOrBot): stri
/**
* Display text for a user's name, ignoring muting, as LocalizableText.
*
* Accepts `null` for the `user` argument; in that case, the text is
* Accepts `null` for the `user` argument; in that case, the name is
* taken from `fallback` if present, and otherwise the text is
* "(unknown user)".
*
* For the same text as LocalizableReactText, see getFullNameReactText.
Expand All @@ -349,11 +350,12 @@ export function getDisplayEmailForUser(realm: RealmState, user: UserOrBot): stri
export function getFullNameText(args: {|
user: UserOrBot | null,
enableGuestUserIndicator: boolean,
fallback?: string,
|}): LocalizableText {
const { user, enableGuestUserIndicator } = args;
const { user, enableGuestUserIndicator, fallback } = args;

if (user == null) {
return '(unknown user)';
return fallback != null ? noTranslation(fallback) : '(unknown user)';
}

if (user.role === Role.Guest && enableGuestUserIndicator) {
Expand All @@ -373,11 +375,12 @@ const italicTextStyle = { fontStyle: 'italic' };
export function getFullNameReactText(args: {|
+user: UserOrBot | null,
+enableGuestUserIndicator: boolean,
+fallback?: string,
|}): LocalizableReactText {
const { user, enableGuestUserIndicator } = args;
const { user, enableGuestUserIndicator, fallback } = args;

if (user == null) {
return '(unknown user)';
return fallback != null ? noTranslation(fallback) : '(unknown user)';
}

if (user.role === Role.Guest && enableGuestUserIndicator) {
Expand All @@ -400,7 +403,8 @@ export function getFullNameReactText(args: {|
/**
* Display text for a user's name, as LocalizableText.
*
* Accepts `null` for the `user` argument; in that case, the text is
* Accepts `null` for the `user` argument; in that case, the name is
* taken from `fallback` if present, and otherwise the text is
* "(unknown user)".
*
* If the user is muted, gives "Muted user".
Expand All @@ -414,11 +418,12 @@ export function getFullNameOrMutedUserText(args: {|
user: UserOrBot | null,
mutedUsers: MutedUsersState,
enableGuestUserIndicator: boolean,
fallback?: string,
|}): LocalizableText {
const { user, mutedUsers, enableGuestUserIndicator } = args;
const { user, mutedUsers, enableGuestUserIndicator, fallback } = args;

if (user == null) {
return '(unknown user)';
return fallback != null ? noTranslation(fallback) : '(unknown user)';
}

if (mutedUsers.has(user.user_id)) {
Expand All @@ -437,11 +442,12 @@ export function getFullNameOrMutedUserReactText(args: {|
user: UserOrBot | null,
mutedUsers: MutedUsersState,
enableGuestUserIndicator: boolean,
fallback?: string,
|}): LocalizableReactText {
const { user, mutedUsers, enableGuestUserIndicator } = args;
const { user, mutedUsers, enableGuestUserIndicator, fallback } = args;

if (user == null) {
return '(unknown user)';
return fallback != null ? noTranslation(fallback) : '(unknown user)';
}

if (mutedUsers.has(user.user_id)) {
Expand Down
13 changes: 9 additions & 4 deletions src/webview/html/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,16 @@ export default (
>
${uiRecipients
.map(r => {
const user = allUsersById.get(r.id);
const user = allUsersById.get(r.id) ?? null;
// TODO use italics for "(guest)"
return user != null
? _(getFullNameOrMutedUserText({ user, mutedUsers, enableGuestUserIndicator }))
: r.full_name;
return _(
getFullNameOrMutedUserText({
user,
mutedUsers,
enableGuestUserIndicator,
fallback: r.full_name,
}),
);
})
.sort()
.join(', ')}
Expand Down
18 changes: 8 additions & 10 deletions src/webview/html/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,14 @@ $!${divOpenHtml}

const { sender_id } = message;
const sender = backgroundData.allUsersById.get(sender_id) ?? null;
const senderFullName =
sender != null
? _(
// TODO use italics for "(guest)"
getFullNameText({
user: sender,
enableGuestUserIndicator: backgroundData.enableGuestUserIndicator,
}),
)
: message.sender_full_name;
const senderFullName = _(
// TODO use italics for "(guest)"
getFullNameText({
user: sender,
enableGuestUserIndicator: backgroundData.enableGuestUserIndicator,
fallback: message.sender_full_name,
}),
);
const avatarUrl = message.avatar_url
.get(
// 48 logical pixels; see `.avatar` and `.avatar img` in
Expand Down

0 comments on commit eb3fb95

Please sign in to comment.