forked from shadowfacts/Tusker
Only show drafts from current account
This commit is contained in:
parent
59277ec64f
commit
4abda02b76
|
@ -12,7 +12,7 @@ import Intents
|
||||||
|
|
||||||
class ComposeViewController: UIViewController {
|
class ComposeViewController: UIViewController {
|
||||||
|
|
||||||
let mastodonController: MastodonController
|
weak var mastodonController: MastodonController!
|
||||||
|
|
||||||
var inReplyToID: String?
|
var inReplyToID: String?
|
||||||
var accountsToMention = [String]()
|
var accountsToMention = [String]()
|
||||||
|
@ -457,7 +457,7 @@ class ComposeViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func draftsButtonPressed() {
|
@objc func draftsButtonPressed() {
|
||||||
let draftsVC = DraftsTableViewController()
|
let draftsVC = DraftsTableViewController(account: mastodonController.accountInfo!)
|
||||||
draftsVC.delegate = self
|
draftsVC.delegate = self
|
||||||
present(UINavigationController(rootViewController: draftsVC), animated: true)
|
present(UINavigationController(rootViewController: draftsVC), animated: true)
|
||||||
}
|
}
|
||||||
|
@ -623,46 +623,7 @@ extension ComposeViewController: DraftsTableViewControllerDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldSelectDraft(_ draft: DraftsManager.Draft, completion: @escaping (Bool) -> Void) {
|
func shouldSelectDraft(_ draft: DraftsManager.Draft, completion: @escaping (Bool) -> Void) {
|
||||||
if draft.accountID != mastodonController.accountInfo!.id {
|
if draft.inReplyToID != self.inReplyToID {
|
||||||
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 {
|
|
||||||
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)
|
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
|
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (_) in
|
||||||
completion(false)
|
completion(false)
|
||||||
|
|
|
@ -17,9 +17,14 @@ protocol DraftsTableViewControllerDelegate: class {
|
||||||
|
|
||||||
class DraftsTableViewController: UITableViewController {
|
class DraftsTableViewController: UITableViewController {
|
||||||
|
|
||||||
|
let account: LocalData.UserAccountInfo
|
||||||
weak var delegate: DraftsTableViewControllerDelegate?
|
weak var delegate: DraftsTableViewControllerDelegate?
|
||||||
|
|
||||||
init() {
|
var drafts = [DraftsManager.Draft]()
|
||||||
|
|
||||||
|
init(account: LocalData.UserAccountInfo) {
|
||||||
|
self.account = account
|
||||||
|
|
||||||
super.init(nibName: "DraftsTableViewController", bundle: nil)
|
super.init(nibName: "DraftsTableViewController", bundle: nil)
|
||||||
|
|
||||||
title = "Drafts"
|
title = "Drafts"
|
||||||
|
@ -37,10 +42,14 @@ class DraftsTableViewController: UITableViewController {
|
||||||
tableView.estimatedRowHeight = 140
|
tableView.estimatedRowHeight = 140
|
||||||
|
|
||||||
tableView.register(UINib(nibName: "DraftTableViewCell", bundle: nil), forCellReuseIdentifier: "draftCell")
|
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 {
|
func draft(for indexPath: IndexPath) -> DraftsManager.Draft {
|
||||||
return DraftsManager.shared.sorted[indexPath.row]
|
return drafts[indexPath.row]
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Table View Data Source
|
// MARK: - Table View Data Source
|
||||||
|
@ -50,7 +59,7 @@ class DraftsTableViewController: UITableViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
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 {
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
|
|
Loading…
Reference in New Issue