From 4abda02b76675b8d9322c7482810aa94c8743cde Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 22 Jan 2020 22:27:58 -0500 Subject: [PATCH] Only show drafts from current account --- .../Compose/ComposeViewController.swift | 45 ++----------------- .../Drafts/DraftsTableViewController.swift | 15 +++++-- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index 5e96dc2206..d4382ef954 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -12,7 +12,7 @@ import Intents class ComposeViewController: UIViewController { - let mastodonController: MastodonController + weak var mastodonController: MastodonController! var inReplyToID: String? var accountsToMention = [String]() @@ -457,7 +457,7 @@ class ComposeViewController: UIViewController { } @objc func draftsButtonPressed() { - let draftsVC = DraftsTableViewController() + let draftsVC = DraftsTableViewController(account: mastodonController.accountInfo!) draftsVC.delegate = self present(UINavigationController(rootViewController: draftsVC), animated: true) } @@ -623,46 +623,7 @@ extension ComposeViewController: DraftsTableViewControllerDelegate { } func shouldSelectDraft(_ draft: DraftsManager.Draft, completion: @escaping (Bool) -> Void) { - if draft.accountID != mastodonController.accountInfo!.id { - let currentAccount = mastodonController.accountInfo! - let currentAcct = "\(currentAccount.username)@\(currentAccount.instanceURL.host!)" - let otherAccount = LocalData.shared.getAccount(id: draft.accountID) - let otherAcct: String! - if let otherAccount = otherAccount { - otherAcct = "\(otherAccount.username)@\(otherAccount.instanceURL.host!)" - } else { - otherAcct = nil - } - - if draft.inReplyToID != nil { - let message: String - if otherAccount != nil { - message = "The selected draft is a reply from a different account, it cannot be loaded from this account. To use it, switch accounts to \(otherAcct!)" - } else { - message = "The selected draft is a reply from an account that has been logged-out of. It cannot be loaded." - } - let alertController = UIAlertController(title: "Reply from Different Account", message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (_) in - completion(false) - })) - presentedViewController!.present(alertController, animated: true) - } else { - let message: String - if otherAccount != nil { - message = "The selected draft is from a different account (\(otherAcct!)) than your currently active account (\(currentAcct)). Do you wish to load it anyway?" - } else { - message = "The selected draft from an account that has been logged-out of." - } - let alertController = UIAlertController(title: "Draft from Different Account", message: message, preferredStyle: .alert) - alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in - completion(false) - })) - alertController.addAction(UIAlertAction(title: "Load Draft", style: .default, handler: { (_) in - completion(true) - })) - presentedViewController!.present(alertController, animated: true) - } - } else if draft.inReplyToID != self.inReplyToID { + if draft.inReplyToID != self.inReplyToID { let alertController = UIAlertController(title: "Different Reply", message: "The selected draft is a reply to a different status, do you wish to use it?", preferredStyle: .alert) alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in completion(false) diff --git a/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift b/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift index 40f90faa34..6273d584d8 100644 --- a/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift +++ b/Tusker/Screens/Compose/Drafts/DraftsTableViewController.swift @@ -17,9 +17,14 @@ protocol DraftsTableViewControllerDelegate: class { class DraftsTableViewController: UITableViewController { + let account: LocalData.UserAccountInfo weak var delegate: DraftsTableViewControllerDelegate? - init() { + var drafts = [DraftsManager.Draft]() + + init(account: LocalData.UserAccountInfo) { + self.account = account + super.init(nibName: "DraftsTableViewController", bundle: nil) title = "Drafts" @@ -37,10 +42,14 @@ class DraftsTableViewController: UITableViewController { tableView.estimatedRowHeight = 140 tableView.register(UINib(nibName: "DraftTableViewCell", bundle: nil), forCellReuseIdentifier: "draftCell") + + drafts = DraftsManager.shared.sorted.filter { (draft) in + draft.accountID == account.id + } } func draft(for indexPath: IndexPath) -> DraftsManager.Draft { - return DraftsManager.shared.sorted[indexPath.row] + return drafts[indexPath.row] } // MARK: - Table View Data Source @@ -50,7 +59,7 @@ class DraftsTableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return DraftsManager.shared.drafts.count + return drafts.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {