mirror of
https://github.com/dergigi/boris.git
synced 2026-01-06 16:34:45 +01:00
- 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.
41 lines
2.0 KiB
JavaScript
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);
|
|
};
|
|
}
|