From 24b671a53ccbaf71edacefa5b0ce5426d646057b Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 31 Aug 2023 21:41:02 +0400 Subject: [PATCH] Various improvements --- .../Telegram-iOS/en.lproj/Localizable.strings | 3 +++ .../GalleryUI/Sources/GalleryController.swift | 2 ++ .../Sources/Items/ChatImageGalleryItem.swift | 14 +++++++++----- .../Sources/SecretMediaPreviewController.swift | 14 +++++++++++--- .../CameraScreen/Sources/CameraScreen.swift | 17 +++++++++++++++-- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 150de95c72..185f84c5be 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -9875,3 +9875,6 @@ Sorry for the inconvenience."; "Story.Editor.TooltipMutedWithAudio" = "Original audio will be removed"; "Story.Editor.TooltipUnmutedWithAudio" = "Original audio will be preserved"; + +"SecretImage.ViewOnce.Title" = "Disappearing Photo"; +"SecretVideo.ViewOnce.Title" = "Disappearing Video"; diff --git a/submodules/GalleryUI/Sources/GalleryController.swift b/submodules/GalleryUI/Sources/GalleryController.swift index baee287134..9c6e0295f5 100644 --- a/submodules/GalleryUI/Sources/GalleryController.swift +++ b/submodules/GalleryUI/Sources/GalleryController.swift @@ -184,6 +184,7 @@ public func galleryItemForEntry( location: location, translateToLanguage: translateToLanguage, peerIsCopyProtected: peerIsCopyProtected, + isSecret: isSecret, displayInfoOnTop: displayInfoOnTop, performAction: performAction, openActionOptions: openActionOptions, @@ -265,6 +266,7 @@ public func galleryItemForEntry( location: location, translateToLanguage: translateToLanguage, peerIsCopyProtected: peerIsCopyProtected, + isSecret: isSecret, displayInfoOnTop: displayInfoOnTop, performAction: performAction, openActionOptions: openActionOptions, diff --git a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift index f6ca4b29c5..3cfe8427e6 100644 --- a/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift +++ b/submodules/GalleryUI/Sources/Items/ChatImageGalleryItem.swift @@ -115,18 +115,20 @@ class ChatImageGalleryItem: GalleryItem { let location: MessageHistoryEntryLocation? let translateToLanguage: String? let peerIsCopyProtected: Bool + let isSecret: Bool let displayInfoOnTop: Bool let performAction: (GalleryControllerInteractionTapAction) -> Void let openActionOptions: (GalleryControllerInteractionTapAction, Message) -> 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.presentationData = presentationData self.message = message self.location = location self.translateToLanguage = translateToLanguage self.peerIsCopyProtected = peerIsCopyProtected + self.isSecret = isSecret self.displayInfoOnTop = displayInfoOnTop self.performAction = performAction self.openActionOptions = openActionOptions @@ -136,7 +138,7 @@ class ChatImageGalleryItem: GalleryItem { func node(synchronous: Bool) -> GalleryItemNode { 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 { 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)) @@ -175,7 +177,7 @@ class ChatImageGalleryItem: GalleryItem { if self.displayInfoOnTop { 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 translateToLanguage: String? private var peerIsCopyProtected: Bool = false + private var isSecret: Bool = false private let presentationData: PresentationData private let imageNode: TransformImageNode @@ -328,11 +331,12 @@ final class ChatImageGalleryItemNode: ZoomableContentGalleryItemNode { 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.translateToLanguage = translateToLanguage 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) } diff --git a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift index 8a0c90bf06..2a72ee37c4 100644 --- a/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift +++ b/submodules/GalleryUI/Sources/SecretMediaPreviewController.swift @@ -60,7 +60,7 @@ private final class SecretMediaPreviewControllerNode: GalleryControllerNode { var beginTimeAndTimeout: (Double, Double)? { didSet { - if let (beginTime, timeout) = self.beginTimeAndTimeout { + if let (beginTime, timeout) = self.beginTimeAndTimeout, Int32(timeout) != viewOnceTimeout { if self.timeoutNode == nil { let timeoutNode = RadialStatusNode(backgroundNodeColor: UIColor(white: 0.0, alpha: 0.5)) self.timeoutNode = timeoutNode @@ -289,10 +289,18 @@ public final class SecretMediaPreviewController: ViewController { if file.isAnimated { strongSelf.title = strongSelf.presentationData.strings.SecretGif_Title } 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 { - 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 { diff --git a/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift b/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift index 6ba26378ce..12ecfd9e54 100644 --- a/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift +++ b/submodules/TelegramUI/Components/CameraScreen/Sources/CameraScreen.swift @@ -1466,6 +1466,7 @@ public class CameraScreen: ViewController { }) } + fileprivate var captureStartTimestamp: Double? private func setupCamera() { guard self.camera == nil else { return @@ -1575,6 +1576,7 @@ public class CameraScreen: ViewController { camera.focus(at: CGPoint(x: 0.5, y: 0.5), autoFocus: true) camera.startCapture() + self.captureStartTimestamp = CACurrentMediaTime() self.camera = camera @@ -2515,8 +2517,19 @@ public class CameraScreen: ViewController { guard let self, !self.didStopCameraCapture else { return } - self.didStopCameraCapture = true - self.node.pauseCameraCapture() + let currentTimestamp = CACurrentMediaTime() + 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