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) {
|
func getData(completion: @escaping (_ data: Data, _ mimeType: String) -> Void) {
|
||||||
switch self {
|
switch self {
|
||||||
case let .image(image):
|
case let .image(image):
|
||||||
// Export as JPEG instead of PNG, otherweise photos straight from the camera are too large
|
completion(image.pngData()!, "image/png")
|
||||||
// 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")
|
|
||||||
case let .asset(asset):
|
case let .asset(asset):
|
||||||
if asset.mediaType == .image {
|
if asset.mediaType == .image {
|
||||||
let options = PHImageRequestOptions()
|
let options = PHImageRequestOptions()
|
||||||
|
|
|
@ -14,17 +14,11 @@ class ProfileViewController: UIPageViewController {
|
||||||
|
|
||||||
weak var mastodonController: MastodonController!
|
weak var mastodonController: MastodonController!
|
||||||
|
|
||||||
// This property is optional because MyProfileViewController may not have the user's account ID
|
// todo: does this still need to be settable?
|
||||||
// when first constructed. It should never be set to nil.
|
var accountID: String! {
|
||||||
var accountID: String? {
|
|
||||||
willSet {
|
|
||||||
if newValue == nil {
|
|
||||||
fatalError("Do not set ProfileViewController.accountID to nil")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
didSet {
|
didSet {
|
||||||
|
updateAccountUI()
|
||||||
pageControllers.forEach { $0.accountID = accountID }
|
pageControllers.forEach { $0.accountID = accountID }
|
||||||
loadAccount()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +50,7 @@ class ProfileViewController: UIPageViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
if let accountID = accountID {
|
mastodonController.persistentContainer.account(for: accountID)?.decrementReferenceCount()
|
||||||
mastodonController.persistentContainer.account(for: accountID)?.decrementReferenceCount()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
|
@ -92,12 +84,8 @@ class ProfileViewController: UIPageViewController {
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.sink { [weak self] (_) in self?.updateAccountUI() }
|
.sink { [weak self] (_) in self?.updateAccountUI() }
|
||||||
|
|
||||||
loadAccount()
|
|
||||||
}
|
|
||||||
|
|
||||||
private func loadAccount() {
|
|
||||||
guard let accountID = accountID else { return }
|
|
||||||
if mastodonController.persistentContainer.account(for: accountID) != nil {
|
if mastodonController.persistentContainer.account(for: accountID) != nil {
|
||||||
|
headerView.updateUI(for: accountID)
|
||||||
updateAccountUI()
|
updateAccountUI()
|
||||||
} else {
|
} else {
|
||||||
let req = Client.getAccount(id: accountID)
|
let req = Client.getAccount(id: accountID)
|
||||||
|
@ -107,6 +95,10 @@ class ProfileViewController: UIPageViewController {
|
||||||
self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in
|
self.mastodonController.persistentContainer.addOrUpdate(account: account, incrementReferenceCount: true) { (account) in
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.updateAccountUI()
|
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() {
|
private func updateAccountUI() {
|
||||||
guard let accountID = accountID,
|
guard let account = mastodonController.persistentContainer.account(for: accountID) else { return }
|
||||||
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)
|
|
||||||
navigationItem.title = account.displayNameWithoutCustomEmoji
|
navigationItem.title = account.displayNameWithoutCustomEmoji
|
||||||
pageControllers.forEach {
|
|
||||||
$0.updateUI(account: account)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func selectPage(at index: Int, animated: Bool, completion: ((Bool) -> Void)? = nil) {
|
private func selectPage(at index: Int, animated: Bool, completion: ((Bool) -> Void)? = nil) {
|
||||||
|
@ -194,15 +177,13 @@ class ProfileViewController: UIPageViewController {
|
||||||
// MARK: Interaction
|
// MARK: Interaction
|
||||||
|
|
||||||
@objc private func composeMentioning() {
|
@objc private func composeMentioning() {
|
||||||
if let accountID = accountID,
|
if let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||||
let account = mastodonController.persistentContainer.account(for: accountID) {
|
|
||||||
compose(mentioningAcct: account.acct)
|
compose(mentioningAcct: account.acct)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func composeDirectMentioning() {
|
private func composeDirectMentioning() {
|
||||||
if let accountID = accountID,
|
if let account = mastodonController.persistentContainer.account(for: accountID) {
|
||||||
let account = mastodonController.persistentContainer.account(for: accountID) {
|
|
||||||
let draft = mastodonController.createDraft(mentioningAcct: account.acct)
|
let draft = mastodonController.createDraft(mentioningAcct: account.acct)
|
||||||
draft.visibility = .direct
|
draft.visibility = .direct
|
||||||
compose(editing: draft)
|
compose(editing: draft)
|
||||||
|
|
Loading…
Reference in New Issue