diff --git a/client/src/components/Board.tsx b/client/src/components/Board.tsx index e0fc799..1db30fe 100644 --- a/client/src/components/Board.tsx +++ b/client/src/components/Board.tsx @@ -1,7 +1,7 @@ import { useEffect, useState, useCallback } from "react"; import PostCard from "./Modals/NoteCard"; import { uniqBy } from "../utils/otherUtils"; // Assume getPow is a correct import now -import { subBoardFeed } from "../utils/subscriptions"; +import { subBoardFeed, subProfile} from "../utils/subscriptions"; import { verifyPow } from "../utils/mine"; import { Event, nip19 } from "nostr-tools"; import NewNoteCard from "./Forms/PostFormCard"; @@ -26,8 +26,9 @@ const Board = () => { useEffect(() => { const onEvent = (event: Event) => setEvents((prevEvents) => [...prevEvents, event]); - console.log(events[events.length]) + console.log(events) const unsubscribe = subBoardFeed(pubkey, onEvent); + subProfile(pubkey, onEvent) return unsubscribe; }, [pubkey]); @@ -58,6 +59,8 @@ const Board = () => { sortByTime ? b.created_at - a.created_at : verifyPow(b) - verifyPow(a) ) + const pinnedEvents = uniqEvents.filter(event => event.pubkey === pubkey && !event.tags.some((tag) => tag[0] === "e")); + if (delayedSort) { sortedEvents = sortedEvents.filter( !setAnon ? (e) => !metadataEvents.some((metadataEvent) => metadataEvent.pubkey === e.pubkey) : () => true @@ -94,6 +97,15 @@ const Board = () => {
+ {pinnedEvents.map((event) => ( +
+ e.pubkey === event.pubkey && e.kind === 0) || null} + replyCount={countReplies(event)} + /> +
+ ))} {sortedEvents.map((event) => ( event.kind === 1 ? { diff --git a/client/src/components/Forms/PostFormCard.tsx b/client/src/components/Forms/PostFormCard.tsx index 8f7c717..6483ab1 100644 --- a/client/src/components/Forms/PostFormCard.tsx +++ b/client/src/components/Forms/PostFormCard.tsx @@ -19,11 +19,6 @@ interface FormProps { board?: string; } -const tagMapping = { - 'Reply': ['e', 'p'], - 'Quote': ['q', 'p'] -}; - const NewNoteCard = ({ refEvent, tagType, @@ -51,19 +46,18 @@ const NewNoteCard = ({ const [uploadingFile, setUploadingFile] = useState(false); useEffect(() => { - if (refEvent && tagType && unsigned.tags.length === 1) { + if (refEvent && tagType) { + unsigned.tags = Array.from(new Set(unsigned.tags.concat(refEvent.tags))); + unsigned.tags.push(['p', refEvent.pubkey]); + if (tagType === 'Reply') { - unsigned.tags.push(['p', refEvent.pubkey]); - unsigned.tags.push(['e', refEvent.id, 'root']); + unsigned.tags.push(['e', refEvent.id, refEvent.tags.some(tag => tag[0] === 'e') ? 'root' : '']); } else { - unsigned.tags = refEvent.tags - unsigned.tags.push(['p', refEvent.pubkey]); - if (tagType === 'Quote') { setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id)); - unsigned.tags.push(['q', refEvent.id]); + unsigned.tags.push(['q', refEvent.id]); } else { - unsigned.tags.push(['e', refEvent.id]); + unsigned.tags.push(['e', refEvent.id]); } } } diff --git a/client/src/utils/subscriptions.ts b/client/src/utils/subscriptions.ts index 8482914..ef3baf3 100644 --- a/client/src/utils/subscriptions.ts +++ b/client/src/utils/subscriptions.ts @@ -213,40 +213,6 @@ export const subNotesOnce = ( }, 2000); }; -// /** quick subscribe to a note id (nip-19) */ -// export const subNotifications = ( -// pubkeys: string[], -// onEvent: SubCallback, -// ) => { -// const replyPubkeys = new Set(); -// sub({ -// cb: (evt, relay) => { -// replyPubkeys.add(evt.pubkey); -// onEvent(evt, relay); -// }, -// filter: { -// "#p": pubkeys, -// kinds: [1], -// limit: 50, -// }, -// unsub: true, -// }); - -// setTimeout(() => { -// // get profile info -// sub({ -// cb: onEvent, -// filter: { -// authors: Array.from(replyPubkeys), -// kinds: [0], -// limit: replyPubkeys.size, -// }, -// unsub: true, -// }); -// replyPubkeys.clear(); -// }, 2000); -// }; - const hasEventTag = (tag: string[]) => tag[0] === 'e'; const isReply = ([tag, , , marker]: string[]) => tag === 'e' && marker !== 'mention'; @@ -342,3 +308,22 @@ export const subBoardFeed = ( }, }); }; + +export const subProfile = ( + pubkey: string, + onEvent: SubCallback, +) => { + unsubAll(); + + sub({ + cb: (evt, relay) => { + onEvent(evt, relay); + }, + filter: { + authors: [pubkey], + kinds: [1, 7], + limit: 25, + }, + unsub: true, + }); +}; \ No newline at end of file