spa(task 13): reactions-loader mit aggregation
loadReactions(dtag) sammelt kind:7-Events mit #a-Filter auf den Post, gruppiert nach content (emoji oder +/-), zählt und sortiert nach Häufigkeit. Leerer content wird als + interpretiert (NIP-25- Konvention für Like-Default). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bab2895848
commit
f470732c2c
|
|
@ -144,3 +144,31 @@ export async function loadReplies(
|
||||||
);
|
);
|
||||||
return events.sort((a, b) => a.created_at - b.created_at);
|
return events.sort((a, b) => a.created_at - b.created_at);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ReactionSummary {
|
||||||
|
/** Emoji oder "+"/"-" */
|
||||||
|
content: string;
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aggregiert kind:7-Reactions auf einen Post.
|
||||||
|
* Gruppiert nach content, zählt Anzahl.
|
||||||
|
*/
|
||||||
|
export async function loadReactions(dtag: string): Promise<ReactionSummary[]> {
|
||||||
|
const relays = get(readRelays);
|
||||||
|
const address = eventAddress(AUTHOR_PUBKEY_HEX, dtag);
|
||||||
|
const events = await collectEvents(relays, {
|
||||||
|
kinds: [7],
|
||||||
|
'#a': [address],
|
||||||
|
limit: 500
|
||||||
|
});
|
||||||
|
const counts = new Map<string, number>();
|
||||||
|
for (const ev of events) {
|
||||||
|
const key = ev.content || '+';
|
||||||
|
counts.set(key, (counts.get(key) ?? 0) + 1);
|
||||||
|
}
|
||||||
|
return [...counts.entries()]
|
||||||
|
.map(([content, count]) => ({ content, count }))
|
||||||
|
.sort((a, b) => b.count - a.count);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue