damus

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

commit 356ef45b9154c84e8a52e59a683585ed06677756
parent f5d140103207e8ac5bccf4933a394be513417a2b
Author: William Casarin <jb55@jb55.com>
Date:   Thu, 25 Jan 2024 12:10:03 -0800

Revert "mute: updating UI to support new mute list"

This reverts commit 75d66434f3045bd5fa6d541233e82f778df9096f.

Diffstat:
Mdamus/Util/Router.swift | 6+++---
Mdamus/Views/DMChatView.swift | 2+-
Mdamus/Views/Events/EventMenu.swift | 53+++++++++++++++++++++++++++++++----------------------
Mdamus/Views/Events/EventMutingContainerView.swift | 28++++++++--------------------
Mdamus/Views/Muting/MutelistView.swift | 108+++++++++++++++++--------------------------------------------------------------
Mdamus/Views/Profile/ProfileView.swift | 7++-----
Mdamus/Views/Reposts/RepostedEvent.swift | 4++--
Mdamus/Views/SideMenuView.swift | 2+-
Mdamus/Views/ThreadView.swift | 4++--
9 files changed, 73 insertions(+), 141 deletions(-)

diff --git a/damus/Util/Router.swift b/damus/Util/Router.swift @@ -14,7 +14,7 @@ enum Route: Hashable { case Relay(relay: String, showActionButtons: Binding<Bool>) case RelayDetail(relay: String, metadata: RelayMetadata?) case Following(following: FollowingModel) - case MuteList(mutelist_items: Set<MuteItem>) + case MuteList(users: [Pubkey]) case RelayConfig case Script(script: ScriptModel) case Bookmarks @@ -58,8 +58,8 @@ enum Route: Hashable { RelayDetailView(state: damusState, relay: relay, nip11: metadata) case .Following(let following): FollowingView(damus_state: damusState, following: following) - case .MuteList(let mutelist_items): - MutelistView(damus_state: damusState, mutelist_items: mutelist_items) + case .MuteList(let users): + MutelistView(damus_state: damusState, users: users) case .RelayConfig: RelayConfigView(state: damusState) case .Bookmarks: diff --git a/damus/Views/DMChatView.swift b/damus/Views/DMChatView.swift @@ -22,7 +22,7 @@ struct DMChatView: View, KeyboardReadable { LazyVStack(alignment: .leading) { ForEach(Array(zip(dms.events, dms.events.indices)), id: \.0.id) { (ev, ind) in DMView(event: dms.events[ind], damus_state: damus_state) - .contextMenu{MenuItems(damus_state: damus_state, event: ev, target_pubkey: ev.pubkey, profileModel: ProfileModel(pubkey: ev.pubkey, damus: damus_state))} + .contextMenu{MenuItems(event: ev, keypair: damus_state.keypair, target_pubkey: ev.pubkey, bookmarks: damus_state.bookmarks, muted_threads: damus_state.muted_threads, settings: damus_state.settings, profileModel: ProfileModel(pubkey: ev.pubkey, damus: damus_state))} } EndBlock(height: 1) } diff --git a/damus/Views/Events/EventMenu.swift b/damus/Views/Events/EventMenu.swift @@ -8,15 +8,21 @@ import SwiftUI struct EventMenuContext: View { - let damus_state: DamusState let event: NostrEvent + let keypair: Keypair let target_pubkey: Pubkey + let bookmarks: BookmarksManager + let muted_threads: MutedThreadsManager let profileModel : ProfileModel + @ObservedObject var settings: UserSettingsStore init(damus: DamusState, event: NostrEvent) { - self.damus_state = damus self.event = event + self.keypair = damus.keypair self.target_pubkey = event.pubkey + self.bookmarks = damus.bookmarks + self.muted_threads = damus.muted_threads + self._settings = ObservedObject(wrappedValue: damus.settings) self.profileModel = ProfileModel(pubkey: target_pubkey, damus: damus) } @@ -28,7 +34,7 @@ struct EventMenuContext: View { // Add our Menu button inside an overlay modifier to avoid affecting the rest of the layout around us. .overlay( Menu { - MenuItems(damus_state: damus_state, event: event, target_pubkey: target_pubkey, profileModel: profileModel) + MenuItems(event: event, keypair: keypair, target_pubkey: target_pubkey, bookmarks: bookmarks, muted_threads: muted_threads, settings: settings, profileModel: profileModel) } label: { Color.clear } @@ -43,31 +49,38 @@ struct EventMenuContext: View { } struct MenuItems: View { - let damus_state: DamusState let event: NostrEvent + let keypair: Keypair let target_pubkey: Pubkey + let bookmarks: BookmarksManager + let muted_threads: MutedThreadsManager let profileModel: ProfileModel + @ObservedObject var settings: UserSettingsStore + @State private var isBookmarked: Bool = false @State private var isMutedThread: Bool = false - init(damus_state: DamusState, event: NostrEvent, target_pubkey: Pubkey, profileModel: ProfileModel) { - let bookmarked = damus_state.bookmarks.isBookmarked(event) + init(event: NostrEvent, keypair: Keypair, target_pubkey: Pubkey, bookmarks: BookmarksManager, muted_threads: MutedThreadsManager, settings: UserSettingsStore, profileModel: ProfileModel) { + let bookmarked = bookmarks.isBookmarked(event) self._isBookmarked = State(initialValue: bookmarked) - let muted_thread = (damus_state.contacts.mutelist?.mute_list?.event_muted_reason(event) != nil) + let muted_thread = muted_threads.isMutedThread(event, keypair: keypair) self._isMutedThread = State(initialValue: muted_thread) - self.damus_state = damus_state + self.bookmarks = bookmarks + self.muted_threads = muted_threads self.event = event + self.keypair = keypair self.target_pubkey = target_pubkey + self.settings = settings self.profileModel = profileModel } var body: some View { Group { Button { - UIPasteboard.general.string = event.get_content(damus_state.keypair) + UIPasteboard.general.string = event.get_content(keypair) } label: { Label(NSLocalizedString("Copy text", comment: "Context menu option for copying the text from an note."), image: "copy2") } @@ -84,7 +97,7 @@ struct MenuItems: View { Label(NSLocalizedString("Copy note ID", comment: "Context menu option for copying the ID of the note."), image: "note-book") } - if damus_state.settings.developer_mode { + if settings.developer_mode { Button { UIPasteboard.general.string = event_to_json(ev: event) } label: { @@ -93,8 +106,8 @@ struct MenuItems: View { } Button { - self.damus_state.bookmarks.updateBookmark(event) - isBookmarked = self.damus_state.bookmarks.isBookmarked(event) + self.bookmarks.updateBookmark(event) + isBookmarked = self.bookmarks.isBookmarked(event) } label: { let imageName = isBookmarked ? "bookmark.fill" : "bookmark" let removeBookmarkString = NSLocalizedString("Remove bookmark", comment: "Context menu option for removing a note bookmark.") @@ -109,13 +122,9 @@ struct MenuItems: View { } // Mute thread - relocated to below Broadcast, as to move further away from Add Bookmark to prevent accidental muted threads if event.known_kind != .dm { - MuteDurationMenu { duration in - if let full_keypair = self.damus_state.keypair.to_full(), - let new_mutelist_ev = toggle_from_mutelist(keypair: full_keypair, prev: damus_state.contacts.mutelist, to_toggle: .thread(event.thread_id(keypair: damus_state.keypair), duration?.date_from_now)) { - damus_state.contacts.set_mutelist(new_mutelist_ev) - damus_state.postbox.send(new_mutelist_ev) - } - let muted = (damus_state.contacts.mutelist?.mute_list?.event_muted_reason(event) != nil) + Button { + self.muted_threads.updateMutedThread(event) + let muted = self.muted_threads.isMutedThread(event, keypair: self.keypair) isMutedThread = muted } label: { let imageName = isMutedThread ? "mute" : "mute" @@ -125,15 +134,15 @@ struct MenuItems: View { } } // Only allow reporting if logged in with private key and the currently viewed profile is not the logged in profile. - if damus_state.keypair.pubkey != target_pubkey && damus_state.keypair.privkey != nil { + if keypair.pubkey != target_pubkey && keypair.privkey != nil { Button(role: .destructive) { notify(.report(.note(ReportNoteTarget(pubkey: target_pubkey, note_id: event.id)))) } label: { Label(NSLocalizedString("Report", comment: "Context menu option for reporting content."), image: "raising-hand") } - MuteDurationMenu { duration in - notify(.mute(.user(target_pubkey, duration?.date_from_now))) + Button(role: .destructive) { + notify(.mute(.user(target_pubkey, nil))) } label: { Label(NSLocalizedString("Mute user", comment: "Context menu option for muting users."), image: "mute") } diff --git a/damus/Views/Events/EventMutingContainerView.swift b/damus/Views/Events/EventMutingContainerView.swift @@ -9,20 +9,15 @@ import SwiftUI /// A container view that shows or hides provided content based on whether the given event should be muted or not, with built-in user controls to show or hide content, and an option to customize the muted box struct EventMutingContainerView<Content: View>: View { - typealias MuteBoxViewClosure = ((_ shown: Binding<Bool>, _ mutedReason: MuteItem?) -> AnyView) - + typealias MuteBoxViewClosure = ((_ shown: Binding<Bool>) -> AnyView) + let damus_state: DamusState let event: NostrEvent let content: Content var customMuteBox: MuteBoxViewClosure? - /// Represents if the note itself should be shown. - /// - /// By default this is the same as `should_show_event`. However, if the user taps the button to manually show a muted note, this can become out of sync with `should_show_event`. @State var shown: Bool - - @State var muted_reason: MuteItem? - + init(damus_state: DamusState, event: NostrEvent, @ViewBuilder content: () -> Content) { self.damus_state = damus_state self.event = event @@ -43,10 +38,10 @@ struct EventMutingContainerView<Content: View>: View { Group { if should_mute { if let customMuteBox { - customMuteBox($shown, muted_reason) + customMuteBox($shown) } else { - EventMutedBoxView(shown: $shown, reason: muted_reason) + EventMutedBoxView(shown: $shown) } } if shown { @@ -57,13 +52,11 @@ struct EventMutingContainerView<Content: View>: View { let new_muted_event_reason = mutes.event_muted_reason(event) if new_muted_event_reason != nil { shown = false - muted_reason = new_muted_event_reason } } .onReceive(handle_notify(.new_unmutes)) { unmutes in if unmutes.event_muted_reason(event) != nil { shown = true - muted_reason = nil } } } @@ -72,21 +65,16 @@ struct EventMutingContainerView<Content: View>: View { /// A box that instructs the user about a content that has been muted. struct EventMutedBoxView: View { @Binding var shown: Bool - var reason: MuteItem? - + var body: some View { ZStack { RoundedRectangle(cornerRadius: 20) .foregroundColor(DamusColors.adaptableGrey) HStack { - if let reason { - Text("Note from a \(reason.title) you've muted", comment: "Text to indicate that what is being shown is a note which has been muted.") - } else { - Text("Note you've muted", comment: "Text to indicate that what is being shown is a note which has been muted.") - } + Text("Note from a user you've muted", comment: "Text to indicate that what is being shown is a note from a user who has been muted.") Spacer() - Button(shown ? NSLocalizedString("Hide", comment: "Button to hide a note which has been muted.") : NSLocalizedString("Show", comment: "Button to show a note which has been muted.")) { + Button(shown ? NSLocalizedString("Hide", comment: "Button to hide a note from a user who has been muted.") : NSLocalizedString("Show", comment: "Button to show a note from a user who has been muted.")) { shown.toggle() } } diff --git a/damus/Views/Muting/MutelistView.swift b/damus/Views/Muting/MutelistView.swift @@ -9,117 +9,55 @@ import SwiftUI struct MutelistView: View { let damus_state: DamusState - @State var mutelist_items: Set<MuteItem> = Set<MuteItem>() - @State var show_add_muteitem: Bool = false - - func RemoveAction(item: MuteItem) -> some View { + @State var users: [Pubkey] + + func RemoveAction(pubkey: Pubkey) -> some View { Button { guard let mutelist = damus_state.contacts.mutelist, let keypair = damus_state.keypair.to_full(), let new_ev = remove_from_mutelist(keypair: keypair, prev: mutelist, - to_remove: item) + to_remove: .user(pubkey, nil)) else { return } - + damus_state.contacts.set_mutelist(new_ev) damus_state.postbox.send(new_ev) - mutelist_items = new_ev.mute_list ?? Set<MuteItem>() + users = get_mutelist_users(new_ev) } label: { Label(NSLocalizedString("Delete", comment: "Button to remove a user from their mutelist."), image: "delete") } .tint(.red) } - + var body: some View { - List { - Section(NSLocalizedString("Users", comment: "Section header title for a list of muted users.")) { - ForEach(mutelist_items.users, id: \.self) { pubkey in - UserViewRow(damus_state: damus_state, pubkey: pubkey) - .id(pubkey) - .swipeActions { - RemoveAction(item: .user(pubkey, nil)) - } - .onTapGesture { - damus_state.nav.push(route: Route.ProfileByKey(pubkey: pubkey)) - } - } - } - Section(NSLocalizedString("Hashtags", comment: "Section header title for a list of hashtags that are muted.")) { - ForEach(mutelist_items.hashtags, id: \.hashtag) { hashtag in - Text("#\(hashtag.hashtag)") - .id(hashtag.hashtag) - .swipeActions { - RemoveAction(item: .hashtag(hashtag, nil)) - } - .onTapGesture { - damus_state.nav.push(route: Route.Search(search: SearchModel.init(state: damus_state, search: NostrFilter(hashtag: [hashtag.hashtag])))) - } + List(users, id: \.self) { pubkey in + UserViewRow(damus_state: damus_state, pubkey: pubkey) + .id(pubkey) + .swipeActions { + RemoveAction(pubkey: pubkey) } - } - Section(NSLocalizedString("Words", comment: "Section header title for a list of words that are muted.")) { - ForEach(mutelist_items.words, id: \.self) { word in - Text("\(word)") - .id(word) - .swipeActions { - RemoveAction(item: .word(word, nil)) - } - } - } - Section(NSLocalizedString("Threads", comment: "Section header title for a list of threads that are muted.")) { - ForEach(mutelist_items.threads, id: \.self) { note_id in - if let event = damus_state.events.lookup(note_id) { - EventView(damus: damus_state, event: event) - .id(note_id.hex()) - .swipeActions { - RemoveAction(item: .thread(note_id, nil)) - } - } else { - Text(NSLocalizedString("Error retrieving muted event", comment: "Text for an item that application failed to retrieve the muted event for.")) - } + .onTapGesture { + damus_state.nav.push(route: Route.ProfileByKey(pubkey: pubkey)) } - } } - .navigationTitle(NSLocalizedString("Muted", comment: "Navigation title of view to see list of muted users & phrases.")) + .navigationTitle(NSLocalizedString("Muted Users", comment: "Navigation title of view to see list of muted users.")) .onAppear { - mutelist_items = damus_state.contacts.mutelist?.mute_list ?? Set<MuteItem>() - } - .onReceive(handle_notify(.new_mutes)) { new_mutes in - mutelist_items = mutelist_items.union(new_mutes) - } - .onReceive(handle_notify(.new_unmutes)) { new_unmutes in - mutelist_items = mutelist_items.subtracting(new_unmutes) - } - .toolbar { - ToolbarItem(placement: .topBarTrailing) { - Button { - self.show_add_muteitem = true - } label: { - Image(systemName: "plus") - } - } - } - .sheet(isPresented: $show_add_muteitem, onDismiss: { self.show_add_muteitem = false }) { - if #available(iOS 16.0, *) { - AddMuteItemView(state: damus_state) - .presentationDetents([.height(300)]) - .presentationDragIndicator(.visible) - } else { - AddMuteItemView(state: damus_state) - } + users = get_mutelist_users(damus_state.contacts.mutelist) } } } + +func get_mutelist_users(_ mutelist: NostrEvent?) -> Array<Pubkey> { + guard let mutelist else { return [] } + return Array(mutelist.referenced_pubkeys) +} + struct MutelistView_Previews: PreviewProvider { static var previews: some View { - MutelistView(damus_state: test_damus_state, mutelist_items: Set([ - .user(test_note.pubkey, nil), - .hashtag(Hashtag(hashtag: "test"), nil), - .word("test", nil), - .thread(test_note.id, nil) - ])) + MutelistView(damus_state: test_damus_state, users: [test_note.pubkey, test_note.pubkey]) } } diff --git a/damus/Views/Profile/ProfileView.swift b/damus/Views/Profile/ProfileView.swift @@ -196,11 +196,8 @@ struct ProfileView: View { damus_state.postbox.send(new_ev) } } else { - MuteDurationMenu { duration in - notify(.mute(.user(profile.pubkey, duration?.date_from_now))) - } label: { - Text(NSLocalizedString("Mute", comment: "Button to mute a profile.")) - .foregroundStyle(.red) + Button(NSLocalizedString("Mute", comment: "Button to mute a profile."), role: .destructive) { + notify(.mute(.user(profile.pubkey, nil))) } } } diff --git a/damus/Views/Reposts/RepostedEvent.swift b/damus/Views/Reposts/RepostedEvent.swift @@ -25,9 +25,9 @@ struct RepostedEvent: View { EventMutingContainerView( damus_state: damus, event: inner_ev, - muteBox: { event_shown, muted_reason in + muteBox: { event_shown in AnyView( - EventMutedBoxView(shown: event_shown, reason: muted_reason) + EventMutedBoxView(shown: event_shown) .padding(.horizontal, 5) // Add a bit of horizontal padding to avoid the mute box from touching the edges of the screen ) }) { diff --git a/damus/Views/SideMenuView.swift b/damus/Views/SideMenuView.swift @@ -66,7 +66,7 @@ struct SideMenuView: View { } } - NavigationLink(value: Route.MuteList(mutelist_items: damus_state.contacts.mutelist?.mute_list ?? Set<MuteItem>())) { + NavigationLink(value: Route.MuteList(users: get_mutelist_users(damus_state.contacts.mutelist))) { navLabel(title: NSLocalizedString("Muted", comment: "Sidebar menu label for muted users view."), img: "mute") } diff --git a/damus/Views/ThreadView.swift b/damus/Views/ThreadView.swift @@ -70,9 +70,9 @@ struct ThreadView: View { EventMutingContainerView( damus_state: state, event: self.thread.event, - muteBox: { event_shown, muted_reason in + muteBox: { event_shown in AnyView( - EventMutedBoxView(shown: event_shown, reason: muted_reason) + EventMutedBoxView(shown: event_shown) .padding(5) ) }