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

View File

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

View File

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