1
0
mirror of git://jb55.com/damus synced 2024-09-16 02:03:45 +00:00

ui: Show muted thread replies at the bottom of the thread view (#1522)

Testing
-------

**PASS**

**Device:** iPhone 14 Pro simulator
**iOS:** 17.0
**Damus:** This commit
**Steps:**

1. Setup accounts "A" and "B" that you control. Account "A" will be on our device under test.
2. Post something
3. Make a reply using Account A (Reply 1)
4. Make a reply using Account B (Reply 2)
5. Make another reply using account A (Reply 3)
6. Order of replies should be (top to bottom): 1, 2, 3
7. Mute user B
8. Order of replies should be: 1, 3, 2

Performance check
-----------------

**Device:** iPhone 14 Pro simulator
**iOS:** 17.0
**Damus:** This commit
**Steps:**

1. Locally change the code and add a print statement right before the sorting begins. In that print statement, include the number of events that will be sorted
2. Run Damus and go to a busy thread (I found one with 45 replies)
3. Go to the thread, and monitor the logs.
4. Navigate a bit between replies and monitor logs.

**Results:** I only saw a few print statements being printed with each navigation action, which indicates that we are not constantly re-sorting this object (which would be inefficient). Therefore, it seems like performance/efficiency would not be a problem.

Changelog-Changed: Show muted thread replies at the bottom of the thread view (#1522)
Closes: https://github.com/damus-io/damus/issues/1522
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino 2023-09-30 04:06:17 +00:00 committed by William Casarin
parent 8a2e87718b
commit b86bac2e42
2 changed files with 24 additions and 3 deletions

View File

@ -1069,6 +1069,14 @@ func event_has_our_pubkey(_ ev: NostrEvent, our_pubkey: Pubkey) -> Bool {
return ev.referenced_pubkeys.contains(our_pubkey)
}
func should_show_event(event: NostrEvent, damus_state: DamusState) -> Bool {
return should_show_event(
keypair: damus_state.keypair,
hellthreads: damus_state.muted_threads,
contacts: damus_state.contacts,
ev: event
)
}
func should_show_event(keypair: Keypair, hellthreads: MutedThreadsManager, contacts: Contacts, ev: NostrEvent) -> Bool {
if contacts.is_muted(ev.pubkey) {

View File

@ -17,8 +17,21 @@ struct ThreadView: View {
state.events.parent_events(event: thread.event, keypair: state.keypair)
}
var child_events: [NostrEvent] {
state.events.child_events(event: thread.event)
var sorted_child_events: [NostrEvent] {
state.events.child_events(event: thread.event).sorted(by: { a, b in
let a_is_muted = !should_show_event(event: a, damus_state: state)
let b_is_muted = !should_show_event(event: b, damus_state: state)
if a_is_muted == b_is_muted {
// If both are muted or unmuted, sort them based on their creation date.
return a.created_at < b.created_at
}
else {
// Muting status is different
// Prioritize the replies that are not muted
return !a_is_muted && b_is_muted
}
})
}
var body: some View {
@ -69,7 +82,7 @@ struct ThreadView: View {
}
*/
ForEach(child_events, id: \.id) { child_event in
ForEach(sorted_child_events, id: \.id) { child_event in
MutedEventView(
damus_state: state,
event: child_event,