fix replies

This commit is contained in:
smolgrrr 2023-12-15 22:33:46 +11:00
parent a0ebb99cf9
commit 88fefc8a1b
3 changed files with 13 additions and 14 deletions

View File

@ -45,10 +45,13 @@ const NewNoteCard = ({
useEffect(() => { useEffect(() => {
if (refEvent && tagType && unsigned.tags.length === 0) { if (refEvent && tagType && unsigned.tags.length === 0) {
const tags = tagMapping[tagType]; if (tagType === 'Reply' && unsigned.tags.length === 0) {
if (tags) { unsigned.tags.push(['p', refEvent.pubkey]);
tags.forEach(tag => unsigned.tags.push([tag, refEvent[tag === 'p' ? 'pubkey' : 'id']])); unsigned.tags.push(['e', refEvent.id, 'root']);
// Ref event should be the latest event they're replying to, and their event should include prev replies } else {
unsigned.tags = refEvent.tags
unsigned.tags.push(['p', refEvent.pubkey]);
unsigned.tags.push(['e', refEvent.id]);
} }
if (tagType === 'Quote') { if (tagType === 'Quote') {
setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id)); setComment(comment + '\nnostr:' + nip19.noteEncode(refEvent.id));

View File

@ -21,12 +21,7 @@ const useUniqEvents = () => {
const uniqEvents = uniqBy(events, "id"); const uniqEvents = uniqBy(events, "id");
const noteEvents = uniqEvents.filter(event => { const noteEvents = uniqEvents.filter(event => event.kind === 1 || event.kind === 6);
if (event.kind === 6) {
console.log(event);
}
return event.kind === 1 || event.kind === 6;
});
const metadataEvents = uniqEvents.filter(event => event.kind === 0); const metadataEvents = uniqEvents.filter(event => event.kind === 0);
return { noteEvents, metadataEvents }; return { noteEvents, metadataEvents };

View File

@ -49,9 +49,10 @@ const Thread = () => {
useEffect(() => { useEffect(() => {
if (!hasRun && events.length > 0) { if (!hasRun && events.length > 0) {
let OPEvent = uniqEvents[0]; let OPEvent = uniqEvents.find(event => event.id === hexID);
setOPEvent(OPEvent); setOPEvent(OPEvent);
console.log(OPEvent)
if (OPEvent && OPEvent.id !== hexID) { if (OPEvent && OPEvent.id !== hexID) {
OPEvent = events.find(e => e.id === hexID) as Event; OPEvent = events.find(e => e.id === hexID) as Event;
} }
@ -154,11 +155,11 @@ const Thread = () => {
{(showForm && postType) && {(showForm && postType) &&
<div className="w-full px-4 sm:px-0 sm:max-w-xl mx-auto my-2"> <div className="w-full px-4 sm:px-0 sm:max-w-xl mx-auto my-2">
<span className='text-center'>{postType}-post</span> <span className='text-center'>{postType}-post</span>
<NewNoteCard refEvent={uniqEvents[0]} tagType={postType}/> <NewNoteCard refEvent={OPEvent} tagType={postType}/>
</div>} </div>}
{showRepost && <div className="w-full px-4 sm:px-0 sm:max-w-xl mx-auto my-2"> {showRepost && OPEvent && <div className="w-full px-4 sm:px-0 sm:max-w-xl mx-auto my-2">
<span className='text-center'>Repost note</span> <span className='text-center'>Repost note</span>
<RepostNote refEvent={uniqEvents[0]}/> <RepostNote refEvent={OPEvent}/>
</div>} </div>}
<div className="flex items-center justify-center w-full py-4"> <div className="flex items-center justify-center w-full py-4">
<label htmlFor="toggleB" className="flex items-center cursor-pointer"> <label htmlFor="toggleB" className="flex items-center cursor-pointer">