Compare commits

..

No commits in common. "1d169bec6745dd6218b303883195eb3fe057d854" and "59277ec64f85a584dc46da5ca566331f7a51ddff" have entirely different histories.

3 changed files with 46 additions and 15 deletions

View File

@ -12,7 +12,7 @@ import Intents
class ComposeViewController: UIViewController {
weak var mastodonController: MastodonController!
let mastodonController: MastodonController
var inReplyToID: String?
var accountsToMention = [String]()
@ -457,7 +457,7 @@ class ComposeViewController: UIViewController {
}
@objc func draftsButtonPressed() {
let draftsVC = DraftsTableViewController(account: mastodonController.accountInfo!)
let draftsVC = DraftsTableViewController()
draftsVC.delegate = self
present(UINavigationController(rootViewController: draftsVC), animated: true)
}
@ -623,7 +623,46 @@ extension ComposeViewController: DraftsTableViewControllerDelegate {
}
func shouldSelectDraft(_ draft: DraftsManager.Draft, completion: @escaping (Bool) -> Void) {
if draft.inReplyToID != self.inReplyToID {
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 {
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)

View File

@ -17,14 +17,9 @@ protocol DraftsTableViewControllerDelegate: class {
class DraftsTableViewController: UITableViewController {
let account: LocalData.UserAccountInfo
weak var delegate: DraftsTableViewControllerDelegate?
var drafts = [DraftsManager.Draft]()
init(account: LocalData.UserAccountInfo) {
self.account = account
init() {
super.init(nibName: "DraftsTableViewController", bundle: nil)
title = "Drafts"
@ -42,14 +37,10 @@ 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 drafts[indexPath.row]
return DraftsManager.shared.sorted[indexPath.row]
}
// MARK: - Table View Data Source
@ -59,7 +50,7 @@ class DraftsTableViewController: UITableViewController {
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return drafts.count
return DraftsManager.shared.drafts.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

View File

@ -95,6 +95,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
}
func updateTimestamp() {
guard superview != nil else { return }
guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
timestampLabel.text = status.createdAt.timeAgoString()