Disable translations in DMs by default

There is an option to enable it now.

Changelog-Changed: Disable translations in DMs by default
This commit is contained in:
William Casarin
2023-04-06 12:07:01 -07:00
parent 7fb1bc48c4
commit 24c82293b3
7 changed files with 34 additions and 19 deletions

View File

@@ -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()

View File

@@ -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))

View File

@@ -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

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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")