Files
boris/node_modules/applesauce-actions/dist/actions/contacts.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

41 lines
2.0 KiB
JavaScript

import { modifyHiddenTags, modifyPublicTags } from "applesauce-factory/operations";
import { addPubkeyTag, removePubkeyTag } from "applesauce-factory/operations/tag";
import { kinds } from "nostr-tools";
/** An action that adds a pubkey to a users contacts event */
export function FollowUser(pubkey, relay, hidden = false) {
return async function* ({ events, factory, self }) {
let contacts = events.getReplaceable(kinds.Contacts, self);
const pointer = { pubkey, relays: relay ? [relay] : undefined };
const operation = addPubkeyTag(pointer);
let draft;
// No contact list, create one
if (!contacts)
draft = await factory.build({ kind: kinds.Contacts }, hidden ? modifyHiddenTags(operation) : modifyPublicTags(operation));
else
draft = await factory.modifyTags(contacts, hidden ? { hidden: operation } : operation);
yield await factory.sign(draft);
};
}
/** An action that removes a pubkey from a users contacts event */
export function UnfollowUser(user, hidden = false) {
return async function* ({ events, factory, self }) {
const contacts = events.getReplaceable(kinds.Contacts, self);
// Unable to find a contacts event, so we can't unfollow
if (!contacts)
return;
const operation = removePubkeyTag(user);
const draft = await factory.modifyTags(contacts, hidden ? { hidden: operation } : operation);
yield await factory.sign(draft);
};
}
/** An action that creates a new kind 3 contacts lists, throws if a contact list already exists */
export function NewContacts(pubkeys) {
return async function* ({ events, factory, self }) {
const contacts = events.getReplaceable(kinds.Contacts, self);
if (contacts)
throw new Error("Contact list already exists");
const draft = await factory.build({ kind: kinds.Contacts }, pubkeys ? modifyPublicTags(...pubkeys.map((p) => addPubkeyTag(p))) : undefined);
yield await factory.sign(draft);
};
}