2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
|
|
|
import { Link } from "inferno-router";
|
2021-03-15 18:09:31 +00:00
|
|
|
import { PersonSafe } from "lemmy-js-client";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { showAvatars, hostname, isCakeDay } from "../utils";
|
|
|
|
import { CakeDay } from "./cake-day";
|
|
|
|
import { PictrsImage } from "./pictrs-image";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
interface PersonListingProps {
|
|
|
|
person: PersonSafe;
|
2020-09-06 16:15:25 +00:00
|
|
|
realLink?: boolean;
|
|
|
|
useApubName?: boolean;
|
|
|
|
muted?: boolean;
|
|
|
|
hideAvatar?: boolean;
|
2020-11-18 22:01:05 +00:00
|
|
|
showApubName?: boolean;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
export class PersonListing extends Component<PersonListingProps, any> {
|
2020-09-06 16:15:25 +00:00
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-03-15 18:09:31 +00:00
|
|
|
let person = this.props.person;
|
|
|
|
let local = person.local == null ? true : person.local;
|
2020-09-06 16:15:25 +00:00
|
|
|
let apubName: string, link: string;
|
|
|
|
|
|
|
|
if (local) {
|
2021-03-15 18:09:31 +00:00
|
|
|
apubName = `@${person.name}`;
|
|
|
|
link = `/u/${person.name}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
} else {
|
2021-03-15 18:09:31 +00:00
|
|
|
apubName = `@${person.name}@${hostname(person.actor_id)}`;
|
|
|
|
link = !this.props.realLink ? `/user/${person.id}` : person.actor_id;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let displayName = this.props.useApubName
|
|
|
|
? apubName
|
2021-04-09 01:59:34 +00:00
|
|
|
: person.display_name
|
|
|
|
? person.display_name
|
2020-09-06 16:15:25 +00:00
|
|
|
: apubName;
|
|
|
|
|
2021-04-09 01:59:34 +00:00
|
|
|
if (this.props.showApubName && !local && person.display_name) {
|
2020-11-18 22:01:05 +00:00
|
|
|
displayName = `${displayName} (${apubName})`;
|
|
|
|
}
|
|
|
|
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Link
|
|
|
|
title={apubName}
|
2021-02-22 02:39:04 +00:00
|
|
|
className={this.props.muted ? "text-muted" : "text-info"}
|
2020-09-06 16:15:25 +00:00
|
|
|
to={link}
|
|
|
|
>
|
2021-03-15 18:09:31 +00:00
|
|
|
{!this.props.hideAvatar && person.avatar && showAvatars() && (
|
|
|
|
<PictrsImage src={person.avatar} icon />
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
<span>{displayName}</span>
|
|
|
|
</Link>
|
|
|
|
|
2021-03-15 18:09:31 +00:00
|
|
|
{isCakeDay(person.published) && <CakeDay creatorName={apubName} />}
|
2020-09-06 16:15:25 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|