mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-22 06:44:23 +01:00
Add interfaces for Mastodon entity types, hide deactivated accounts
This commit is contained in:
@@ -3,6 +3,7 @@ import { escape } from 'entities';
|
||||
import { nip19, UnsignedEvent } from 'nostr-tools';
|
||||
|
||||
import { Conf } from '@/config.ts';
|
||||
import { MastodonAccount } from '@/entities/MastodonAccount.ts';
|
||||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||
import { getLnurl } from '@/utils/lnurl.ts';
|
||||
import { nip05Cache } from '@/utils/nip05.ts';
|
||||
@@ -17,10 +18,17 @@ interface ToAccountOpts {
|
||||
async function renderAccount(
|
||||
event: Omit<DittoEvent, 'id' | 'sig'>,
|
||||
opts: ToAccountOpts = {},
|
||||
) {
|
||||
): Promise<MastodonAccount> {
|
||||
const { withSource = false } = opts;
|
||||
const { pubkey } = event;
|
||||
|
||||
const names = getTagSet(event.user?.tags ?? [], 'n');
|
||||
if (names.has('disabled') || names.has('suspended')) {
|
||||
const account = await accountFromPubkey(pubkey, opts);
|
||||
account.pleroma.deactivated = true;
|
||||
return account;
|
||||
}
|
||||
|
||||
const {
|
||||
name,
|
||||
nip05,
|
||||
@@ -34,7 +42,6 @@ async function renderAccount(
|
||||
|
||||
const npub = nip19.npubEncode(pubkey);
|
||||
const parsed05 = await parseAndVerifyNip05(nip05, pubkey);
|
||||
const names = getTagSet(event.user?.tags ?? [], 'n');
|
||||
|
||||
return {
|
||||
id: pubkey,
|
||||
@@ -77,6 +84,7 @@ async function renderAccount(
|
||||
accepts_zaps: Boolean(getLnurl({ lud06, lud16 })),
|
||||
},
|
||||
pleroma: {
|
||||
deactivated: names.has('disabled') || names.has('suspended'),
|
||||
is_admin: names.has('admin'),
|
||||
is_moderator: names.has('admin') || names.has('moderator'),
|
||||
is_suggested: names.has('suggested'),
|
||||
@@ -92,7 +100,7 @@ async function renderAccount(
|
||||
};
|
||||
}
|
||||
|
||||
function accountFromPubkey(pubkey: string, opts: ToAccountOpts = {}) {
|
||||
function accountFromPubkey(pubkey: string, opts: ToAccountOpts = {}): Promise<MastodonAccount> {
|
||||
const event: UnsignedEvent = {
|
||||
kind: 0,
|
||||
pubkey,
|
||||
|
||||
@@ -2,6 +2,8 @@ import { NostrEvent } from '@nostrify/nostrify';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
import { Conf } from '@/config.ts';
|
||||
import { MastodonMention } from '@/entities/MastodonMention.ts';
|
||||
import { MastodonStatus } from '@/entities/MastodonStatus.ts';
|
||||
import { type DittoEvent } from '@/interfaces/DittoEvent.ts';
|
||||
import { Storages } from '@/storages.ts';
|
||||
import { nostrDate } from '@/utils.ts';
|
||||
@@ -17,7 +19,7 @@ interface RenderStatusOpts {
|
||||
depth?: number;
|
||||
}
|
||||
|
||||
async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<any> {
|
||||
async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<MastodonStatus | undefined> {
|
||||
const { viewerPubkey, depth = 1 } = opts;
|
||||
|
||||
if (depth > 2 || depth < 0) return;
|
||||
@@ -130,12 +132,14 @@ async function renderStatus(event: DittoEvent, opts: RenderStatusOpts): Promise<
|
||||
};
|
||||
}
|
||||
|
||||
async function renderReblog(event: DittoEvent, opts: RenderStatusOpts) {
|
||||
async function renderReblog(event: DittoEvent, opts: RenderStatusOpts): Promise<MastodonStatus | undefined> {
|
||||
const { viewerPubkey } = opts;
|
||||
if (!event.repost) return;
|
||||
|
||||
const status = await renderStatus(event, {}); // omit viewerPubkey intentionally
|
||||
const reblog = await renderStatus(event.repost, { viewerPubkey });
|
||||
if (!status) return;
|
||||
|
||||
const reblog = await renderStatus(event.repost, { viewerPubkey }) ?? null;
|
||||
|
||||
return {
|
||||
...status,
|
||||
@@ -145,7 +149,7 @@ async function renderReblog(event: DittoEvent, opts: RenderStatusOpts) {
|
||||
};
|
||||
}
|
||||
|
||||
async function toMention(pubkey: string, event?: NostrEvent) {
|
||||
async function toMention(pubkey: string, event?: NostrEvent): Promise<MastodonMention> {
|
||||
const account = event ? await renderAccount(event) : undefined;
|
||||
|
||||
if (account) {
|
||||
@@ -166,9 +170,7 @@ async function toMention(pubkey: string, event?: NostrEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
type Mention = Awaited<ReturnType<typeof toMention>>;
|
||||
|
||||
function buildInlineRecipients(mentions: Mention[]): string {
|
||||
function buildInlineRecipients(mentions: MastodonMention[]): string {
|
||||
if (!mentions.length) return '';
|
||||
|
||||
const elements = mentions.reduce<string[]>((acc, { url, username }) => {
|
||||
|
||||
Reference in New Issue
Block a user