Run NSDataDetector link detection on background queue (IOS-285)

This commit is contained in:
Marcus Kida 2024-07-31 11:53:13 +02:00
parent d84ca7bc75
commit 147c417a74
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40

View File

@ -324,6 +324,7 @@ extension ComposeContentViewModel {
// bind text
$content
.receive(on: DispatchQueue.global(qos: .background))
.map { [weak self] input in
guard let self, let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) else {
return input.count
@ -342,6 +343,7 @@ extension ComposeContentViewModel {
.charactersReservedPerURL ?? MastodonAuthentication.fallbackCharactersReservedPerURL
return lengthWithoutLinks + (matches.count * charactersReservedPerURL)
}
.receive(on: RunLoop.main)
.assign(to: &$contentWeightedLength)
Publishers.CombineLatest(