Add preference for requiring confirmation before reblogging

This commit is contained in:
Shadowfacts 2021-04-05 17:48:03 -04:00
parent 13a4221fce
commit 8ea15d3bab
3 changed files with 32 additions and 2 deletions

View File

@ -58,6 +58,7 @@ class Preferences: Codable, ObservableObject {
self.expandAllContentWarnings = try container.decodeIfPresent(Bool.self, forKey: .expandAllContentWarnings) ?? false
self.collapseLongPosts = try container.decodeIfPresent(Bool.self, forKey: .collapseLongPosts) ?? true
self.oppositeCollapseKeywords = try container.decodeIfPresent([String].self, forKey: .oppositeCollapseKeywords) ?? []
self.confirmBeforeReblog = try container.decodeIfPresent(Bool.self, forKey: .confirmBeforeReblog) ?? false
self.showFavoriteAndReblogCounts = try container.decode(Bool.self, forKey: .showFavoriteAndReblogCounts)
self.defaultNotificationsMode = try container.decode(NotificationsMode.self, forKey: .defaultNotificationsType)
@ -91,6 +92,7 @@ class Preferences: Codable, ObservableObject {
try container.encode(expandAllContentWarnings, forKey: .expandAllContentWarnings)
try container.encode(collapseLongPosts, forKey: .collapseLongPosts)
try container.encode(oppositeCollapseKeywords, forKey: .oppositeCollapseKeywords)
try container.encode(confirmBeforeReblog, forKey: .confirmBeforeReblog)
try container.encode(showFavoriteAndReblogCounts, forKey: .showFavoriteAndReblogCounts)
try container.encode(defaultNotificationsMode, forKey: .defaultNotificationsType)
@ -125,6 +127,7 @@ class Preferences: Codable, ObservableObject {
@Published var expandAllContentWarnings = false
@Published var collapseLongPosts = true
@Published var oppositeCollapseKeywords: [String] = []
@Published var confirmBeforeReblog = false
// MARK: Digital Wellness
@Published var showFavoriteAndReblogCounts = true
@ -157,6 +160,7 @@ class Preferences: Codable, ObservableObject {
case expandAllContentWarnings
case collapseLongPosts
case oppositeCollapseKeywords
case confirmBeforeReblog
case showFavoriteAndReblogCounts
case defaultNotificationsType

View File

@ -13,14 +13,23 @@ struct BehaviorPrefsView: View {
var body: some View {
List {
untitledSection
linksSection
contentWarningsSection
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitle(Text("Behavior"))
}
private var untitledSection: some View {
Section {
Toggle(isOn: $preferences.confirmBeforeReblog) {
Text("Require Confirmation Before Reblogging")
}
}
}
var linksSection: some View {
private var linksSection: some View {
Section(header: Text("Links")) {
Toggle(isOn: $preferences.openLinksInApps) {
Text("Open Links in Apps")
@ -34,7 +43,7 @@ struct BehaviorPrefsView: View {
}
}
var contentWarningsSection: some View {
private var contentWarningsSection: some View {
Section(header: Text("Content Warnings")) {
Toggle(isOn: $preferences.collapseLongPosts) {
Text("Collapse Long Posts")

View File

@ -403,6 +403,23 @@ class BaseStatusTableViewCell: UITableViewCell {
@IBAction func reblogPressed() {
guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
// if we are about to reblog and the user has confirmation enabled
if !reblogged,
Preferences.shared.confirmBeforeReblog {
let alert = UIAlertController(title: "Confirm Reblog", message: "Are you sure you want to reblog this post by @\(status.account.acct)?", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Reblog", style: .default) { (_) in
self.toggleReblogInternal()
})
delegate?.present(alert, animated: true)
} else {
toggleReblogInternal()
}
}
private func toggleReblogInternal() {
guard let status = mastodonController.persistentContainer.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
let oldValue = reblogged
reblogged = !reblogged