mute: adding filtering support for MuteItem events

This patch depends on: Receiving New Mute List Type

- Changes NewMutesNotify, NewUnmutesNotify & MuteNotify to use MuteItem instead of Pubkey
- Changes is_muted in Contacts.swift to take in a MuteItem instead of a Pubkey
    - A lot of changes here were just modifying callers of that to accept the new parameter type

Related: https://github.com/damus-io/damus/issues/1718
Related: https://github.com/damus-io/damus/issues/856
Lighting Address: fishcharlie@strike.me

Signed-off-by: Charlie Fish <contact@charlie.fish>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Charlie Fish
2024-01-17 18:17:40 -07:00
committed by William Casarin
parent 2861ee2c12
commit 61a9e44898
11 changed files with 43 additions and 49 deletions

View File

@@ -39,7 +39,7 @@ struct DirectMessagesView: View {
func filter_dms(dms: [DirectMessageModel]) -> [DirectMessageModel] {
return dms.filter({ dm in
return damus_state.settings.friend_filter.filter(contacts: damus_state.contacts, pubkey: dm.pubkey) && !damus_state.contacts.is_muted(dm.pubkey)
return damus_state.settings.friend_filter.filter(contacts: damus_state.contacts, pubkey: dm.pubkey) && !damus_state.contacts.is_muted(.user(dm.pubkey, nil))
})
}

View File

@@ -142,7 +142,7 @@ struct MenuItems: View {
}
Button(role: .destructive) {
notify(.mute(target_pubkey))
notify(.mute(.user(target_pubkey, nil)))
} label: {
Label(NSLocalizedString("Mute user", comment: "Context menu option for muting users."), image: "mute")
}

View File

@@ -49,12 +49,13 @@ struct EventMutingContainerView<Content: View>: View {
}
}
.onReceive(handle_notify(.new_mutes)) { mutes in
if mutes.contains(event.pubkey) {
let new_muted_event_reason = mutes.event_muted_reason(event)
if new_muted_event_reason != nil {
shown = false
}
}
.onReceive(handle_notify(.new_unmutes)) { unmutes in
if unmutes.contains(event.pubkey) {
if unmutes.event_muted_reason(event) != nil {
shown = true
}
}

View File

@@ -179,7 +179,7 @@ struct ProfileView: View {
notify(.report(.user(profile.pubkey)))
}
if damus_state.contacts.is_muted(profile.pubkey) {
if damus_state.contacts.is_muted(.user(profile.pubkey, nil)) {
Button(NSLocalizedString("Unmute", comment: "Button to unmute a profile.")) {
guard
let keypair = damus_state.keypair.to_full(),
@@ -197,7 +197,7 @@ struct ProfileView: View {
}
} else {
Button(NSLocalizedString("Mute", comment: "Button to mute a profile."), role: .destructive) {
notify(.mute(profile.pubkey))
notify(.mute(.user(profile.pubkey, nil)))
}
}
}