This commit is contained in:
Ilya Laktyushin 2026-05-14 12:45:26 +02:00
parent 7a7333edab
commit 91eb779ae2
614 changed files with 33270 additions and 37190 deletions

View file

@ -603,9 +603,14 @@ private func refreshTextMentions(text: NSString, initialAttributedText: NSAttrib
}
}
private func isTextUrlInnerCharacter(_ c: UnicodeScalar) -> Bool {
return alphanumericCharacters.contains(c) || c == " " as UnicodeScalar
}
private let textUrlEdgeCharacters = CharacterSet.alphanumerics
private let textUrlCharacters: CharacterSet = {
var set = textUrlEdgeCharacters
set.insert(charactersIn: "@_")
set.formUnion(.whitespacesAndNewlines)
return set
}()
private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributedString, attributedText: NSMutableAttributedString, fullRange: NSRange) {
var textUrlRanges: [(NSRange, ChatTextInputTextUrlAttribute)] = []
@ -623,7 +628,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed
var validLower = range.lowerBound
inner1: for i in range.lowerBound ..< range.upperBound {
if let c = UnicodeScalar(text.character(at: i)) {
if isTextUrlInnerCharacter(c) {
if textUrlCharacters.contains(c) {
validLower = i
break inner1
}
@ -634,7 +639,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed
var validUpper = range.upperBound
inner2: for i in (validLower ..< range.upperBound).reversed() {
if let c = UnicodeScalar(text.character(at: i)) {
if isTextUrlInnerCharacter(c) {
if textUrlCharacters.contains(c) {
validUpper = i + 1
break inner2
}
@ -646,7 +651,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed
let minLower = (i == 0) ? fullRange.lowerBound : textUrlRanges[i - 1].0.upperBound
inner3: for i in (minLower ..< validLower).reversed() {
if let c = UnicodeScalar(text.character(at: i)) {
if alphanumericCharacters.contains(c) {
if textUrlEdgeCharacters.contains(c) {
validLower = i
} else {
break inner3
@ -659,7 +664,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed
let maxUpper = (i == textUrlRanges.count - 1) ? fullRange.upperBound : textUrlRanges[i + 1].0.lowerBound
inner3: for i in validUpper ..< maxUpper {
if let c = UnicodeScalar(text.character(at: i)) {
if alphanumericCharacters.contains(c) {
if textUrlEdgeCharacters.contains(c) {
validUpper = i + 1
} else {
break inner3
@ -681,7 +686,7 @@ private func refreshTextUrls(text: NSString, initialAttributedText: NSAttributed
var combine = true
inner: for j in textUrlRanges[i].0.upperBound ..< textUrlRanges[i + 1].0.lowerBound {
if let c = UnicodeScalar(text.character(at: j)) {
if isTextUrlInnerCharacter(c) {
if textUrlCharacters.contains(c) {
} else {
combine = false
break inner

View file

@ -1,6 +1,5 @@
import Foundation
import UIKit
import Postbox
import TelegramCore
import Display
import libprisma
@ -127,7 +126,7 @@ private func generateMessageSyntaxHighlight(spec: CachedMessageSyntaxHighlight.S
return MessageSyntaxHighlight(entities: entities)
}
public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], strings: PresentationStrings? = nil, dateTimeFormat: PresentationDateTimeFormat? = nil, baseColor: UIColor, linkColor: UIColor, baseQuoteTintColor: UIColor? = nil, baseQuoteSecondaryTintColor: UIColor? = nil, baseQuoteTertiaryTintColor: UIColor? = nil, codeBlockTitleColor: UIColor? = nil, codeBlockAccentColor: UIColor? = nil, codeBlockBackgroundColor: UIColor? = nil, baseFont: UIFont, linkFont: UIFont, boldFont: UIFont, italicFont: UIFont, boldItalicFont: UIFont, fixedFont: UIFont, blockQuoteFont: UIFont, underlineLinks: Bool = true, external: Bool = false, message: Message?, entityFiles: [MediaId: TelegramMediaFile] = [:], adjustQuoteFontSize: Bool = false, cachedMessageSyntaxHighlight: CachedMessageSyntaxHighlight? = nil, paragraphAlignment: NSTextAlignment? = nil) -> NSAttributedString {
public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEntity], strings: PresentationStrings? = nil, dateTimeFormat: PresentationDateTimeFormat? = nil, baseColor: UIColor, linkColor: UIColor, baseQuoteTintColor: UIColor? = nil, baseQuoteSecondaryTintColor: UIColor? = nil, baseQuoteTertiaryTintColor: UIColor? = nil, codeBlockTitleColor: UIColor? = nil, codeBlockAccentColor: UIColor? = nil, codeBlockBackgroundColor: UIColor? = nil, baseFont: UIFont, linkFont: UIFont, boldFont: UIFont, italicFont: UIFont, boldItalicFont: UIFont, fixedFont: UIFont, blockQuoteFont: UIFont, underlineLinks: Bool = true, external: Bool = false, message: EngineRawMessage?, entityFiles: [EngineMedia.Id: TelegramMediaFile] = [:], adjustQuoteFontSize: Bool = false, cachedMessageSyntaxHighlight: CachedMessageSyntaxHighlight? = nil, paragraphAlignment: NSTextAlignment? = nil) -> NSAttributedString {
let baseQuoteTintColor = baseQuoteTintColor ?? baseColor
var nsString: NSString?
@ -380,7 +379,7 @@ public func stringWithAppliedEntities(_ text: String, entities: [MessageTextEnti
addFontAttributes(range, .smaller)
}
case let .CustomEmoji(_, fileId):
let mediaId = MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)
let mediaId = EngineMedia.Id(namespace: Namespaces.Media.CloudFile, id: fileId)
var emojiFile: TelegramMediaFile?
if let file = message?.associatedMedia[mediaId] as? TelegramMediaFile {
emojiFile = file
@ -662,7 +661,7 @@ public func asyncUpdateMessageSyntaxHighlight(engine: TelegramEngine, messageId:
}
}
if let entry = CodableEntry(CachedMessageSyntaxHighlight(values: updated)) {
if let entry = EngineCodableEntry(CachedMessageSyntaxHighlight(values: updated)) {
return engine.messages.storeLocallyDerivedData(messageId: messageId, data: ["code": entry]).start(completed: {
subscriber.putCompletion()
})