From 42e7fd676bebdd44899bad2bfb55e8dd7ea81bbf Mon Sep 17 00:00:00 2001 From: booster Date: Fri, 25 Oct 2024 15:42:22 +0300 Subject: [PATCH] Added action info to DivPatchProvider commit_hash:b9380a7c873096142cb69b6684b61adf2dce4cf8 --- .../ios/DivKit/Actions/DivActionHandler.swift | 4 ++-- .../DivKit/Actions/DivActionURLHandler.swift | 18 +++++++++++++---- .../ios/DivKit/Patches/DivPatchProvider.swift | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/client/ios/DivKit/Actions/DivActionHandler.swift b/client/ios/DivKit/Actions/DivActionHandler.swift index 10666a31f..82852c829 100644 --- a/client/ios/DivKit/Actions/DivActionHandler.swift +++ b/client/ios/DivKit/Actions/DivActionHandler.swift @@ -156,7 +156,7 @@ public final class DivActionHandler { /// Deprecated. This method is intended for backward compatibility only. Do not use it. public func handleDivActionUrl(_ url: URL, cardId: DivCardID) -> Bool { - divActionURLHandler.handleURL(url, path: cardId.path) + divActionURLHandler.handleURL(url, cardId: cardId) } func handle( @@ -281,7 +281,7 @@ public final class DivActionHandler { let isDivActionURLHandled = divActionURLHandler.handleURL( url, - path: info.path, + info: info, completion: { [weak self] result in guard let self else { return diff --git a/client/ios/DivKit/Actions/DivActionURLHandler.swift b/client/ios/DivKit/Actions/DivActionURLHandler.swift index 4e2451052..f5010629d 100644 --- a/client/ios/DivKit/Actions/DivActionURLHandler.swift +++ b/client/ios/DivKit/Actions/DivActionURLHandler.swift @@ -64,19 +64,28 @@ public final class DivActionURLHandler { cardId: DivCardID, completion: @escaping (Result) -> Void = { _ in } ) -> Bool { - handleURL(url, path: cardId.path, completion: completion) + let info = DivActionInfo( + path: cardId.path, + logId: cardId.rawValue, + url: url, + logUrl: nil, + referer: nil, + source: .tap, + payload: nil + ) + return handleURL(url, info: info, completion: completion) } func handleURL( _ url: URL, - path: UIElementPath, + info: DivActionInfo, completion: @escaping (Result) -> Void = { _ in } ) -> Bool { guard let intent = DivActionIntent(url: url) else { return false } - let cardId = path.cardId + let cardId = info.path.cardId switch intent { case let .showTooltip(id, multiple): let tooltipInfo = TooltipInfo(id: id, showsOnStart: false, multiple: multiple) @@ -93,6 +102,7 @@ public final class DivActionURLHandler { case let .download(patchUrl): patchProvider.getPatch( url: patchUrl, + info: info, completion: { [unowned self] in self.applyPatch(cardId: cardId, result: $0, completion: completion) } @@ -106,7 +116,7 @@ public final class DivActionURLHandler { updateCard(.state(cardId)) case let .setVariable(name, value): variableUpdater.update( - path: path, + path: info.path, name: DivVariableName(rawValue: name), value: value ) diff --git a/client/ios/DivKit/Patches/DivPatchProvider.swift b/client/ios/DivKit/Patches/DivPatchProvider.swift index 31093faf0..f87398a99 100644 --- a/client/ios/DivKit/Patches/DivPatchProvider.swift +++ b/client/ios/DivKit/Patches/DivPatchProvider.swift @@ -22,10 +22,30 @@ public protocol DivPatchProvider { /// `Error` on failure. func getPatch(url: URL, completion: @escaping DivPatchProviderCompletion) + /// Downloads a patch from the specified URL. + /// + /// - Parameters: + /// - url: The URL from which to download the patch. + /// - action: Corresponding action info. + /// - completion: The completion handler to be called when the download is complete. + /// The `Result` object contains the downloaded patch data on success or an + /// `Error` on failure. + func getPatch(url: URL, info: DivActionInfo, completion: @escaping DivPatchProviderCompletion) + /// Cancels any ongoing patch download requests. func cancelRequests() } +extension DivPatchProvider { + public func getPatch( + url: URL, + info _: DivActionInfo, + completion: @escaping DivPatchProviderCompletion + ) { + getPatch(url: url, completion: completion) + } +} + public typealias DivPatchProviderCompletion = (Result) -> Void public func parseDivPatch(_ data: Data) throws -> DivPatch {