mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Various improvements
This commit is contained in:
@@ -985,6 +985,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
|
||||
private var cachedChatListText: (String, String)?
|
||||
private var cachedChatListSearchResult: CachedChatListSearchResult?
|
||||
private var cachedChatListQuoteSearchResult: CachedChatListSearchResult?
|
||||
private var cachedCustomTextEntities: CachedCustomTextEntities?
|
||||
|
||||
var layoutParams: (ChatListItem, first: Bool, last: Bool, firstWithHeader: Bool, nextIsPinned: Bool, ListViewItemLayoutParams, countersSize: CGFloat)?
|
||||
@@ -1585,6 +1586,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
let currentItem = self.layoutParams?.0
|
||||
let currentChatListText = self.cachedChatListText
|
||||
let currentChatListSearchResult = self.cachedChatListSearchResult
|
||||
let currentChatListQuoteSearchResult = self.cachedChatListQuoteSearchResult
|
||||
let currentCustomTextEntities = self.cachedCustomTextEntities
|
||||
|
||||
return { item, params, first, last, firstWithHeader, nextIsPinned in
|
||||
@@ -1869,6 +1871,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
|
||||
var chatListText: (String, String)?
|
||||
var chatListSearchResult: CachedChatListSearchResult?
|
||||
var chatListQuoteSearchResult: CachedChatListSearchResult?
|
||||
var customTextEntities: CachedCustomTextEntities?
|
||||
|
||||
let contentImageSide: CGFloat = max(10.0, min(20.0, floor(item.presentationData.fontSize.baseDisplaySize * 18.0 / 17.0)))
|
||||
@@ -2016,15 +2019,45 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
composedString = NSMutableAttributedString(attributedString: messageString)
|
||||
}
|
||||
|
||||
var composedReplyString: NSMutableAttributedString?
|
||||
if let searchQuery = item.interaction.searchTextHighightState {
|
||||
var quoteText: String?
|
||||
for attribute in message.attributes {
|
||||
if let attribute = attribute as? ReplyMessageAttribute {
|
||||
if let quote = attribute.quote {
|
||||
quoteText = quote.text
|
||||
}
|
||||
} else if let attribute = attribute as? QuotedReplyMessageAttribute {
|
||||
if let quote = attribute.quote {
|
||||
quoteText = quote.text
|
||||
}
|
||||
}
|
||||
}
|
||||
if let quoteText {
|
||||
let quoteString = foldLineBreaks(stringWithAppliedEntities(quoteText, entities: [], baseColor: theme.messageTextColor, linkColor: theme.messageTextColor, baseFont: textFont, linkFont: textFont, boldFont: textFont, italicFont: italicTextFont, boldItalicFont: textFont, fixedFont: textFont, blockQuoteFont: textFont, underlineLinks: false, message: nil))
|
||||
composedReplyString = NSMutableAttributedString(attributedString: quoteString)
|
||||
}
|
||||
|
||||
if let cached = currentChatListSearchResult, cached.matches(text: composedString.string, searchQuery: searchQuery) {
|
||||
chatListSearchResult = cached
|
||||
} else {
|
||||
let (ranges, text) = findSubstringRanges(in: composedString.string, query: searchQuery)
|
||||
chatListSearchResult = CachedChatListSearchResult(text: text, searchQuery: searchQuery, resultRanges: ranges)
|
||||
}
|
||||
|
||||
if let composedReplyString {
|
||||
if let cached = currentChatListQuoteSearchResult, cached.matches(text: composedReplyString.string, searchQuery: searchQuery) {
|
||||
chatListQuoteSearchResult = cached
|
||||
} else {
|
||||
let (ranges, text) = findSubstringRanges(in: composedReplyString.string, query: searchQuery)
|
||||
chatListQuoteSearchResult = CachedChatListSearchResult(text: text, searchQuery: searchQuery, resultRanges: ranges)
|
||||
}
|
||||
} else {
|
||||
chatListQuoteSearchResult = nil
|
||||
}
|
||||
} else {
|
||||
chatListSearchResult = nil
|
||||
chatListQuoteSearchResult = nil
|
||||
}
|
||||
|
||||
if let chatListSearchResult = chatListSearchResult, let firstRange = chatListSearchResult.resultRanges.first {
|
||||
@@ -2053,6 +2086,34 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
composedString = composedString.attributedSubstring(from: NSMakeRange(leftOrigin, composedString.length - leftOrigin)).mutableCopy() as! NSMutableAttributedString
|
||||
composedString.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: textFont, NSAttributedString.Key.foregroundColor: theme.messageTextColor]), at: 0)
|
||||
}
|
||||
} else if var composedReplyString, let chatListQuoteSearchResult, let firstRange = chatListQuoteSearchResult.resultRanges.first {
|
||||
for range in chatListQuoteSearchResult.resultRanges {
|
||||
let stringRange = NSRange(range, in: chatListQuoteSearchResult.text)
|
||||
if stringRange.location >= 0 && stringRange.location + stringRange.length <= composedReplyString.length {
|
||||
var stringRange = stringRange
|
||||
if stringRange.location > composedReplyString.length {
|
||||
continue
|
||||
} else if stringRange.location + stringRange.length > composedReplyString.length {
|
||||
stringRange.length = composedReplyString.length - stringRange.location
|
||||
}
|
||||
composedReplyString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: stringRange)
|
||||
}
|
||||
}
|
||||
|
||||
let firstRangeOrigin = chatListQuoteSearchResult.text.distance(from: chatListQuoteSearchResult.text.startIndex, to: firstRange.lowerBound)
|
||||
if firstRangeOrigin > 24 {
|
||||
var leftOrigin: Int = 0
|
||||
(composedReplyString.string as NSString).enumerateSubstrings(in: NSMakeRange(0, firstRangeOrigin), options: [.byWords, .reverse]) { (str, range1, _, _) in
|
||||
let distanceFromEnd = firstRangeOrigin - range1.location
|
||||
if (distanceFromEnd > 12 || range1.location == 0) && leftOrigin == 0 {
|
||||
leftOrigin = range1.location
|
||||
}
|
||||
}
|
||||
composedReplyString = composedReplyString.attributedSubstring(from: NSMakeRange(leftOrigin, composedReplyString.length - leftOrigin)).mutableCopy() as! NSMutableAttributedString
|
||||
composedReplyString.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: textFont, NSAttributedString.Key.foregroundColor: theme.messageTextColor]), at: 0)
|
||||
}
|
||||
|
||||
composedString = composedReplyString
|
||||
}
|
||||
|
||||
attributedText = composedString
|
||||
@@ -2712,6 +2773,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
strongSelf.currentItemHeight = itemHeight
|
||||
strongSelf.cachedChatListText = chatListText
|
||||
strongSelf.cachedChatListSearchResult = chatListSearchResult
|
||||
strongSelf.cachedChatListQuoteSearchResult = chatListQuoteSearchResult
|
||||
strongSelf.cachedCustomTextEntities = customTextEntities
|
||||
strongSelf.onlineIsVoiceChat = onlineIsVoiceChat
|
||||
|
||||
|
||||
Reference in New Issue
Block a user