diff --git a/Pachyderm/Utilities/CharacterCounter.swift b/Pachyderm/Utilities/CharacterCounter.swift index 709aa4ac..59bf1f25 100644 --- a/Pachyderm/Utilities/CharacterCounter.swift +++ b/Pachyderm/Utilities/CharacterCounter.swift @@ -13,12 +13,12 @@ public struct CharacterCounter { static let linkDetector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) static let mention = try! NSRegularExpression(pattern: "(@[a-z0-9_]+)(?:@[a-z0-9\\-\\.]+[a-z0-9]+)?", options: .caseInsensitive) - public static func count(text: String) -> Int { + public static func count(text: String, for instance: Instance? = nil) -> Int { let mentionsRemoved = removeMentions(in: text) var count = mentionsRemoved.count for match in linkDetector.matches(in: mentionsRemoved, options: [], range: NSRange(location: 0, length: mentionsRemoved.utf16.count)) { count -= match.range.length - count += 23 // Mastodon link length + count += instance?.configuration?.statuses.charactersReservedPerURL ?? 23 // default Mastodon link length } return count } diff --git a/Tusker/Screens/Compose/ComposeView.swift b/Tusker/Screens/Compose/ComposeView.swift index ab5d8a90..09963f0f 100644 --- a/Tusker/Screens/Compose/ComposeView.swift +++ b/Tusker/Screens/Compose/ComposeView.swift @@ -30,7 +30,7 @@ struct ComposeView: View { var charactersRemaining: Int { let limit = mastodonController.instance?.maxStatusCharacters ?? 500 let cwCount = draft.contentWarningEnabled ? draft.contentWarning.count : 0 - return limit - (cwCount + CharacterCounter.count(text: draft.text)) + return limit - (cwCount + CharacterCounter.count(text: draft.text, for: mastodonController.instance)) } var requiresAttachmentDescriptions: Bool {