Skip to content

Commit

Permalink
Run NSDataDetector link detection on background queue (IOS-285)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimar committed Jul 31, 2024
1 parent d84ca7b commit 147c417
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -342,6 +343,7 @@ extension ComposeContentViewModel {
.charactersReservedPerURL ?? MastodonAuthentication.fallbackCharactersReservedPerURL
return lengthWithoutLinks + (matches.count * charactersReservedPerURL)
}
.receive(on: RunLoop.main)
.assign(to: &$contentWeightedLength)

Publishers.CombineLatest(
Expand Down

0 comments on commit 147c417

Please sign in to comment.