mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
fix: get all zap related authors (receivers, senders) inside gatherAuthors() function
This commit is contained in:
parent
4be6fe004d
commit
ead96af16f
1 changed files with 18 additions and 32 deletions
|
|
@ -65,10 +65,6 @@ async function hydrateEvents(opts: HydrateOpts): Promise<DittoEvent[]> {
|
|||
cache.push(event);
|
||||
}
|
||||
|
||||
for (const event of await gatherZapSender({ events: cache, store, signal })) {
|
||||
cache.push(event);
|
||||
}
|
||||
|
||||
const stats = {
|
||||
authors: await gatherAuthorStats(cache, kysely as Kysely<DittoTables>),
|
||||
events: await gatherEventStats(cache, kysely as Kysely<DittoTables>),
|
||||
|
|
@ -230,13 +226,26 @@ function gatherQuotes({ events, store, signal }: HydrateOpts): Promise<DittoEven
|
|||
|
||||
/** Collect authors from the events. */
|
||||
function gatherAuthors({ events, store, signal }: HydrateOpts): Promise<DittoEvent[]> {
|
||||
const pubkeys = new Set(events.map((event) => {
|
||||
const pubkeys = new Set<string>();
|
||||
|
||||
for (const event of events) {
|
||||
if (event.kind === 9735) {
|
||||
const pubkey = event.tags.find(([name]) => name === 'p')?.[1];
|
||||
if (pubkey) return pubkey;
|
||||
const zapReceiver = event.tags.find(([name]) => name === 'p')?.[1];
|
||||
if (zapReceiver) {
|
||||
pubkeys.add(zapReceiver);
|
||||
}
|
||||
|
||||
const zapRequestString = event?.tags?.find(([name]) => name === 'description')?.[1];
|
||||
const zapRequest = n.json().pipe(n.event()).optional().catch(undefined).parse(zapRequestString);
|
||||
// By getting the pubkey from the zap request we guarantee who is the sender
|
||||
// some clients don't put the P tag in the zap receipt...
|
||||
const zapSender = zapRequest?.pubkey;
|
||||
if (zapSender) {
|
||||
pubkeys.add(zapSender);
|
||||
}
|
||||
}
|
||||
return event.pubkey;
|
||||
}));
|
||||
pubkeys.add(event.pubkey);
|
||||
}
|
||||
|
||||
return store.query(
|
||||
[{ kinds: [0], authors: [...pubkeys], limit: pubkeys.size }],
|
||||
|
|
@ -336,29 +345,6 @@ function gatherZapped({ events, store, signal }: HydrateOpts): Promise<DittoEven
|
|||
);
|
||||
}
|
||||
|
||||
/** Collect author that zapped. */
|
||||
function gatherZapSender({ events, store, signal }: HydrateOpts): Promise<DittoEvent[]> {
|
||||
const pubkeys = new Set<string>();
|
||||
|
||||
for (const event of events) {
|
||||
if (event.kind === 9735) {
|
||||
const zapRequestString = event?.tags?.find(([name]) => name === 'description')?.[1];
|
||||
const zapRequest = n.json().pipe(n.event()).optional().catch(undefined).parse(zapRequestString);
|
||||
// By getting the pubkey from the zap request we guarantee who is the sender
|
||||
// some clients don't put the P tag in the zap receipt...
|
||||
const zapSender = zapRequest?.pubkey;
|
||||
if (zapSender) {
|
||||
pubkeys.add(zapSender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return store.query(
|
||||
[{ kinds: [0], limit: pubkeys.size }],
|
||||
{ signal },
|
||||
);
|
||||
}
|
||||
|
||||
/** Collect author stats from the events. */
|
||||
async function gatherAuthorStats(
|
||||
events: DittoEvent[],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue