mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Search filters fixes
This commit is contained in:
parent
c54dfcce23
commit
6789c8b486
@ -21,7 +21,7 @@ public enum ChatListSearchItemHeaderType {
|
|||||||
case chats
|
case chats
|
||||||
case chatTypes
|
case chatTypes
|
||||||
case faq
|
case faq
|
||||||
case messages(Int32)
|
case messages
|
||||||
|
|
||||||
fileprivate func title(strings: PresentationStrings) -> String {
|
fileprivate func title(strings: PresentationStrings) -> String {
|
||||||
switch self {
|
switch self {
|
||||||
@ -57,8 +57,8 @@ public enum ChatListSearchItemHeaderType {
|
|||||||
return strings.ChatList_ChatTypesSection
|
return strings.ChatList_ChatTypesSection
|
||||||
case .faq:
|
case .faq:
|
||||||
return strings.Settings_FrequentlyAskedQuestions
|
return strings.Settings_FrequentlyAskedQuestions
|
||||||
case let .messages(count):
|
case let .messages:
|
||||||
return strings.ChatList_Search_Messages(count)
|
return strings.DialogList_SearchSectionMessages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.chatListDisplayNode.requestOpenMessageFromSearch = { [weak self] peer, messageId in
|
self.chatListDisplayNode.requestOpenMessageFromSearch = { [weak self] peer, messageId, deactivateOnAction in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
strongSelf.openMessageFromSearchDisposable.set((storedMessageFromSearchPeer(account: strongSelf.context.account, peer: peer)
|
strongSelf.openMessageFromSearchDisposable.set((storedMessageFromSearchPeer(account: strongSelf.context.account, peer: peer)
|
||||||
|> deliverOnMainQueue).start(next: { [weak strongSelf] actualPeerId in
|
|> deliverOnMainQueue).start(next: { [weak strongSelf] actualPeerId in
|
||||||
@ -670,7 +670,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
|
|||||||
scrollToEndIfExists = true
|
scrollToEndIfExists = true
|
||||||
}
|
}
|
||||||
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(actualPeerId), subject: .message(id: messageId, highlight: true), purposefulAction: {
|
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(actualPeerId), subject: .message(id: messageId, highlight: true), purposefulAction: {
|
||||||
self?.deactivateSearch(animated: false)
|
if deactivateOnAction {
|
||||||
|
self?.deactivateSearch(animated: false)
|
||||||
|
}
|
||||||
}, scrollToEndIfExists: scrollToEndIfExists, options: strongSelf.groupId == PeerGroupId.root ? [.removeOnMasterDetails] : []))
|
}, scrollToEndIfExists: scrollToEndIfExists, options: strongSelf.groupId == PeerGroupId.root ? [.removeOnMasterDetails] : []))
|
||||||
strongSelf.chatListDisplayNode.containerNode.currentItemNode.clearHighlightAnimated(true)
|
strongSelf.chatListDisplayNode.containerNode.currentItemNode.clearHighlightAnimated(true)
|
||||||
}
|
}
|
||||||
|
@ -1001,7 +1001,7 @@ final class ChatListControllerNode: ASDisplayNode {
|
|||||||
var requestDeactivateSearch: (() -> Void)?
|
var requestDeactivateSearch: (() -> Void)?
|
||||||
var requestOpenPeerFromSearch: ((Peer, Bool) -> Void)?
|
var requestOpenPeerFromSearch: ((Peer, Bool) -> Void)?
|
||||||
var requestOpenRecentPeerOptions: ((Peer) -> Void)?
|
var requestOpenRecentPeerOptions: ((Peer) -> Void)?
|
||||||
var requestOpenMessageFromSearch: ((Peer, MessageId) -> Void)?
|
var requestOpenMessageFromSearch: ((Peer, MessageId, Bool) -> Void)?
|
||||||
var requestAddContact: ((String) -> Void)?
|
var requestAddContact: ((String) -> Void)?
|
||||||
var peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?
|
var peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?
|
||||||
var dismissSelfIfCompletedPresentation: (() -> Void)?
|
var dismissSelfIfCompletedPresentation: (() -> Void)?
|
||||||
@ -1160,9 +1160,9 @@ final class ChatListControllerNode: ASDisplayNode {
|
|||||||
}, openDisabledPeer: { _ in
|
}, openDisabledPeer: { _ in
|
||||||
}, openRecentPeerOptions: { [weak self] peer in
|
}, openRecentPeerOptions: { [weak self] peer in
|
||||||
self?.requestOpenRecentPeerOptions?(peer)
|
self?.requestOpenRecentPeerOptions?(peer)
|
||||||
}, openMessage: { [weak self] peer, messageId in
|
}, openMessage: { [weak self] peer, messageId, deactivateOnAction in
|
||||||
if let requestOpenMessageFromSearch = self?.requestOpenMessageFromSearch {
|
if let requestOpenMessageFromSearch = self?.requestOpenMessageFromSearch {
|
||||||
requestOpenMessageFromSearch(peer, messageId)
|
requestOpenMessageFromSearch(peer, messageId, deactivateOnAction)
|
||||||
}
|
}
|
||||||
}, addContact: { [weak self] phoneNumber in
|
}, addContact: { [weak self] phoneNumber in
|
||||||
if let requestAddContact = self?.requestAddContact {
|
if let requestAddContact = self?.requestAddContact {
|
||||||
|
@ -82,7 +82,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
|
|||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
private let peersFilter: ChatListNodePeersFilter
|
private let peersFilter: ChatListNodePeersFilter
|
||||||
private var interaction: ChatListSearchInteraction?
|
private var interaction: ChatListSearchInteraction?
|
||||||
private let openMessage: (Peer, MessageId) -> Void
|
private let openMessage: (Peer, MessageId, Bool) -> Void
|
||||||
private let navigationController: NavigationController?
|
private let navigationController: NavigationController?
|
||||||
|
|
||||||
let filterContainerNode: ChatListSearchFiltersContainerNode
|
let filterContainerNode: ChatListSearchFiltersContainerNode
|
||||||
@ -122,7 +122,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
|
|||||||
|
|
||||||
private var validLayout: (ContainerViewLayout, CGFloat)?
|
private var validLayout: (ContainerViewLayout, CGFloat)?
|
||||||
|
|
||||||
public init(context: AccountContext, filter: ChatListNodePeersFilter, groupId: PeerGroupId, openPeer originalOpenPeer: @escaping (Peer, Bool) -> Void, openDisabledPeer: @escaping (Peer) -> Void, openRecentPeerOptions: @escaping (Peer) -> Void, openMessage originalOpenMessage: @escaping (Peer, MessageId) -> Void, addContact: ((String) -> Void)?, peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?, present: @escaping (ViewController, Any?) -> Void, presentInGlobalOverlay: @escaping (ViewController, Any?) -> Void, navigationController: NavigationController?) {
|
public init(context: AccountContext, filter: ChatListNodePeersFilter, groupId: PeerGroupId, openPeer originalOpenPeer: @escaping (Peer, Bool) -> Void, openDisabledPeer: @escaping (Peer) -> Void, openRecentPeerOptions: @escaping (Peer) -> Void, openMessage originalOpenMessage: @escaping (Peer, MessageId, Bool) -> Void, addContact: ((String) -> Void)?, peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?, present: @escaping (ViewController, Any?) -> Void, presentInGlobalOverlay: @escaping (ViewController, Any?) -> Void, navigationController: NavigationController?) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.peersFilter = filter
|
self.peersFilter = filter
|
||||||
self.navigationController = navigationController
|
self.navigationController = navigationController
|
||||||
@ -150,7 +150,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
|
|||||||
}, openDisabledPeer: { peer in
|
}, openDisabledPeer: { peer in
|
||||||
openDisabledPeer(peer)
|
openDisabledPeer(peer)
|
||||||
}, openMessage: { peer, messageId in
|
}, openMessage: { peer, messageId in
|
||||||
originalOpenMessage(peer, messageId)
|
originalOpenMessage(peer, messageId, true)
|
||||||
if peer.id.namespace != Namespaces.Peer.SecretChat {
|
if peer.id.namespace != Namespaces.Peer.SecretChat {
|
||||||
addAppLogEvent(postbox: context.account.postbox, type: "search_global_open_message", peerId: peer.id, data: .dictionary(["msg_id": .number(Double(messageId.id))]))
|
addAppLogEvent(postbox: context.account.postbox, type: "search_global_open_message", peerId: peer.id, data: .dictionary(["msg_id": .number(Double(messageId.id))]))
|
||||||
}
|
}
|
||||||
@ -627,7 +627,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
|
|||||||
})))
|
})))
|
||||||
items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { [weak self] c, _ in
|
items.append(.action(ContextMenuActionItem(text: self.presentationData.strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { [weak self] c, _ in
|
||||||
c.dismiss(completion: { [weak self] in
|
c.dismiss(completion: { [weak self] in
|
||||||
self?.openMessage(message.peers[message.id.peerId]!, message.id)
|
self?.openMessage(message.peers[message.id.peerId]!, message.id, false)
|
||||||
})
|
})
|
||||||
})))
|
})))
|
||||||
|
|
||||||
@ -673,7 +673,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
|
|||||||
|
|
||||||
items.append(.action(ContextMenuActionItem(text: strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { c, f in
|
items.append(.action(ContextMenuActionItem(text: strings.SharedMedia_ViewInChat, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/GoToMessage"), color: theme.contextMenu.primaryColor) }, action: { c, f in
|
||||||
c.dismiss(completion: {
|
c.dismiss(completion: {
|
||||||
self?.openMessage(message.peers[message.id.peerId]!, message.id)
|
self?.openMessage(message.peers[message.id.peerId]!, message.id, false)
|
||||||
})
|
})
|
||||||
})))
|
})))
|
||||||
|
|
||||||
|
@ -505,7 +505,7 @@ public enum ChatListSearchEntry: Comparable, Identifiable {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
case let .message(message, peer, readState, presentationData, totalCount, selected, displayCustomHeader):
|
case let .message(message, peer, readState, presentationData, totalCount, selected, displayCustomHeader):
|
||||||
let header = ChatListSearchItemHeader(type: .messages(totalCount), theme: presentationData.theme, strings: presentationData.strings, actionTitle: nil, action: nil)
|
let header = ChatListSearchItemHeader(type: .messages, theme: presentationData.theme, strings: presentationData.strings, actionTitle: nil, action: nil)
|
||||||
let selection: ChatHistoryMessageSelection = selected.flatMap { .selectable(selected: $0) } ?? .none
|
let selection: ChatHistoryMessageSelection = selected.flatMap { .selectable(selected: $0) } ?? .none
|
||||||
if let tagMask = tagMask, tagMask != .photoOrVideo {
|
if let tagMask = tagMask, tagMask != .photoOrVideo {
|
||||||
return ListMessageItem(presentationData: ChatPresentationData(theme: ChatPresentationThemeData(theme: presentationData.theme, wallpaper: .builtin(WallpaperSettings())), fontSize: presentationData.fontSize, strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, disableAnimations: presentationData.disableAnimations, largeEmoji: false, chatBubbleCorners: PresentationChatBubbleCorners(mainRadius: 0.0, auxiliaryRadius: 0.0, mergeBubbleCorners: false)), context: context, chatLocation: .peer(peer.peerId), interaction: listInteraction, message: message, selection: selection, displayHeader: enableHeaders && !displayCustomHeader, customHeader: nil, hintIsLink: tagMask == .webPage, isGlobalSearchResult: true)
|
return ListMessageItem(presentationData: ChatPresentationData(theme: ChatPresentationThemeData(theme: presentationData.theme, wallpaper: .builtin(WallpaperSettings())), fontSize: presentationData.fontSize, strings: presentationData.strings, dateTimeFormat: presentationData.dateTimeFormat, nameDisplayOrder: presentationData.nameDisplayOrder, disableAnimations: presentationData.disableAnimations, largeEmoji: false, chatBubbleCorners: PresentationChatBubbleCorners(mainRadius: 0.0, auxiliaryRadius: 0.0, mergeBubbleCorners: false)), context: context, chatLocation: .peer(peer.peerId), interaction: listInteraction, message: message, selection: selection, displayHeader: enableHeaders && !displayCustomHeader, customHeader: nil, hintIsLink: tagMask == .webPage, isGlobalSearchResult: true)
|
||||||
@ -2260,7 +2260,7 @@ private final class ChatListSearchShimmerNode: ASDisplayNode {
|
|||||||
gesture?.cancel()
|
gesture?.cancel()
|
||||||
}, present: { _ in })
|
}, present: { _ in })
|
||||||
|
|
||||||
let items = (0 ..< 1).compactMap { _ -> ListViewItem? in
|
let items = (0 ..< 2).compactMap { _ -> ListViewItem? in
|
||||||
switch key {
|
switch key {
|
||||||
case .chats:
|
case .chats:
|
||||||
return ChatListItem(presentationData: chatListPresentationData, context: context, peerGroupId: .root, filterData: nil, index: ChatListIndex(pinningIndex: 0, messageIndex: MessageIndex(id: MessageId(peerId: peer1.id, namespace: 0, id: 0), timestamp: timestamp1)), content: .peer(messages: [Message(stableId: 0, stableVersion: 0, id: MessageId(peerId: peer1.id, namespace: 0, id: 0), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, threadId: nil, timestamp: timestamp1, flags: [], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: peer1, text: "Text", attributes: [], media: [], peers: peers, associatedMessages: SimpleDictionary(), associatedMessageIds: [])], peer: RenderedPeer(peer: peer1), combinedReadState: CombinedPeerReadState(states: [(Namespaces.Message.Cloud, PeerReadState.idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false))]), isRemovedFromTotalUnreadCount: false, presence: nil, summaryInfo: ChatListMessageTagSummaryInfo(tagSummaryCount: nil, actionsSummaryCount: nil), embeddedState: nil, inputActivities: nil, promoInfo: nil, ignoreUnreadBadge: false, displayAsMessage: false, hasFailedMessages: false), editing: false, hasActiveRevealControls: false, selected: false, header: nil, enableContextActions: false, hiddenOffset: false, interaction: interaction)
|
return ChatListItem(presentationData: chatListPresentationData, context: context, peerGroupId: .root, filterData: nil, index: ChatListIndex(pinningIndex: 0, messageIndex: MessageIndex(id: MessageId(peerId: peer1.id, namespace: 0, id: 0), timestamp: timestamp1)), content: .peer(messages: [Message(stableId: 0, stableVersion: 0, id: MessageId(peerId: peer1.id, namespace: 0, id: 0), globallyUniqueId: nil, groupingKey: nil, groupInfo: nil, threadId: nil, timestamp: timestamp1, flags: [], tags: [], globalTags: [], localTags: [], forwardInfo: nil, author: peer1, text: "Text", attributes: [], media: [], peers: peers, associatedMessages: SimpleDictionary(), associatedMessageIds: [])], peer: RenderedPeer(peer: peer1), combinedReadState: CombinedPeerReadState(states: [(Namespaces.Message.Cloud, PeerReadState.idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false))]), isRemovedFromTotalUnreadCount: false, presence: nil, summaryInfo: ChatListMessageTagSummaryInfo(tagSummaryCount: nil, actionsSummaryCount: nil), embeddedState: nil, inputActivities: nil, promoInfo: nil, ignoreUnreadBadge: false, displayAsMessage: false, hasFailedMessages: false), editing: false, hasActiveRevealControls: false, selected: false, header: nil, enableContextActions: false, hiddenOffset: false, interaction: interaction)
|
||||||
|
@ -964,7 +964,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
|||||||
|
|
||||||
attributedText = NSAttributedString(string: foldLineBreaks(embeddedState.text.string.replacingOccurrences(of: "\n\n", with: " ")), font: textFont, textColor: theme.messageTextColor)
|
attributedText = NSAttributedString(string: foldLineBreaks(embeddedState.text.string.replacingOccurrences(of: "\n\n", with: " ")), font: textFont, textColor: theme.messageTextColor)
|
||||||
} else if let message = messages.last {
|
} else if let message = messages.last {
|
||||||
let composedString: NSMutableAttributedString
|
var composedString: NSMutableAttributedString
|
||||||
if let inlineAuthorPrefix = inlineAuthorPrefix {
|
if let inlineAuthorPrefix = inlineAuthorPrefix {
|
||||||
composedString = NSMutableAttributedString()
|
composedString = NSMutableAttributedString()
|
||||||
composedString.append(NSAttributedString(string: "\(inlineAuthorPrefix): ", font: textFont, textColor: theme.titleColor))
|
composedString.append(NSAttributedString(string: "\(inlineAuthorPrefix): ", font: textFont, textColor: theme.titleColor))
|
||||||
@ -984,13 +984,26 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
|||||||
chatListSearchResult = nil
|
chatListSearchResult = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if let chatListSearchResult = chatListSearchResult {
|
if let chatListSearchResult = chatListSearchResult, let firstRange = chatListSearchResult.resultRanges.first {
|
||||||
for range in chatListSearchResult.resultRanges {
|
for range in chatListSearchResult.resultRanges {
|
||||||
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
||||||
if stringRange.location >= 0 && stringRange.location + stringRange.length <= composedString.length {
|
if stringRange.location >= 0 && stringRange.location + stringRange.length <= composedString.length {
|
||||||
composedString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: stringRange)
|
composedString.addAttribute(.foregroundColor, value: theme.messageHighlightedTextColor, range: stringRange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let firstRangeOrigin = chatListSearchResult.text.distance(from: chatListSearchResult.text.startIndex, to: firstRange.lowerBound)
|
||||||
|
if firstRangeOrigin > 24 {
|
||||||
|
var leftOrigin: Int = 0
|
||||||
|
(composedString.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attributedText = composedString
|
attributedText = composedString
|
||||||
@ -2061,19 +2074,3 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func foldLineBreaks(_ text: String) -> String {
|
|
||||||
let lines = text.split { $0.isNewline }
|
|
||||||
var result = ""
|
|
||||||
for line in lines {
|
|
||||||
if line.isEmpty {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if result.isEmpty {
|
|
||||||
result += line
|
|
||||||
} else {
|
|
||||||
result += " " + line
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
@ -43,7 +43,7 @@ public func findSubstringRanges(in string: String, query: String) -> ([Range<Str
|
|||||||
if length > 0 {
|
if length > 0 {
|
||||||
let difference = abs(length - Double(count))
|
let difference = abs(length - Double(count))
|
||||||
let rating = difference / length
|
let rating = difference / length
|
||||||
if rating < 0.33 {
|
if rating < 0.37 {
|
||||||
var range = range
|
var range = range
|
||||||
if hasLeadingSymbol && range.lowerBound > searchRange.lowerBound {
|
if hasLeadingSymbol && range.lowerBound > searchRange.lowerBound {
|
||||||
range = text.index(before: range.lowerBound)..<range.upperBound
|
range = text.index(before: range.lowerBound)..<range.upperBound
|
||||||
|
@ -193,7 +193,7 @@ public final class ListMessageFileItemNode: ListMessageNode {
|
|||||||
private var contentSizeValue: CGSize?
|
private var contentSizeValue: CGSize?
|
||||||
private var currentLeftOffset: CGFloat = 0.0
|
private var currentLeftOffset: CGFloat = 0.0
|
||||||
|
|
||||||
private var cachedChatListSearchResult: CachedChatListSearchResult?
|
private var cachedSearchResult: CachedChatListSearchResult?
|
||||||
|
|
||||||
public required init() {
|
public required init() {
|
||||||
self.contextSourceNode = ContextExtractedContentContainingNode()
|
self.contextSourceNode = ContextExtractedContentContainingNode()
|
||||||
@ -345,7 +345,7 @@ public final class ListMessageFileItemNode: ListMessageNode {
|
|||||||
let currentMedia = self.currentMedia
|
let currentMedia = self.currentMedia
|
||||||
let currentMessage = self.message
|
let currentMessage = self.message
|
||||||
let currentIconImage = self.currentIconImage
|
let currentIconImage = self.currentIconImage
|
||||||
let currentChatListSearchResult = self.cachedChatListSearchResult
|
let currentSearchResult = self.cachedSearchResult
|
||||||
|
|
||||||
let currentItem = self.appliedItem
|
let currentItem = self.appliedItem
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ public final class ListMessageFileItemNode: ListMessageNode {
|
|||||||
let descriptionFont = Font.regular(floor(item.presentationData.fontSize.baseDisplaySize * 14.0 / 17.0))
|
let descriptionFont = Font.regular(floor(item.presentationData.fontSize.baseDisplaySize * 14.0 / 17.0))
|
||||||
let dateFont = Font.regular(floor(item.presentationData.fontSize.itemListBaseFontSize * 14.0 / 17.0))
|
let dateFont = Font.regular(floor(item.presentationData.fontSize.itemListBaseFontSize * 14.0 / 17.0))
|
||||||
|
|
||||||
var leftInset: CGFloat = 65.0 + params.leftInset
|
let leftInset: CGFloat = 65.0 + params.leftInset
|
||||||
let rightInset: CGFloat = 8.0 + params.rightInset
|
let rightInset: CGFloat = 8.0 + params.rightInset
|
||||||
|
|
||||||
var leftOffset: CGFloat = 0.0
|
var leftOffset: CGFloat = 0.0
|
||||||
@ -579,11 +579,13 @@ public final class ListMessageFileItemNode: ListMessageNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var chatListSearchResult: CachedChatListSearchResult?
|
var chatListSearchResult: CachedChatListSearchResult?
|
||||||
|
let messageText = foldLineBreaks(item.message.text)
|
||||||
|
|
||||||
if let searchQuery = item.interaction.searchTextHighightState {
|
if let searchQuery = item.interaction.searchTextHighightState {
|
||||||
if let cached = currentChatListSearchResult, cached.matches(text: item.message.text, searchQuery: searchQuery) {
|
if let cached = currentSearchResult, cached.matches(text: messageText, searchQuery: searchQuery) {
|
||||||
chatListSearchResult = cached
|
chatListSearchResult = cached
|
||||||
} else {
|
} else {
|
||||||
let (ranges, text) = findSubstringRanges(in: item.message.text, query: searchQuery)
|
let (ranges, text) = findSubstringRanges(in: messageText, query: searchQuery)
|
||||||
chatListSearchResult = CachedChatListSearchResult(text: text, searchQuery: searchQuery, resultRanges: ranges)
|
chatListSearchResult = CachedChatListSearchResult(text: text, searchQuery: searchQuery, resultRanges: ranges)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -591,21 +593,29 @@ public final class ListMessageFileItemNode: ListMessageNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var captionText: NSMutableAttributedString?
|
var captionText: NSMutableAttributedString?
|
||||||
if let chatListSearchResult = chatListSearchResult, !chatListSearchResult.resultRanges.isEmpty, let firstRange = chatListSearchResult.resultRanges.first {
|
if let chatListSearchResult = chatListSearchResult, let firstRange = chatListSearchResult.resultRanges.first {
|
||||||
let text = NSMutableAttributedString(string: item.message.text, font: descriptionFont, textColor: item.presentationData.theme.theme.list.itemSecondaryTextColor)
|
var text = NSMutableAttributedString(string: messageText, font: descriptionFont, textColor: item.presentationData.theme.theme.list.itemSecondaryTextColor)
|
||||||
for range in chatListSearchResult.resultRanges {
|
for range in chatListSearchResult.resultRanges {
|
||||||
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
||||||
if stringRange.location >= 0 && stringRange.location + stringRange.length <= text.length {
|
if stringRange.location >= 0 && stringRange.location + stringRange.length <= text.length {
|
||||||
text.addAttribute(.foregroundColor, value: item.presentationData.theme.theme.chatList.messageHighlightedTextColor, range: stringRange)
|
text.addAttribute(.foregroundColor, value: item.presentationData.theme.theme.chatList.messageHighlightedTextColor, range: stringRange)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
captionText = text
|
|
||||||
|
|
||||||
let firstRangeOrigin = chatListSearchResult.text.distance(from: chatListSearchResult.text.startIndex, to: firstRange.lowerBound)
|
let firstRangeOrigin = chatListSearchResult.text.distance(from: chatListSearchResult.text.startIndex, to: firstRange.lowerBound)
|
||||||
if firstRangeOrigin > 20 {
|
if firstRangeOrigin > 24 {
|
||||||
captionText = text.attributedSubstring(from: NSMakeRange(firstRangeOrigin - 10, text.length - firstRangeOrigin + 10)).mutableCopy() as? NSMutableAttributedString
|
var leftOrigin: Int = 0
|
||||||
captionText?.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: descriptionFont, NSAttributedString.Key.foregroundColor: item.presentationData.theme.theme.list.itemSecondaryTextColor]), at: 0)
|
(text.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text = text.attributedSubstring(from: NSMakeRange(leftOrigin, text.length - leftOrigin)).mutableCopy() as! NSMutableAttributedString
|
||||||
|
text.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: descriptionFont, NSAttributedString.Key.foregroundColor: item.presentationData.theme.theme.list.itemSecondaryTextColor]), at: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
captionText = text
|
||||||
}
|
}
|
||||||
|
|
||||||
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||||
@ -616,7 +626,7 @@ public final class ListMessageFileItemNode: ListMessageNode {
|
|||||||
|
|
||||||
let (titleNodeLayout, titleNodeApply) = titleNodeMakeLayout(TextNodeLayoutArguments(attributedString: titleText, backgroundColor: nil, maximumNumberOfLines: 2, truncationType: .middle, constrainedSize: CGSize(width: params.width - leftInset - leftOffset - rightInset - dateNodeLayout.size.width - 4.0, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
let (titleNodeLayout, titleNodeApply) = titleNodeMakeLayout(TextNodeLayoutArguments(attributedString: titleText, backgroundColor: nil, maximumNumberOfLines: 2, truncationType: .middle, constrainedSize: CGSize(width: params.width - leftInset - leftOffset - rightInset - dateNodeLayout.size.width - 4.0, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||||
|
|
||||||
let (textNodeLayout, textNodeApply) = textNodeMakeLayout(TextNodeLayoutArguments(attributedString: captionText, backgroundColor: nil, maximumNumberOfLines: 3, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - rightInset - 30.0, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
let (textNodeLayout, textNodeApply) = textNodeMakeLayout(TextNodeLayoutArguments(attributedString: captionText, backgroundColor: nil, maximumNumberOfLines: 2, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - rightInset - 30.0, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||||
|
|
||||||
let (descriptionNodeLayout, descriptionNodeApply) = descriptionNodeMakeLayout(TextNodeLayoutArguments(attributedString: descriptionText, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - rightInset - 30.0, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
let (descriptionNodeLayout, descriptionNodeApply) = descriptionNodeMakeLayout(TextNodeLayoutArguments(attributedString: descriptionText, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - rightInset - 30.0, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||||
|
|
||||||
|
@ -454,7 +454,8 @@ public final class ListMessageSnippetItemNode: ListMessageNode {
|
|||||||
chatListSearchResult = nil
|
chatListSearchResult = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if let chatListSearchResult = chatListSearchResult, !chatListSearchResult.resultRanges.isEmpty, let firstRange = chatListSearchResult.resultRanges.first {
|
var descriptionMaxNumberOfLines = 3
|
||||||
|
if let chatListSearchResult = chatListSearchResult, let firstRange = chatListSearchResult.resultRanges.first {
|
||||||
var text = NSMutableAttributedString(string: item.message.text, font: descriptionFont, textColor: item.presentationData.theme.theme.list.itemSecondaryTextColor)
|
var text = NSMutableAttributedString(string: item.message.text, font: descriptionFont, textColor: item.presentationData.theme.theme.list.itemSecondaryTextColor)
|
||||||
for range in chatListSearchResult.resultRanges {
|
for range in chatListSearchResult.resultRanges {
|
||||||
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
let stringRange = NSRange(range, in: chatListSearchResult.text)
|
||||||
@ -464,12 +465,20 @@ public final class ListMessageSnippetItemNode: ListMessageNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let firstRangeOrigin = chatListSearchResult.text.distance(from: chatListSearchResult.text.startIndex, to: firstRange.lowerBound)
|
let firstRangeOrigin = chatListSearchResult.text.distance(from: chatListSearchResult.text.startIndex, to: firstRange.lowerBound)
|
||||||
if firstRangeOrigin > 20 {
|
if firstRangeOrigin > 24 {
|
||||||
text = text.attributedSubstring(from: NSMakeRange(firstRangeOrigin - 10, text.length - firstRangeOrigin + 10)).mutableCopy() as! NSMutableAttributedString
|
var leftOrigin: Int = 0
|
||||||
|
(text.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
text = text.attributedSubstring(from: NSMakeRange(leftOrigin, text.length - leftOrigin)).mutableCopy() as! NSMutableAttributedString
|
||||||
text.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: descriptionFont, NSAttributedString.Key.foregroundColor: item.presentationData.theme.theme.list.itemSecondaryTextColor]), at: 0)
|
text.insert(NSAttributedString(string: "\u{2026}", attributes: [NSAttributedString.Key.font: descriptionFont, NSAttributedString.Key.foregroundColor: item.presentationData.theme.theme.list.itemSecondaryTextColor]), at: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptionText = text
|
descriptionText = text
|
||||||
|
descriptionMaxNumberOfLines = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||||
@ -480,7 +489,7 @@ public final class ListMessageSnippetItemNode: ListMessageNode {
|
|||||||
|
|
||||||
let (titleNodeLayout, titleNodeApply) = titleNodeMakeLayout(TextNodeLayoutArguments(attributedString: title, backgroundColor: nil, maximumNumberOfLines: 2, truncationType: .middle, constrainedSize: CGSize(width: params.width - leftInset - leftOffset - 8.0 - params.rightInset - 16.0 - dateNodeLayout.size.width, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
let (titleNodeLayout, titleNodeApply) = titleNodeMakeLayout(TextNodeLayoutArguments(attributedString: title, backgroundColor: nil, maximumNumberOfLines: 2, truncationType: .middle, constrainedSize: CGSize(width: params.width - leftInset - leftOffset - 8.0 - params.rightInset - 16.0 - dateNodeLayout.size.width, height: CGFloat.infinity), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||||
|
|
||||||
let (descriptionNodeLayout, descriptionNodeApply) = descriptionNodeMakeLayout(TextNodeLayoutArguments(attributedString: descriptionText, backgroundColor: nil, maximumNumberOfLines: 3, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - params.rightInset - 16.0 - 8.0, height: CGFloat.infinity), alignment: .natural, lineSpacing: 0.3, cutout: nil, insets: UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)))
|
let (descriptionNodeLayout, descriptionNodeApply) = descriptionNodeMakeLayout(TextNodeLayoutArguments(attributedString: descriptionText, backgroundColor: nil, maximumNumberOfLines: descriptionMaxNumberOfLines, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - params.rightInset - 16.0 - 8.0, height: CGFloat.infinity), alignment: .natural, lineSpacing: 0.3, cutout: nil, insets: UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)))
|
||||||
|
|
||||||
let (linkNodeLayout, linkNodeApply) = linkNodeMakeLayout(TextNodeLayoutArguments(attributedString: linkText, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - params.rightInset - 16.0 - 8.0, height: CGFloat.infinity), alignment: .natural, lineSpacing: 0.3, cutout: isInstantView ? TextNodeCutout(topLeft: CGSize(width: 14.0, height: 8.0)) : nil, insets: UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)))
|
let (linkNodeLayout, linkNodeApply) = linkNodeMakeLayout(TextNodeLayoutArguments(attributedString: linkText, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - params.rightInset - 16.0 - 8.0, height: CGFloat.infinity), alignment: .natural, lineSpacing: 0.3, cutout: isInstantView ? TextNodeCutout(topLeft: CGSize(width: 14.0, height: 8.0)) : nil, insets: UIEdgeInsets(top: 1.0, left: 1.0, bottom: 1.0, right: 1.0)))
|
||||||
var instantViewImage: UIImage?
|
var instantViewImage: UIImage?
|
||||||
|
@ -219,7 +219,7 @@ final class PeerSelectionControllerNode: ASDisplayNode {
|
|||||||
}, openDisabledPeer: { [weak self] peer in
|
}, openDisabledPeer: { [weak self] peer in
|
||||||
self?.requestOpenDisabledPeer?(peer)
|
self?.requestOpenDisabledPeer?(peer)
|
||||||
}, openRecentPeerOptions: { _ in
|
}, openRecentPeerOptions: { _ in
|
||||||
}, openMessage: { [weak self] peer, messageId in
|
}, openMessage: { [weak self] peer, messageId, _ in
|
||||||
if let requestOpenMessageFromSearch = self?.requestOpenMessageFromSearch {
|
if let requestOpenMessageFromSearch = self?.requestOpenMessageFromSearch {
|
||||||
requestOpenMessageFromSearch(peer, messageId)
|
requestOpenMessageFromSearch(peer, messageId)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user