2020-09-06 16:15:25 +00:00
|
|
|
import { Component } from 'inferno';
|
|
|
|
import { Link } from 'inferno-router';
|
|
|
|
import { UserView } from 'lemmy-js-client';
|
2020-10-14 19:36:37 +00:00
|
|
|
import { showAvatars, hostname, isCakeDay } from '../utils';
|
2020-09-06 16:15:25 +00:00
|
|
|
import { CakeDay } from './cake-day';
|
2020-10-14 19:36:37 +00:00
|
|
|
import { PictrsImage } from './pictrs-image';
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
export interface UserOther {
|
|
|
|
name: string;
|
|
|
|
preferred_username?: string;
|
|
|
|
id?: number; // Necessary if its federated
|
|
|
|
avatar?: string;
|
|
|
|
local?: boolean;
|
|
|
|
actor_id?: string;
|
|
|
|
published?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface UserListingProps {
|
|
|
|
user: UserView | UserOther;
|
|
|
|
realLink?: boolean;
|
|
|
|
useApubName?: boolean;
|
|
|
|
muted?: boolean;
|
|
|
|
hideAvatar?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class UserListing extends Component<UserListingProps, any> {
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let user = this.props.user;
|
|
|
|
let local = user.local == null ? true : user.local;
|
|
|
|
let apubName: string, link: string;
|
|
|
|
|
|
|
|
if (local) {
|
|
|
|
apubName = `@${user.name}`;
|
|
|
|
link = `/u/${user.name}`;
|
|
|
|
} else {
|
|
|
|
apubName = `@${user.name}@${hostname(user.actor_id)}`;
|
|
|
|
link = !this.props.realLink ? `/user/${user.id}` : user.actor_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
let displayName = this.props.useApubName
|
|
|
|
? apubName
|
|
|
|
: user.preferred_username
|
|
|
|
? user.preferred_username
|
|
|
|
: apubName;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Link
|
|
|
|
title={apubName}
|
|
|
|
className={this.props.muted ? 'text-muted' : 'text-info'}
|
|
|
|
to={link}
|
2020-11-17 01:34:41 +00:00
|
|
|
target={this.props.realLink ? '_blank' : ''}
|
2020-09-06 16:15:25 +00:00
|
|
|
>
|
|
|
|
{!this.props.hideAvatar && user.avatar && showAvatars() && (
|
2020-10-14 19:36:37 +00:00
|
|
|
<PictrsImage src={user.avatar} icon />
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
<span>{displayName}</span>
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
{isCakeDay(user.published) && <CakeDay creatorName={apubName} />}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|