From f7421d83efaa41f6d173160b5a3f4fd9fd106ae0 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 19 Jan 2020 23:48:36 -0500 Subject: [PATCH] Add preference to mention reblogger when replying to a reblogged status --- Tusker/Preferences/Preferences.swift | 4 ++++ .../Screens/Compose/ComposeViewController.swift | 7 ++++--- .../Screens/Preferences/BehaviorPrefsView.swift | 3 +++ Tusker/TuskerNavigationDelegate.swift | 12 +++++++++--- .../Status/TimelineStatusTableViewCell.swift | 16 +++++++++++++++- 5 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Tusker/Preferences/Preferences.swift b/Tusker/Preferences/Preferences.swift index 12fdd88f..df3ad2e9 100644 --- a/Tusker/Preferences/Preferences.swift +++ b/Tusker/Preferences/Preferences.swift @@ -46,6 +46,7 @@ class Preferences: Codable, ObservableObject { self.automaticallySaveDrafts = try container.decode(Bool.self, forKey: .automaticallySaveDrafts) self.requireAttachmentDescriptions = try container.decode(Bool.self, forKey: .requireAttachmentDescriptions) self.contentWarningCopyMode = try container.decode(ContentWarningCopyMode.self, forKey: .contentWarningCopyMode) + self.mentionReblogger = try container.decode(Bool.self, forKey: .mentionReblogger) self.blurAllMedia = try container.decode(Bool.self, forKey: .blurAllMedia) self.openLinksInApps = try container.decode(Bool.self, forKey: .openLinksInApps) self.useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari) @@ -70,6 +71,7 @@ class Preferences: Codable, ObservableObject { try container.encode(automaticallySaveDrafts, forKey: .automaticallySaveDrafts) try container.encode(requireAttachmentDescriptions, forKey: .requireAttachmentDescriptions) try container.encode(contentWarningCopyMode, forKey: .contentWarningCopyMode) + try container.encode(mentionReblogger, forKey: .mentionReblogger) try container.encode(blurAllMedia, forKey: .blurAllMedia) try container.encode(openLinksInApps, forKey: .openLinksInApps) try container.encode(useInAppSafari, forKey: .useInAppSafari) @@ -93,6 +95,7 @@ class Preferences: Codable, ObservableObject { @Published var automaticallySaveDrafts = true @Published var requireAttachmentDescriptions = false @Published var contentWarningCopyMode = ContentWarningCopyMode.asIs + @Published var mentionReblogger = false @Published var blurAllMedia = false @Published var openLinksInApps = true @Published var useInAppSafari = true @@ -116,6 +119,7 @@ class Preferences: Codable, ObservableObject { case automaticallySaveDrafts case requireAttachmentDescriptions case contentWarningCopyMode + case mentionReblogger case blurAllMedia case openLinksInApps case useInAppSafari diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 165fa0bb..977be20f 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -13,7 +13,7 @@ import Intents class ComposeViewController: UIViewController { var inReplyToID: String? - var accountsToMention: [String] + var accountsToMention = [String]() var initialText: String? var contentWarningEnabled = false { didSet { @@ -74,11 +74,12 @@ class ComposeViewController: UIViewController { self.inReplyToID = inReplyToID if let inReplyToID = inReplyToID, let inReplyTo = MastodonCache.status(for: inReplyToID) { accountsToMention = [inReplyTo.account.acct] + inReplyTo.mentions.map { $0.acct } - } else if let mentioningAcct = mentioningAcct { - accountsToMention = [mentioningAcct] } else { accountsToMention = [] } + if let mentioningAcct = mentioningAcct { + accountsToMention.append(mentioningAcct) + } if let ownAccount = MastodonController.account { accountsToMention.removeAll(where: { acct in ownAccount.acct == acct }) } diff --git a/Tusker/Screens/Preferences/BehaviorPrefsView.swift b/Tusker/Screens/Preferences/BehaviorPrefsView.swift index 540f466e..ae221e0a 100644 --- a/Tusker/Screens/Preferences/BehaviorPrefsView.swift +++ b/Tusker/Screens/Preferences/BehaviorPrefsView.swift @@ -49,6 +49,9 @@ struct BehaviorPrefsView: View { Text("Prepend 're: '").tag(ContentWarningCopyMode.prependRe) Text("Don't copy").tag(ContentWarningCopyMode.doNotCopy) } + Toggle(isOn: $preferences.mentionReblogger) { + Text("Mention Reblogger") + } } } diff --git a/Tusker/TuskerNavigationDelegate.swift b/Tusker/TuskerNavigationDelegate.swift index f22b126d..43cf731f 100644 --- a/Tusker/TuskerNavigationDelegate.swift +++ b/Tusker/TuskerNavigationDelegate.swift @@ -32,6 +32,8 @@ protocol TuskerNavigationDelegate { func reply(to statusID: String) + func reply(to statusID: String, mentioningAcct: String?) + func largeImage(_ image: UIImage, description: String?, sourceView: UIImageView) -> LargeImageViewController func largeImage(gifData: Data, description: String?, sourceView: UIImageView) -> LargeImageViewController @@ -125,15 +127,19 @@ extension TuskerNavigationDelegate where Self: UIViewController { compose(mentioning: nil) } - func compose(mentioning: String? = nil) { - let compose = ComposeViewController( mentioningAcct: mentioning) + func compose(mentioning: String?) { + let compose = ComposeViewController(mentioningAcct: mentioning) let vc = UINavigationController(rootViewController: compose) vc.presentationController?.delegate = compose present(vc, animated: true) } func reply(to statusID: String) { - let compose = ComposeViewController(inReplyTo: statusID) + reply(to: statusID, mentioningAcct: nil) + } + + func reply(to statusID: String, mentioningAcct: String?) { + let compose = ComposeViewController(inReplyTo: statusID, mentioningAcct: mentioningAcct) let vc = UINavigationController(rootViewController: compose) vc.presentationController?.delegate = compose present(vc, animated: true) diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 0ce1aab8..5393529d 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -112,6 +112,16 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { } } + func reply() { + if Preferences.shared.mentionReblogger, + let rebloggerID = rebloggerID, + let rebloggerAccount = MastodonCache.account(for: rebloggerID) { + delegate?.reply(to: statusID, mentioningAcct: rebloggerAccount.acct) + } else { + delegate?.reply(to: statusID) + } + } + override func prepareForReuse() { super.prepareForReuse() updateTimestampWorkItem?.cancel() @@ -124,6 +134,10 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { delegate?.selected(account: rebloggerID) } + override func replyPressed() { + reply() + } + override func getStatusCellPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> BaseStatusTableViewCell.PreviewProviders? { return ( content: { ConversationTableViewController(for: self.statusID, state: self.statusState.copy()) }, @@ -205,7 +219,7 @@ extension TimelineStatusTableViewCell: TableViewSwipeActionProvider { func trailingSwipeActionsConfiguration() -> UISwipeActionsConfiguration? { let reply = UIContextualAction(style: .normal, title: "Reply") { (action, view, completion) in completion(true) - self.delegate?.reply(to: self.statusID) + self.reply() } reply.image = UIImage(systemName: "arrowshape.turn.up.left.fill") reply.backgroundColor = tintColor