mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Message preview and effect improvements
This commit is contained in:
parent
b420532822
commit
fe788ed9ea
@ -1037,6 +1037,9 @@ public protocol ChatMessageItemNodeProtocol: ListViewItemNode {
|
||||
func targetReactionView(value: MessageReaction.Reaction) -> UIView?
|
||||
func targetForStoryTransition(id: StoryId) -> UIView?
|
||||
func contentFrame() -> CGRect
|
||||
func matchesMessage(id: MessageId) -> Bool
|
||||
func cancelInsertionAnimations()
|
||||
func messages() -> [Message]
|
||||
}
|
||||
|
||||
public final class ChatControllerNavigationData: CustomViewControllerNavigationData {
|
||||
|
@ -1032,6 +1032,12 @@ final class AttachmentPanel: ASDisplayNode, ASScrollViewDelegate {
|
||||
schedule: { [weak textInputPanelNode] messageEffect in
|
||||
textInputPanelNode?.sendMessage(.schedule, messageEffect)
|
||||
},
|
||||
openPremiumPaywall: { [weak self] c in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.controller?.push(c)
|
||||
},
|
||||
reactionItems: effectItems,
|
||||
availableMessageEffects: availableMessageEffects,
|
||||
isPremium: hasPremium
|
||||
|
@ -177,6 +177,7 @@ public func makeChatSendMessageActionSheetController(
|
||||
completion: @escaping () -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
openPremiumPaywall: @escaping (ViewController) -> Void,
|
||||
reactionItems: [ReactionItem]? = nil,
|
||||
availableMessageEffects: AvailableMessageEffects? = nil,
|
||||
isPremium: Bool = false
|
||||
@ -221,6 +222,7 @@ public func makeChatSendMessageActionSheetController(
|
||||
completion: completion,
|
||||
sendMessage: sendMessage,
|
||||
schedule: schedule,
|
||||
openPremiumPaywall: openPremiumPaywall,
|
||||
reactionItems: reactionItems,
|
||||
availableMessageEffects: availableMessageEffects,
|
||||
isPremium: isPremium
|
||||
|
@ -71,6 +71,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
let completion: () -> Void
|
||||
let sendMessage: (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void
|
||||
let schedule: (ChatSendMessageActionSheetController.SendParameters?) -> Void
|
||||
let openPremiumPaywall: (ViewController) -> Void
|
||||
let reactionItems: [ReactionItem]?
|
||||
let availableMessageEffects: AvailableMessageEffects?
|
||||
let isPremium: Bool
|
||||
@ -94,6 +95,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
completion: @escaping () -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
openPremiumPaywall: @escaping (ViewController) -> Void,
|
||||
reactionItems: [ReactionItem]?,
|
||||
availableMessageEffects: AvailableMessageEffects?,
|
||||
isPremium: Bool
|
||||
@ -116,6 +118,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
self.completion = completion
|
||||
self.sendMessage = sendMessage
|
||||
self.schedule = schedule
|
||||
self.openPremiumPaywall = openPremiumPaywall
|
||||
self.reactionItems = reactionItems
|
||||
self.availableMessageEffects = availableMessageEffects
|
||||
self.isPremium = isPremium
|
||||
@ -153,6 +156,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
|
||||
private var sendButton: SendButton?
|
||||
private var messageItemView: MessageItemView?
|
||||
private var internalWallpaperBackgroundNode: WallpaperBackgroundNode?
|
||||
private var actionsStackNode: ContextControllerActionsStackNode?
|
||||
private var reactionContextNode: ReactionContextNode?
|
||||
|
||||
@ -174,6 +178,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
private var loadEffectAnimationDisposable: Disposable?
|
||||
|
||||
private var animateInTimestamp: Double?
|
||||
private var performedActionsOnAnimateOut: Bool = false
|
||||
private var presentationAnimationState: PresentationAnimationState = .initial
|
||||
private var appliedAnimationState: PresentationAnimationState = .initial
|
||||
private var animateOutToEmpty: Bool = false
|
||||
@ -226,13 +231,13 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
self.animateOutToEmpty = true
|
||||
|
||||
self.environment?.controller()?.dismiss()
|
||||
|
||||
let sendParameters = ChatSendMessageActionSheetController.SendParameters(
|
||||
effect: self.selectedMessageEffect.flatMap({ ChatSendMessageActionSheetController.SendParameters.Effect(id: $0.id) }),
|
||||
textIsAboveMedia: self.mediaCaptionIsAbove
|
||||
)
|
||||
|
||||
component.sendMessage(.generic, sendParameters)
|
||||
self.environment?.controller()?.dismiss()
|
||||
}
|
||||
|
||||
func animateIn() {
|
||||
@ -247,6 +252,15 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
|
||||
func animateOut(completion: @escaping () -> Void) {
|
||||
if let controller = self.environment?.controller() {
|
||||
controller.forEachController { c in
|
||||
if let c = c as? UndoOverlayController {
|
||||
c.dismiss()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if case .animatedOut = self.presentationAnimationState {
|
||||
} else {
|
||||
self.presentationAnimationState = .animatedOut(completion: completion)
|
||||
@ -361,9 +375,14 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
)
|
||||
}
|
||||
|
||||
var isMessageVisible = component.mediaPreview != nil
|
||||
|
||||
let textString: NSAttributedString
|
||||
if let attributedText = component.textInputView.attributedText {
|
||||
textString = attributedText
|
||||
if textString.length != 0 {
|
||||
isMessageVisible = true
|
||||
}
|
||||
} else {
|
||||
textString = NSAttributedString(string: " ", font: Font.regular(17.0), textColor: .black)
|
||||
}
|
||||
@ -439,6 +458,8 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
}
|
||||
)))
|
||||
|
||||
items.append(.separator)
|
||||
}
|
||||
if !reminders {
|
||||
items.append(.action(ContextMenuActionItem(
|
||||
@ -508,6 +529,10 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
)))
|
||||
}
|
||||
|
||||
if case .separator = items.last {
|
||||
items.removeLast()
|
||||
}
|
||||
|
||||
let actionsStackNode: ContextControllerActionsStackNode
|
||||
if let current = self.actionsStackNode {
|
||||
actionsStackNode = current
|
||||
@ -536,7 +561,9 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
}
|
||||
)
|
||||
actionsStackNode.layer.anchorPoint = CGPoint(x: 1.0, y: 0.0)
|
||||
if isMessageVisible {
|
||||
actionsStackNode.layer.anchorPoint = CGPoint(x: 1.0, y: 0.0)
|
||||
}
|
||||
|
||||
actionsStackNode.push(
|
||||
item: ContextControllerActionsListStackItem(
|
||||
@ -570,6 +597,24 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
self.addSubview(messageItemView)
|
||||
}
|
||||
|
||||
let wallpaperBackgroundNode: WallpaperBackgroundNode
|
||||
if let externalWallpaperBackgroundNode = component.wallpaperBackgroundNode {
|
||||
wallpaperBackgroundNode = externalWallpaperBackgroundNode
|
||||
} else if let current = self.internalWallpaperBackgroundNode {
|
||||
wallpaperBackgroundNode = current
|
||||
wallpaperBackgroundNode.frame = CGRect(origin: CGPoint(), size: availableSize)
|
||||
wallpaperBackgroundNode.updateLayout(size: availableSize, displayMode: .aspectFill, transition: .immediate)
|
||||
} else {
|
||||
wallpaperBackgroundNode = createWallpaperBackgroundNode(context: component.context, forChatDisplay: true, useSharedAnimationPhase: false)
|
||||
wallpaperBackgroundNode.frame = CGRect(origin: CGPoint(), size: availableSize)
|
||||
wallpaperBackgroundNode.updateLayout(size: availableSize, displayMode: .aspectFill, transition: .immediate)
|
||||
wallpaperBackgroundNode.updateBubbleTheme(bubbleTheme: presentationData.theme, bubbleCorners: presentationData.chatBubbleCorners)
|
||||
wallpaperBackgroundNode.update(wallpaper: presentationData.chatWallpaper, animated: false)
|
||||
self.internalWallpaperBackgroundNode = wallpaperBackgroundNode
|
||||
self.insertSubview(wallpaperBackgroundNode.view, at: 0)
|
||||
wallpaperBackgroundNode.alpha = 0.0
|
||||
}
|
||||
|
||||
let localSourceTextInputViewFrame = convertFrame(component.textInputView.bounds, from: component.textInputView, to: self)
|
||||
|
||||
let sourceMessageTextInsets = UIEdgeInsets(top: 7.0, left: 12.0, bottom: 6.0, right: 20.0)
|
||||
@ -605,7 +650,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
let messageItemSize = messageItemView.update(
|
||||
context: component.context,
|
||||
presentationData: presentationData,
|
||||
backgroundNode: component.wallpaperBackgroundNode,
|
||||
backgroundNode: wallpaperBackgroundNode,
|
||||
textString: textString,
|
||||
sourceTextInputView: component.textInputView as? ChatInputTextView,
|
||||
emojiViewProvider: component.emojiViewProvider,
|
||||
@ -882,13 +927,23 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
guard let self, let component = self.component else {
|
||||
return
|
||||
}
|
||||
|
||||
if let controller = self.environment?.controller() {
|
||||
controller.forEachController { c in
|
||||
if let c = c as? UndoOverlayController {
|
||||
c.dismiss()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:localize
|
||||
let presentationData = component.updatedPresentationData?.initial ?? component.context.sharedContext.currentPresentationData.with({ $0 })
|
||||
self.environment?.controller()?.present(UndoOverlayController(
|
||||
presentationData: presentationData,
|
||||
content: .premiumPaywall(
|
||||
title: nil,
|
||||
text: "Subscribe to [TelegramPremium]() to add this animated effect.",
|
||||
text: "Subscribe to [Telegram Premium]() to add this animated effect.",
|
||||
customUndoText: nil,
|
||||
timeout: nil,
|
||||
linkAction: nil
|
||||
@ -900,11 +955,12 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
if case .info = action {
|
||||
self.window?.endEditing(true)
|
||||
self.animateOutToEmpty = true
|
||||
self.environment?.controller()?.dismiss()
|
||||
|
||||
//TODO:localize
|
||||
let premiumController = component.context.sharedContext.makePremiumIntroController(context: component.context, source: .animatedEmoji, forceDark: false, dismissed: nil)
|
||||
let _ = premiumController
|
||||
//parentNavigationController.pushViewController(premiumController)
|
||||
component.openPremiumPaywall(premiumController)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -922,7 +978,10 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
let sendButtonSize = CGSize(width: min(sourceSendButtonFrame.width, 44.0), height: sourceSendButtonFrame.height)
|
||||
var readySendButtonFrame = CGRect(origin: CGPoint(x: sourceSendButtonFrame.maxX - sendButtonSize.width, y: sourceSendButtonFrame.minY), size: sendButtonSize)
|
||||
|
||||
let sourceActionsStackFrame = CGRect(origin: CGPoint(x: readySendButtonFrame.minX + 1.0 - actionsStackSize.width, y: sourceMessageItemFrame.maxY + messageActionsSpacing), size: actionsStackSize)
|
||||
var sourceActionsStackFrame = CGRect(origin: CGPoint(x: readySendButtonFrame.minX + 1.0 - actionsStackSize.width, y: sourceMessageItemFrame.maxY + messageActionsSpacing), size: actionsStackSize)
|
||||
if !isMessageVisible {
|
||||
sourceActionsStackFrame.origin.y = sourceSendButtonFrame.maxY - sourceActionsStackFrame.height - 5.0
|
||||
}
|
||||
|
||||
var readyMessageItemFrame = CGRect(origin: CGPoint(x: readySendButtonFrame.minX + 8.0 - messageItemSize.width, y: readySendButtonFrame.maxY - 6.0 - messageItemSize.height), size: messageItemSize)
|
||||
if let mediaPreview = component.mediaPreview {
|
||||
@ -935,6 +994,9 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
|
||||
var readyActionsStackFrame = CGRect(origin: CGPoint(x: readySendButtonFrame.minX + 1.0 - actionsStackSize.width, y: readyMessageItemFrame.maxY + messageActionsSpacing), size: actionsStackSize)
|
||||
if !isMessageVisible {
|
||||
readyActionsStackFrame.origin.y = readySendButtonFrame.maxY - readyActionsStackFrame.height - 5.0
|
||||
}
|
||||
|
||||
let bottomOverflow = readyActionsStackFrame.maxY - (availableSize.height - environment.safeInsets.bottom)
|
||||
if bottomOverflow > 0.0 {
|
||||
@ -1002,6 +1064,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
}
|
||||
|
||||
transition.setFrame(view: messageItemView, frame: messageItemFrame)
|
||||
transition.setAlpha(view: messageItemView, alpha: isMessageVisible ? 1.0 : 0.0)
|
||||
messageItemView.updateClippingRect(
|
||||
sourceMediaPreview: component.mediaPreview,
|
||||
isAnimatedIn: self.presentationAnimationState.key == .animatedIn,
|
||||
@ -1010,7 +1073,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
transition: transition
|
||||
)
|
||||
|
||||
transition.setPosition(view: actionsStackNode.view, position: CGPoint(x: actionsStackFrame.maxX, y: actionsStackFrame.minY))
|
||||
transition.setPosition(view: actionsStackNode.view, position: CGPoint(x: actionsStackFrame.minX + actionsStackNode.layer.anchorPoint.x * actionsStackFrame.width, y: actionsStackFrame.minY + actionsStackNode.layer.anchorPoint.y * actionsStackFrame.height))
|
||||
transition.setBounds(view: actionsStackNode.view, bounds: CGRect(origin: CGPoint(), size: actionsStackFrame.size))
|
||||
if !transition.animation.isImmediate && previousAnimationState.key != self.presentationAnimationState.key {
|
||||
switch self.presentationAnimationState {
|
||||
@ -1155,7 +1218,7 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
component.sourceSendButton.isHidden = false
|
||||
|
||||
transition.setAlpha(view: sendButton, alpha: 0.0)
|
||||
if let messageItemView = self.messageItemView {
|
||||
if let messageItemView = self.messageItemView, isMessageVisible {
|
||||
transition.setAlpha(view: messageItemView, alpha: 0.0)
|
||||
}
|
||||
}
|
||||
@ -1168,13 +1231,16 @@ final class ChatSendMessageContextScreenComponent: Component {
|
||||
return
|
||||
}
|
||||
if case let .animatedOut(completion) = self.presentationAnimationState {
|
||||
if let component = self.component, !self.animateOutToEmpty {
|
||||
if component.mediaPreview == nil {
|
||||
component.textInputView.isHidden = false
|
||||
if !self.performedActionsOnAnimateOut {
|
||||
self.performedActionsOnAnimateOut = true
|
||||
if let component = self.component, !self.animateOutToEmpty {
|
||||
if component.mediaPreview == nil {
|
||||
component.textInputView.isHidden = false
|
||||
}
|
||||
component.sourceSendButton.isHidden = false
|
||||
}
|
||||
component.sourceSendButton.isHidden = false
|
||||
completion()
|
||||
}
|
||||
completion()
|
||||
}
|
||||
})
|
||||
|
||||
@ -1226,6 +1292,7 @@ public class ChatSendMessageContextScreen: ViewControllerComponentContainer, Cha
|
||||
completion: @escaping () -> Void,
|
||||
sendMessage: @escaping (ChatSendMessageActionSheetController.SendMode, ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
schedule: @escaping (ChatSendMessageActionSheetController.SendParameters?) -> Void,
|
||||
openPremiumPaywall: @escaping (ViewController) -> Void,
|
||||
reactionItems: [ReactionItem]?,
|
||||
availableMessageEffects: AvailableMessageEffects?,
|
||||
isPremium: Bool
|
||||
@ -1253,6 +1320,7 @@ public class ChatSendMessageContextScreen: ViewControllerComponentContainer, Cha
|
||||
completion: completion,
|
||||
sendMessage: sendMessage,
|
||||
schedule: schedule,
|
||||
openPremiumPaywall: openPremiumPaywall,
|
||||
reactionItems: reactionItems,
|
||||
availableMessageEffects: availableMessageEffects,
|
||||
isPremium: isPremium
|
||||
|
@ -574,7 +574,7 @@ open class NavigationController: UINavigationController, ContainableController,
|
||||
|
||||
modalStyleOverlayTransitionFactor = max(modalStyleOverlayTransitionFactor, overlayContainer.controller.modalStyleOverlayTransitionFactor)
|
||||
|
||||
if overlayContainer.isReady {
|
||||
if overlayContainer.isReady && !overlayContainer.isRemoved {
|
||||
let wasNotAdded = overlayContainer.supernode == nil
|
||||
|
||||
if overlayWantsToBeBelowKeyboard {
|
||||
@ -1529,26 +1529,26 @@ open class NavigationController: UINavigationController, ContainableController,
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
if inGlobal {
|
||||
for i in 0 ..< strongSelf.globalOverlayContainers.count {
|
||||
let overlayContainer = strongSelf.globalOverlayContainers[i]
|
||||
if overlayContainer.controller === controller {
|
||||
overlayContainer.removeFromSupernode()
|
||||
strongSelf.globalOverlayContainers.remove(at: i)
|
||||
strongSelf.internalGlobalOverlayControllersUpdated()
|
||||
break
|
||||
}
|
||||
|
||||
for i in 0 ..< strongSelf.globalOverlayContainers.count {
|
||||
let overlayContainer = strongSelf.globalOverlayContainers[i]
|
||||
if overlayContainer.controller === controller {
|
||||
overlayContainer.isRemoved = true
|
||||
overlayContainer.removeFromSupernode()
|
||||
strongSelf.globalOverlayContainers.remove(at: i)
|
||||
strongSelf.internalGlobalOverlayControllersUpdated()
|
||||
break
|
||||
}
|
||||
} else {
|
||||
for i in 0 ..< strongSelf.overlayContainers.count {
|
||||
let overlayContainer = strongSelf.overlayContainers[i]
|
||||
if overlayContainer.controller === controller {
|
||||
overlayContainer.removeFromSupernode()
|
||||
strongSelf.overlayContainers.remove(at: i)
|
||||
strongSelf._overlayControllersPromise.set(strongSelf.overlayContainers.map({ $0.controller }))
|
||||
strongSelf.internalOverlayControllersUpdated()
|
||||
break
|
||||
}
|
||||
}
|
||||
for i in 0 ..< strongSelf.overlayContainers.count {
|
||||
let overlayContainer = strongSelf.overlayContainers[i]
|
||||
if overlayContainer.controller === controller {
|
||||
overlayContainer.isRemoved = true
|
||||
overlayContainer.removeFromSupernode()
|
||||
strongSelf.overlayContainers.remove(at: i)
|
||||
strongSelf._overlayControllersPromise.set(strongSelf.overlayContainers.map({ $0.controller }))
|
||||
strongSelf.internalOverlayControllersUpdated()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ final class NavigationOverlayContainer: ASDisplayNode {
|
||||
let blocksInteractionUntilReady: Bool
|
||||
|
||||
private(set) var isReady: Bool = false
|
||||
var isRemoved: Bool = false
|
||||
var isReadyUpdated: (() -> Void)?
|
||||
private var isReadyDisposable: Disposable?
|
||||
|
||||
|
@ -461,7 +461,11 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable {
|
||||
if case .media = controller.subject {
|
||||
persistentItems = true
|
||||
}
|
||||
let previewNode = MediaPickerSelectedListNode(context: controller.context, persistentItems: persistentItems, isExternalPreview: true)
|
||||
var isObscuredExternalPreview = false
|
||||
if case .selected = self.currentDisplayMode {
|
||||
isObscuredExternalPreview = true
|
||||
}
|
||||
let previewNode = MediaPickerSelectedListNode(context: controller.context, persistentItems: persistentItems, isExternalPreview: true, isObscuredExternalPreview: isObscuredExternalPreview)
|
||||
let clippingRect = CGRect(origin: CGPoint(x: 0.0, y: navigationHeight), size: CGSize(width: layout.size.width, height: max(0.0, layout.size.height - navigationHeight - layout.intrinsicInsets.bottom - layout.additionalInsets.bottom - 1.0)))
|
||||
previewNode.globalClippingRect = self.view.convert(clippingRect, to: nil)
|
||||
previewNode.interaction = self.controller?.interaction
|
||||
@ -1000,7 +1004,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable {
|
||||
persistentItems = true
|
||||
}
|
||||
|
||||
let selectionNode = MediaPickerSelectedListNode(context: controller.context, persistentItems: persistentItems, isExternalPreview: false)
|
||||
let selectionNode = MediaPickerSelectedListNode(context: controller.context, persistentItems: persistentItems, isExternalPreview: false, isObscuredExternalPreview: false)
|
||||
selectionNode.alpha = animated ? 0.0 : 1.0
|
||||
selectionNode.layer.allowsGroupOpacity = true
|
||||
selectionNode.isUserInteractionEnabled = false
|
||||
|
@ -510,6 +510,7 @@ final class MediaPickerSelectedListNode: ASDisplayNode, ASScrollViewDelegate, AS
|
||||
private let context: AccountContext
|
||||
private let persistentItems: Bool
|
||||
private let isExternalPreview: Bool
|
||||
private let isObscuredExternalPreview: Bool
|
||||
var globalClippingRect: CGRect?
|
||||
var layoutType: ChatSendMessageContextScreenMediaPreviewLayoutType {
|
||||
return .media
|
||||
@ -539,10 +540,11 @@ final class MediaPickerSelectedListNode: ASDisplayNode, ASScrollViewDelegate, AS
|
||||
return self.ready.get()
|
||||
}
|
||||
|
||||
init(context: AccountContext, persistentItems: Bool, isExternalPreview: Bool) {
|
||||
init(context: AccountContext, persistentItems: Bool, isExternalPreview: Bool, isObscuredExternalPreview: Bool) {
|
||||
self.context = context
|
||||
self.persistentItems = persistentItems
|
||||
self.isExternalPreview = isExternalPreview
|
||||
self.isObscuredExternalPreview = isObscuredExternalPreview
|
||||
|
||||
self.scrollNode = ASScrollNode()
|
||||
self.scrollNode.clipsToBounds = false
|
||||
@ -633,7 +635,7 @@ final class MediaPickerSelectedListNode: ASDisplayNode, ASScrollViewDelegate, AS
|
||||
}
|
||||
|
||||
for (identifier, itemNode) in strongSelf.itemNodes {
|
||||
if let (transitionView, _, _) = strongSelf.getTransitionView(identifier) {
|
||||
if !strongSelf.isObscuredExternalPreview, let (transitionView, _, _) = strongSelf.getTransitionView(identifier) {
|
||||
itemNode.animateFrom(transitionView, transition: transition)
|
||||
} else {
|
||||
if strongSelf.isExternalPreview {
|
||||
@ -694,7 +696,7 @@ final class MediaPickerSelectedListNode: ASDisplayNode, ASScrollViewDelegate, AS
|
||||
}
|
||||
|
||||
for (identifier, itemNode) in self.itemNodes {
|
||||
if let (transitionView, maybeDustNode, completion) = self.getTransitionView(identifier) {
|
||||
if !self.isObscuredExternalPreview, let (transitionView, maybeDustNode, completion) = self.getTransitionView(identifier) {
|
||||
itemNode.animateTo(transitionView, dustNode: maybeDustNode, transition: transition, completion: completion)
|
||||
} else {
|
||||
if self.isExternalPreview {
|
||||
|
@ -1844,9 +1844,11 @@ public final class ReactionContextNode: ASDisplayNode, ASScrollViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
return context.availableMessageEffects
|
||||
|> take(1)
|
||||
|> mapToSignal { availableMessageEffects -> Signal<[EmojiPagerContentComponent.ItemGroup], NoError> in
|
||||
return combineLatest(
|
||||
context.availableMessageEffects |> take(1),
|
||||
hasPremium |> take(1)
|
||||
)
|
||||
|> mapToSignal { availableMessageEffects, hasPremium -> Signal<[EmojiPagerContentComponent.ItemGroup], NoError> in
|
||||
guard let availableMessageEffects else {
|
||||
return .single([])
|
||||
}
|
||||
@ -1895,13 +1897,30 @@ public final class ReactionContextNode: ASDisplayNode, ASScrollViewDelegate {
|
||||
tintMode = .primary
|
||||
}
|
||||
|
||||
let icon: EmojiPagerContentComponent.Item.Icon
|
||||
if i == 0 {
|
||||
if !hasPremium && item.isPremium {
|
||||
icon = .locked
|
||||
} else {
|
||||
icon = .none
|
||||
}
|
||||
} else {
|
||||
if !hasPremium && item.isPremium {
|
||||
icon = .locked
|
||||
} else if let staticIcon = item.staticIcon {
|
||||
icon = .customFile(staticIcon)
|
||||
} else {
|
||||
icon = .text(item.emoticon)
|
||||
}
|
||||
}
|
||||
|
||||
let animationData = EntityKeyboardAnimationData(file: itemFile, partialReference: .none)
|
||||
let resultItem = EmojiPagerContentComponent.Item(
|
||||
animationData: animationData,
|
||||
content: .animation(animationData),
|
||||
itemFile: itemFile,
|
||||
subgroupId: nil,
|
||||
icon: .none,
|
||||
icon: icon,
|
||||
tintMode: tintMode
|
||||
)
|
||||
|
||||
@ -2160,6 +2179,15 @@ public final class ReactionContextNode: ASDisplayNode, ASScrollViewDelegate {
|
||||
let context = self.context
|
||||
let resultSignal: Signal<(items: [EmojiPagerContentComponent.ItemGroup], isFinalResult: Bool), NoError>
|
||||
if self.isMessageEffects {
|
||||
let hasPremium = context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.Peer(id: context.account.peerId))
|
||||
|> map { peer -> Bool in
|
||||
guard case let .user(user) = peer else {
|
||||
return false
|
||||
}
|
||||
return user.isPremium
|
||||
}
|
||||
|> distinctUntilChanged
|
||||
|
||||
let keywords: Signal<[String], NoError> = .single(value.identifiers)
|
||||
resultSignal = keywords
|
||||
|> mapToSignal { keywords -> Signal<(items: [EmojiPagerContentComponent.ItemGroup], isFinalResult: Bool), NoError> in
|
||||
@ -2168,9 +2196,11 @@ public final class ReactionContextNode: ASDisplayNode, ASScrollViewDelegate {
|
||||
allEmoticons[keyword] = keyword
|
||||
}
|
||||
|
||||
return context.availableMessageEffects
|
||||
|> take(1)
|
||||
|> mapToSignal { availableMessageEffects -> Signal<(items: [EmojiPagerContentComponent.ItemGroup], isFinalResult: Bool), NoError> in
|
||||
return combineLatest(
|
||||
context.availableMessageEffects |> take(1),
|
||||
hasPremium |> take(1)
|
||||
)
|
||||
|> mapToSignal { availableMessageEffects, hasPremium -> Signal<(items: [EmojiPagerContentComponent.ItemGroup], isFinalResult: Bool), NoError> in
|
||||
guard let availableMessageEffects else {
|
||||
return .single(([], true))
|
||||
}
|
||||
@ -2219,13 +2249,30 @@ public final class ReactionContextNode: ASDisplayNode, ASScrollViewDelegate {
|
||||
tintMode = .primary
|
||||
}
|
||||
|
||||
let icon: EmojiPagerContentComponent.Item.Icon
|
||||
if i == 0 {
|
||||
if !hasPremium && item.isPremium {
|
||||
icon = .locked
|
||||
} else {
|
||||
icon = .none
|
||||
}
|
||||
} else {
|
||||
if !hasPremium && item.isPremium {
|
||||
icon = .locked
|
||||
} else if let staticIcon = item.staticIcon {
|
||||
icon = .customFile(staticIcon)
|
||||
} else {
|
||||
icon = .text(item.emoticon)
|
||||
}
|
||||
}
|
||||
|
||||
let animationData = EntityKeyboardAnimationData(file: itemFile, partialReference: .none)
|
||||
let resultItem = EmojiPagerContentComponent.Item(
|
||||
animationData: animationData,
|
||||
content: .animation(animationData),
|
||||
itemFile: itemFile,
|
||||
subgroupId: nil,
|
||||
icon: .none,
|
||||
icon: icon,
|
||||
tintMode: tintMode
|
||||
)
|
||||
|
||||
|
@ -371,7 +371,6 @@ swift_library(
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageAttachedContentButtonNode",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageWebpageBubbleContentNode",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageItem",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageItemView",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageStickerItemNode",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageSwipeToReplyNode",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageSelectionNode",
|
||||
|
@ -141,6 +141,8 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
private var wasPending: Bool = false
|
||||
private var didChangeFromPendingToSent: Bool = false
|
||||
|
||||
private var fetchEffectDisposable: Disposable?
|
||||
|
||||
required public init(rotated: Bool) {
|
||||
self.contextSourceNode = ContextExtractedContentContainingNode()
|
||||
self.containerNode = ContextControllerSourceNode()
|
||||
@ -593,7 +595,9 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
let isPlaying = self.visibilityStatus == true && !self.forceStopAnimations
|
||||
if !isPlaying {
|
||||
self.removeAdditionalAnimations()
|
||||
self.removeEffectAnimations()
|
||||
}
|
||||
|
||||
if let animationNode = self.animationNode as? AnimatedStickerNode {
|
||||
if self.isPlaying != isPlaying || (isPlaying && !self.didSetUpAnimationNode) {
|
||||
self.isPlaying = isPlaying
|
||||
@ -623,6 +627,23 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
}
|
||||
|
||||
if isPlaying, let animationNode = self.animationNode as? AnimatedStickerNode {
|
||||
var effectAlreadySeen = true
|
||||
if item.message.flags.contains(.Incoming) {
|
||||
if let unreadRange = item.controllerInteraction.unreadMessageRange[UnreadMessageRangeKey(peerId: item.message.id.peerId, namespace: item.message.id.namespace)] {
|
||||
if unreadRange.contains(item.message.id.id) {
|
||||
if !item.controllerInteraction.seenOneTimeAnimatedMedia.contains(item.message.id) {
|
||||
effectAlreadySeen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if self.didChangeFromPendingToSent {
|
||||
if !item.controllerInteraction.seenOneTimeAnimatedMedia.contains(item.message.id) {
|
||||
effectAlreadySeen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var alreadySeen = true
|
||||
if isEmoji && self.emojiString == nil {
|
||||
if !item.controllerInteraction.seenOneTimeAnimatedMedia.contains(item.message.id) {
|
||||
@ -659,6 +680,10 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
animationNode.playOnce()
|
||||
}
|
||||
}
|
||||
|
||||
if !effectAlreadySeen {
|
||||
self.playMessageEffect(force: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1030,6 +1055,8 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
isReplyThread = true
|
||||
}
|
||||
|
||||
let messageEffect = item.message.messageEffect(availableMessageEffects: item.associatedData.availableMessageEffects)
|
||||
|
||||
let statusSuggestedWidthAndContinue = makeDateAndStatusLayout(ChatMessageDateAndStatusNode.Arguments(
|
||||
context: item.context,
|
||||
presentationData: item.presentationData,
|
||||
@ -1045,7 +1072,7 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
reactionPeers: dateReactionsAndPeers.peers,
|
||||
displayAllReactionPeers: item.message.id.peerId.namespace == Namespaces.Peer.CloudUser,
|
||||
areReactionsTags: item.message.areReactionsTags(accountPeerId: item.context.account.peerId),
|
||||
messageEffect: item.message.messageEffect(availableMessageEffects: item.associatedData.availableMessageEffects),
|
||||
messageEffect: messageEffect,
|
||||
replyCount: dateReplies,
|
||||
isPinned: item.message.tags.contains(.pinned) && !item.associatedData.isInPinnedListMode && !isReplyThread,
|
||||
hasAutoremove: item.message.isSelfExpiring,
|
||||
@ -1757,6 +1784,13 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
}
|
||||
item.controllerInteraction.displayImportedMessageTooltip(strongSelf.dateAndStatusNode)
|
||||
}
|
||||
} else if messageEffect != nil {
|
||||
strongSelf.dateAndStatusNode.pressed = {
|
||||
guard let strongSelf = weakSelf.value, let item = strongSelf.item else {
|
||||
return
|
||||
}
|
||||
item.controllerInteraction.playMessageEffect(item.message)
|
||||
}
|
||||
} else {
|
||||
strongSelf.dateAndStatusNode.pressed = nil
|
||||
}
|
||||
@ -2987,6 +3021,14 @@ public class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
|
||||
|
||||
return (image, self.imageNode.frame)
|
||||
}
|
||||
|
||||
override public func messageEffectTargetView() -> UIView? {
|
||||
if let result = self.dateAndStatusNode.messageEffectTargetView() {
|
||||
return result
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public struct AnimatedEmojiSoundsConfiguration {
|
||||
|
@ -638,10 +638,6 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
|
||||
private var replyRecognizer: ChatSwipeToReplyRecognizer?
|
||||
private var currentSwipeAction: ChatControllerInteractionSwipeAction?
|
||||
|
||||
private var fetchEffectDisposable: Disposable?
|
||||
|
||||
//private let debugNode: ASDisplayNode
|
||||
|
||||
override public var visibility: ListViewItemNodeVisibility {
|
||||
didSet {
|
||||
if self.visibility != oldValue {
|
||||
@ -842,7 +838,6 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.fetchEffectDisposable?.dispose()
|
||||
}
|
||||
|
||||
override public func cancelInsertionAnimations() {
|
||||
@ -5878,172 +5873,6 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
|
||||
return false
|
||||
}
|
||||
|
||||
private var forceStopAnimations: Bool = false
|
||||
private var playedPremiumStickerAnimation: Bool = false
|
||||
private var additionalAnimationNodes: [ChatMessageTransitionNode.DecorationItemNode] = []
|
||||
|
||||
private func playPremiumStickerAnimation(effect: AvailableMessageEffects.MessageEffect, force: Bool) {
|
||||
guard let item = self.item else {
|
||||
return
|
||||
}
|
||||
if self.playedPremiumStickerAnimation && !force {
|
||||
return
|
||||
}
|
||||
self.playedPremiumStickerAnimation = true
|
||||
|
||||
if let effectAnimation = effect.effectAnimation {
|
||||
self.playEffectAnimation(resource: effectAnimation.resource, isStickerEffect: true)
|
||||
if self.fetchEffectDisposable == nil {
|
||||
self.fetchEffectDisposable = freeMediaFileResourceInteractiveFetched(account: item.context.account, userLocation: .other, fileReference: .standalone(media: effectAnimation), resource: effectAnimation.resource).startStrict()
|
||||
}
|
||||
} else {
|
||||
let effectSticker = effect.effectSticker
|
||||
if let effectFile = effectSticker.videoThumbnails.first {
|
||||
self.playEffectAnimation(resource: effectFile.resource, isStickerEffect: true)
|
||||
if self.fetchEffectDisposable == nil {
|
||||
self.fetchEffectDisposable = freeMediaFileResourceInteractiveFetched(account: item.context.account, userLocation: .other, fileReference: .standalone(media: effectSticker), resource: effectFile.resource).startStrict()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func playEffectAnimation(resource: MediaResource, isStickerEffect: Bool = false) {
|
||||
guard let item = self.item else {
|
||||
return
|
||||
}
|
||||
guard let transitionNode = item.controllerInteraction.getMessageTransitionNode() as? ChatMessageTransitionNode else {
|
||||
return
|
||||
}
|
||||
|
||||
let source = AnimatedStickerResourceSource(account: item.context.account, resource: resource, fitzModifier: nil)
|
||||
|
||||
let animationSize = CGSize(width: 380.0, height: 380.0)
|
||||
let animationNodeFrame: CGRect
|
||||
|
||||
var messageEffectView: UIView?
|
||||
for contentNode in self.contentNodes {
|
||||
if let result = contentNode.messageEffectTargetView() {
|
||||
messageEffectView = result
|
||||
break
|
||||
}
|
||||
}
|
||||
if messageEffectView == nil {
|
||||
if let mosaicStatusNode = self.mosaicStatusNode, let result = mosaicStatusNode.messageEffectTargetView() {
|
||||
messageEffectView = result
|
||||
}
|
||||
}
|
||||
|
||||
if let messageEffectView {
|
||||
animationNodeFrame = animationSize.centered(around: messageEffectView.convert(messageEffectView.bounds, to: self.view).center)
|
||||
} else {
|
||||
animationNodeFrame = animationSize.centered(around: self.backgroundNode.frame.center)
|
||||
}
|
||||
|
||||
if self.additionalAnimationNodes.count >= 4 {
|
||||
return
|
||||
}
|
||||
|
||||
let incomingMessage = item.message.effectivelyIncoming(item.context.account.peerId)
|
||||
|
||||
do {
|
||||
let pathPrefix = item.context.account.postbox.mediaBox.shortLivedResourceCachePathPrefix(resource.id)
|
||||
|
||||
let additionalAnimationNode: AnimatedStickerNode
|
||||
var effectiveScale: CGFloat = 1.0
|
||||
#if targetEnvironment(simulator)
|
||||
additionalAnimationNode = DirectAnimatedStickerNode()
|
||||
effectiveScale = 1.4
|
||||
#else
|
||||
if "".isEmpty {
|
||||
additionalAnimationNode = DirectAnimatedStickerNode()
|
||||
effectiveScale = 1.4
|
||||
} else {
|
||||
additionalAnimationNode = LottieMetalAnimatedStickerNode()
|
||||
}
|
||||
#endif
|
||||
additionalAnimationNode.updateLayout(size: animationSize)
|
||||
additionalAnimationNode.setup(source: source, width: Int(animationSize.width * effectiveScale), height: Int(animationSize.height * effectiveScale), playbackMode: .once, mode: .direct(cachePathPrefix: pathPrefix))
|
||||
var animationFrame: CGRect
|
||||
if isStickerEffect {
|
||||
let offsetScale: CGFloat = 0.3
|
||||
animationFrame = animationNodeFrame.offsetBy(dx: incomingMessage ? animationNodeFrame.width * offsetScale : -animationNodeFrame.width * offsetScale, dy: -10.0)
|
||||
} else {
|
||||
animationFrame = animationNodeFrame.insetBy(dx: -animationNodeFrame.width, dy: -animationNodeFrame.height)
|
||||
.offsetBy(dx: incomingMessage ? animationNodeFrame.width - 10.0 : -animationNodeFrame.width + 10.0, dy: 0.0)
|
||||
animationFrame = animationFrame.offsetBy(dx: CGFloat.random(in: -30.0 ... 30.0), dy: CGFloat.random(in: -30.0 ... 30.0))
|
||||
}
|
||||
|
||||
animationFrame = animationFrame.offsetBy(dx: 0.0, dy: self.insets.top)
|
||||
additionalAnimationNode.frame = animationFrame
|
||||
if incomingMessage {
|
||||
additionalAnimationNode.transform = CATransform3DMakeScale(-1.0, 1.0, 1.0)
|
||||
}
|
||||
|
||||
let decorationNode = transitionNode.add(decorationView: additionalAnimationNode.view, itemNode: self)
|
||||
additionalAnimationNode.completed = { [weak self, weak decorationNode, weak transitionNode] _ in
|
||||
guard let decorationNode = decorationNode else {
|
||||
return
|
||||
}
|
||||
self?.additionalAnimationNodes.removeAll(where: { $0 === decorationNode })
|
||||
transitionNode?.remove(decorationNode: decorationNode)
|
||||
}
|
||||
additionalAnimationNode.isPlayingChanged = { [weak self, weak decorationNode, weak transitionNode] isPlaying in
|
||||
if !isPlaying {
|
||||
guard let decorationNode = decorationNode else {
|
||||
return
|
||||
}
|
||||
self?.additionalAnimationNodes.removeAll(where: { $0 === decorationNode })
|
||||
transitionNode?.remove(decorationNode: decorationNode)
|
||||
}
|
||||
}
|
||||
|
||||
self.additionalAnimationNodes.append(decorationNode)
|
||||
|
||||
additionalAnimationNode.visibility = true
|
||||
}
|
||||
}
|
||||
|
||||
private func removeAdditionalAnimations() {
|
||||
for decorationNode in self.additionalAnimationNodes {
|
||||
if let additionalAnimationNode = decorationNode.contentView.asyncdisplaykit_node as? AnimatedStickerNode {
|
||||
additionalAnimationNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak additionalAnimationNode] _ in
|
||||
additionalAnimationNode?.visibility = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func currentMessageEffect() -> AvailableMessageEffects.MessageEffect? {
|
||||
guard let item = self.item else {
|
||||
return nil
|
||||
}
|
||||
var messageEffect: AvailableMessageEffects.MessageEffect?
|
||||
for attribute in item.message.attributes {
|
||||
if let attribute = attribute as? EffectMessageAttribute {
|
||||
if let availableMessageEffects = item.associatedData.availableMessageEffects {
|
||||
for effect in availableMessageEffects.messageEffects {
|
||||
if effect.id == attribute.id {
|
||||
messageEffect = effect
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return messageEffect
|
||||
}
|
||||
|
||||
private func playMessageEffect(force: Bool) {
|
||||
if let messageEffect = self.currentMessageEffect() {
|
||||
self.playPremiumStickerAnimation(effect: messageEffect, force: force)
|
||||
}
|
||||
}
|
||||
|
||||
override public func playMessageEffect() {
|
||||
self.playMessageEffect(force: true)
|
||||
}
|
||||
|
||||
private func updateVisibility() {
|
||||
guard let item = self.item else {
|
||||
return
|
||||
@ -6058,12 +5887,8 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
|
||||
isPlaying = false
|
||||
}
|
||||
|
||||
if self.forceStopAnimations {
|
||||
isPlaying = false
|
||||
}
|
||||
|
||||
if !isPlaying {
|
||||
self.removeAdditionalAnimations()
|
||||
self.removeEffectAnimations()
|
||||
}
|
||||
|
||||
if isPlaying {
|
||||
@ -6091,4 +5916,17 @@ public class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewI
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public func messageEffectTargetView() -> UIView? {
|
||||
for contentNode in self.contentNodes {
|
||||
if let result = contentNode.messageEffectTargetView() {
|
||||
return result
|
||||
}
|
||||
}
|
||||
if let mosaicStatusNode = self.mosaicStatusNode, let result = mosaicStatusNode.messageEffectTargetView() {
|
||||
return result
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ swift_library(
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageItemCommon",
|
||||
"//submodules/TextFormat",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageItem",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageTransitionNode",
|
||||
"//submodules/TelegramAnimatedStickerNode",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -14,6 +14,10 @@ import ChatControllerInteraction
|
||||
import ChatMessageItemCommon
|
||||
import TextFormat
|
||||
import ChatMessageItem
|
||||
import ChatMessageTransitionNode
|
||||
import AnimatedStickerNode
|
||||
import TelegramAnimatedStickerNode
|
||||
import LottieMetal
|
||||
|
||||
public func chatMessageItemLayoutConstants(_ constants: (ChatMessageItemLayoutConstants, ChatMessageItemLayoutConstants), params: ListViewItemLayoutParams, presentationData: ChatPresentationData) -> ChatMessageItemLayoutConstants {
|
||||
var result: ChatMessageItemLayoutConstants
|
||||
@ -653,6 +657,11 @@ open class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol {
|
||||
|
||||
open var awaitingAppliedReaction: (MessageReaction.Reaction?, () -> Void)?
|
||||
|
||||
private var fetchEffectDisposable: Disposable?
|
||||
|
||||
public var playedEffectAnimation: Bool = false
|
||||
public var effectAnimationNodes: [ChatMessageTransitionNode.DecorationItemNode] = []
|
||||
|
||||
public required init(rotated: Bool) {
|
||||
super.init(layerBacked: false, dynamicBounce: true, rotated: rotated)
|
||||
if rotated {
|
||||
@ -664,6 +673,10 @@ open class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.fetchEffectDisposable?.dispose()
|
||||
}
|
||||
|
||||
override open func reuse() {
|
||||
super.reuse()
|
||||
|
||||
@ -710,6 +723,28 @@ open class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
public func matchesMessage(id: MessageId) -> Bool {
|
||||
if let item = self.item {
|
||||
for (message, _) in item.content {
|
||||
if message.id == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public func messages() -> [Message] {
|
||||
guard let item = self.item else {
|
||||
return []
|
||||
}
|
||||
var messages: [Message] = []
|
||||
for (message, _) in item.content {
|
||||
messages.append(message)
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
open func transitionNode(id: MessageId, media: Media, adjustRect: Bool) -> (ASDisplayNode, CGRect, () -> (UIView?, UIView?))? {
|
||||
return nil
|
||||
}
|
||||
@ -888,6 +923,146 @@ open class ChatMessageItemView: ListViewItemNode, ChatMessageItemNodeProtocol {
|
||||
return self.bounds
|
||||
}
|
||||
|
||||
open func playMessageEffect() {
|
||||
private func playEffectAnimation(effect: AvailableMessageEffects.MessageEffect, force: Bool) {
|
||||
guard let item = self.item else {
|
||||
return
|
||||
}
|
||||
if self.playedEffectAnimation && !force {
|
||||
return
|
||||
}
|
||||
self.playedEffectAnimation = true
|
||||
|
||||
if let effectAnimation = effect.effectAnimation {
|
||||
self.playEffectAnimation(resource: effectAnimation.resource)
|
||||
if self.fetchEffectDisposable == nil {
|
||||
self.fetchEffectDisposable = freeMediaFileResourceInteractiveFetched(account: item.context.account, userLocation: .other, fileReference: .standalone(media: effectAnimation), resource: effectAnimation.resource).startStrict()
|
||||
}
|
||||
} else {
|
||||
let effectSticker = effect.effectSticker
|
||||
if let effectFile = effectSticker.videoThumbnails.first {
|
||||
self.playEffectAnimation(resource: effectFile.resource)
|
||||
if self.fetchEffectDisposable == nil {
|
||||
self.fetchEffectDisposable = freeMediaFileResourceInteractiveFetched(account: item.context.account, userLocation: .other, fileReference: .standalone(media: effectSticker), resource: effectFile.resource).startStrict()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open func messageEffectTargetView() -> UIView? {
|
||||
return nil
|
||||
}
|
||||
|
||||
private func playEffectAnimation(resource: MediaResource) {
|
||||
guard let item = self.item else {
|
||||
return
|
||||
}
|
||||
guard let transitionNode = item.controllerInteraction.getMessageTransitionNode() as? ChatMessageTransitionNode else {
|
||||
return
|
||||
}
|
||||
|
||||
let source = AnimatedStickerResourceSource(account: item.context.account, resource: resource, fitzModifier: nil)
|
||||
|
||||
let animationSize = CGSize(width: 380.0, height: 380.0)
|
||||
let animationNodeFrame: CGRect
|
||||
|
||||
guard let messageEffectView = self.messageEffectTargetView() else {
|
||||
return
|
||||
}
|
||||
|
||||
animationNodeFrame = animationSize.centered(around: messageEffectView.convert(messageEffectView.bounds, to: self.view).center)
|
||||
|
||||
if self.effectAnimationNodes.count >= 2 {
|
||||
return
|
||||
}
|
||||
|
||||
let incomingMessage = item.message.effectivelyIncoming(item.context.account.peerId)
|
||||
|
||||
do {
|
||||
let pathPrefix = item.context.account.postbox.mediaBox.shortLivedResourceCachePathPrefix(resource.id)
|
||||
|
||||
let additionalAnimationNode: AnimatedStickerNode
|
||||
var effectiveScale: CGFloat = 1.0
|
||||
#if targetEnvironment(simulator)
|
||||
additionalAnimationNode = DirectAnimatedStickerNode()
|
||||
effectiveScale = 1.4
|
||||
#else
|
||||
if "".isEmpty {
|
||||
additionalAnimationNode = DirectAnimatedStickerNode()
|
||||
effectiveScale = 1.4
|
||||
} else {
|
||||
additionalAnimationNode = LottieMetalAnimatedStickerNode()
|
||||
}
|
||||
#endif
|
||||
additionalAnimationNode.updateLayout(size: animationSize)
|
||||
additionalAnimationNode.setup(source: source, width: Int(animationSize.width * effectiveScale), height: Int(animationSize.height * effectiveScale), playbackMode: .once, mode: .direct(cachePathPrefix: pathPrefix))
|
||||
var animationFrame: CGRect
|
||||
let offsetScale: CGFloat = 0.3
|
||||
animationFrame = animationNodeFrame.offsetBy(dx: incomingMessage ? animationNodeFrame.width * offsetScale : -animationNodeFrame.width * offsetScale, dy: -10.0)
|
||||
|
||||
animationFrame = animationFrame.offsetBy(dx: 0.0, dy: self.insets.top)
|
||||
additionalAnimationNode.frame = animationFrame
|
||||
if incomingMessage {
|
||||
additionalAnimationNode.transform = CATransform3DMakeScale(-1.0, 1.0, 1.0)
|
||||
}
|
||||
|
||||
let decorationNode = transitionNode.add(decorationView: additionalAnimationNode.view, itemNode: self)
|
||||
additionalAnimationNode.completed = { [weak self, weak decorationNode, weak transitionNode] _ in
|
||||
guard let decorationNode = decorationNode else {
|
||||
return
|
||||
}
|
||||
self?.effectAnimationNodes.removeAll(where: { $0 === decorationNode })
|
||||
transitionNode?.remove(decorationNode: decorationNode)
|
||||
}
|
||||
additionalAnimationNode.isPlayingChanged = { [weak self, weak decorationNode, weak transitionNode] isPlaying in
|
||||
if !isPlaying {
|
||||
guard let decorationNode = decorationNode else {
|
||||
return
|
||||
}
|
||||
self?.effectAnimationNodes.removeAll(where: { $0 === decorationNode })
|
||||
transitionNode?.remove(decorationNode: decorationNode)
|
||||
}
|
||||
}
|
||||
|
||||
self.effectAnimationNodes.append(decorationNode)
|
||||
|
||||
additionalAnimationNode.visibility = true
|
||||
}
|
||||
}
|
||||
|
||||
public func removeEffectAnimations() {
|
||||
for decorationNode in self.effectAnimationNodes {
|
||||
if let additionalAnimationNode = decorationNode.contentView.asyncdisplaykit_node as? AnimatedStickerNode {
|
||||
additionalAnimationNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak additionalAnimationNode] _ in
|
||||
additionalAnimationNode?.visibility = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func currentMessageEffect() -> AvailableMessageEffects.MessageEffect? {
|
||||
guard let item = self.item else {
|
||||
return nil
|
||||
}
|
||||
var messageEffect: AvailableMessageEffects.MessageEffect?
|
||||
for attribute in item.message.attributes {
|
||||
if let attribute = attribute as? EffectMessageAttribute {
|
||||
if let availableMessageEffects = item.associatedData.availableMessageEffects {
|
||||
for effect in availableMessageEffects.messageEffects {
|
||||
if effect.id == attribute.id {
|
||||
messageEffect = effect
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
return messageEffect
|
||||
}
|
||||
|
||||
public func playMessageEffect(force: Bool) {
|
||||
if let messageEffect = self.currentMessageEffect() {
|
||||
self.playEffectAnimation(effect: messageEffect, force: force)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,9 @@ public class ChatMessageStickerItemNode: ChatMessageItemView {
|
||||
|
||||
private var enableSynchronousImageApply: Bool = false
|
||||
|
||||
private var wasPending: Bool = false
|
||||
private var didChangeFromPendingToSent: Bool = false
|
||||
|
||||
override public var visibility: ListViewItemNodeVisibility {
|
||||
didSet {
|
||||
let wasVisible = oldValue != .none
|
||||
@ -92,6 +95,8 @@ public class ChatMessageStickerItemNode: ChatMessageItemView {
|
||||
if self.visibilityStatus != oldValue {
|
||||
self.threadInfoNode?.visibility = self.visibilityStatus == true
|
||||
self.replyInfoNode?.visibility = self.visibilityStatus == true
|
||||
|
||||
self.updateVisibility()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -280,6 +285,13 @@ public class ChatMessageStickerItemNode: ChatMessageItemView {
|
||||
override public func setupItem(_ item: ChatMessageItem, synchronousLoad: Bool) {
|
||||
super.setupItem(item, synchronousLoad: synchronousLoad)
|
||||
|
||||
if item.message.id.namespace == Namespaces.Message.Local || item.message.id.namespace == Namespaces.Message.ScheduledLocal || item.message.id.namespace == Namespaces.Message.QuickReplyLocal {
|
||||
self.wasPending = true
|
||||
}
|
||||
if self.wasPending && (item.message.id.namespace != Namespaces.Message.Local && item.message.id.namespace != Namespaces.Message.ScheduledLocal && item.message.id.namespace != Namespaces.Message.QuickReplyLocal) {
|
||||
self.didChangeFromPendingToSent = true
|
||||
}
|
||||
|
||||
self.replyRecognizer?.allowBothDirections = false//!item.context.sharedContext.immediateExperimentalUISettings.unidirectionalSwipeToReply
|
||||
if self.isNodeLoaded {
|
||||
self.view.disablesInteractiveTransitionGestureRecognizer = false//!item.context.sharedContext.immediateExperimentalUISettings.unidirectionalSwipeToReply
|
||||
@ -1352,6 +1364,8 @@ public class ChatMessageStickerItemNode: ChatMessageItemView {
|
||||
|
||||
f()
|
||||
}
|
||||
|
||||
strongSelf.updateVisibility()
|
||||
}
|
||||
}
|
||||
|
||||
@ -2130,4 +2144,53 @@ public class ChatMessageStickerItemNode: ChatMessageItemView {
|
||||
|
||||
return (image, self.imageNode.frame)
|
||||
}
|
||||
|
||||
private func updateVisibility() {
|
||||
guard let item = self.item else {
|
||||
return
|
||||
}
|
||||
|
||||
var isPlaying = true
|
||||
if case .visible = self.visibility {
|
||||
} else {
|
||||
isPlaying = false
|
||||
}
|
||||
|
||||
if !isPlaying {
|
||||
self.removeEffectAnimations()
|
||||
}
|
||||
|
||||
if isPlaying {
|
||||
var alreadySeen = true
|
||||
if item.message.flags.contains(.Incoming) {
|
||||
if let unreadRange = item.controllerInteraction.unreadMessageRange[UnreadMessageRangeKey(peerId: item.message.id.peerId, namespace: item.message.id.namespace)] {
|
||||
if unreadRange.contains(item.message.id.id) {
|
||||
if !item.controllerInteraction.seenOneTimeAnimatedMedia.contains(item.message.id) {
|
||||
alreadySeen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if self.didChangeFromPendingToSent {
|
||||
if !item.controllerInteraction.seenOneTimeAnimatedMedia.contains(item.message.id) {
|
||||
alreadySeen = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !alreadySeen {
|
||||
item.controllerInteraction.seenOneTimeAnimatedMedia.insert(item.message.id)
|
||||
|
||||
self.playMessageEffect(force: false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override public func messageEffectTargetView() -> UIView? {
|
||||
if let result = self.dateAndStatusNode.messageEffectTargetView() {
|
||||
return result
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ swift_library(
|
||||
],
|
||||
deps = [
|
||||
"//submodules/AsyncDisplayKit",
|
||||
"//submodules/TelegramUI/Components/Chat/ChatMessageItemView",
|
||||
"//submodules/AccountContext",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
|
@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import ChatMessageItemView
|
||||
import AccountContext
|
||||
import AsyncDisplayKit
|
||||
|
||||
public protocol ChatMessageTransitionNodeDecorationItemNode: ASDisplayNode {
|
||||
@ -10,6 +10,6 @@ public protocol ChatMessageTransitionNodeDecorationItemNode: ASDisplayNode {
|
||||
public protocol ChatMessageTransitionNode: AnyObject {
|
||||
typealias DecorationItemNode = ChatMessageTransitionNodeDecorationItemNode
|
||||
|
||||
func add(decorationView: UIView, itemNode: ChatMessageItemView) -> DecorationItemNode
|
||||
func add(decorationView: UIView, itemNode: ChatMessageItemNodeProtocol) -> DecorationItemNode
|
||||
func remove(decorationNode: DecorationItemNode)
|
||||
}
|
||||
|
@ -1384,6 +1384,7 @@ public final class EmojiPagerContentComponent: Component {
|
||||
|
||||
private var component: EmojiPagerContentComponent?
|
||||
private weak var state: EmptyComponentState?
|
||||
private var isUpdating: Bool = false
|
||||
private var pagerEnvironment: PagerComponentChildEnvironment?
|
||||
private var keyboardChildEnvironment: EntityKeyboardChildEnvironment?
|
||||
private var activeItemUpdated: ActionSlot<(AnyHashable, AnyHashable?, Transition)>?
|
||||
@ -4055,6 +4056,11 @@ public final class EmojiPagerContentComponent: Component {
|
||||
}
|
||||
|
||||
func update(component: EmojiPagerContentComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: Transition) -> CGSize {
|
||||
self.isUpdating = true
|
||||
defer {
|
||||
self.isUpdating = false
|
||||
}
|
||||
|
||||
let previousComponent = self.component
|
||||
|
||||
self.component = component
|
||||
@ -4581,6 +4587,10 @@ public final class EmojiPagerContentComponent: Component {
|
||||
Transition(animation: .curve(duration: 0.4, curve: .spring)))
|
||||
}
|
||||
}
|
||||
|
||||
if !strongSelf.isUpdating {
|
||||
strongSelf.state?.updated(transition: Transition(animation: .curve(duration: 0.4, curve: .spring)))
|
||||
}
|
||||
}
|
||||
}, updateQuery: { [weak self] query in
|
||||
guard let strongSelf = self else {
|
||||
|
@ -213,6 +213,20 @@ public final class EmojiSearchHeaderView: UIView, UITextFieldDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
override public func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
|
||||
if let textField = self.textField, let text = textField.text, text.isEmpty {
|
||||
if self.bounds.contains(point), let placeholderContentView = self.placeholderContent.view as? EmojiSearchSearchBarComponent.View {
|
||||
let leftTextPosition = placeholderContentView.leftTextPosition()
|
||||
if point.x >= 0.0 && point.x <= placeholderContentView.frame.minX + leftTextPosition {
|
||||
if let result = placeholderContentView.hitTest(self.convert(point, to: placeholderContentView), with: event) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
|
||||
private func activateTextInput() {
|
||||
guard let params = self.params else {
|
||||
return
|
||||
@ -226,7 +240,11 @@ public final class EmojiSearchHeaderView: UIView, UITextFieldDelegate {
|
||||
textField.autocorrectionType = .no
|
||||
textField.returnKeyType = .search
|
||||
self.textField = textField
|
||||
self.insertSubview(textField, belowSubview: self.clearIconView)
|
||||
if let placeholderContentView = self.placeholderContent.view {
|
||||
self.insertSubview(textField, belowSubview: placeholderContentView)
|
||||
} else {
|
||||
self.insertSubview(textField, belowSubview: self.clearIconView)
|
||||
}
|
||||
textField.delegate = self
|
||||
textField.addTarget(self, action: #selector(self.textFieldChanged(_:)), for: .editingChanged)
|
||||
}
|
||||
@ -244,6 +262,9 @@ public final class EmojiSearchHeaderView: UIView, UITextFieldDelegate {
|
||||
}
|
||||
|
||||
@objc private func cancelPressed() {
|
||||
let textField = self.textField
|
||||
self.textField = nil
|
||||
|
||||
self.currentPresetSearchTerm = nil
|
||||
self.updateQuery(nil)
|
||||
|
||||
@ -251,9 +272,6 @@ public final class EmojiSearchHeaderView: UIView, UITextFieldDelegate {
|
||||
self.clearIconTintView.isHidden = true
|
||||
self.clearIconButton.isHidden = true
|
||||
|
||||
let textField = self.textField
|
||||
self.textField = nil
|
||||
|
||||
self.deactivated(textField?.isFirstResponder ?? false)
|
||||
|
||||
if let textField {
|
||||
@ -601,7 +619,6 @@ public final class EmojiSearchHeaderView: UIView, UITextFieldDelegate {
|
||||
}
|
||||
let _ = hasText
|
||||
|
||||
/*self.tintTextView.view?.isHidden = hasText
|
||||
self.textView.view?.isHidden = hasText*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -429,6 +429,15 @@ final class EmojiSearchSearchBarComponent: Component {
|
||||
return super.hitTest(point, with: event)
|
||||
}
|
||||
|
||||
func leftTextPosition() -> CGFloat {
|
||||
guard let itemLayout = self.itemLayout else {
|
||||
return 0.0
|
||||
}
|
||||
|
||||
let visibleBounds = self.scrollView.bounds
|
||||
return (itemLayout.itemStartX - itemLayout.textSpacing) + visibleBounds.minX
|
||||
}
|
||||
|
||||
private func updateScrolling(transition: Transition, fromScrolling: Bool) {
|
||||
guard let component = self.component, let itemLayout = self.itemLayout else {
|
||||
return
|
||||
|
@ -703,6 +703,11 @@ final class PeerSelectionControllerNode: ASDisplayNode {
|
||||
}
|
||||
}, schedule: { [weak textInputPanelNode] messageEffect in
|
||||
textInputPanelNode?.sendMessage(.schedule, messageEffect)
|
||||
}, openPremiumPaywall: { [weak controller] c in
|
||||
guard let controller else {
|
||||
return
|
||||
}
|
||||
controller.push(c)
|
||||
})
|
||||
strongSelf.presentInGlobalOverlay(controller, nil)
|
||||
}, openScheduledMessages: {
|
||||
|
@ -2124,6 +2124,11 @@ extension ChatControllerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
var invertedMediaAttribute: InvertMediaMessageAttribute?
|
||||
if let attribute = message.attributes.first(where: { $0 is InvertMediaMessageAttribute }) {
|
||||
invertedMediaAttribute = attribute as? InvertMediaMessageAttribute
|
||||
}
|
||||
|
||||
let text = trimChatInputText(convertMarkdownToAttributes(editMessage.inputState.inputText))
|
||||
|
||||
let entities = generateTextEntities(text.string, enabledTypes: .all, currentEntities: generateChatInputTextEntities(text))
|
||||
@ -2209,7 +2214,7 @@ extension ChatControllerImpl {
|
||||
let currentWebpagePreviewAttribute = currentMessage.webpagePreviewAttribute ?? WebpagePreviewMessageAttribute(leadingPreview: false, forceLargeMedia: nil, isManuallyAdded: true, isSafe: false)
|
||||
|
||||
if currentMessage.text != text.string || currentEntities != entities || updatingMedia || webpagePreviewAttribute != currentWebpagePreviewAttribute || disableUrlPreview {
|
||||
strongSelf.context.account.pendingUpdateMessageManager.add(messageId: editMessage.messageId, text: text.string, media: media, entities: entitiesAttribute, inlineStickers: inlineStickers, webpagePreviewAttribute: webpagePreviewAttribute, disableUrlPreview: disableUrlPreview)
|
||||
strongSelf.context.account.pendingUpdateMessageManager.add(messageId: editMessage.messageId, text: text.string, media: media, entities: entitiesAttribute, inlineStickers: inlineStickers, webpagePreviewAttribute: webpagePreviewAttribute, invertMediaAttribute: invertedMediaAttribute, disableUrlPreview: disableUrlPreview)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,6 @@ extension ChatControllerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
messageItemNode?.playMessageEffect()
|
||||
messageItemNode?.playMessageEffect(force: true)
|
||||
}
|
||||
}
|
||||
|
@ -140,8 +140,13 @@ func chatMessageDisplaySendMessageOptions(selfController: ChatControllerImpl, no
|
||||
return
|
||||
}
|
||||
selfController.controllerInteraction?.scheduleCurrentMessage()
|
||||
}, openPremiumPaywall: { [weak selfController] c in
|
||||
guard let selfController else {
|
||||
return
|
||||
}
|
||||
selfController.push(c)
|
||||
},
|
||||
reactionItems: effectItems,
|
||||
reactionItems: (!textInputView.text.isEmpty || mediaPreview != nil) ? effectItems : nil,
|
||||
availableMessageEffects: availableMessageEffects,
|
||||
isPremium: hasPremium
|
||||
)
|
||||
|
@ -448,7 +448,7 @@ private var nextClientId: Int32 = 1
|
||||
public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHistoryListNode {
|
||||
static let fixedAdMessageStableId: UInt32 = UInt32.max - 5000
|
||||
|
||||
private let context: AccountContext
|
||||
public let context: AccountContext
|
||||
private let chatLocation: ChatLocation
|
||||
private let chatLocationContextHolder: Atomic<ChatLocationContextHolder?>
|
||||
private let source: ChatHistoryListSource
|
||||
|
@ -13,7 +13,6 @@ import ChatControllerInteraction
|
||||
import FeaturedStickersScreen
|
||||
import ChatTextInputMediaRecordingButton
|
||||
import ReplyAccessoryPanelNode
|
||||
import ChatMessageItemView
|
||||
import ChatMessageStickerItemNode
|
||||
import ChatMessageInstantVideoItemNode
|
||||
import ChatMessageAnimatedStickerItemNode
|
||||
@ -21,6 +20,7 @@ import ChatMessageTransitionNode
|
||||
import ChatMessageBubbleItemNode
|
||||
import ChatEmptyNode
|
||||
import ChatMediaInputStickerGridItem
|
||||
import AccountContext
|
||||
|
||||
private func convertAnimatingSourceRect(_ rect: CGRect, fromView: UIView, toView: UIView?) -> CGRect {
|
||||
if let presentationLayer = fromView.layer.presentation() {
|
||||
@ -241,7 +241,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
}
|
||||
|
||||
final class DecorationItemNodeImpl: ASDisplayNode, ChatMessageTransitionNode.DecorationItemNode {
|
||||
let itemNode: ChatMessageItemView
|
||||
let itemNode: ChatMessageItemNodeProtocol
|
||||
let contentView: UIView
|
||||
private let getContentAreaInScreenSpace: () -> CGRect
|
||||
|
||||
@ -251,7 +251,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
|
||||
fileprivate weak var overlayController: OverlayTransitionContainerController?
|
||||
|
||||
init(itemNode: ChatMessageItemView, contentView: UIView, getContentAreaInScreenSpace: @escaping () -> CGRect) {
|
||||
init(itemNode: ChatMessageItemNodeProtocol, contentView: UIView, getContentAreaInScreenSpace: @escaping () -> CGRect) {
|
||||
self.itemNode = itemNode
|
||||
self.contentView = contentView
|
||||
self.getContentAreaInScreenSpace = getContentAreaInScreenSpace
|
||||
@ -291,17 +291,17 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
}
|
||||
|
||||
final class CustomOffsetHandlerImpl {
|
||||
weak var itemNode: ChatMessageItemView?
|
||||
weak var itemNode: ChatMessageItemNodeProtocol?
|
||||
let update: (CGFloat, ContainedViewLayoutTransition) -> Bool
|
||||
|
||||
init(itemNode: ChatMessageItemView, update: @escaping (CGFloat, ContainedViewLayoutTransition) -> Bool) {
|
||||
init(itemNode: ChatMessageItemNodeProtocol, update: @escaping (CGFloat, ContainedViewLayoutTransition) -> Bool) {
|
||||
self.itemNode = itemNode
|
||||
self.update = update
|
||||
}
|
||||
}
|
||||
|
||||
private final class AnimatingItemNode: ASDisplayNode {
|
||||
let itemNode: ChatMessageItemView
|
||||
let itemNode: ChatMessageItemNodeProtocol
|
||||
private let contextSourceNode: ContextExtractedContentContainingNode
|
||||
private let source: ChatMessageTransitionNodeImpl.Source
|
||||
private let getContentAreaInScreenSpace: () -> CGRect
|
||||
@ -315,7 +315,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
var animationEnded: (() -> Void)?
|
||||
var updateAfterCompletion: Bool = false
|
||||
|
||||
init(itemNode: ChatMessageItemView, contextSourceNode: ContextExtractedContentContainingNode, source: ChatMessageTransitionNodeImpl.Source, getContentAreaInScreenSpace: @escaping () -> CGRect) {
|
||||
init(itemNode: ChatMessageItemNodeProtocol, contextSourceNode: ContextExtractedContentContainingNode, source: ChatMessageTransitionNodeImpl.Source, getContentAreaInScreenSpace: @escaping () -> CGRect) {
|
||||
self.itemNode = itemNode
|
||||
self.getContentAreaInScreenSpace = getContentAreaInScreenSpace
|
||||
|
||||
@ -962,7 +962,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
self.listNode.setCurrentSendAnimationCorrelationIds(correlationIds)
|
||||
}
|
||||
|
||||
public func add(decorationView: UIView, itemNode: ChatMessageItemView) -> DecorationItemNode {
|
||||
public func add(decorationView: UIView, itemNode: ChatMessageItemNodeProtocol) -> DecorationItemNode {
|
||||
let decorationItemNode = DecorationItemNodeImpl(itemNode: itemNode, contentView: decorationView, getContentAreaInScreenSpace: self.getContentAreaInScreenSpace)
|
||||
decorationItemNode.updateLayout(size: self.bounds.size)
|
||||
|
||||
@ -980,7 +980,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
}
|
||||
}
|
||||
|
||||
public func addCustomOffsetHandler(itemNode: ChatMessageItemView, update: @escaping (CGFloat, ContainedViewLayoutTransition) -> Bool) -> Disposable {
|
||||
public func addCustomOffsetHandler(itemNode: ChatMessageItemNodeProtocol, update: @escaping (CGFloat, ContainedViewLayoutTransition) -> Bool) -> Disposable {
|
||||
let handler = CustomOffsetHandlerImpl(itemNode: itemNode, update: update)
|
||||
self.customOffsetHandlers.append(handler)
|
||||
|
||||
@ -994,7 +994,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
}
|
||||
}
|
||||
|
||||
private func beginAnimation(itemNode: ChatMessageItemView, source: Source) {
|
||||
private func beginAnimation(itemNode: ChatMessageItemNodeProtocol, source: Source) {
|
||||
var contextSourceNode: ContextExtractedContentContainingNode?
|
||||
if let itemNode = itemNode as? ChatMessageBubbleItemNode {
|
||||
contextSourceNode = itemNode.mainContextSourceNode
|
||||
@ -1016,7 +1016,7 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
let overlayController = OverlayTransitionContainerController()
|
||||
overlayController.displayNode.addSubnode(animatingItemNode)
|
||||
animatingItemNode.overlayController = overlayController
|
||||
itemNode.item?.context.sharedContext.mainWindow?.presentInGlobalOverlay(overlayController)
|
||||
self.listNode.context.sharedContext.mainWindow?.presentInGlobalOverlay(overlayController)
|
||||
default:
|
||||
self.addSubnode(animatingItemNode)
|
||||
}
|
||||
@ -1031,8 +1031,8 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
strongSelf.animatingItemNodes.remove(at: index)
|
||||
}
|
||||
|
||||
if animatingItemNode.updateAfterCompletion, let item = animatingItemNode.itemNode.item {
|
||||
for (message, _) in item.content {
|
||||
if animatingItemNode.updateAfterCompletion {
|
||||
for message in animatingItemNode.itemNode.messages() {
|
||||
strongSelf.listNode.requestMessageUpdate(stableId: message.stableId)
|
||||
break
|
||||
}
|
||||
@ -1081,14 +1081,9 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
|
||||
var messageItemNode: ListViewItemNode?
|
||||
self.listNode.forEachItemNode { itemNode in
|
||||
if let itemNode = itemNode as? ChatMessageItemView {
|
||||
if let item = itemNode.item {
|
||||
for (message, _) in item.content {
|
||||
if message.id == messageId {
|
||||
messageItemNode = itemNode
|
||||
break
|
||||
}
|
||||
}
|
||||
if let itemNode = itemNode as? ChatMessageItemNodeProtocol {
|
||||
if itemNode.matchesMessage(id: messageId) {
|
||||
messageItemNode = itemNode
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1153,11 +1148,9 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
|
||||
func isAnimatingMessage(stableId: UInt32) -> Bool {
|
||||
for itemNode in self.animatingItemNodes {
|
||||
if let item = itemNode.itemNode.item {
|
||||
for (message, _) in item.content {
|
||||
if message.stableId == stableId {
|
||||
return true
|
||||
}
|
||||
for message in itemNode.itemNode.messages() {
|
||||
if message.stableId == stableId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1166,11 +1159,9 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
|
||||
func scheduleUpdateMessageAfterAnimationCompleted(stableId: UInt32) {
|
||||
for itemNode in self.animatingItemNodes {
|
||||
if let item = itemNode.itemNode.item {
|
||||
for (message, _) in item.content {
|
||||
if message.stableId == stableId {
|
||||
itemNode.updateAfterCompletion = true
|
||||
}
|
||||
for message in itemNode.itemNode.messages() {
|
||||
if message.stableId == stableId {
|
||||
itemNode.updateAfterCompletion = true
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1178,11 +1169,9 @@ public final class ChatMessageTransitionNodeImpl: ASDisplayNode, ChatMessageTran
|
||||
|
||||
func hasScheduledUpdateMessageAfterAnimationCompleted(stableId: UInt32) -> Bool {
|
||||
for itemNode in self.animatingItemNodes {
|
||||
if let item = itemNode.itemNode.item {
|
||||
for (message, _) in item.content {
|
||||
if message.stableId == stableId {
|
||||
return itemNode.updateAfterCompletion
|
||||
}
|
||||
for message in itemNode.itemNode.messages() {
|
||||
if message.stableId == stableId {
|
||||
return itemNode.updateAfterCompletion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user