Various improvements

This commit is contained in:
Ilya Laktyushin 2023-08-31 21:41:02 +04:00
parent 70db4d9718
commit 24b671a53c
5 changed files with 40 additions and 10 deletions

View File

@ -9875,3 +9875,6 @@ Sorry for the inconvenience.";
"Story.Editor.TooltipMutedWithAudio" = "Original audio will be removed"; "Story.Editor.TooltipMutedWithAudio" = "Original audio will be removed";
"Story.Editor.TooltipUnmutedWithAudio" = "Original audio will be preserved"; "Story.Editor.TooltipUnmutedWithAudio" = "Original audio will be preserved";
"SecretImage.ViewOnce.Title" = "Disappearing Photo";
"SecretVideo.ViewOnce.Title" = "Disappearing Video";

View File

@ -184,6 +184,7 @@ public func galleryItemForEntry(
location: location, location: location,
translateToLanguage: translateToLanguage, translateToLanguage: translateToLanguage,
peerIsCopyProtected: peerIsCopyProtected, peerIsCopyProtected: peerIsCopyProtected,
isSecret: isSecret,
displayInfoOnTop: displayInfoOnTop, displayInfoOnTop: displayInfoOnTop,
performAction: performAction, performAction: performAction,
openActionOptions: openActionOptions, openActionOptions: openActionOptions,
@ -265,6 +266,7 @@ public func galleryItemForEntry(
location: location, location: location,
translateToLanguage: translateToLanguage, translateToLanguage: translateToLanguage,
peerIsCopyProtected: peerIsCopyProtected, peerIsCopyProtected: peerIsCopyProtected,
isSecret: isSecret,
displayInfoOnTop: displayInfoOnTop, displayInfoOnTop: displayInfoOnTop,
performAction: performAction, performAction: performAction,
openActionOptions: openActionOptions, openActionOptions: openActionOptions,

View File

@ -115,18 +115,20 @@ class ChatImageGalleryItem: GalleryItem {
let location: MessageHistoryEntryLocation? let location: MessageHistoryEntryLocation?
let translateToLanguage: String? let translateToLanguage: String?
let peerIsCopyProtected: Bool let peerIsCopyProtected: Bool
let isSecret: Bool
let displayInfoOnTop: Bool let displayInfoOnTop: Bool
let performAction: (GalleryControllerInteractionTapAction) -> Void let performAction: (GalleryControllerInteractionTapAction) -> Void
let openActionOptions: (GalleryControllerInteractionTapAction, Message) -> Void let openActionOptions: (GalleryControllerInteractionTapAction, Message) -> Void
let present: (ViewController, Any?) -> Void let present: (ViewController, Any?) -> Void
init(context: AccountContext, presentationData: PresentationData, message: Message, location: MessageHistoryEntryLocation?, translateToLanguage: String? = nil, peerIsCopyProtected: Bool = false, displayInfoOnTop: Bool, performAction: @escaping (GalleryControllerInteractionTapAction) -> Void, openActionOptions: @escaping (GalleryControllerInteractionTapAction, Message) -> Void, present: @escaping (ViewController, Any?) -> Void) { init(context: AccountContext, presentationData: PresentationData, message: Message, location: MessageHistoryEntryLocation?, translateToLanguage: String? = nil, peerIsCopyProtected: Bool = false, isSecret: Bool = false, displayInfoOnTop: Bool, performAction: @escaping (GalleryControllerInteractionTapAction) -> Void, openActionOptions: @escaping (GalleryControllerInteractionTapAction, Message) -> Void, present: @escaping (ViewController, Any?) -> Void) {
self.context = context self.context = context
self.presentationData = presentationData self.presentationData = presentationData
self.message = message self.message = message
self.location = location self.location = location
self.translateToLanguage = translateToLanguage self.translateToLanguage = translateToLanguage
self.peerIsCopyProtected = peerIsCopyProtected self.peerIsCopyProtected = peerIsCopyProtected
self.isSecret = isSecret
self.displayInfoOnTop = displayInfoOnTop self.displayInfoOnTop = displayInfoOnTop
self.performAction = performAction self.performAction = performAction
self.openActionOptions = openActionOptions self.openActionOptions = openActionOptions
@ -136,7 +138,7 @@ class ChatImageGalleryItem: GalleryItem {
func node(synchronous: Bool) -> GalleryItemNode { func node(synchronous: Bool) -> GalleryItemNode {
let node = ChatImageGalleryItemNode(context: self.context, presentationData: self.presentationData, performAction: self.performAction, openActionOptions: self.openActionOptions, present: self.present) let node = ChatImageGalleryItemNode(context: self.context, presentationData: self.presentationData, performAction: self.performAction, openActionOptions: self.openActionOptions, present: self.present)
node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected) node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected, isSecret: self.isSecret)
for media in self.message.media { for media in self.message.media {
if let invoice = media as? TelegramMediaInvoice, let extendedMedia = invoice.extendedMedia, case let .full(fullMedia) = extendedMedia, let image = fullMedia as? TelegramMediaImage { if let invoice = media as? TelegramMediaInvoice, let extendedMedia = invoice.extendedMedia, case let .full(fullMedia) = extendedMedia, let image = fullMedia as? TelegramMediaImage {
node.setImage(userLocation: .peer(self.message.id.peerId), imageReference: .message(message: MessageReference(self.message), media: image)) node.setImage(userLocation: .peer(self.message.id.peerId), imageReference: .message(message: MessageReference(self.message), media: image))
@ -175,7 +177,7 @@ class ChatImageGalleryItem: GalleryItem {
if self.displayInfoOnTop { if self.displayInfoOnTop {
node.titleContentView?.setMessage(self.message, presentationData: self.presentationData, accountPeerId: self.context.account.peerId) node.titleContentView?.setMessage(self.message, presentationData: self.presentationData, accountPeerId: self.context.account.peerId)
} }
node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected) node.setMessage(self.message, displayInfo: !self.displayInfoOnTop, translateToLanguage: self.translateToLanguage, peerIsCopyProtected: self.peerIsCopyProtected, isSecret: self.isSecret)
} }
} }
@ -204,6 +206,7 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
private var message: Message? private var message: Message?
private var translateToLanguage: String? private var translateToLanguage: String?
private var peerIsCopyProtected: Bool = false private var peerIsCopyProtected: Bool = false
private var isSecret: Bool = false
private let presentationData: PresentationData private let presentationData: PresentationData
private let imageNode: TransformImageNode private let imageNode: TransformImageNode
@ -328,11 +331,12 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode {
transition.updateFrame(node: self.statusNode, frame: CGRect(origin: CGPoint(), size: statusSize)) transition.updateFrame(node: self.statusNode, frame: CGRect(origin: CGPoint(), size: statusSize))
} }
fileprivate func setMessage(_ message: Message, displayInfo: Bool, translateToLanguage: String?, peerIsCopyProtected: Bool) { fileprivate func setMessage(_ message: Message, displayInfo: Bool, translateToLanguage: String?, peerIsCopyProtected: Bool, isSecret: Bool) {
self.message = message self.message = message
self.translateToLanguage = translateToLanguage self.translateToLanguage = translateToLanguage
self.peerIsCopyProtected = peerIsCopyProtected self.peerIsCopyProtected = peerIsCopyProtected
self.imageNode.captureProtected = message.isCopyProtected() self.isSecret = isSecret
self.imageNode.captureProtected = message.isCopyProtected() || peerIsCopyProtected || isSecret
self.footerContentNode.setMessage(message, displayInfo: displayInfo, translateToLanguage: translateToLanguage, peerIsCopyProtected: peerIsCopyProtected) self.footerContentNode.setMessage(message, displayInfo: displayInfo, translateToLanguage: translateToLanguage, peerIsCopyProtected: peerIsCopyProtected)
} }

View File

@ -60,7 +60,7 @@ private final class SecretMediaPreviewControllerNode: GalleryControllerNode {
var beginTimeAndTimeout: (Double, Double)? { var beginTimeAndTimeout: (Double, Double)? {
didSet { didSet {
if let (beginTime, timeout) = self.beginTimeAndTimeout { if let (beginTime, timeout) = self.beginTimeAndTimeout, Int32(timeout) != viewOnceTimeout {
if self.timeoutNode == nil { if self.timeoutNode == nil {
let timeoutNode = RadialStatusNode(backgroundNodeColor: UIColor(white: 0.0, alpha: 0.5)) let timeoutNode = RadialStatusNode(backgroundNodeColor: UIColor(white: 0.0, alpha: 0.5))
self.timeoutNode = timeoutNode self.timeoutNode = timeoutNode
@ -289,10 +289,18 @@ public final class SecretMediaPreviewController: ViewController {
if file.isAnimated { if file.isAnimated {
strongSelf.title = strongSelf.presentationData.strings.SecretGif_Title strongSelf.title = strongSelf.presentationData.strings.SecretGif_Title
} else { } else {
strongSelf.title = strongSelf.presentationData.strings.SecretVideo_Title if strongSelf.currentNodeMessageIsViewOnce {
strongSelf.title = strongSelf.presentationData.strings.SecretVideo_ViewOnce_Title
} else {
strongSelf.title = strongSelf.presentationData.strings.SecretVideo_Title
}
} }
} else { } else {
strongSelf.title = strongSelf.presentationData.strings.SecretImage_Title if strongSelf.currentNodeMessageIsViewOnce {
strongSelf.title = strongSelf.presentationData.strings.SecretImage_ViewOnce_Title
} else {
strongSelf.title = strongSelf.presentationData.strings.SecretImage_Title
}
} }
if let beginTimeAndTimeout = beginTimeAndTimeout { if let beginTimeAndTimeout = beginTimeAndTimeout {

View File

@ -1466,6 +1466,7 @@ public class CameraScreen: ViewController {
}) })
} }
fileprivate var captureStartTimestamp: Double?
private func setupCamera() { private func setupCamera() {
guard self.camera == nil else { guard self.camera == nil else {
return return
@ -1575,6 +1576,7 @@ public class CameraScreen: ViewController {
camera.focus(at: CGPoint(x: 0.5, y: 0.5), autoFocus: true) camera.focus(at: CGPoint(x: 0.5, y: 0.5), autoFocus: true)
camera.startCapture() camera.startCapture()
self.captureStartTimestamp = CACurrentMediaTime()
self.camera = camera self.camera = camera
@ -2515,8 +2517,19 @@ public class CameraScreen: ViewController {
guard let self, !self.didStopCameraCapture else { guard let self, !self.didStopCameraCapture else {
return return
} }
self.didStopCameraCapture = true let currentTimestamp = CACurrentMediaTime()
self.node.pauseCameraCapture() if let startTimestamp = self.node.captureStartTimestamp {
let difference = currentTimestamp - startTimestamp
if difference < 2.0 {
Queue.mainQueue().after(2.0 - difference) {
self.didStopCameraCapture = true
self.node.pauseCameraCapture()
}
} else {
self.didStopCameraCapture = true
self.node.pauseCameraCapture()
}
}
} }
let resumeCameraCapture = { [weak self] in let resumeCameraCapture = { [weak self] in