Search filters fixes

This commit is contained in:
Ilya Laktyushin 2020-09-26 13:50:08 +03:00
parent f836ba1f09
commit 130cd724a3
4 changed files with 88 additions and 32 deletions

View File

@ -98,7 +98,6 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
private let searchQuery = Promise<String?>(nil)
private var searchOptionsValue: ChatListSearchOptions?
private let searchOptions = Promise<ChatListSearchOptions?>(nil)
private let searchDisposable = MetaDisposable()
private var presentationData: PresentationData
private var presentationDataDisposable: Disposable?
@ -155,7 +154,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
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))]))
}
}, openUrl: { url in
}, openUrl: { [weak self] url in
openUserGeneratedUrl(context: context, url: url, concealed: false, present: { c in
present(c, nil)
}, openResolved: { [weak self] resolved in
@ -329,7 +328,8 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
} else {
isGroup = false
}
suggestedFilters.append(.peer(peer.id, isGroup, peer.displayTitle(strings: self.presentationData.strings, displayOrder: self.presentationData.nameDisplayOrder), peer.compactDisplayTitle))
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
suggestedFilters.append(.peer(peer.id, isGroup, peer.displayTitle(strings: presentationData.strings, displayOrder: presentationData.nameDisplayOrder), peer.compactDisplayTitle))
}
}
return suggestedFilters
@ -375,7 +375,6 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
deinit {
self.activeActionDisposable.dispose()
self.searchDisposable.dispose()
self.presentationDataDisposable?.dispose()
self.suggestedFiltersDisposable.dispose()
}
@ -545,7 +544,18 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
transition.updateFrame(node: self.paneContainerNode, frame: CGRect(x: 0.0, y: topInset, width: layout.size.width, height: layout.size.height - topInset))
self.paneContainerNode.update(size: CGSize(width: layout.size.width, height: layout.size.height - topInset), sideInset: layout.safeInsets.left, bottomInset: layout.inputHeight ?? 0.0, visibleHeight: layout.size.height - topInset, presentationData: self.presentationData, transition: transition)
var bottomInset = layout.intrinsicInsets.bottom
if let inputHeight = layout.inputHeight {
bottomInset = inputHeight
} else {
if !layout.safeInsets.left.isZero {
bottomInset -= 34.0
} else {
bottomInset -= 49.0
}
}
self.paneContainerNode.update(size: CGSize(width: layout.size.width, height: layout.size.height - topInset), sideInset: layout.safeInsets.left, bottomInset: bottomInset, visibleHeight: layout.size.height - topInset, presentationData: self.presentationData, transition: transition)
}
private var currentMessages: ([PeerId: Peer], [MessageId: Message]) {
@ -713,7 +723,64 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
}
func deleteMessages(messageIds: Set<MessageId>?) {
let messageIds = messageIds ?? self.stateValue.selectedMessageIds
if let messageIds = messageIds ?? self.stateValue.selectedMessageIds, !messageIds.isEmpty {
self.activeActionDisposable.set((self.context.sharedContext.chatAvailableMessageActions(postbox: self.context.account.postbox, accountPeerId: self.context.account.peerId, messageIds: messageIds)
|> deliverOnMainQueue).start(next: { [weak self] actions in
if let strongSelf = self, !actions.options.isEmpty {
let actionSheet = ActionSheetController(presentationData: strongSelf.presentationData)
var items: [ActionSheetItem] = []
var personalPeerName: String?
var isChannel = false
// if let user = peer as? TelegramUser {
// personalPeerName = user.compactDisplayTitle
// } else if let channel = peer as? TelegramChannel, case .broadcast = channel.info {
// isChannel = true
// }
if actions.options.contains(.deleteGlobally) {
let globalTitle: String
if isChannel {
globalTitle = strongSelf.presentationData.strings.Conversation_DeleteMessagesForMe
} else if let personalPeerName = personalPeerName {
globalTitle = strongSelf.presentationData.strings.Conversation_DeleteMessagesFor(personalPeerName).0
} else {
globalTitle = strongSelf.presentationData.strings.Conversation_DeleteMessagesForEveryone
}
items.append(ActionSheetButtonItem(title: globalTitle, color: .destructive, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
if let strongSelf = self {
// strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone)
let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forEveryone).start()
}
}))
}
if actions.options.contains(.deleteLocally) {
var localOptionText = strongSelf.presentationData.strings.Conversation_DeleteMessagesForMe
// if strongSelf.context.account.peerId == strongSelf.peerId {
// if messageIds.count == 1 {
// localOptionText = strongSelf.presentationData.strings.Conversation_Moderate_Delete
// } else {
// localOptionText = strongSelf.presentationData.strings.Conversation_DeleteManyMessages
// }
// }
items.append(ActionSheetButtonItem(title: localOptionText, color: .destructive, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
if let strongSelf = self {
// strongSelf.headerNode.navigationButtonContainer.performAction?(.selectionDone)
let _ = deleteMessagesInteractively(account: strongSelf.context.account, messageIds: Array(messageIds), type: .forLocalPeer).start()
}
}))
}
actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [
ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in
actionSheet?.dismissAnimated()
})
])])
strongSelf.view.endEditing(true)
strongSelf.present?(actionSheet, nil)
}
}))
}
}
func forwardMessages(messageIds: Set<MessageId>?) {

View File

@ -406,8 +406,7 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {
}
if let selectedFrame = selectedFrame {
let wasAdded = self.selectedLineNode.isHidden
self.selectedLineNode.isHidden = false
let wasAdded = self.selectedLineNode.alpha < 1.0
let lineFrame = CGRect(origin: CGPoint(x: selectedFrame.minX, y: size.height - 4.0), size: CGSize(width: selectedFrame.width, height: 4.0))
if wasAdded {
self.selectedLineNode.frame = lineFrame
@ -441,7 +440,7 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {
self.previousSelectedAbsFrame = selectedFrame.offsetBy(dx: -self.scrollNode.bounds.minX, dy: 0.0)
self.previousSelectedFrame = selectedFrame
} else {
self.selectedLineNode.isHidden = true
transition.updateAlpha(node: self.selectedLineNode, alpha: 0.0)
self.previousSelectedAbsFrame = nil
self.previousSelectedFrame = nil
}

View File

@ -875,19 +875,19 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
let location: SearchMessagesLocation
if let options = options {
if let (peerId, _, _) = options.peer {
location = .peer(peerId: peerId, fromId: nil, tags: self.tagMask, topMsgId: nil, minDate: options.minDate?.0, maxDate: options.maxDate?.0)
location = .peer(peerId: peerId, fromId: nil, tags: tagMask, topMsgId: nil, minDate: options.minDate?.0, maxDate: options.maxDate?.0)
} else {
if let groupId = groupId {
location = .group(groupId: groupId, tags: self.tagMask, minDate: options.minDate?.0, maxDate: options.maxDate?.0)
location = .group(groupId: groupId, tags: tagMask, minDate: options.minDate?.0, maxDate: options.maxDate?.0)
} else {
location = .general(tags: self.tagMask, minDate: options.minDate?.0, maxDate: options.maxDate?.0)
location = .general(tags: tagMask, minDate: options.minDate?.0, maxDate: options.maxDate?.0)
}
}
} else {
if let groupId = groupId {
location = .group(groupId: groupId, tags: self.tagMask, minDate: nil, maxDate: nil)
location = .group(groupId: groupId, tags: tagMask, minDate: nil, maxDate: nil)
} else {
location = .general(tags: self.tagMask, minDate: nil, maxDate: nil)
location = .general(tags: tagMask, minDate: nil, maxDate: nil)
}
}
@ -1250,7 +1250,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
}
}
return transitionNode
}, addToTransitionSurface: { view in
}, addToTransitionSurface: { [weak self] view in
self?.addToTransitionSurface(view: view)
}, openUrl: { url in
interaction.openUrl(url)
@ -1304,20 +1304,11 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
strongSelf._isSearching.set(isSearching)
if strongSelf.tagMask == .photoOrVideo {
var totalCount: Int32 = 0
if let entries = entriesAndFlags?.0 {
for entry in entries {
if case let .message(_, _, _, _, count, _, _) = entry {
totalCount = count
break
}
}
}
var entries: [ChatListSearchEntry]? = entriesAndFlags?.0 ?? []
if isSearching && (entries?.isEmpty ?? true) {
entries = nil
}
strongSelf.mediaNode.updateHistory(entries: entries, totalCount: totalCount, updateType: .Initial)
strongSelf.mediaNode.updateHistory(entries: entries, totalCount: 0, updateType: .Initial)
}
var entriesAndFlags = entriesAndFlags
@ -1328,6 +1319,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
for entry in entries {
if case let .localPeer(peer, _, _, _, _, _, _, _, _) = entry {
peers.append(peer)
} else if case .globalPeer = entry {
} else {
filteredEntries.append(entry)
}
@ -1345,7 +1337,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
let firstTime = previousEntries == nil
let transition = chatListSearchContainerPreparedTransition(from: previousEntries ?? [], to: newEntries, displayingResults: entriesAndFlags?.0 != nil, isEmpty: !isSearching && (entriesAndFlags?.0.isEmpty ?? false), isLoading: isSearching, animated: animated, context: context, presentationData: strongSelf.presentationData, enableHeaders: true, filter: peersFilter, tagMask: tagMask, interaction: chatListInteraction, listInteraction: listInteraction, peerContextAction: { message, node, rect, gesture in
interaction.peerContextAction?(message, node, rect, gesture)
}, toggleExpandLocalResults: {
}, toggleExpandLocalResults: { [weak self] in
guard let strongSelf = self else {
return
}
@ -1354,7 +1346,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
state.expandLocalSearch = !state.expandLocalSearch
return state
}
}, toggleExpandGlobalResults: {
}, toggleExpandGlobalResults: { [weak self] in
guard let strongSelf = self else {
return
}
@ -1484,9 +1476,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
}, clearRecentlySearchedPeers: {
interaction.clearRecentSearch()
}, deletePeer: { peerId in
if let strongSelf = self {
let _ = removeRecentlySearchedPeer(postbox: strongSelf.context.account.postbox, peerId: peerId).start()
}
let _ = removeRecentlySearchedPeer(postbox: context.account.postbox, peerId: peerId).start()
})
strongSelf.enqueueRecentTransition(transition, firstTime: firstTime)
}

View File

@ -353,7 +353,7 @@ public final class ListMessageSnippetItemNode: ListMessageNode {
let rawUrlString = urlString
var parsedUrl = URL(string: urlString)
if parsedUrl == nil || parsedUrl!.host == nil || parsedUrl!.host!.isEmpty {
if (parsedUrl == nil || parsedUrl!.host == nil || parsedUrl!.host!.isEmpty) && !urlString.contains("@") {
urlString = "http://" + urlString
parsedUrl = URL(string: urlString)
}
@ -400,7 +400,7 @@ public final class ListMessageSnippetItemNode: ListMessageNode {
var (urlString, concealed) = parseUrl(url: url, wasConcealed: false)
let rawUrlString = urlString
var parsedUrl = URL(string: urlString)
if parsedUrl == nil || parsedUrl!.host == nil || parsedUrl!.host!.isEmpty {
if (parsedUrl == nil || parsedUrl!.host == nil || parsedUrl!.host!.isEmpty) && !urlString.contains("@") {
urlString = "http://" + urlString
parsedUrl = URL(string: urlString)
}