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 AVFoundation
|
||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
import Display
|
import Display
|
||||||
|
import SwiftSignalKit
|
||||||
import TelegramCore
|
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 {
|
public class VideoStickerNode: ASDisplayNode {
|
||||||
|
private let eventsNode: VideoStickerNodeDisplayEvents
|
||||||
|
|
||||||
private var layerHolder: SampleBufferLayer?
|
private var layerHolder: SampleBufferLayer?
|
||||||
private var manager: SoftwareVideoLayerFrameManager?
|
private var manager: SoftwareVideoLayerFrameManager?
|
||||||
|
|
||||||
@ -15,22 +54,53 @@ public class VideoStickerNode: ASDisplayNode {
|
|||||||
|
|
||||||
private var validLayout: CGSize?
|
private var validLayout: CGSize?
|
||||||
|
|
||||||
public func update(isPlaying: Bool) {
|
private var isDisplaying: Bool = false {
|
||||||
let displayLink: ConstantDisplayLinkAnimator
|
didSet {
|
||||||
if let current = self.displayLink {
|
self.updateIsPlaying()
|
||||||
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
|
|
||||||
}
|
}
|
||||||
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) {
|
public func update(account: Account, fileReference: FileMediaReference) {
|
||||||
|
@ -117,6 +117,7 @@ public func mediaContentKind(_ media: EngineMedia, message: EngineMessage? = nil
|
|||||||
return .image
|
return .image
|
||||||
case let .file(file):
|
case let .file(file):
|
||||||
var fileName: String = ""
|
var fileName: String = ""
|
||||||
|
var isAnimation = false
|
||||||
for attribute in file.attributes {
|
for attribute in file.attributes {
|
||||||
switch attribute {
|
switch attribute {
|
||||||
case let .Sticker(text, _, _):
|
case let .Sticker(text, _, _):
|
||||||
@ -137,7 +138,7 @@ public func mediaContentKind(_ media: EngineMedia, message: EngineMessage? = nil
|
|||||||
}
|
}
|
||||||
case let .Video(_, _, flags):
|
case let .Video(_, _, flags):
|
||||||
if file.isAnimated {
|
if file.isAnimated {
|
||||||
return .animation
|
isAnimation = true
|
||||||
} else {
|
} else {
|
||||||
if flags.contains(.instantRoundVideo) {
|
if flags.contains(.instantRoundVideo) {
|
||||||
return .videoMessage
|
return .videoMessage
|
||||||
@ -149,7 +150,10 @@ public func mediaContentKind(_ media: EngineMedia, message: EngineMessage? = nil
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if file.isAnimatedSticker {
|
if isAnimation {
|
||||||
|
return .animation
|
||||||
|
}
|
||||||
|
if file.isVideoSticker || file.isAnimatedSticker {
|
||||||
return .sticker("")
|
return .sticker("")
|
||||||
}
|
}
|
||||||
return .file(fileName)
|
return .file(fileName)
|
||||||
|
@ -902,19 +902,22 @@ private func infoItems(data: PeerInfoScreenData?, context: AccountContext, prese
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let cachedData = data.cachedData as? CachedUserData {
|
var isBlocked = false
|
||||||
if cachedData.isBlocked {
|
if let cachedData = data.cachedData as? CachedUserData, cachedData.isBlocked {
|
||||||
items[.peerInfo]!.append(PeerInfoScreenActionItem(id: 4, text: user.botInfo != nil ? presentationData.strings.Bot_Unblock : presentationData.strings.Conversation_Unblock, action: {
|
isBlocked = true
|
||||||
interaction.updateBlocked(false)
|
}
|
||||||
}))
|
|
||||||
|
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 {
|
} else {
|
||||||
if user.flags.contains(.isSupport) || data.isContact {
|
items[.peerInfo]!.append(PeerInfoScreenActionItem(id: 4, text: user.botInfo != nil ? presentationData.strings.Bot_Stop : presentationData.strings.Conversation_BlockUser, color: .destructive, action: {
|
||||||
} else {
|
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