From 8ea15d3bab3dc3abd2104cfbbe3b2e623e2bb5ab Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 5 Apr 2021 17:48:03 -0400 Subject: [PATCH] Add preference for requiring confirmation before reblogging --- Tusker/Preferences/Preferences.swift | 4 ++++ .../Screens/Preferences/BehaviorPrefsView.swift | 13 +++++++++++-- .../Views/Status/BaseStatusTableViewCell.swift | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 82a077569a..4a0ec2332e 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -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 diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index 8657d117ba..49956db53a 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -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") diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 05364e72b4..72e7788acc 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -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