Skip to content

Commit

Permalink
improve replies in threads
Browse files Browse the repository at this point in the history
  • Loading branch information
neb-b committed Jan 22, 2023
1 parent f6e85b4 commit 87589f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/core/nostr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,21 @@ const getRelatedEvents = async (
}
})

const relatedNotes = await getNostrEvents(relays, {
const relatedRes = getNostrEvents(relays, {
kinds: [nostrEventKinds.note, nostrEventKinds.repost],
limit: repliesSet.size,
ids: Array.from(new Set([...repliesSet, ...repostsSet])),
ids: Array.from(repostsSet),
"#e": [...repliesSet, ...repostsSet, ...notes.map((note) => note.id)],
})

const replyRes = getNostrEvents(relays, {
kinds: [nostrEventKinds.note],
limit: repliesSet.size,
ids: Array.from(repliesSet),
})

const [relatedNotes, replyNotes] = await Promise.all([relatedRes, replyRes])

// Get profiles from all the events
const profilePubkeysSet = new Set<string>()
notes.forEach((event) => {
Expand All @@ -195,6 +203,9 @@ const getRelatedEvents = async (
relatedNotes.forEach((event) => {
profilePubkeysSet.add(event.pubkey)
})
replyNotes.forEach((event) => {
profilePubkeysSet.add(event.pubkey)
})

const profilesEvents = (await getNostrEvents(relays, {
kinds: [nostrEventKinds.profile],
Expand All @@ -217,7 +228,7 @@ const getRelatedEvents = async (
})

resolve({
related: [...alreadyFetchedReposts, ...relatedNotes],
related: [...alreadyFetchedReposts, ...relatedNotes, ...replyNotes],
profiles: userProfileInfos,
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/store/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const useThread = (noteId: string) => {
.reduce((acc, noteFromNoteById) => {
const noteTags = noteFromNoteById.tags.filter((tag) => tag[0] === "e").map((tag) => tag[1])

if (noteTags[0] === noteToDisplay.id && noteFromNoteById.kind !== nostrEventKinds.repost) {
if (noteTags.includes(noteToDisplay.id) && noteFromNoteById.kind !== nostrEventKinds.repost) {
acc.push(noteFromNoteById)
}

Expand Down

0 comments on commit 87589f6

Please sign in to comment.