Set choosing sticker activity when interacting with search by emoji

This commit is contained in:
Ilya Laktyushin 2021-09-14 12:18:37 +03:00
parent d022ad7d91
commit 0f87a813e9
10 changed files with 73 additions and 22 deletions

View File

@ -340,7 +340,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
private let recordingActivityPromise = ValuePromise<ChatRecordingActivity>(.none, ignoreRepeated: true)
private var recordingActivityDisposable: Disposable?
private var acquiredRecordingActivityDisposable: Disposable?
private let choosingStickerActivityPromise = Promise<Bool>(false)
private let choosingStickerActivityPromise = ValuePromise<Bool>(false)
private var choosingStickerActivityDisposable: Disposable?
private var searchDisposable: MetaDisposable?
@ -2879,6 +2879,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return nil
}
return strongSelf.chatDisplayNode.messageTransitionNode
}, updateChoosingSticker: { [weak self] value in
if let strongSelf = self {
strongSelf.choosingStickerActivityPromise.set(value)
}
}, requestMessageUpdate: { [weak self] id in
if let strongSelf = self {
strongSelf.chatDisplayNode.historyNode.requestMessageUpdate(id)
@ -3876,6 +3880,13 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
})
self.choosingStickerActivityDisposable = (self.choosingStickerActivityPromise.get()
|> mapToSignal { value -> Signal<Bool, NoError> in
if value {
return .single(true)
} else {
return .single(false) |> delay(2.0, queue: Queue.mainQueue())
}
}
|> deliverOnMainQueue).start(next: { [weak self] value in
if let strongSelf = self {
strongSelf.context.account.updateLocalInputActivity(peerId: activitySpace, activity: .choosingSticker, isPresent: value)
@ -4534,9 +4545,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
if let currentItem = self.tempVoicePlaylistCurrentItem {
self.chatDisplayNode.historyNode.voicePlaylistItemChanged(nil, currentItem)
}
self.choosingStickerActivityPromise.set(self.chatDisplayNode.choosingSticker)
self.chatDisplayNode.historyNode.didScrollWithOffset = { [weak self] offset, transition, itemNode in
guard let strongSelf = self else {
return

View File

@ -123,7 +123,8 @@ public final class ChatControllerInteraction {
let copyText: (String) -> Void
let displayUndo: (UndoOverlayContent) -> Void
let isAnimatingMessage: (UInt32) -> Bool
var getMessageTransitionNode: () -> ChatMessageTransitionNode?
let getMessageTransitionNode: () -> ChatMessageTransitionNode?
let updateChoosingSticker: (Bool) -> Void
let requestMessageUpdate: (MessageId) -> Void
let cancelInteractiveKeyboardGestures: () -> Void
@ -219,6 +220,7 @@ public final class ChatControllerInteraction {
displayUndo: @escaping (UndoOverlayContent) -> Void,
isAnimatingMessage: @escaping (UInt32) -> Bool,
getMessageTransitionNode: @escaping () -> ChatMessageTransitionNode?,
updateChoosingSticker: @escaping (Bool) -> Void,
requestMessageUpdate: @escaping (MessageId) -> Void,
cancelInteractiveKeyboardGestures: @escaping () -> Void,
automaticMediaDownloadSettings: MediaAutoDownloadSettings,
@ -300,6 +302,7 @@ public final class ChatControllerInteraction {
self.displayUndo = displayUndo
self.isAnimatingMessage = isAnimatingMessage
self.getMessageTransitionNode = getMessageTransitionNode
self.updateChoosingSticker = updateChoosingSticker
self.requestMessageUpdate = requestMessageUpdate
self.cancelInteractiveKeyboardGestures = cancelInteractiveKeyboardGestures
@ -358,6 +361,7 @@ public final class ChatControllerInteraction {
return false
}, getMessageTransitionNode: {
return nil
}, updateChoosingSticker: { _ in
}, requestMessageUpdate: { _ in
}, cancelInteractiveKeyboardGestures: {
}, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings,

View File

@ -122,11 +122,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
private(set) var textInputPanelNode: ChatTextInputPanelNode?
private var inputMediaNode: ChatMediaInputNode?
private let choosingStickerPromise = Promise<Bool>(false)
var choosingSticker: Signal<Bool, NoError> {
return self.choosingStickerPromise.get()
}
let navigateButtons: ChatHistoryNavigationButtons
private var ignoreUpdateHeight = false
@ -865,7 +860,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
}
if let inputMediaNode = inputNode as? ChatMediaInputNode, self.inputMediaNode == nil {
self.inputMediaNode = inputMediaNode
self.choosingStickerPromise.set(inputMediaNode.choosingSticker)
inputMediaNode.requestDisableStickerAnimations = { [weak self] disabled in
self?.controller?.disableStickerAnimations = disabled
}
@ -1961,7 +1955,6 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
self?.controller?.disableStickerAnimations = disabled
}
self.inputMediaNode = inputNode
self.choosingStickerPromise.set(inputNode.choosingSticker)
if let (validLayout, _) = self.validLayout {
let _ = inputNode.updateLayout(width: validLayout.size.width, leftInset: validLayout.safeInsets.left, rightInset: validLayout.safeInsets.right, bottomInset: validLayout.intrinsicInsets.bottom, standardInputHeight: validLayout.standardInputHeight, inputHeight: validLayout.inputHeight ?? 0.0, maximumHeight: validLayout.standardInputHeight, inputPanelHeight: 44.0, transition: .immediate, interfaceState: self.chatPresentationInterfaceState, deviceMetrics: validLayout.deviceMetrics, isVisible: false)
}

View File

@ -496,17 +496,14 @@ final class ChatMediaInputNode: ChatInputNode {
private var scrollingStickerPacksListPromise = ValuePromise<Bool>(false)
private var scrollingStickersGridPromise = ValuePromise<Bool>(false)
private var previewingStickersPromise = ValuePromise<Bool>(false)
var choosingSticker: Signal<Bool, NoError> {
private var choosingSticker: Signal<Bool, NoError> {
return combineLatest(self.scrollingStickerPacksListPromise.get(), self.scrollingStickersGridPromise.get(), self.previewingStickersPromise.get())
|> mapToSignal { scrollingStickerPacksList, scrollingStickersGrid, previewingStickers -> Signal<Bool, NoError> in
if scrollingStickerPacksList || scrollingStickersGrid || previewingStickers {
return .single(true)
} else {
return .single(false) |> delay(2.0, queue: Queue.mainQueue())
}
|> map { scrollingStickerPacksList, scrollingStickersGrid, previewingStickers -> Bool in
return scrollingStickerPacksList || scrollingStickersGrid || previewingStickers
}
|> distinctUntilChanged
}
private var choosingStickerDisposable: Disposable?
private var panelFocusScrollToIndex: Int?
private var panelFocusInitialPosition: CGPoint?
@ -1324,10 +1321,18 @@ final class ChatMediaInputNode: ChatInputNode {
strongSelf.startCollapseTimer(timeout: decelerated ? 0.5 : 2.5)
}
}
self.choosingStickerDisposable = (self.choosingSticker
|> deliverOnMainQueue).start(next: { [weak self] value in
if let strongSelf = self {
strongSelf.controllerInteraction.updateChoosingSticker(value)
}
})
}
deinit {
self.disposable.dispose()
self.choosingStickerDisposable?.dispose()
self.searchContainerNodeLoadedDisposable.dispose()
self.panelFocusTimer?.invalidate()
}

View File

@ -529,6 +529,7 @@ final class ChatRecentActionsControllerNode: ViewControllerTracingNode {
return false
}, getMessageTransitionNode: {
return nil
}, updateChoosingSticker: { _ in
}, requestMessageUpdate: { _ in
}, cancelInteractiveKeyboardGestures: {
}, automaticMediaDownloadSettings: self.automaticMediaDownloadSettings,

View File

@ -155,6 +155,7 @@ private final class DrawingStickersScreenNode: ViewControllerTracingNode {
return false
}, getMessageTransitionNode: {
return nil
}, updateChoosingSticker: { _ in
}, requestMessageUpdate: { _ in
}, cancelInteractiveKeyboardGestures: {
}, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings,

View File

@ -43,6 +43,16 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
var getControllerInteraction: (() -> ChatControllerInteraction?)?
private var scrollingStickersGridPromise = ValuePromise<Bool>(false)
private var previewingStickersPromise = ValuePromise<Bool>(false)
var choosingSticker: Signal<Bool, NoError> {
return combineLatest(self.scrollingStickersGridPromise.get(), self.previewingStickersPromise.get())
|> map { scrollingStickersGrid, previewingStickers -> Bool in
return scrollingStickersGrid || previewingStickers
}
|> distinctUntilChanged
}
init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings) {
self.context = context
self.theme = theme
@ -146,6 +156,9 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
let controller = PeekController(presentationData: presentationData, content: content, sourceNode: {
return sourceNode
})
controller.visibilityUpdated = { [weak self] visible in
self?.previewingStickersPromise.set(visible)
}
strongSelf.getControllerInteraction?()?.presentGlobalOverlayController(controller, nil)
return controller
}
@ -171,6 +184,20 @@ private final class InlineReactionSearchStickersNode: ASDisplayNode, UIScrollVie
}
}
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.scrollingStickersGridPromise.set(true)
}
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
if !decelerate {
self.scrollingStickersGridPromise.set(false)
}
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
self.scrollingStickersGridPromise.set(false)
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if !self.ignoreScrolling {
self.updateVisibleItems(synchronous: false)
@ -402,6 +429,8 @@ final class InlineReactionSearchPanel: ChatInputContextPanelNode {
private var validLayout: (CGSize, CGFloat)?
private var query: String?
private var choosingStickerDisposable: Disposable?
override init(context: AccountContext, theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize) {
self.containerNode = ASDisplayNode()
@ -491,11 +520,17 @@ final class InlineReactionSearchPanel: ChatInputContextPanelNode {
self.view.disablesInteractiveTransitionGestureRecognizer = true
self.view.disablesInteractiveKeyboardGestureRecognizer = true
self.choosingStickerDisposable = (self.stickersNode.choosingSticker
|> deliverOnMainQueue).start(next: { [weak self] value in
if let strongSelf = self {
strongSelf.controllerInteraction?.updateChoosingSticker(value)
}
})
}
override func didLoad() {
super.didLoad()
deinit {
self.choosingStickerDisposable?.dispose()
}
func updateResults(results: [TelegramMediaFile], query: String?) {

View File

@ -147,6 +147,7 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, UIGestu
return false
}, getMessageTransitionNode: {
return nil
}, updateChoosingSticker: { _ in
}, requestMessageUpdate: { _ in
}, cancelInteractiveKeyboardGestures: {
}, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings, pollActionState: ChatInterfacePollActionState(), stickerSettings: ChatInterfaceStickerSettings(loopAnimatedStickers: false), presentationContext: ChatPresentationContext(backgroundNode: nil))

View File

@ -2182,6 +2182,7 @@ private final class PeerInfoScreenNode: ViewControllerTracingNode, UIScrollViewD
return false
}, getMessageTransitionNode: {
return nil
}, updateChoosingSticker: { _ in
}, requestMessageUpdate: { _ in
}, cancelInteractiveKeyboardGestures: {
}, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings,

View File

@ -1294,6 +1294,7 @@ public final class SharedAccountContextImpl: SharedAccountContext {
return false
}, getMessageTransitionNode: {
return nil
}, updateChoosingSticker: { _ in
}, requestMessageUpdate: { _ in
}, cancelInteractiveKeyboardGestures: {
}, automaticMediaDownloadSettings: MediaAutoDownloadSettings.defaultSettings,