Various fixes

This commit is contained in:
Ilya Laktyushin 2023-12-29 13:56:47 +04:00
parent 5c52a012fa
commit 9323f91c56
5 changed files with 42 additions and 4 deletions

View File

@ -10850,3 +10850,7 @@ Sorry for the inconvenience.";
"Chat.TapToPlayVoiceMessageOnceTooltip" = "Tap to set this message to **Play Once**"; "Chat.TapToPlayVoiceMessageOnceTooltip" = "Tap to set this message to **Play Once**";
"Chat.PlayVoiceMessageOnceTooltip" = "The recipients will be able to listen to it only once."; "Chat.PlayVoiceMessageOnceTooltip" = "The recipients will be able to listen to it only once.";
"Chat.PlayOnceMesasgeClose" = "Close";
"Chat.PlayOnceMesasgeCloseAndDelete" = "Close and Delete";
"Chat.PlayOnceMesasge.DisableScreenCapture" = "Sorry, you can't play this message while screen recording is active.";

View File

@ -216,11 +216,12 @@ public func galleryItemForEntry(
} else if let file = media as? TelegramMediaFile { } else if let file = media as? TelegramMediaFile {
if file.isVideo { if file.isVideo {
let content: UniversalVideoContent let content: UniversalVideoContent
let captureProtected = message.isCopyProtected() || message.containsSecretMedia || message.minAutoremoveOrClearTimeout == viewOnceTimeout
if file.isAnimated { if file.isAnimated {
content = NativeVideoContent(id: .message(message.stableId, file.fileId), userLocation: .peer(message.id.peerId), fileReference: .message(message: MessageReference(message), media: file), imageReference: mediaImage.flatMap({ ImageMediaReference.message(message: MessageReference(message), media: $0) }), loopVideo: true, enableSound: false, tempFilePath: tempFilePath, captureProtected: message.isCopyProtected() || message.containsSecretMedia, storeAfterDownload: generateStoreAfterDownload?(message, file)) content = NativeVideoContent(id: .message(message.stableId, file.fileId), userLocation: .peer(message.id.peerId), fileReference: .message(message: MessageReference(message), media: file), imageReference: mediaImage.flatMap({ ImageMediaReference.message(message: MessageReference(message), media: $0) }), loopVideo: true, enableSound: false, tempFilePath: tempFilePath, captureProtected: captureProtected, storeAfterDownload: generateStoreAfterDownload?(message, file))
} else { } else {
if true || (file.mimeType == "video/mpeg4" || file.mimeType == "video/mov" || file.mimeType == "video/mp4") { if true || (file.mimeType == "video/mpeg4" || file.mimeType == "video/mov" || file.mimeType == "video/mp4") {
content = NativeVideoContent(id: .message(message.stableId, file.fileId), userLocation: .peer(message.id.peerId), fileReference: .message(message: MessageReference(message), media: file), imageReference: mediaImage.flatMap({ ImageMediaReference.message(message: MessageReference(message), media: $0) }), streamVideo: .conservative, loopVideo: loopVideos, tempFilePath: tempFilePath, captureProtected: message.isCopyProtected() || message.containsSecretMedia, storeAfterDownload: generateStoreAfterDownload?(message, file)) content = NativeVideoContent(id: .message(message.stableId, file.fileId), userLocation: .peer(message.id.peerId), fileReference: .message(message: MessageReference(message), media: file), imageReference: mediaImage.flatMap({ ImageMediaReference.message(message: MessageReference(message), media: $0) }), streamVideo: .conservative, loopVideo: loopVideos, tempFilePath: tempFilePath, captureProtected: captureProtected, storeAfterDownload: generateStoreAfterDownload?(message, file))
} else { } else {
content = PlatformVideoContent(id: .message(message.id, message.stableId, file.fileId), userLocation: .peer(message.id.peerId), content: .file(.message(message: MessageReference(message), media: file)), streamVideo: streamVideos, loopVideo: loopVideos) content = PlatformVideoContent(id: .message(message.id, message.stableId, file.fileId), userLocation: .peer(message.id.peerId), content: .file(.message(message: MessageReference(message), media: file)), streamVideo: streamVideos, loopVideo: loopVideos)
} }

View File

@ -525,7 +525,7 @@ public final class SecretMediaPreviewController: ViewController {
} }
} }
guard let item = galleryItemForEntry(context: self.context, presentationData: self.presentationData, entry: MessageHistoryEntry(message: message, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)), streamVideos: false, hideControls: true, isSecret: true, playbackRate: { nil }, tempFilePath: tempFilePath, playbackCompleted: { [weak self] in guard let item = galleryItemForEntry(context: self.context, presentationData: self.presentationData, entry: MessageHistoryEntry(message: message, isRead: false, location: nil, monthLocation: nil, attributes: MutableMessageHistoryEntryAttributes(authorIsContact: false)), streamVideos: false, hideControls: true, isSecret: true, playbackRate: { nil }, peerIsCopyProtected: true, tempFilePath: tempFilePath, playbackCompleted: { [weak self] in
if let self { if let self {
if self.currentNodeMessageIsViewOnce || (duration < 30.0 && !self.currentMessageIsDismissed) { if self.currentNodeMessageIsViewOnce || (duration < 30.0 && !self.currentMessageIsDismissed) {
if let node = self.controllerNode.pager.centralItemNode() as? UniversalVideoGalleryItemNode { if let node = self.controllerNode.pager.centralItemNode() as? UniversalVideoGalleryItemNode {

View File

@ -81,6 +81,8 @@ public final class ScreenCaptureDetectionManager {
private var screenRecordingDisposable: Disposable? private var screenRecordingDisposable: Disposable?
private var screenRecordingCheckTimer: SwiftSignalKit.Timer? private var screenRecordingCheckTimer: SwiftSignalKit.Timer?
public var isRecordingActive = false
public init(check: @escaping () -> Bool) { public init(check: @escaping () -> Bool) {
self.observer = NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: .main, using: { [weak self] _ in self.observer = NotificationCenter.default.addObserver(forName: UIApplication.userDidTakeScreenshotNotification, object: nil, queue: .main, using: { [weak self] _ in
guard let _ = self else { guard let _ = self else {
@ -94,6 +96,7 @@ public final class ScreenCaptureDetectionManager {
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
strongSelf.isRecordingActive = value
if value { if value {
if strongSelf.screenRecordingCheckTimer == nil { if strongSelf.screenRecordingCheckTimer == nil {
strongSelf.screenRecordingCheckTimer = SwiftSignalKit.Timer(timeout: 0.5, repeat: true, completion: { strongSelf.screenRecordingCheckTimer = SwiftSignalKit.Timer(timeout: 0.5, repeat: true, completion: {

View File

@ -11586,6 +11586,29 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return false return false
} }
}) })
} else if peerId.namespace == Namespaces.Peer.CloudUser {
self.screenCaptureManager = ScreenCaptureDetectionManager(check: { [weak self] in
guard let self else {
return false
}
let _ = (self.context.sharedContext.mediaManager.globalMediaPlayerState
|> filter { playlistStateAndType in
if let (_, state, _) = playlistStateAndType, case .state = state {
return true
} else {
return false
}
}
|> take(1)).startStandalone(next: { [weak self] playlistStateAndType in
if let self, let (_, playbackState, _) = playlistStateAndType, case let .state(state) = playbackState {
if let source = state.item.playbackData?.source, case let .telegramFile(_, _, isViewOnce) = source, isViewOnce {
self.context.sharedContext.mediaManager.setPlaylist(nil, type: .voice, control: .playback(.pause))
}
}
})
return true
})
} }
} }
@ -18951,6 +18974,13 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
} }
func openViewOnceMediaMessage(_ message: Message) { func openViewOnceMediaMessage(_ message: Message) {
if self.screenCaptureManager?.isRecordingActive == true {
let controller = textAlertController(context: self.context, updatedPresentationData: self.updatedPresentationData, title: nil, text: self.presentationData.strings.Chat_PlayOnceMesasge_DisableScreenCapture, actions: [TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Common_OK, action: {
})])
self.present(controller, in: .window(.root))
return
}
let isIncoming = message.effectivelyIncoming(self.context.account.peerId) let isIncoming = message.effectivelyIncoming(self.context.account.peerId)
var presentImpl: ((ViewController) -> Void)? var presentImpl: ((ViewController) -> Void)?
@ -18971,7 +19001,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
} }
)), )),
items: .single(ContextController.Items(content: .list([]))), items: .single(ContextController.Items(content: .list([]))),
closeActionTitle: isIncoming ? "Delete and Close" : "Close", closeActionTitle: isIncoming ? self.presentationData.strings.Chat_PlayOnceMesasgeCloseAndDelete : self.presentationData.strings.Chat_PlayOnceMesasgeClose,
closeAction: { [weak self] in closeAction: { [weak self] in
if let self { if let self {
self.context.sharedContext.mediaManager.setPlaylist(nil, type: .voice, control: .playback(.pause)) self.context.sharedContext.mediaManager.setPlaylist(nil, type: .voice, control: .playback(.pause))