Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use muted display names, and always show instance for non-local. #1975 #2064 #2425

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions src/shared/components/community/community-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,38 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
}

render() {
const community = this.props.community;
let title: string, link: string;
const { community, useApubName } = this.props;
const local = community.local === null ? true : community.local;
const domain = hostname(community.actor_id);

let link: string;
let serverStr: string | undefined = undefined;

const title = useApubName
? community.name
: community.title ?? community.name;

if (local) {
title = community.title;
link = `/c/${community.name}`;
} else {
const name_ = `${community.name}@${domain}`;
title = `${community.title}@${domain}`;
link = !this.props.realLink ? `/c/${name_}` : community.actor_id;
serverStr = `@${hostname(community.actor_id)}`;
link = !this.props.realLink
? `/c/${community.name}${serverStr}`
: community.actor_id;
}
const classes = `community-link ${this.props.muted ? "text-muted" : ""}`;

const apubName = `!${community.name}@${domain}`;
const displayName = this.props.useApubName ? apubName : title;
return !this.props.realLink ? (
<Link
title={apubName}
className={`community-link ${this.props.muted ? "text-muted" : ""}`}
to={link}
>
{this.avatarAndName(displayName)}
<Link title={title} className={classes} to={link}>
{this.avatarAndName(title, serverStr)}
</Link>
) : (
<a
title={apubName}
className={`community-link ${this.props.muted ? "text-muted" : ""}`}
href={link}
rel={relTags}
>
{this.avatarAndName(displayName)}
<a title={title} className={classes} href={link} rel={relTags}>
{this.avatarAndName(title, serverStr)}
</a>
);
}

avatarAndName(displayName: string) {
avatarAndName(title: string, serverStr?: string) {
const icon = this.props.community.icon;
const nsfw = this.props.community.nsfw;

Expand All @@ -65,7 +61,12 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
!this.props.community.removed &&
showAvatars() &&
icon && <PictrsImage src={icon} icon nsfw={nsfw} />}
<span className="overflow-wrap-anywhere">{displayName}</span>
<span className="overflow-wrap-anywhere">
{title}
{serverStr !== undefined && (
<small className="text-muted">{serverStr}</small>
)}
</span>
</>
);
}
Expand Down
62 changes: 24 additions & 38 deletions src/shared/components/person/person-listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,64 +24,47 @@ export class PersonListing extends Component<PersonListingProps, any> {
}

render() {
const person = this.props.person;
const { person, useApubName } = this.props;
const local = person.local;
let apubName: string, link: string;
let link: string;
let serverStr: string | undefined = undefined;

const name = useApubName ? person.name : person.display_name ?? person.name;

if (local) {
apubName = `@${person.name}`;
link = `/u/${person.name}`;
} else {
const domain = hostname(person.actor_id);
apubName = `@${person.name}@${domain}`;
serverStr = `@${hostname(person.actor_id)}`;
link = !this.props.realLink
? `/u/${person.name}@${domain}`
? `/u/${person.name}${serverStr}`
: person.actor_id;
}

let displayName = this.props.useApubName
? apubName
: person.display_name ?? apubName;

if (this.props.showApubName && !local && person.display_name) {
displayName = `${displayName} (${apubName})`;
}

const classes = classNames(
"person-listing d-inline-flex align-items-baseline",
{
"text-muted": this.props.muted,
"text-info": !this.props.muted,
},
);
Comment on lines +43 to +49
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A ternary using muted would be more concise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using that special classNames function, it can't work in that way.

return (
<>
{!this.props.realLink ? (
<Link
title={apubName}
className={classNames(
"person-listing d-inline-flex align-items-baseline",
{
"text-muted": this.props.muted,
"text-info": !this.props.muted,
},
)}
to={link}
>
{this.avatarAndName(displayName)}
<Link title={name} className={classes} to={link}>
{this.avatarAndName(name, serverStr)}
</Link>
) : (
<a
title={apubName}
className={`person-listing d-inline-flex align-items-baseline ${
this.props.muted ? "text-muted" : "text-info"
}`}
href={link}
rel={relTags}
>
{this.avatarAndName(displayName)}
<a title={name} className={classes} href={link} rel={relTags}>
{this.avatarAndName(name, serverStr)}
</a>
)}

{isCakeDay(person.published) && <CakeDay creatorName={apubName} />}
{isCakeDay(person.published) && <CakeDay creatorName={name} />}
</>
);
}

avatarAndName(displayName: string) {
avatarAndName(name: string, serverStr?: string) {
const avatar = this.props.person.avatar;
return (
<>
Expand All @@ -93,7 +76,10 @@ export class PersonListing extends Component<PersonListingProps, any> {
icon
/>
)}
<span>{displayName}</span>
<span>{name}</span>
{serverStr !== undefined && (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any falsey values you're trying to avoid matching?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix in a sec.

<small className="text-muted">{serverStr}</small>
)}
</>
);
}
Expand Down