Pull the URL reserved chars count from the instance

This commit is contained in:
Jed Fox 2022-12-29 08:21:37 -05:00
parent d8c4d788f6
commit 0e217b1268
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
1 changed files with 4 additions and 4 deletions

View File

@ -277,10 +277,11 @@ extension ComposeContentViewModel {
$content
.sink { [weak self] _ in
DispatchQueue.main.async {
guard let attributedText = self?.contentMetaText?.textView.attributedText else {
guard let self, let attributedText = self.contentMetaText?.textView.attributedText else {
self?.contentWeightedLength = 0
return
}
let urlCharCount = self.authContext.mastodonAuthenticationBox.authenticationRecord.object(in: self.context.managedObjectContext)?.instance?.configuration?.statuses?.charactersReservedPerURL ?? 23
// Reference: StatusLengthValidator.countable_text
// not entirely accurate: Ruby code says To ensure that we only
// give length concessions to entities that will be correctly
@ -293,15 +294,14 @@ extension ComposeContentViewModel {
let meta = attributes[NSAttributedString.Key("MetaAttributeKey.meta")] as? Meta
switch meta {
case .url:
// StatusLengthValidator::URL_PLACEHOLDER_CHARS
length += 23
length += urlCharCount
case .mention(_, mention: let mention, userInfo: _):
length += ("@" + mention.prefix(while: { $0 != "@" })).count
default:
length += range.length
}
}
self?.contentWeightedLength = length
self.contentWeightedLength = length
}
}
.store(in: &disposeBag)