2020-11-27 19:27:44 +01:00
|
|
|
import type { IMedia } from "@/types/media.model";
|
|
|
|
import { ActorType } from "../enums";
|
2019-12-03 11:29:51 +01:00
|
|
|
|
2019-04-26 15:22:16 +02:00
|
|
|
export interface IActor {
|
2020-02-18 08:57:00 +01:00
|
|
|
id?: string;
|
2019-04-26 15:22:16 +02:00
|
|
|
url: string;
|
|
|
|
name: string;
|
2020-02-18 08:57:00 +01:00
|
|
|
domain: string | null;
|
2020-11-23 16:58:50 +01:00
|
|
|
mediaSize: number;
|
2019-04-26 15:22:16 +02:00
|
|
|
summary: string;
|
|
|
|
preferredUsername: string;
|
|
|
|
suspended: boolean;
|
2020-11-26 11:41:13 +01:00
|
|
|
avatar?: IMedia | null;
|
|
|
|
banner?: IMedia | null;
|
2019-12-03 11:29:51 +01:00
|
|
|
type: ActorType;
|
2019-04-26 15:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Actor implements IActor {
|
2020-02-18 08:57:00 +01:00
|
|
|
id?: string;
|
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
avatar: IMedia | null = null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-26 11:41:13 +01:00
|
|
|
banner: IMedia | null = null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-04-26 15:22:16 +02:00
|
|
|
domain: string | null = null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2020-11-23 16:58:50 +01:00
|
|
|
mediaSize = 0;
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
name = "";
|
|
|
|
|
|
|
|
preferredUsername = "";
|
|
|
|
|
|
|
|
summary = "";
|
|
|
|
|
|
|
|
suspended = false;
|
|
|
|
|
|
|
|
url = "";
|
|
|
|
|
2019-12-03 11:29:51 +01:00
|
|
|
type: ActorType = ActorType.PERSON;
|
2019-04-26 15:22:16 +02:00
|
|
|
|
2020-11-06 11:34:32 +01:00
|
|
|
constructor(hash: IActor | Record<any, unknown> = {}) {
|
2019-04-26 15:22:16 +02:00
|
|
|
Object.assign(this, hash);
|
|
|
|
}
|
|
|
|
|
|
|
|
get displayNameAndUsername(): string {
|
|
|
|
return `${this.name} (${this.usernameWithDomain})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
usernameWithDomain(): string {
|
2020-02-18 08:57:00 +01:00
|
|
|
const domain = this.domain ? `@${this.domain}` : "";
|
2019-04-26 15:22:16 +02:00
|
|
|
return `@${this.preferredUsername}${domain}`;
|
|
|
|
}
|
|
|
|
|
2019-09-11 09:59:01 +02:00
|
|
|
public displayName(): string {
|
2021-05-02 19:27:23 +02:00
|
|
|
return displayName(this);
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
export function usernameWithDomain(actor: IActor, force = false): string {
|
2021-06-16 11:25:53 +02:00
|
|
|
if (!actor) return "";
|
|
|
|
if (actor?.domain) {
|
2020-02-18 08:57:00 +01:00
|
|
|
return `${actor.preferredUsername}@${actor.domain}`;
|
2020-08-31 12:40:30 +02:00
|
|
|
}
|
|
|
|
if (force) {
|
2020-08-27 11:53:24 +02:00
|
|
|
return `${actor.preferredUsername}@${window.location.hostname}`;
|
2019-04-26 15:22:16 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
return actor.preferredUsername;
|
2019-04-26 15:22:16 +02:00
|
|
|
}
|
2020-06-11 19:13:21 +02:00
|
|
|
|
2021-05-02 19:27:23 +02:00
|
|
|
export function displayName(actor: IActor): string {
|
|
|
|
return actor.name != null && actor.name !== ""
|
|
|
|
? actor.name
|
|
|
|
: usernameWithDomain(actor);
|
|
|
|
}
|
|
|
|
|
2020-06-11 19:13:21 +02:00
|
|
|
export function displayNameAndUsername(actor: IActor): string {
|
|
|
|
if (actor.name) {
|
|
|
|
return `${actor.name} (@${usernameWithDomain(actor)})`;
|
|
|
|
}
|
|
|
|
return usernameWithDomain(actor);
|
|
|
|
}
|