notification exceptions

This commit is contained in:
overtake 2018-11-20 23:25:08 +04:00
parent 2b1ffa0677
commit 076bf34396
2 changed files with 68 additions and 23 deletions

View File

@ -513,7 +513,7 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode {
private let recentListNode: ListView
private let listNode: ListView
private let dimNode: ASDisplayNode
private var enqueuedRecentTransitions: [(ChatListSearchContainerRecentTransition, Bool)] = []
private var enqueuedTransitions: [(ChatListSearchContainerTransition, Bool)] = []
private var validLayout: ContainerViewLayout?
@ -536,8 +536,12 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode {
return self._isSearching.get()
}
private let filter: ChatListNodePeersFilter
init(account: Account, filter: ChatListNodePeersFilter, groupId: PeerGroupId?, openPeer: @escaping (Peer, Bool) -> Void, openRecentPeerOptions: @escaping (Peer) -> Void, openMessage: @escaping (Peer, MessageId) -> Void, addContact: ((String) -> Void)?) {
self.account = account
self.filter = filter
self.dimNode = ASDisplayNode()
self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 }
self.presentationDataPromise = Promise(ChatListPresentationData(theme: self.presentationData.theme, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameSortOrder: self.presentationData.nameSortOrder, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: self.presentationData.disableAnimations))
@ -549,12 +553,17 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode {
super.init()
self.backgroundColor = self.presentationData.theme.chatList.backgroundColor
self.dimNode.backgroundColor = filter.contains(.excludeRecent) ? UIColor.black.withAlphaComponent(0.5) : self.presentationData.theme.chatList.backgroundColor
//self.backgroundColor =
self.addSubnode(self.dimNode)
self.addSubnode(self.recentListNode)
self.addSubnode(self.listNode)
self.listNode.isHidden = true
self.recentListNode.isHidden = filter.contains(.excludeRecent)
let presentationDataPromise = self.presentationDataPromise
let foundItems = searchQuery.get()
@ -847,6 +856,17 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode {
}
}
override func didLoad() {
super.didLoad()
self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture(_:))))
}
@objc func dimTapGesture(_ recognizer: UITapGestureRecognizer) {
if case .ended = recognizer.state {
self.cancel?()
}
}
deinit {
self.updatedRecentPeersDisposable.dispose()
self.recentDisposable.dispose()
@ -924,10 +944,9 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode {
let displayingResults = transition.displayingResults
self.listNode.transaction(deleteIndices: transition.deletions, insertIndicesAndItems: transition.insertions, updateIndicesAndItems: transition.updates, options: options, updateSizeAndInsets: nil, updateOpaqueState: nil, completion: { [weak self] _ in
if let strongSelf = self {
if displayingResults != !strongSelf.listNode.isHidden {
strongSelf.listNode.isHidden = !displayingResults
strongSelf.recentListNode.isHidden = displayingResults
}
strongSelf.listNode.isHidden = !displayingResults
strongSelf.recentListNode.isHidden = displayingResults || strongSelf.filter.contains(.excludeRecent)
strongSelf.dimNode.isHidden = displayingResults
}
})
}
@ -939,6 +958,10 @@ final class ChatListSearchContainerNode: SearchDisplayControllerContentNode {
let hadValidLayout = self.validLayout != nil
self.validLayout = layout
let topInset = navigationBarHeight
transition.updateFrame(node: self.dimNode, frame: CGRect(origin: CGPoint(x: 0.0, y: topInset), size: CGSize(width: layout.size.width, height: layout.size.height - topInset)))
var duration: Double = 0.0
var curve: UInt = 0
switch transition {

View File

@ -583,22 +583,18 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
let presentationData = account.telegramApplicationContext.currentPresentationData.modify {$0}
let updatePeerSound: (PeerId, PeerMessageSound) -> Void = { peerId, sound in
_ = (combineLatest(updatePeerNotificationSoundInteractive(account: account, peerId: peerId, sound: sound), account.postbox.loadedPeerWithId(peerId)) |> deliverOnMainQueue).start(next: { _, peer in
updateState { value in
return value.withUpdatedPeerSound(peer, sound)
}
updateNotificationsView()
})
let updatePeerSound: (PeerId, PeerMessageSound) -> Signal<Void, NoError> = { peerId, sound in
return updatePeerNotificationSoundInteractive(account: account, peerId: peerId, sound: sound) |> deliverOnMainQueue
// _ = (combineLatest(, account.postbox.loadedPeerWithId(peerId)) |> deliverOnMainQueue).start(next: { _, peer in
// updateState { value in
// return value.withUpdatedPeerSound(peer, sound)
// }
// updateNotificationsView()
// })
}
let updatePeerNotificationInterval:(PeerId, Int32?) -> Void = { peerId, muteInterval in
_ = (combineLatest(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: muteInterval), account.postbox.loadedPeerWithId(peerId)) |> deliverOnMainQueue).start(next: { _, peer in
updateState { value in
return value.withUpdatedPeerMuteInterval(peer, muteInterval)
}
updateNotificationsView()
})
let updatePeerNotificationInterval:(PeerId, Int32?) -> Signal<Void, NoError> = { peerId, muteInterval in
return updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: muteInterval) |> deliverOnMainQueue
}
@ -626,6 +622,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
} |> deliverOnMainQueue).start(completed: { [weak strongSelf] in
if let strongSelf = strongSelf, let infoController = peerInfoController(account: strongSelf.account, peer: peer) {
strongSelf.pushController(infoController)
strongSelf.requestDeactivateSearch()
}
})
}
@ -646,7 +643,24 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
controller.peerSelected = { [weak controller] peerId in
controller?.dismiss()
presentControllerImpl?(notificationPeerExceptionController(account: account, peerId: peerId, mode: mode, updatePeerSound: updatePeerSound, updatePeerNotificationInterval: updatePeerNotificationInterval), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
presentControllerImpl?(notificationPeerExceptionController(account: account, peerId: peerId, mode: mode, updatePeerSound: { peerId, sound in
_ = updatePeerSound(peerId, sound).start(next: { _ in
_ = (account.postbox.loadedPeerWithId(peerId) |> deliverOnMainQueue).start(next: { peer in
updateState { value in
return value.withUpdatedPeerSound(peer, sound)
}
updateNotificationsView()
})
})
}, updatePeerNotificationInterval: { peerId, muteInterval in
_ = (account.postbox.loadedPeerWithId(peerId) |> deliverOnMainQueue).start(next: { peer in
updateState { value in
return value.withUpdatedPeerMuteInterval(peer, muteInterval)
}
updateNotificationsView()
})
}), ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
}
presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
}, updateRevealedPeerId: { peerId in
@ -659,8 +673,15 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
updatePeers(transaction: transaction, peers: [peer], update: { _, updated in return updated})
}
} |> deliverOnMainQueue).start(completed: {
updatePeerSound(peer.id, .default)
updatePeerNotificationInterval(peer.id, nil)
_ = combineLatest(updatePeerSound(peer.id, .default), updatePeerNotificationInterval(peer.id, nil)).start(next: { _, _ in
updateState { value in
return value.withUpdatedPeerMuteInterval(peer, nil).withUpdatedPeerSound(peer, .default)
}
updateNotificationsView()
})
})
})
@ -777,6 +798,7 @@ final class NotificationExceptionsControllerNode: ViewControllerTracingNode {
options.insert(.Synchronous)
options.insert(.LowLatency)
} else if transition.animated {
options.insert(.Synchronous)
options.insert(.AnimateInsertion)
}
self.listNode.transaction(deleteIndices: transition.deletions, insertIndicesAndItems: transition.insertions, updateIndicesAndItems: transition.updates, options: options, updateOpaqueState: nil, completion: { [weak self] _ in