Compare commits
No commits in common. "8a528936b8fd5f3c33d6cf7dba91f52d4a4d1bb8" and "45ac40b125b453da51beab7b9218d83f6b256570" have entirely different histories.
8a528936b8
...
45ac40b125
|
@ -51,10 +51,7 @@ enum CompositionAttachmentData {
|
|||
func getData(completion: @escaping (_ data: Data, _ mimeType: String) -> Void) {
|
||||
switch self {
|
||||
case let .image(image):
|
||||
// Export as JPEG instead of PNG, otherweise photos straight from the camera are too large
|
||||
// for Mastodon in its default configuration (max of 10MB).
|
||||
// The quality of 0.8 was chosen completely arbitrarily, it may need to be tuned in the future.
|
||||
completion(image.jpegData(compressionQuality: 0.8)!, "image/jpeg")
|
||||
completion(image.pngData()!, "image/png")
|
||||
case let .asset(asset):
|
||||
if asset.mediaType == .image {
|
||||
let options = PHImageRequestOptions()
|
||||
|
|
|
@ -14,17 +14,11 @@ class ProfileViewController: UIPageViewController {
|
|||
|
||||
weak var mastodonController: MastodonController!
|
||||
|
||||
// This property is optional because MyProfileViewController may not have the user's account ID
|
||||
// when first constructed. It should never be set to nil.
|
||||
var accountID: String? {
|
||||
willSet {
|
||||
if newValue == nil {
|
||||
fatalError("Do not set ProfileViewController.accountID to nil")
|
||||
}
|
||||
}
|
||||
// todo: does this still need to be settable?
|
||||
var accountID: String! {
|
||||
didSet {
|
||||
updateAccountUI()
|
||||
pageControllers.forEach { $0.accountID = accountID }
|
||||
loadAccount()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,9 +50,7 @@ class ProfileViewController: UIPageViewController {
|
|||
}
|
||||
|
||||
deinit {
|
||||
if let accountID = accountID {
|
||||
mastodonController.persistentContainer.account(for: accountID)?.decrementReferenceCount()
|
||||
}
|
||||
mastodonController.persistentContainer.account(for: accountID)?.decrementReferenceCount()
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
|
@ -92,12 +84,8 @@ class ProfileViewController: UIPageViewController {
|
|||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] (_) in self?.updateAccountUI() }
|
||||
|
||||
loadAccount()
|
||||
}
|
||||
|
||||
private func loadAccount() {
|
||||
guard let accountID = accountID else { return }
|
||||
if mastodonController.persistentContainer.account(for: accountID) != nil {
|
||||
headerView.updateUI(for: accountID)
|
||||
updateAccountUI()
|
||||
} else {
|
||||
let req = Client.getAccount(id: accountID)
|
||||
|
@ -107,6 +95,10 @@ class ProfileViewController: UIPageViewController {
|
|||
self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in
|
||||
DispatchQueue.main.async {
|
||||
self.updateAccountUI()
|
||||
self.headerView.updateUI(for: self.accountID)
|
||||
self.pageControllers.forEach {
|
||||
$0.updateUI(account: account)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,17 +106,8 @@ class ProfileViewController: UIPageViewController {
|
|||
}
|
||||
|
||||
private func updateAccountUI() {
|
||||
guard let accountID = accountID,
|
||||
let account = mastodonController.persistentContainer.account(for: accountID) else {
|
||||
return
|
||||
}
|
||||
|
||||
// Optionally invoke updateUI on headerView because viewDidLoad may not have been called yet
|
||||
headerView?.updateUI(for: accountID)
|
||||
guard let account = mastodonController.persistentContainer.account(for: accountID) else { return }
|
||||
navigationItem.title = account.displayNameWithoutCustomEmoji
|
||||
pageControllers.forEach {
|
||||
$0.updateUI(account: account)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectPage(at index: Int, animated: Bool, completion: ((Bool) -> Void)? = nil) {
|
||||
|
@ -194,15 +177,13 @@ class ProfileViewController: UIPageViewController {
|
|||
// MARK: Interaction
|
||||
|
||||
@objc private func composeMentioning() {
|
||||
if let accountID = accountID,
|
||||
let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||
if let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||
compose(mentioningAcct: account.acct)
|
||||
}
|
||||
}
|
||||
|
||||
private func composeDirectMentioning() {
|
||||
if let accountID = accountID,
|
||||
let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||
if let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||
let draft = mastodonController.createDraft(mentioningAcct: account.acct)
|
||||
draft.visibility = .direct
|
||||
compose(editing: draft)
|
||||
|
|
Loading…
Reference in New Issue