2020-02-18 08:57:00 +01:00
|
|
|
import { IPicture } from "@/types/picture.model";
|
2019-05-22 14:12:11 +02:00
|
|
|
|
2019-12-03 11:29:51 +01:00
|
|
|
export enum ActorType {
|
2020-02-18 08:57:00 +01:00
|
|
|
PERSON = "PERSON",
|
|
|
|
APPLICATION = "APPLICATION",
|
|
|
|
GROUP = "GROUP",
|
|
|
|
ORGANISATION = "ORGANISATION",
|
|
|
|
SERVICE = "SERVICE",
|
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;
|
2019-04-26 15:22:16 +02:00
|
|
|
summary: string;
|
|
|
|
preferredUsername: string;
|
|
|
|
suspended: boolean;
|
2020-09-29 09:53:48 +02:00
|
|
|
avatar?: IPicture | null;
|
|
|
|
banner?: IPicture | 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;
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
avatar: IPicture | null = null;
|
2020-02-18 08:57:00 +01:00
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
banner: IPicture | 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
|
|
|
|
|
|
|
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-02-18 08:57:00 +01:00
|
|
|
constructor(hash: IActor | {} = {}) {
|
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 {
|
2020-02-18 08:57:00 +01:00
|
|
|
return this.name != null && this.name !== "" ? this.name : this.usernameWithDomain();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 11:53:24 +02:00
|
|
|
export function usernameWithDomain(actor: IActor, force = false): string {
|
2020-02-18 08:57:00 +01:00
|
|
|
if (actor.domain) {
|
|
|
|
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
|
|
|
|
|
|
|
export function displayNameAndUsername(actor: IActor): string {
|
|
|
|
if (actor.name) {
|
|
|
|
return `${actor.name} (@${usernameWithDomain(actor)})`;
|
|
|
|
}
|
|
|
|
return usernameWithDomain(actor);
|
|
|
|
}
|