Improve recently searched list filtering

This commit is contained in:
Ali
2022-04-20 21:03:41 +04:00
parent 333d34e4b7
commit 999db0b76a
2 changed files with 58 additions and 6 deletions

View File

@@ -49,10 +49,13 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
let presentationData = context.sharedContext.currentPresentationData.with({ $0 })
let strings = presentationData.strings
return context.account.postbox.transaction { transaction -> (PeerGroupId, ChatListIndex)? in
transaction.getPeerChatListIndex(peerId)
}
|> mapToSignal { groupAndIndex -> Signal<[ContextMenuItem], NoError> in
return combineLatest(
context.account.postbox.transaction { transaction -> (PeerGroupId, ChatListIndex)? in
transaction.getPeerChatListIndex(peerId)
},
context.engine.peers.recentlySearchedPeers() |> take(1)
)
|> mapToSignal { groupAndIndex, recentlySearchedPeers -> Signal<[ContextMenuItem], NoError> in
let location: TogglePeerChatPinnedLocation
var chatListFilter: ChatListFilter?
if case let .chatList(filter) = source, let chatFilter = filter {
@@ -100,7 +103,15 @@ func chatContextMenuItems(context: AccountContext, peerId: PeerId, promoInfo: Ch
})))
items.append(.separator)
case .search:
break
if recentlySearchedPeers.contains(where: { $0.peer.peerId == peerId }) {
items.append(.action(ContextMenuActionItem(text: strings.ChatList_Context_RemoveFromRecents, textColor: .destructive, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Clear"), color: theme.contextMenu.destructiveColor) }, action: { _, f in
let _ = (context.engine.peers.removeRecentlySearchedPeer(peerId: peerId)
|> deliverOnMainQueue).start(completed: {
f(.default)
})
})))
items.append(.separator)
}
}
}