diff --git a/README.md b/README.md index d735ed0b..83663dca 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ If you like Coracle and want to support its development, you can donate sats via - [ ] Everything waits for even the slowest relay to connect before returning events - [ ] Alerts are not showing likes, just generally screwy. Maybe because I threadify before adding to the db? +- [ ] Change network tab to list relays the user is connected to - [ ] Sync mentions box and in-reply mentions - [ ] Add petnames for channels - [ ] Add notifications for chat messages diff --git a/src/app/index.js b/src/app/index.js index cc4fb344..3a76e49d 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -1,4 +1,4 @@ -import {whereEq, sortBy, identity, when, assoc, reject} from 'ramda' +import {pluck, whereEq, sortBy, identity, when, assoc, reject} from 'ramda' import {navigate} from 'svelte-routing' import {createMap, ellipsize} from 'hurdak/lib/hurdak' import {get} from 'svelte/store' @@ -124,9 +124,8 @@ export const annotate = (note, context) => { } } -export const threadify = (events, context, {muffle = []} = {}) => { +export const threadify = (events, context, {muffle = [], showReplies = true} = {}) => { const contextById = createMap('id', events.concat(context)) - // Show parents when possible. For reactions, if there's no parent, // throw it away. Sort by created date descending const notes = sortBy( @@ -136,6 +135,23 @@ export const threadify = (events, context, {muffle = []} = {}) => { .filter(e => e && !muffle.includes(e.pubkey)) ) + if (!showReplies) { + return notes.filter(note => !findReplyId(note)).map(n => annotate(n, context)) + } + + // Don't show notes that will also show up as children + const noteIds = new Set(pluck('id', notes)) + // Annotate our feed with parents, reactions, replies. - return notes.filter(note => !findReplyId(note)).map(n => annotate(n, context)) + return notes + .filter(note => !noteIds.has(findReplyId(note))) + .map(note => { + let parent = contextById[findReplyId(note)] + + if (parent) { + parent = annotate(parent, context) + } + + return annotate({...note, parent}, context) + }) } diff --git a/src/views/notes/Global.svelte b/src/views/notes/Global.svelte index 83721ec9..19c5375c 100644 --- a/src/views/notes/Global.svelte +++ b/src/views/notes/Global.svelte @@ -13,7 +13,7 @@ listen(relays, {...filter, since: now()}, batch(300, async notes => { const context = await loaders.loadContext(relays, notes) - onNotes(threadify(notes, context, {muffle: getMuffle()})) + onNotes(threadify(notes, context, {muffle: getMuffle(), showReplies: false})) })) const loadNotes = async () => { @@ -23,7 +23,7 @@ cursor.onChunk(notes) - return threadify(notes, context, {muffle: getMuffle()}) + return threadify(notes, context, {muffle: getMuffle(), showReplies: false}) } diff --git a/src/views/notes/Network.svelte b/src/views/notes/Network.svelte index 69f65a08..3535c0cc 100644 --- a/src/views/notes/Network.svelte +++ b/src/views/notes/Network.svelte @@ -19,7 +19,7 @@ listen(relays, {...filter, since: now()}, batch(300, async notes => { const context = await loaders.loadContext(relays, notes) - onNotes(threadify(notes, context, {muffle: getMuffle()})) + onNotes(threadify(notes, context, {muffle: getMuffle(), showReplies: false})) })) const loadNotes = async () => { @@ -29,7 +29,7 @@ cursor.onChunk(notes) - return threadify(notes, context, {muffle: getMuffle()}) + return threadify(notes, context, {muffle: getMuffle(), showReplies: false}) }