Files
boris/node_modules/applesauce-factory/dist/operations/share.js
Gigi 5d53a827e0 feat: initialize markr nostr bookmark client
- Add project structure with TypeScript, React, and Vite
- Implement nostr authentication using browser extension (NIP-07)
- Add NIP-51 compliant bookmark fetching and display
- Create minimal UI with login and bookmark components
- Integrate applesauce-core and applesauce-react libraries
- Add responsive styling with dark/light mode support
- Include comprehensive README with setup instructions

This is a minimal MVP for a nostr bookmark client that allows users to
view their bookmarks according to NIP-51 specification.
2025-10-02 07:17:07 +02:00

36 lines
1.7 KiB
JavaScript

import { getAddressPointerForEvent, getEventPointerForEvent } from "applesauce-core/helpers";
import { kinds } from "nostr-tools";
import { isAddressableKind } from "nostr-tools/kinds";
import { ensureAddressPointerTag, ensureEventPointerTag, ensureKTag, ensureProfilePointerTag, } from "../helpers/common-tags.js";
import { setContent } from "./content.js";
// TODO: some of these operations should be refactored to use "modifyPublicTags"
/** Includes NIP-18 repost tags */
export function setShareTags(event) {
return async (draft, ctx) => {
let tags = Array.from(draft.tags);
const hint = await ctx.getEventRelayHint?.(event.id);
// add "e" tag
tags = ensureEventPointerTag(tags, getEventPointerForEvent(event, hint ? [hint] : undefined));
// add "a" tag
if (isAddressableKind(event.kind)) {
tags = ensureAddressPointerTag(tags, getAddressPointerForEvent(event, hint ? [hint] : undefined));
}
// add "p" tag for notify
const pubkeyHint = await ctx.getPubkeyRelayHint?.(event.pubkey);
tags = ensureProfilePointerTag(tags, { pubkey: event.pubkey, relays: pubkeyHint ? [pubkeyHint] : undefined });
// add "k" tag
tags = ensureKTag(tags, event.kind);
return { ...draft, tags };
};
}
/** Sets the NIP-18 repost kind based on the kind of event being shared */
export function setShareKind(event) {
return (draft) => {
return { ...draft, kind: event.kind === kinds.ShortTextNote ? kinds.Repost : kinds.GenericRepost };
};
}
/** Sets the content of the event to a JSON string of the shared event */
export function embedSharedEvent(event) {
return setContent(JSON.stringify(event));
}