damus

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

commit 24c82293b3574250bcd04fa72dbb44826eb18229
parent 7fb1bc48c45a9287602b586a81a0a010c1142885
Author: William Casarin <jb55@jb55.com>
Date:   Thu,  6 Apr 2023 12:07:01 -0700

Disable translations in DMs by default

There is an option to enable it now.

Changelog-Changed: Disable translations in DMs by default

Diffstat:
Mdamus/Models/UserSettingsStore.swift | 7+++++++
Mdamus/Views/DMView.swift | 10+++++++++-
Mdamus/Views/DirectMessagesView.swift | 10+++++++++-
Mdamus/Views/EventView.swift | 18++----------------
Mdamus/Views/Events/TextEvent.swift | 1+
Mdamus/Views/NoteContentView.swift | 2+-
Mdamus/Views/Settings/TranslationSettingsView.swift | 5+++++
7 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift @@ -163,6 +163,12 @@ class UserSettingsStore: ObservableObject { UserDefaults.standard.set(notification_only_from_following, forKey: "notification_only_from_following") } } + + @Published var translate_dms: Bool { + didSet { + UserDefaults.standard.set(translate_dms, forKey: "translate_dms") + } + } @Published var truncate_timeline_text: Bool { didSet { @@ -275,6 +281,7 @@ class UserSettingsStore: ObservableObject { like_notification = UserDefaults.standard.object(forKey: "like_notification") as? Bool ?? true dm_notification = UserDefaults.standard.object(forKey: "dm_notification") as? Bool ?? true notification_only_from_following = UserDefaults.standard.object(forKey: "notification_only_from_following") as? Bool ?? false + translate_dms = UserDefaults.standard.object(forKey: "translate_dms") as? Bool ?? false truncate_timeline_text = UserDefaults.standard.object(forKey: "truncate_timeline_text") as? Bool ?? false truncate_mention_text = UserDefaults.standard.object(forKey: "truncate_mention_text") as? Bool ?? false disable_animation = should_disable_image_animation() diff --git a/damus/Views/DMView.swift b/damus/Views/DMView.swift @@ -25,6 +25,14 @@ struct DMView: View { } } + var dm_options: EventViewOptions { + if self.damus_state.settings.translate_dms { + return [] + } + + return [.no_translate] + } + var DM: some View { HStack { if is_ours { @@ -33,7 +41,7 @@ struct DMView: View { let should_show_img = should_show_images(settings: damus_state.settings, contacts: damus_state.contacts, ev: event, our_pubkey: damus_state.pubkey) - NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: .normal, artifacts: .just_content(event.get_content(damus_state.keypair.privkey)), options: []) + NoteContentView(damus_state: damus_state, event: event, show_images: should_show_img, size: .normal, artifacts: .just_content(event.get_content(damus_state.keypair.privkey)), options: dm_options) .padding([.top, .leading, .trailing], 10) .padding([.bottom], 25) .background(VisualEffectView(effect: UIBlurEffect(style: .prominent)) diff --git a/damus/Views/DirectMessagesView.swift b/damus/Views/DirectMessagesView.swift @@ -51,10 +51,18 @@ struct DirectMessagesView: View { } } + var options: EventViewOptions { + if self.damus_state.settings.translate_dms { + return [.truncate_content] + } + + return [.truncate_content, .no_translate] + } + func MaybeEvent(_ tup: (String, DirectMessageModel)) -> some View { Group { if let ev = tup.1.events.last { - EventView(damus: damus_state, event: ev, pubkey: tup.0) + EventView(damus: damus_state, event: ev, pubkey: tup.0, options: options) .onTapGesture { pubkey = tup.0 active_model = tup.1 diff --git a/damus/Views/EventView.swift b/damus/Views/EventView.swift @@ -22,25 +22,11 @@ struct EventView: View { @EnvironmentObject var action_bar: ActionBarModel - init(damus: DamusState, event: NostrEvent, options: EventViewOptions) { + init(damus: DamusState, event: NostrEvent, pubkey: String? = nil, options: EventViewOptions = []) { self.event = event self.options = options self.damus = damus - self.pubkey = event.pubkey - } - - init(damus: DamusState, event: NostrEvent) { - self.event = event - self.options = [] - self.damus = damus - self.pubkey = event.pubkey - } - - init(damus: DamusState, event: NostrEvent, pubkey: String) { - self.event = event - self.options = [.no_action_bar] - self.damus = damus - self.pubkey = pubkey + self.pubkey = pubkey ?? event.pubkey } var body: some View { diff --git a/damus/Views/Events/TextEvent.swift b/damus/Views/Events/TextEvent.swift @@ -15,6 +15,7 @@ struct EventViewOptions: OptionSet { static let wide = EventViewOptions(rawValue: 1 << 3) static let truncate_content = EventViewOptions(rawValue: 1 << 4) static let pad_content = EventViewOptions(rawValue: 1 << 5) + static let no_translate = EventViewOptions(rawValue: 1 << 6) } struct TextEvent: View { diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift @@ -106,7 +106,7 @@ struct NoteContentView: View { } } - if size == .selected || damus_state.settings.auto_translate { + if !options.contains(.no_translate) && (size == .selected || damus_state.settings.auto_translate) { if with_padding { translateView .padding(.horizontal) diff --git a/damus/Views/Settings/TranslationSettingsView.swift b/damus/Views/Settings/TranslationSettingsView.swift @@ -69,6 +69,11 @@ struct TranslationSettingsView: View { Toggle(NSLocalizedString("Automatically translate notes", comment: "Toggle to automatically translate notes."), isOn: $settings.auto_translate) .toggleStyle(.switch) } + + if settings.translation_service != .none { + Toggle(NSLocalizedString("Translate DMs", comment: "Toggle to translate direct messages."), isOn: $settings.translate_dms) + .toggleStyle(.switch) + } } } .navigationTitle("Translation")