diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift index 73afc11a..e943a6c7 100644 --- a/damus/Models/HomeModel.swift +++ b/damus/Models/HomeModel.swift @@ -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) { diff --git a/damus/Views/ThreadView.swift b/damus/Views/ThreadView.swift index 2e10501c..7789176f 100644 --- a/damus/Views/ThreadView.swift +++ b/damus/Views/ThreadView.swift @@ -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,