From 2e2b278e851a7c96a58b588881244371f54c817f Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Thu, 19 Feb 2026 14:57:47 +0400 Subject: [PATCH 1/2] match code --- .../Messages/RequestMessageActionCallback.swift | 16 +++++++++++----- .../Messages/TelegramEngineMessages.swift | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift index 73bd5d546a..732f974e18 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/RequestMessageActionCallback.swift @@ -272,7 +272,7 @@ func _internal_declineUrlAuth(account: Account, url: String) -> Signal ignoreValues } -func _internal_acceptMessageActionUrlAuth(account: Account, subject: MessageActionUrlSubject, allowWriteAccess: Bool, sharePhoneNumber: Bool) -> Signal { +func _internal_acceptMessageActionUrlAuth(account: Account, subject: MessageActionUrlSubject, allowWriteAccess: Bool, sharePhoneNumber: Bool, matchCode: String? = nil) -> Signal { var flags: Int32 = 0 if allowWriteAccess { flags |= Int32(1 << 0) @@ -280,7 +280,10 @@ func _internal_acceptMessageActionUrlAuth(account: Account, subject: MessageActi if sharePhoneNumber { flags |= Int32(1 << 3) } - + if matchCode != nil { + flags |= Int32(1 << 4) + } + let request: Signal switch subject { case let .message(messageId, buttonId): @@ -290,8 +293,11 @@ func _internal_acceptMessageActionUrlAuth(account: Account, subject: MessageActi |> castError(MTRpcError.self) |> mapToSignal { peer -> Signal in if let inputPeer = apiInputPeer(peer) { - let flags: Int32 = 1 << 1 - return account.network.request(Api.functions.messages.acceptUrlAuth(flags: flags, peer: inputPeer, msgId: messageId.id, buttonId: buttonId, url: nil, matchCode: nil)) + var msgFlags: Int32 = 1 << 1 + if matchCode != nil { + msgFlags |= Int32(1 << 4) + } + return account.network.request(Api.functions.messages.acceptUrlAuth(flags: msgFlags, peer: inputPeer, msgId: messageId.id, buttonId: buttonId, url: nil, matchCode: matchCode)) |> map(Optional.init) } else { return .single(nil) @@ -299,7 +305,7 @@ func _internal_acceptMessageActionUrlAuth(account: Account, subject: MessageActi } case let .url(url): flags |= (1 << 2) - request = account.network.request(Api.functions.messages.acceptUrlAuth(flags: flags, peer: nil, msgId: nil, buttonId: nil, url: url, matchCode: nil)) + request = account.network.request(Api.functions.messages.acceptUrlAuth(flags: flags, peer: nil, msgId: nil, buttonId: nil, url: url, matchCode: matchCode)) |> map(Optional.init) } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 9ce598629e..fd987c94ae 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -99,8 +99,8 @@ public extension TelegramEngine { return _internal_requestMessageActionUrlAuth(account: self.account, subject: subject) } - public func acceptMessageActionUrlAuth(subject: MessageActionUrlSubject, allowWriteAccess: Bool, sharePhoneNumber: Bool) -> Signal { - return _internal_acceptMessageActionUrlAuth(account: self.account, subject: subject, allowWriteAccess: allowWriteAccess, sharePhoneNumber: sharePhoneNumber) + public func acceptMessageActionUrlAuth(subject: MessageActionUrlSubject, allowWriteAccess: Bool, sharePhoneNumber: Bool, matchCode: String? = nil) -> Signal { + return _internal_acceptMessageActionUrlAuth(account: self.account, subject: subject, allowWriteAccess: allowWriteAccess, sharePhoneNumber: sharePhoneNumber, matchCode: matchCode) } public func declineUrlAuth(url: String) -> Signal { From 670c547aad691644521add00755dcb874487b4de Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Fri, 20 Feb 2026 10:58:14 +0400 Subject: [PATCH 2/2] copy protection improvements --- .../TelegramEngine/Peers/CopyProtection.swift | 43 +++++++++++++++++-- .../Peers/TelegramEnginePeers.swift | 2 +- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/CopyProtection.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/CopyProtection.swift index eeb9058f1a..0f88652490 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/CopyProtection.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/CopyProtection.swift @@ -4,15 +4,52 @@ import SwiftSignalKit import TelegramApi import MtProtoKit -func _internal_toggleMessageCopyProtection(account: Account, peerId: PeerId, enabled: Bool, requestMessageId: EngineMessage.Id?) -> Signal { - return account.postbox.transaction { transaction -> Signal in +public enum CopyProtectionResult { + case applied + case requested +} + +func _internal_toggleMessageCopyProtection(account: Account, peerId: PeerId, enabled: Bool, requestMessageId: EngineMessage.Id?) -> Signal { + return account.postbox.transaction { transaction -> Signal in if let peer = transaction.getPeer(peerId), let inputPeer = apiInputPeer(peer) { var flags: Int32 = 0 if let _ = requestMessageId { flags = (1 << 0) } - return account.network.request(Api.functions.messages.toggleNoForwards(flags: flags, peer: inputPeer, enabled: enabled ? .boolTrue : .boolFalse, requestMsgId: requestMessageId?.id)) |> `catch` { _ in .complete() } |> map { updates -> Void in + return account.network.request(Api.functions.messages.toggleNoForwards(flags: flags, peer: inputPeer, enabled: enabled ? .boolTrue : .boolFalse, requestMsgId: requestMessageId?.id)) |> `catch` { _ in .complete() } |> mapToSignal { updates -> Signal in account.stateManager.addUpdates(updates) + + var isRequest = false + switch updates { + case let .updates(data): + for update in data.updates { + if case let .updateNewMessage(msgData) = update, case let .messageService(serviceData) = msgData.message, case .messageActionNoForwardsRequest = serviceData.action { + isRequest = true + } + } + default: + break + } + + if !isRequest { + return account.postbox.transaction { transaction -> CopyProtectionResult in + transaction.updatePeerCachedData(peerIds: [peerId], update: { _, current in + if let previous = current as? CachedUserData { + var updatedFlags = previous.flags + if enabled { + updatedFlags.insert(.copyProtectionEnabled) + } else { + updatedFlags.remove(.copyProtectionEnabled) + } + return previous.withUpdatedFlags(updatedFlags) + } + return current + }) + return .applied + } + } else { + return .single(.requested) + } } } else { return .complete() diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift index 8e0d5d238a..4b3dfda9b2 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/TelegramEnginePeers.swift @@ -505,7 +505,7 @@ public extension TelegramEngine { return _internal_toggleShouldChannelMessagesSignatures(account: self.account, peerId: peerId, signaturesEnabled: signaturesEnabled, profilesEnabled: profilesEnabled) } - public func toggleMessageCopyProtection(peerId: PeerId, enabled: Bool, requestMessageId: EngineMessage.Id? = nil) -> Signal { + public func toggleMessageCopyProtection(peerId: PeerId, enabled: Bool, requestMessageId: EngineMessage.Id? = nil) -> Signal { return _internal_toggleMessageCopyProtection(account: self.account, peerId: peerId, enabled: enabled, requestMessageId: requestMessageId) }