From 144516eae54beccc0065abd75ea49dcc1b36d4b2 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 26 Aug 2025 21:14:46 +0400 Subject: [PATCH] Various improvements --- .../TelegramEngine/Data/PeersData.swift | 33 +++++++++++++++++++ .../OverlayAudioPlayerControllerNode.swift | 23 +++++++++++-- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift b/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift index eceaab249d..305f4882f0 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Data/PeersData.swift @@ -2303,6 +2303,39 @@ public extension TelegramEngine.EngineData.Item { } } + public struct CopyProtectionEnabled: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem { + public typealias Result = Bool + + fileprivate var id: EnginePeer.Id + public var mapKey: EnginePeer.Id { + return self.id + } + + public init(id: EnginePeer.Id) { + self.id = id + } + + var key: PostboxViewKey { + return .basicPeer(self.id) + } + + func extract(view: PostboxView) -> Result { + guard let view = view as? BasicPeerView else { + preconditionFailure() + } + guard let peer = view.peer else { + return false + } + if let group = peer as? TelegramGroup { + return group.flags.contains(.copyProtectionEnabled) + } else if let channel = peer as? TelegramChannel { + return channel.flags.contains(.copyProtectionEnabled) + } else { + return false + } + } + } + public struct BotPreview: TelegramEngineDataItem, TelegramEngineMapKeyDataItem, PostboxViewDataItem { public typealias Result = CachedUserData.BotPreview? diff --git a/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift b/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift index cd2a276ac9..1ec0d69465 100644 --- a/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift +++ b/submodules/TelegramUI/Sources/OverlayAudioPlayerControllerNode.swift @@ -57,6 +57,8 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu private var savedIdsPromise = Promise?>() private var savedIds: Set? + private var copyProtectionEnabled = false + init( context: AccountContext, chatLocation: ChatLocation, @@ -388,14 +390,25 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu } }) - self.savedIdsDisposable = (context.engine.peers.savedMusicIds() - |> deliverOnMainQueue).start(next: { [weak self] savedIds in + let copyProtectionEnabled: Signal + if case let .peer(peerId) = self.chatLocation { + copyProtectionEnabled = context.engine.data.subscribe(TelegramEngine.EngineData.Item.Peer.CopyProtectionEnabled(id: peerId)) + } else { + copyProtectionEnabled = .single(false) + } + + self.savedIdsDisposable = combineLatest( + queue: Queue.mainQueue(), + context.engine.peers.savedMusicIds(), + copyProtectionEnabled + ).start(next: { [weak self] savedIds, copyProtectionEnabled in guard let self else { return } let isFirstTime = self.savedIds == nil self.savedIds = savedIds self.savedIdsPromise.set(.single(savedIds)) + self.copyProtectionEnabled = copyProtectionEnabled let transition: ContainedViewLayoutTransition = isFirstTime ? .immediate : .animated(duration: 0.5, curve: .spring) self.updateFloatingHeaderOffset(offset: self.floatingHeaderOffset ?? 0.0, transition: transition) @@ -638,6 +651,12 @@ final class OverlayAudioPlayerControllerNode: ViewControllerTracingNode, ASGestu } private var isSaved: Bool? { + if self .copyProtectionEnabled { + return nil + } + if case let .peer(peerId) = self.chatLocation, peerId.namespace == Namespaces.Peer.SecretChat { + return nil + } guard let fileReference = self.controlsNode.currentFileReference else { return nil }