From cbadbd9c1a371a5a360bb26f1319ea1a1cf9f42e Mon Sep 17 00:00:00 2001 From: Amit Ron Date: Wed, 9 Nov 2022 02:29:17 +0200 Subject: [PATCH] new feature (copied from glitch-soc :) ) -- option to prepend "re: " to content warnings when replying --- Localizations/en.lproj/Localizable.strings | 1 + .../ServiceLayer/Utilities/AppPreferences.swift | 6 ++++++ .../View Models/NewStatusViewModel.swift | 15 +++++++++++++-- Views/SwiftUI/PreferencesView.swift | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Localizations/en.lproj/Localizable.strings b/Localizations/en.lproj/Localizable.strings index 4689fa2..81555a8 100644 --- a/Localizations/en.lproj/Localizable.strings +++ b/Localizations/en.lproj/Localizable.strings @@ -248,6 +248,7 @@ "preferences.require-double-tap-to-favorite" = "Require double tap to favorite"; "preferences.show-reblog-and-favorite-counts" = "Show boost and favorite counts"; "preferences.status-word" = "Status word"; +"preferences.add-reply-prefix-cw" = "Prepend \"re: \" to content warnings when replying"; "filters.active" = "Active"; "filters.expired" = "Expired"; "filter.add-new" = "Add New Filter"; diff --git a/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift b/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift index 50e0d42..3ee1983 100644 --- a/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift +++ b/ServiceLayer/Sources/ServiceLayer/Utilities/AppPreferences.swift @@ -181,6 +181,11 @@ public extension AppPreferences { get { self[.useUniversalLinks] ?? true } set { self[.useUniversalLinks] = newValue } } + + var addReplyPrefixToContentWarning: Bool { + get { self[.addReplyPrefixToContentWarning] ?? false } + set { self[.addReplyPrefixToContentWarning] = newValue } + } } private extension AppPreferences { @@ -202,6 +207,7 @@ private extension AppPreferences { case notificationSounds case openLinksInDefaultBrowser case useUniversalLinks + case addReplyPrefixToContentWarning } subscript(index: Item) -> T? { diff --git a/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift b/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift index 261277f..350bd23 100644 --- a/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/NewStatusViewModel.swift @@ -22,6 +22,8 @@ public final class NewStatusViewModel: ObservableObject { private let compositionEventsSubject = PassthroughSubject() private var cancellables = Set() + private let REPLY_CONTENT_WARNING_PREFIX = "re: " + // swiftlint:disable:next function_body_length public init(allIdentitiesService: AllIdentitiesService, identityContext: IdentityContext, @@ -83,8 +85,17 @@ public final class NewStatusViewModel: ObservableObject { compositionViewModel.text = mentions.joined(separator: " ").appending(" ") } - compositionViewModel.contentWarning = inReplyTo.spoilerText - compositionViewModel.displayContentWarning = !inReplyTo.spoilerText.isEmpty + let contentWarning = inReplyTo.spoilerText + let hasContentWarning = !contentWarning.isEmpty + + let needsPrefix = + hasContentWarning + && identityContext.appPreferences.addReplyPrefixToContentWarning + && !contentWarning.hasPrefix(REPLY_CONTENT_WARNING_PREFIX) + let prefix = needsPrefix ? REPLY_CONTENT_WARNING_PREFIX : "" + + compositionViewModel.displayContentWarning = hasContentWarning + compositionViewModel.contentWarning = prefix + contentWarning } else if let directMessageTo = directMessageTo { compositionViewModel.text = directMessageTo.accountName.appending(" ") visibility = .direct diff --git a/Views/SwiftUI/PreferencesView.swift b/Views/SwiftUI/PreferencesView.swift index f9e68e5..f38843a 100644 --- a/Views/SwiftUI/PreferencesView.swift +++ b/Views/SwiftUI/PreferencesView.swift @@ -142,6 +142,8 @@ struct PreferencesView: View { } } } + Toggle("preferences.add-reply-prefix-cw", + isOn: $identityContext.appPreferences.addReplyPrefixToContentWarning) } } .navigationTitle("preferences")