mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Video Stickers Fixes
This commit is contained in:
parent
8b645037a6
commit
26f6e04fb3
@ -2,9 +2,48 @@ import Foundation
|
||||
import AVFoundation
|
||||
import AsyncDisplayKit
|
||||
import Display
|
||||
import SwiftSignalKit
|
||||
import TelegramCore
|
||||
|
||||
private class VideoStickerNodeDisplayEvents: ASDisplayNode {
|
||||
private var value: Bool = false
|
||||
var updated: ((Bool) -> Void)?
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
|
||||
self.isLayerBacked = true
|
||||
}
|
||||
|
||||
override func didEnterHierarchy() {
|
||||
super.didEnterHierarchy()
|
||||
|
||||
if !self.value {
|
||||
self.value = true
|
||||
self.updated?(true)
|
||||
}
|
||||
}
|
||||
|
||||
override func didExitHierarchy() {
|
||||
super.didExitHierarchy()
|
||||
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
if !strongSelf.isInHierarchy {
|
||||
if strongSelf.value {
|
||||
strongSelf.value = false
|
||||
strongSelf.updated?(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class VideoStickerNode: ASDisplayNode {
|
||||
private let eventsNode: VideoStickerNodeDisplayEvents
|
||||
|
||||
private var layerHolder: SampleBufferLayer?
|
||||
private var manager: SoftwareVideoLayerFrameManager?
|
||||
|
||||
@ -15,22 +54,53 @@ public class VideoStickerNode: ASDisplayNode {
|
||||
|
||||
private var validLayout: CGSize?
|
||||
|
||||
public func update(isPlaying: Bool) {
|
||||
let displayLink: ConstantDisplayLinkAnimator
|
||||
if let current = self.displayLink {
|
||||
displayLink = current
|
||||
} else {
|
||||
displayLink = ConstantDisplayLinkAnimator { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.manager?.tick(timestamp: strongSelf.displayLinkTimestamp)
|
||||
strongSelf.displayLinkTimestamp += 1.0 / 30.0
|
||||
}
|
||||
displayLink.frameInterval = 2
|
||||
self.displayLink = displayLink
|
||||
private var isDisplaying: Bool = false {
|
||||
didSet {
|
||||
self.updateIsPlaying()
|
||||
}
|
||||
self.displayLink?.isPaused = !isPlaying
|
||||
}
|
||||
private var isPlaying: Bool = false
|
||||
|
||||
public override init() {
|
||||
self.eventsNode = VideoStickerNodeDisplayEvents()
|
||||
|
||||
super.init()
|
||||
|
||||
self.eventsNode.updated = { [weak self] value in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.isDisplaying = value
|
||||
}
|
||||
self.addSubnode(self.eventsNode)
|
||||
}
|
||||
|
||||
private func updateIsPlaying() {
|
||||
let isPlaying = self.isPlaying && self.isDisplaying
|
||||
if isPlaying {
|
||||
let displayLink: ConstantDisplayLinkAnimator
|
||||
if let current = self.displayLink {
|
||||
displayLink = current
|
||||
} else {
|
||||
displayLink = ConstantDisplayLinkAnimator { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.manager?.tick(timestamp: strongSelf.displayLinkTimestamp)
|
||||
strongSelf.displayLinkTimestamp += 1.0 / 30.0
|
||||
}
|
||||
displayLink.frameInterval = 2
|
||||
self.displayLink = displayLink
|
||||
}
|
||||
displayLink.isPaused = !isPlaying
|
||||
} else {
|
||||
self.displayLink?.isPaused = true
|
||||
}
|
||||
}
|
||||
|
||||
public func update(isPlaying: Bool) {
|
||||
self.isPlaying = isPlaying
|
||||
self.updateIsPlaying()
|
||||
}
|
||||
|
||||
public func update(account: Account, fileReference: FileMediaReference) {
|
||||
|
@ -117,6 +117,7 @@ public func mediaContentKind(_ media: EngineMedia, message: EngineMessage? = nil
|
||||
return .image
|
||||
case let .file(file):
|
||||
var fileName: String = ""
|
||||
var isAnimation = false
|
||||
for attribute in file.attributes {
|
||||
switch attribute {
|
||||
case let .Sticker(text, _, _):
|
||||
@ -137,7 +138,7 @@ public func mediaContentKind(_ media: EngineMedia, message: EngineMessage? = nil
|
||||
}
|
||||
case let .Video(_, _, flags):
|
||||
if file.isAnimated {
|
||||
return .animation
|
||||
isAnimation = true
|
||||
} else {
|
||||
if flags.contains(.instantRoundVideo) {
|
||||
return .videoMessage
|
||||
@ -149,7 +150,10 @@ public func mediaContentKind(_ media: EngineMedia, message: EngineMessage? = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
if file.isAnimatedSticker {
|
||||
if isAnimation {
|
||||
return .animation
|
||||
}
|
||||
if file.isVideoSticker || file.isAnimatedSticker {
|
||||
return .sticker("")
|
||||
}
|
||||
return .file(fileName)
|
||||
|
@ -902,19 +902,22 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
if let cachedData = data.cachedData as? CachedUserData {
|
||||
if cachedData.isBlocked {
|
||||
items[.peerInfo]!.append(PeerInfoScreenActionItem(id: 4, text: user.botInfo != nil ? presentationData.strings.Bot_Unblock : presentationData.strings.Conversation_Unblock, action: {
|
||||
interaction.updateBlocked(false)
|
||||
}))
|
||||
|
||||
var isBlocked = false
|
||||
if let cachedData = data.cachedData as? CachedUserData, cachedData.isBlocked {
|
||||
isBlocked = true
|
||||
}
|
||||
|
||||
if isBlocked {
|
||||
items[.peerInfo]!.append(PeerInfoScreenActionItem(id: 4, text: user.botInfo != nil ? presentationData.strings.Bot_Unblock : presentationData.strings.Conversation_Unblock, action: {
|
||||
interaction.updateBlocked(false)
|
||||
}))
|
||||
} else {
|
||||
if user.flags.contains(.isSupport) || data.isContact {
|
||||
} else {
|
||||
if user.flags.contains(.isSupport) || data.isContact {
|
||||
} else {
|
||||
items[.peerInfo]!.append(PeerInfoScreenActionItem(id: 4, text: user.botInfo != nil ? presentationData.strings.Bot_Stop : presentationData.strings.Conversation_BlockUser, color: .destructive, action: {
|
||||
interaction.updateBlocked(true)
|
||||
}))
|
||||
}
|
||||
items[.peerInfo]!.append(PeerInfoScreenActionItem(id: 4, text: user.botInfo != nil ? presentationData.strings.Bot_Stop : presentationData.strings.Conversation_BlockUser, color: .destructive, action: {
|
||||
interaction.updateBlocked(true)
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user