mirror of
https://github.com/purrgrammer/grimoire.git
synced 2026-04-10 15:36:53 +02:00
* fix: use semantic author for zap targeting
When zapping certain event kinds (zaps, streams), use the semantic
author instead of event.pubkey:
- Zaps (9735): Target the zapper, not the lightning service
- Streams (30311): Target the host, not the event publisher
Changes:
- Extract getSemanticAuthor() to shared utility (src/lib/semantic-author.ts)
- Update BaseEventRenderer to use semantic author when opening zap dialog
- Update ZapWindow to resolve recipient using semantic author
- Refactor DynamicWindowTitle to use shared utility
This ensures that when you zap an event, you're zapping the right person
(the one who semantically "owns" or created the event), not just whoever
signed it.
* fix: load event in DynamicWindowTitle to derive zap recipient
When opening a zap dialog via 'zap naddr1...' or 'zap nevent1...', the
window title was showing "ZAP" instead of "Zap {host name}" because
DynamicWindowTitle only had access to the empty recipientPubkey from
the initial props.
Now DynamicWindowTitle:
- Loads the event from eventPointer if present
- Derives the recipient using getSemanticAuthor() if recipientPubkey is empty
- Falls back to explicit recipientPubkey if provided
This ensures the window title shows the correct recipient name
immediately, matching the behavior in the ZapWindow component itself.
---------
Co-authored-by: Claude <noreply@anthropic.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
/**
|
|
* Semantic Author Utilities
|
|
*
|
|
* Determines the "semantic author" of an event based on kind-specific logic.
|
|
* For most events, this is event.pubkey, but for certain event types the
|
|
* semantic author may be different (e.g., zapper for zaps, host for streams).
|
|
*/
|
|
|
|
import type { NostrEvent } from "@/types/nostr";
|
|
import { getZapSender } from "applesauce-common/helpers/zap";
|
|
import { getLiveHost } from "@/lib/live-activity";
|
|
|
|
/**
|
|
* Get the semantic author of an event based on kind-specific logic
|
|
* Returns the pubkey that should be displayed as the "author" for UI purposes
|
|
*
|
|
* Examples:
|
|
* - Zaps (9735): Returns the zapper (P tag), not the lightning service pubkey
|
|
* - Live activities (30311): Returns the host (first p tag with "Host" role)
|
|
* - Regular events: Returns event.pubkey
|
|
*
|
|
* This function should be used when determining:
|
|
* - Who to display as the author in UI
|
|
* - Who to zap when zapping an event
|
|
* - Who the "owner" of the event is semantically
|
|
*/
|
|
export function getSemanticAuthor(event: NostrEvent): string {
|
|
switch (event.kind) {
|
|
case 9735: {
|
|
// Zap: show the zapper, not the lightning service pubkey
|
|
const zapSender = getZapSender(event);
|
|
return zapSender || event.pubkey;
|
|
}
|
|
case 30311: {
|
|
// Live activity: show the host
|
|
return getLiveHost(event);
|
|
}
|
|
default:
|
|
return event.pubkey;
|
|
}
|
|
}
|