new feature (copied from glitch-soc :) ) -- option to prepend "re: " to content warnings when replying

This commit is contained in:
Amit Ron 2022-11-09 02:29:17 +02:00
parent 667e39554a
commit cbadbd9c1a
4 changed files with 22 additions and 2 deletions

View file

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

View file

@ -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<T>(index: Item) -> T? {

View file

@ -22,6 +22,8 @@ public final class NewStatusViewModel: ObservableObject {
private let compositionEventsSubject = PassthroughSubject<CompositionViewModel.Event, Never>()
private var cancellables = Set<AnyCancellable>()
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

View file

@ -142,6 +142,8 @@ struct PreferencesView: View {
}
}
}
Toggle("preferences.add-reply-prefix-cw",
isOn: $identityContext.appPreferences.addReplyPrefixToContentWarning)
}
}
.navigationTitle("preferences")