Skip to content

Commit

Permalink
Search filters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Sep 22, 2020
1 parent 5988ed6 commit d523ab8
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 70 deletions.
1 change: 1 addition & 0 deletions submodules/ChatListUI/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ swift_library(
"//submodules/ShareController:ShareController",
"//submodules/GridMessageSelectionNode:GridMessageSelectionNode",
"//submodules/ChatListFilterSettingsHeaderItem:ChatListFilterSettingsHeaderItem",
"//submodules/TelegramStringFormatting:TelegramStringFormatting",
],
visibility = [
"//visibility:public",
Expand Down
24 changes: 12 additions & 12 deletions submodules/ChatListUI/Sources/ChatListFilterTabContainerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -415,26 +415,26 @@ enum ChatListFilterTabEntry: Equatable {
switch self {
case .all:
return .all
case let .filter(filter):
return .filter(filter.id)
case let .filter(id, _, _):
return .filter(id)
}
}

func title(strings: PresentationStrings) -> String {
switch self {
case .all:
return strings.ChatList_Tabs_AllChats
case let .filter(filter):
return filter.text
case let .filter(_, text, _):
return text
}
}

func shortTitle(strings: PresentationStrings) -> String {
switch self {
case .all:
return strings.ChatList_Tabs_All
case let .filter(filter):
return filter.text
case let .filter(_, text, _):
return text
}
}
}
Expand Down Expand Up @@ -700,8 +700,8 @@ final class ChatListFilterTabContainerNode: ASDisplayNode {
strongSelf.scrollNode.view.panGestureRecognizer.isEnabled = true
strongSelf.scrollNode.view.setContentOffset(strongSelf.scrollNode.view.contentOffset, animated: false)
switch filter {
case let .filter(filter):
strongSelf.contextGesture?(filter.id, sourceNode, gesture)
case let .filter(id, _, _):
strongSelf.contextGesture?(id, sourceNode, gesture)
default:
strongSelf.contextGesture?(nil, sourceNode, gesture)
}
Expand All @@ -716,9 +716,9 @@ final class ChatListFilterTabContainerNode: ASDisplayNode {
unreadCount = count
unreadHasUnmuted = true
isNoFilter = true
case let .filter(filter):
unreadCount = filter.unread.value
unreadHasUnmuted = filter.unread.hasUnmuted
case let .filter(_, _, unread):
unreadCount = unread.value
unreadHasUnmuted = unread.hasUnmuted
}
if !wasAdded && (itemNode.unreadCount != 0) != (unreadCount != 0) {
badgeAnimations[filter.id] = (unreadCount != 0) ? .in : .out
Expand Down Expand Up @@ -789,7 +789,7 @@ final class ChatListFilterTabContainerNode: ASDisplayNode {

var longTitlesWidth: CGFloat = resolvedSideInset
for i in 0 ..< tabSizes.count {
let (itemId, paneNodeSize, paneNodeShortSize, paneNode, wasAdded) = tabSizes[i]
let (_, paneNodeSize, _, _, _) = tabSizes[i]
longTitlesWidth += paneNodeSize.width
if i != tabSizes.count - 1 {
longTitlesWidth += minSpacing
Expand Down
12 changes: 7 additions & 5 deletions submodules/ChatListUI/Sources/ChatListSearchContainerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ final class ChatListSearchInteraction {
let peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?
let present: (ViewController, Any?) -> Void
let dismissInput: () -> Void
let updateSuggestedPeers: ([Peer]) -> Void
let updateSuggestedPeers: ([Peer], ChatListSearchPaneKey) -> Void
let getSelectedMessageIds: () -> Set<MessageId>?

init(openPeer: @escaping (Peer, Bool) -> Void, openDisabledPeer: @escaping (Peer) -> Void, openMessage: @escaping (Peer, MessageId) -> Void, openUrl: @escaping (String) -> Void, clearRecentSearch: @escaping () -> Void, addContact: @escaping (String) -> Void, toggleMessageSelection: @escaping (MessageId, Bool) -> Void, messageContextAction: @escaping ((Message, ASDisplayNode?, CGRect?, UIGestureRecognizer?) -> Void), mediaMessageContextAction: @escaping ((Message, ASDisplayNode?, CGRect?, UIGestureRecognizer?) -> Void), peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?, present: @escaping (ViewController, Any?) -> Void, dismissInput: @escaping () -> Void, updateSuggestedPeers: @escaping ([Peer]) -> Void, getSelectedMessageIds: @escaping () -> Set<MessageId>?) {
init(openPeer: @escaping (Peer, Bool) -> Void, openDisabledPeer: @escaping (Peer) -> Void, openMessage: @escaping (Peer, MessageId) -> Void, openUrl: @escaping (String) -> Void, clearRecentSearch: @escaping () -> Void, addContact: @escaping (String) -> Void, toggleMessageSelection: @escaping (MessageId, Bool) -> Void, messageContextAction: @escaping ((Message, ASDisplayNode?, CGRect?, UIGestureRecognizer?) -> Void), mediaMessageContextAction: @escaping ((Message, ASDisplayNode?, CGRect?, UIGestureRecognizer?) -> Void), peerContextAction: ((Peer, ChatListSearchContextActionSource, ASDisplayNode, ContextGesture?) -> Void)?, present: @escaping (ViewController, Any?) -> Void, dismissInput: @escaping () -> Void, updateSuggestedPeers: @escaping ([Peer], ChatListSearchPaneKey) -> Void, getSelectedMessageIds: @escaping () -> Set<MessageId>?) {
self.openPeer = openPeer
self.openDisabledPeer = openDisabledPeer
self.openMessage = openMessage
Expand Down Expand Up @@ -215,8 +215,10 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
present(c, a)
}, dismissInput: { [weak self] in
self?.dismissInput()
}, updateSuggestedPeers: { [weak self] peers in
self?.suggestedPeers.set(.single(peers))
}, updateSuggestedPeers: { [weak self] peers, key in
if let strongSelf = self, strongSelf.paneContainerNode.currentPaneKey == key {
strongSelf.suggestedPeers.set(.single(peers))
}
}, getSelectedMessageIds: { [weak self] () -> Set<MessageId>? in
if let strongSelf = self {
return strongSelf.stateValue.selectedMessageIds
Expand Down Expand Up @@ -297,7 +299,7 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo

self.suggestedFiltersDisposable.set((combineLatest(self.suggestedPeers.get(), self.suggestedDates.get())
|> mapToSignal { peers, dates -> Signal<([Peer], [(Date, String?)]), NoError> in
if peers.isEmpty && dates.isEmpty {
if (peers.isEmpty && dates.isEmpty) || peers.isEmpty {
return .single((peers, dates))
} else {
return (.complete() |> delay(0.2, queue: Queue.mainQueue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {
}

self.addSubnode(self.scrollNode)
self.addSubnode(self.selectedLineNode)
self.scrollNode.addSubnode(self.selectedLineNode)
}

func cancelAnimations() {
Expand Down Expand Up @@ -254,6 +254,7 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {

transition.updateFrame(node: self.scrollNode, frame: CGRect(origin: CGPoint(), size: size))

var hasSelection = false
for i in 0 ..< filters.count {
let filter = filters[i]
if case let .filter(type) = filter {
Expand All @@ -272,6 +273,7 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {
let selectionFraction: CGFloat
if selectedFilter == filter.id {
selectionFraction = 1.0 - abs(transitionFraction)
hasSelection = true
} else if i != 0 && selectedFilter == filters[i - 1].id {
selectionFraction = max(0.0, -transitionFraction)
} else if i != filters.count - 1 && selectedFilter == filters[i + 1].id {
Expand Down Expand Up @@ -323,7 +325,7 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {
}

let minSpacing: CGFloat = 24.0
let spacing = minSpacing
var spacing = minSpacing

let resolvedSideInset: CGFloat = 16.0 + sideInset
var leftOffset: CGFloat = resolvedSideInset
Expand All @@ -340,6 +342,10 @@ final class ChatListSearchFiltersContainerNode: ASDisplayNode {
}
longTitlesWidth += resolvedSideInset

if longTitlesWidth < size.width && hasSelection {
spacing = (size.width - titlesWidth - resolvedSideInset * 2.0) / CGFloat(tabSizes.count - 1)
}

let verticalOffset: CGFloat = -3.0
for i in 0 ..< tabSizes.count {
let (_, paneNodeSize, paneNode, wasAdded) = tabSizes[i]
Expand Down
28 changes: 23 additions & 5 deletions submodules/ChatListUI/Sources/ChatListSearchListPaneNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
private let interaction: ChatListSearchInteraction
private let peersFilter: ChatListNodePeersFilter
private var presentationData: PresentationData
private let key: ChatListSearchPaneKey
private let tagMask: MessageTags?
private let navigationController: NavigationController?

Expand Down Expand Up @@ -695,13 +696,30 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {

private var hiddenMediaDisposable: Disposable?

init(context: AccountContext, interaction: ChatListSearchInteraction, tagMask: MessageTags?, peersFilter: ChatListNodePeersFilter, searchQuery: Signal<String?, NoError>, searchOptions: Signal<ChatListSearchOptions?, NoError>, navigationController: NavigationController?) {
init(context: AccountContext, interaction: ChatListSearchInteraction, key: ChatListSearchPaneKey, peersFilter: ChatListNodePeersFilter, searchQuery: Signal<String?, NoError>, searchOptions: Signal<ChatListSearchOptions?, NoError>, navigationController: NavigationController?) {
self.context = context
self.interaction = interaction
self.key = key
self.peersFilter = peersFilter
self.tagMask = tagMask
self.navigationController = navigationController

let tagMask: MessageTags?
switch key {
case .chats:
tagMask = nil
case .media:
tagMask = .photoOrVideo
case .links:
tagMask = .webPage
case .files:
tagMask = .file
case .music:
tagMask = .music
case .voice:
tagMask = .voiceOrInstantVideo
}
self.tagMask = tagMask

self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
self.presentationDataPromise.set(.single(ChatListPresentationData(theme: self.presentationData.theme, fontSize: self.presentationData.listsFontSize, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameSortOrder: self.presentationData.nameSortOrder, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: self.presentationData.disableAnimations)))

Expand Down Expand Up @@ -1190,8 +1208,8 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
return
}
switch item.content {
case let .peer(peer):
if let peer = peer.peer.peer {
case let .peer(_, peer, _, _, _, _, _, _, _, _, _, _):
if let peer = peer.peer {
peerContextAction(peer, .search, node, gesture)
}
case .groupReference:
Expand Down Expand Up @@ -1353,7 +1371,7 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
strongSelf.ready.set(.single(true))
strongSelf.didSetReady = true
} else if tagMask != nil {
interaction.updateSuggestedPeers(Array(peers.prefix(8)))
interaction.updateSuggestedPeers(Array(peers.prefix(8)), strongSelf.key)
}
}
}))
Expand Down
4 changes: 2 additions & 2 deletions submodules/ChatListUI/Sources/ChatListSearchMediaNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private final class VisualMediaItemNode: ASDisplayNode {
if case .ended = recognizer.state {
if let (gesture, _) = recognizer.lastRecognizedGestureAndLocation {
if case .tap = gesture {
if let (item, _, _, _) = self.item {
if let _ = self.item {
var media: Media?
for value in message.media {
if let image = value as? TelegramMediaImage {
Expand Down Expand Up @@ -225,7 +225,7 @@ private final class VisualMediaItemNode: ASDisplayNode {

self.fetchStatusDisposable.set((messageMediaFileStatus(context: context, messageId: message.id, file: file)
|> deliverOnMainQueue).start(next: { [weak self] status in
if let strongSelf = self, let (item, _, _, _) = strongSelf.item {
if let strongSelf = self, let _ = strongSelf.item {
strongSelf.resourceStatus = status

let isStreamable = isMediaStreamable(message: message, media: file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,7 @@ private final class ChatListSearchPendingPane {
key: ChatListSearchPaneKey,
hasBecomeReady: @escaping (ChatListSearchPaneKey) -> Void
) {
let paneNode: ChatListSearchPaneNode
switch key {
case .chats:
paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, tagMask: nil, peersFilter: peersFilter, searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)
case .media:
paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, tagMask: .photoOrVideo, peersFilter: [], searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)
case .files:
paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, tagMask: .file, peersFilter: [], searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)
case .links:
paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, tagMask: .webPage, peersFilter: [], searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)
case .voice:
paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, tagMask: .voiceOrInstantVideo, peersFilter: [], searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)
case .music:
paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, tagMask: .music, peersFilter: [], searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)
}
let paneNode = ChatListSearchListPaneNode(context: context, interaction: interaction, key: key, peersFilter: key == .chats ? peersFilter : [], searchQuery: searchQuery, searchOptions: searchOptions, navigationController: navigationController)

self.pane = ChatListSearchPaneWrapper(key: key, node: paneNode)
self.disposable = (paneNode.isReady
Expand Down Expand Up @@ -493,7 +479,7 @@ final class ChatListSearchPaneContainerNode: ASDisplayNode, UIGestureRecognizerD
transition.animateFrame(node: pane.node, from: paneFrame, to: paneFrame.offsetBy(dx: -paneSwitchAnimationOffset, dy: 0.0), completion: isAnimatingOut ? nil : { _ in
paneCompletion()
})
} else if let previousPaneKey = previousPaneKey, key == self.currentPaneKey {
} else if let _ = previousPaneKey, key == self.currentPaneKey {
pane.node.frame = adjustedFrame
let isAnimatingOut = pane.isAnimatingOut
pane.isAnimatingOut = true
Expand Down
54 changes: 33 additions & 21 deletions submodules/ChatListUI/Sources/DateSuggestion.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import TelegramPresentationData
import TelegramStringFormatting

private let telegramReleaseDate = Date(timeIntervalSince1970: 1376438400.0)

Expand Down Expand Up @@ -106,35 +107,46 @@ func suggestDates(for string: String, strings: PresentationStrings, dateTimeForm

}
}
} else {
for (day, value) in weekDays {
let dayName = value.0.lowercased()
let shortDayName = value.1.lowercased()
if string == shortDayName || (string.count >= shortDayName.count && dayName.hasPrefix(string)) {
var nextDateComponent = calendar.dateComponents([.hour, .minute, .second], from: now)
nextDateComponent.weekday = day + calendar.firstWeekday
if let date = calendar.nextDate(after: now, matching: nextDateComponent, matchingPolicy: .nextTime, direction: .backward) {
let upperDate = getUpperDate(for: date)
for i in 0..<5 {
if let date = calendar.date(byAdding: .hour, value: -24 * 7 * i, to: upperDate) {
if calendar.isDate(date, equalTo: now, toGranularity: .weekOfYear) {
result.append((date, value.0))
} else {
result.append((date, nil))
}
}

for (day, value) in weekDays {
let dayName = value.0.lowercased()
let shortDayName = value.1.lowercased()
if string == shortDayName || (string.count >= shortDayName.count && dayName.hasPrefix(string)) {
var nextDateComponent = calendar.dateComponents([.hour, .minute, .second], from: now)
nextDateComponent.weekday = day + calendar.firstWeekday
if let date = calendar.nextDate(after: now, matching: nextDateComponent, matchingPolicy: .nextTime, direction: .backward) {
let upperDate = getUpperDate(for: date)
for i in 0..<5 {
if let date = calendar.date(byAdding: .hour, value: -24 * 7 * i, to: upperDate) {
if calendar.isDate(date, equalTo: now, toGranularity: .weekOfYear) {
result.append((date, value.0))
} else {
result.append((date, nil))
}
}
}
}
}
for (month, value) in months {
let monthName = value.0.lowercased()
let shortMonthName = value.1.lowercased()
if string == shortMonthName || (string.count >= shortMonthName.count && monthName.hasPrefix(string)) {
}

let cleanString = string.trimmingCharacters(in: .decimalDigits).trimmingCharacters(in: .whitespacesAndNewlines)
let cleanDigits = string.trimmingCharacters(in: .letters).trimmingCharacters(in: .whitespacesAndNewlines)

for (month, value) in months {
let monthName = value.0.lowercased()
let shortMonthName = value.1.lowercased()
if cleanString == shortMonthName || (cleanString.count >= shortMonthName.count && monthName.hasPrefix(cleanString)) {
if cleanDigits.count == 4, let year = Int(cleanDigits) {
let date = getUpperMonthDate(month: month, year: year)
if date <= now && date > telegramReleaseDate {
result.append((date, stringForMonth(strings: strings, month: Int32(month - 1), ofYear: Int32(year - 1900))))
}
} else if cleanDigits.isEmpty {
for i in (year - 7 ... year).reversed() {
let date = getUpperMonthDate(month: month, year: i)
if date <= now && date > telegramReleaseDate {
result.append((date, nil))
result.append((date, stringForMonth(strings: strings, month: Int32(month - 1), ofYear: Int32(i - 1900))))
}
}
}
Expand Down
Loading

0 comments on commit d523ab8

Please sign in to comment.