feat: add accepts_zaps_cashu boolean field to DittoEvent and hydrate it

This commit is contained in:
P. Reis 2025-03-27 09:48:29 -03:00
parent 8a75f9e944
commit 69fe86890f
4 changed files with 30 additions and 0 deletions

View file

@ -57,4 +57,6 @@ export interface DittoEvent extends NostrEvent {
zap_message?: string;
/** Language of the event (kind 1s are more accurate). */
language?: LanguageCode;
/** Whether or not pubkey accepts cashu. */
accepts_zaps_cashu?: boolean;
}

View file

@ -50,6 +50,10 @@ async function hydrateEvents(opts: HydrateOpts): Promise<DittoEvent[]> {
cache.push(event);
}
for (const event of await gatherAcceptCashu({ ...opts, events: cache })) {
cache.push(event);
}
const authorStats = await gatherAuthorStats(cache, db.kysely);
const eventStats = await gatherEventStats(cache, db.kysely);
@ -194,6 +198,10 @@ export function assembleEvents(
event.zap_message = zapRequest?.content ?? '';
}
event.accepts_zaps_cashu = b.find((e) => matchFilter({ kinds: [10019], authors: [event.pubkey] }, e))
? true
: false;
event.author_stats = authorStats[event.pubkey];
event.event_stats = eventStats[event.id];
}
@ -353,6 +361,24 @@ async function gatherInfo({ conf, events, relay, signal }: HydrateOpts): Promise
);
}
/** Collect nutzap informational events. */
function gatherAcceptCashu({ events, relay, signal }: HydrateOpts): Promise<DittoEvent[]> {
const pubkeys = new Set<string>();
for (const event of events) {
pubkeys.add(event.pubkey);
}
if (!pubkeys.size) {
return Promise.resolve([]);
}
return relay.query(
[{ kinds: [10019], authors: [...pubkeys], limit: pubkeys.size }],
{ signal },
);
}
/** Collect author stats from the events. */
async function gatherAuthorStats(
events: DittoEvent[],

View file

@ -117,6 +117,7 @@ function renderAccount(event: Omit<DittoEvent, 'id' | 'sig'>, opts: ToAccountOpt
username: parsed05?.nickname || npub.substring(0, 8),
ditto: {
accepts_zaps: Boolean(getLnurl({ lud06, lud16 })),
accepts_zaps_cashu: Boolean(event?.accepts_zaps_cashu),
external_url: Conf.external(nprofile),
streak: {
days: streakDays,

View file

@ -44,6 +44,7 @@ export interface MastodonAccount {
username: string;
ditto: {
accepts_zaps: boolean;
accepts_zaps_cashu: boolean;
external_url: string;
streak: {
days: number;