Compare commits
No commits in common. "59277ec64f85a584dc46da5ca566331f7a51ddff" and "12b6623113e218b792633f19820b98a5e3ef8fcd" have entirely different histories.
59277ec64f
...
12b6623113
|
@ -39,8 +39,8 @@ class DraftsManager: Codable {
|
|||
return drafts.sorted(by: { $0.lastModified > $1.lastModified })
|
||||
}
|
||||
|
||||
func create(accountID: String, text: String, contentWarning: String?, inReplyToID: String?, attachments: [DraftAttachment]) -> Draft {
|
||||
let draft = Draft(accountID: accountID, text: text, contentWarning: contentWarning, inReplyToID: inReplyToID, attachments: attachments)
|
||||
func create(text: String, contentWarning: String?, inReplyToID: String?, attachments: [DraftAttachment]) -> Draft {
|
||||
let draft = Draft(text: text, contentWarning: contentWarning, inReplyToID: inReplyToID, attachments: attachments)
|
||||
drafts.append(draft)
|
||||
return draft
|
||||
}
|
||||
|
@ -55,16 +55,14 @@ class DraftsManager: Codable {
|
|||
extension DraftsManager {
|
||||
class Draft: Codable, Equatable {
|
||||
let id: UUID
|
||||
private(set) var accountID: String
|
||||
private(set) var text: String
|
||||
private(set) var contentWarning: String?
|
||||
private(set) var attachments: [DraftAttachment]
|
||||
private(set) var inReplyToID: String?
|
||||
private(set) var lastModified: Date
|
||||
|
||||
init(accountID: String, text: String, contentWarning: String?, inReplyToID: String?, attachments: [DraftAttachment], lastModified: Date = Date()) {
|
||||
init(text: String, contentWarning: String?, inReplyToID: String?, attachments: [DraftAttachment], lastModified: Date = Date()) {
|
||||
self.id = UUID()
|
||||
self.accountID = accountID
|
||||
self.text = text
|
||||
self.contentWarning = contentWarning
|
||||
self.inReplyToID = inReplyToID
|
||||
|
@ -72,8 +70,7 @@ extension DraftsManager {
|
|||
self.lastModified = lastModified
|
||||
}
|
||||
|
||||
func update(accountID: String, text: String, contentWarning: String?, attachments: [DraftAttachment]) {
|
||||
self.accountID = accountID
|
||||
func update(text: String, contentWarning: String?, attachments: [DraftAttachment]) {
|
||||
self.text = text
|
||||
self.contentWarning = contentWarning
|
||||
self.lastModified = Date()
|
||||
|
|
|
@ -101,10 +101,6 @@ class LocalData: ObservableObject {
|
|||
accounts.removeAll(where: { $0.id == info.id })
|
||||
}
|
||||
|
||||
func getAccount(id: String) -> UserAccountInfo? {
|
||||
return accounts.first(where: { $0.id == id })
|
||||
}
|
||||
|
||||
func getMostRecentAccount() -> UserAccountInfo? {
|
||||
guard onboardingComplete else { return nil }
|
||||
let mostRecent: UserAccountInfo?
|
||||
|
|
|
@ -193,7 +193,6 @@ class ComposeViewController: UIViewController {
|
|||
}
|
||||
|
||||
let replyView = ComposeStatusReplyView.create()
|
||||
replyView.mastodonController = mastodonController
|
||||
replyView.updateUI(for: inReplyTo)
|
||||
stackView.insertArrangedSubview(replyView, at: 0)
|
||||
|
||||
|
@ -368,11 +367,10 @@ class ComposeViewController: UIViewController {
|
|||
attachments.append(.init(attachment: attachment, description: description))
|
||||
}
|
||||
let cw = contentWarningEnabled ? contentWarningTextField.text : nil
|
||||
let account = mastodonController.accountInfo!
|
||||
if let currentDraft = self.currentDraft {
|
||||
currentDraft.update(accountID: account.id, text: self.statusTextView.text, contentWarning: cw, attachments: attachments)
|
||||
currentDraft.update(text: self.statusTextView.text, contentWarning: cw, attachments: attachments)
|
||||
} else {
|
||||
self.currentDraft = DraftsManager.shared.create(accountID: account.id, text: self.statusTextView.text, contentWarning: cw, inReplyToID: inReplyToID, attachments: attachments)
|
||||
self.currentDraft = DraftsManager.shared.create(text: self.statusTextView.text, contentWarning: cw, inReplyToID: inReplyToID, attachments: attachments)
|
||||
}
|
||||
DraftsManager.save()
|
||||
}
|
||||
|
@ -623,46 +621,8 @@ 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 {
|
||||
// todo: better text for this
|
||||
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)
|
||||
|
|
|
@ -11,8 +11,6 @@ import Pachyderm
|
|||
|
||||
class ComposeStatusReplyView: UIView {
|
||||
|
||||
weak var mastodonController: MastodonController?
|
||||
|
||||
@IBOutlet weak var avatarImageView: UIImageView!
|
||||
@IBOutlet weak var displayNameLabel: UILabel!
|
||||
@IBOutlet weak var usernameLabel: UILabel!
|
||||
|
@ -36,7 +34,6 @@ class ComposeStatusReplyView: UIView {
|
|||
func updateUI(for status: Status) {
|
||||
displayNameLabel.text = status.account.realDisplayName
|
||||
usernameLabel.text = "@\(status.account.acct)"
|
||||
statusContentTextView.overrideMastodonController = mastodonController
|
||||
statusContentTextView.statusID = status.id
|
||||
|
||||
ImageCache.avatars.get(status.account.avatar) { (data) in
|
||||
|
|
|
@ -16,8 +16,7 @@ private let emojiRegex = try! NSRegularExpression(pattern: ":(\\w+):", options:
|
|||
class ContentTextView: LinkTextView {
|
||||
|
||||
weak var navigationDelegate: TuskerNavigationDelegate?
|
||||
weak var overrideMastodonController: MastodonController?
|
||||
var mastodonController: MastodonController? { overrideMastodonController ?? navigationDelegate?.apiController }
|
||||
var mastodonController: MastodonController? { navigationDelegate?.apiController }
|
||||
|
||||
var defaultFont: UIFont = .systemFont(ofSize: 17)
|
||||
var defaultColor: UIColor = .label
|
||||
|
|
Loading…
Reference in New Issue