56 lines
1.0 KiB
TypeScript
56 lines
1.0 KiB
TypeScript
import { nip19 } from "@nostr/tools";
|
|
import { NEvent } from "../nostr.ts";
|
|
|
|
export interface ProfileData {
|
|
name: string;
|
|
about?: string;
|
|
picture?: string;
|
|
nip05?: string;
|
|
lud16?: string;
|
|
}
|
|
|
|
export default class Profile {
|
|
event: NEvent;
|
|
private data: ProfileData;
|
|
username?: string;
|
|
|
|
constructor(event: NEvent, username?: string) {
|
|
this.event = event;
|
|
this.data = JSON.parse(event.content);
|
|
this.username = username;
|
|
}
|
|
|
|
get updatedAt(): number {
|
|
return this.event.created_at;
|
|
}
|
|
|
|
get name(): string {
|
|
return this.data.display_name || this.data.displayName ||
|
|
this.data.name || "Anonymous";
|
|
}
|
|
|
|
get about(): string {
|
|
return this.data.about || "";
|
|
}
|
|
|
|
get picture(): string | undefined {
|
|
return this.data.picture;
|
|
}
|
|
|
|
get nip05(): string | undefined {
|
|
return this.data.nip05;
|
|
}
|
|
|
|
get lud16(): string | undefined {
|
|
return this.data.lud16;
|
|
}
|
|
|
|
get pubkey(): string {
|
|
return this.event.pubkey;
|
|
}
|
|
|
|
get npub(): string {
|
|
return nip19.npubEncode(this.pubkey);
|
|
}
|
|
}
|