forked from shadowfacts/Tusker
Fix pasting using compose app shortcut while app isn't running
This commit is contained in:
parent
c224d11417
commit
b5fa0bceab
|
@ -88,11 +88,16 @@ class MastodonController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getOwnInstance() {
|
func getOwnInstance(completion: ((Instance) -> Void)? = nil) {
|
||||||
|
if let instance = self.instance {
|
||||||
|
completion?(instance)
|
||||||
|
} else {
|
||||||
let request = Client.getInstance()
|
let request = Client.getInstance()
|
||||||
run(request) { (response) in
|
run(request) { (response) in
|
||||||
guard case let .success(instance, _) = response else { fatalError() }
|
guard case let .success(instance, _) = response else { fatalError() }
|
||||||
self.instance = instance
|
self.instance = instance
|
||||||
|
completion?(instance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,8 +137,14 @@ class ComposeViewController: UIViewController {
|
||||||
|
|
||||||
// we have to set the font here, because the monospaced digit font is not available in IB
|
// we have to set the font here, because the monospaced digit font is not available in IB
|
||||||
charactersRemainingLabel.font = .monospacedDigitSystemFont(ofSize: 17, weight: .regular)
|
charactersRemainingLabel.font = .monospacedDigitSystemFont(ofSize: 17, weight: .regular)
|
||||||
updateCharactersRemaining()
|
|
||||||
updatePlaceholder()
|
updatePlaceholder()
|
||||||
|
// if the compose screen is opened via the home screen shortcut and app isn't running,
|
||||||
|
// the msatodon instance may not have been loaded yet
|
||||||
|
mastodonController.getOwnInstance { (_) in
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.updateCharactersRemaining()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
composeAttachmentsViewController = ComposeAttachmentsViewController(attachments: currentDraft?.attachments ?? [], mastodonController: mastodonController)
|
composeAttachmentsViewController = ComposeAttachmentsViewController(attachments: currentDraft?.attachments ?? [], mastodonController: mastodonController)
|
||||||
composeRequiresAttachmentDescriptionsDidChange()
|
composeRequiresAttachmentDescriptionsDidChange()
|
||||||
|
@ -266,7 +272,7 @@ class ComposeViewController: UIViewController {
|
||||||
func updateCharactersRemaining() {
|
func updateCharactersRemaining() {
|
||||||
let count = CharacterCounter.count(text: statusTextView.text)
|
let count = CharacterCounter.count(text: statusTextView.text)
|
||||||
let cwCount = contentWarningEnabled ? (contentWarningTextField.text?.count ?? 0) : 0
|
let cwCount = contentWarningEnabled ? (contentWarningTextField.text?.count ?? 0) : 0
|
||||||
let remaining = (mastodonController.instance.maxStatusCharacters ?? 500) - count - cwCount
|
let remaining = (mastodonController.instance?.maxStatusCharacters ?? 500) - count - cwCount
|
||||||
if remaining < 0 {
|
if remaining < 0 {
|
||||||
charactersRemainingLabel.textColor = .red
|
charactersRemainingLabel.textColor = .red
|
||||||
compositionState.formUnion(.tooManyCharacters)
|
compositionState.formUnion(.tooManyCharacters)
|
||||||
|
|
Loading…
Reference in New Issue