damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit ace8a7081b7da0de4d032a9272e9c876cac33877
parent 75d66434f3045bd5fa6d541233e82f778df9096f
Author: Charlie Fish <contact@charlie.fish>
Date:   Wed, 17 Jan 2024 18:17:42 -0700

mute: adding ability to mute hashtag from SearchView

This patch depends on: Updating UI to support new mute list

- Adding the ability to mute a hashtag from SearchView

Related: https://github.com/damus-io/damus/issues/1718
Related: https://github.com/damus-io/damus/issues/856
Lighting-address: fishcharlie@strike.me
Changelog-Added: Add ability to mute hashtag from SearchView
Signed-off-by: Charlie Fish <contact@charlie.fish>
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mdamus/Views/SearchView.swift | 64+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)

diff --git a/damus/Views/SearchView.swift b/damus/Views/SearchView.swift @@ -11,7 +11,8 @@ struct SearchView: View { let appstate: DamusState @ObservedObject var search: SearchModel @Environment(\.dismiss) var dismiss - + @State var is_hashtag_muted: Bool = false + var content_filter: (NostrEvent) -> Bool { let filters = ContentFilters.defaults(damus_state: self.appstate) return ContentFilters(filters: filters).filter @@ -41,9 +42,70 @@ struct SearchView: View { } .onReceive(handle_notify(.new_mutes)) { notif in search.filter_muted() + + if let hashtag_string = search.search.hashtag?.first, + notif.contains(MuteItem.hashtag(Hashtag(hashtag: hashtag_string), nil)) { + is_hashtag_muted = true + } + } + .onReceive(handle_notify(.new_unmutes)) { unmutes in + if let hashtag_string = search.search.hashtag?.first, + unmutes.contains(MuteItem.hashtag(Hashtag(hashtag: hashtag_string), nil)) { + is_hashtag_muted = false + } + } + .toolbar { + if let hashtag = search.search.hashtag?.first { + ToolbarItem(placement: .topBarTrailing) { + Menu { + if is_hashtag_muted { + Button { + guard + let full_keypair = appstate.keypair.to_full(), + let existing_mutelist = appstate.contacts.mutelist, + let mutelist = remove_from_mutelist(keypair: full_keypair, prev: existing_mutelist, to_remove: .hashtag(Hashtag(hashtag: hashtag), nil)) + else { + return + } + + appstate.contacts.set_mutelist(mutelist) + appstate.postbox.send(mutelist) + } label: { + Text("Unmute Hashtag", comment: "Label represnting a button that the user can tap to unmute a given hashtag so they start seeing it in their feed again.") + } + } else { + MuteDurationMenu { duration in + mute_hashtag(hashtag_string: hashtag, expiration_time: duration?.date_from_now) + } label: { + Text("Mute Hashtag", comment: "Label represnting a button that the user can tap to mute a given hashtag so they don't see it in their feed anymore.") + } + } + } label: { + Image(systemName: "ellipsis") + } + } + } + } + .onAppear { + if let hashtag_string = search.search.hashtag?.first { + is_hashtag_muted = (appstate.contacts.mutelist?.mute_list ?? []).contains(MuteItem.hashtag(Hashtag(hashtag: hashtag_string), nil)) + } } } + func mute_hashtag(hashtag_string: String, expiration_time: Date?) { + guard + let full_keypair = appstate.keypair.to_full(), + let existing_mutelist = appstate.contacts.mutelist, + let mutelist = create_or_update_mutelist(keypair: full_keypair, mprev: existing_mutelist, to_add: .hashtag(Hashtag(hashtag: hashtag_string), expiration_time)) + else { + return + } + + appstate.contacts.set_mutelist(mutelist) + appstate.postbox.send(mutelist) + } + var described_search: DescribedSearch { return describe_search(search.search) }