Only hide replies on feeds

This commit is contained in:
Jonathan Staab 2023-01-25 09:36:42 -08:00
parent 59c4fec4f0
commit 7cc9ebc080
4 changed files with 25 additions and 8 deletions

View File

@ -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

View File

@ -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)
})
}

View File

@ -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})
}
</script>

View File

@ -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})
}
</script>