mirror of
https://github.com/divkit/divkit.git
synced 2026-05-07 20:02:32 +00:00
Added action info to DivPatchProvider
commit_hash:b9380a7c873096142cb69b6684b61adf2dce4cf8
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -64,19 +64,28 @@ public final class DivActionURLHandler {
|
||||
cardId: DivCardID,
|
||||
completion: @escaping (Result<Void, Error>) -> 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, Error>) -> 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
|
||||
)
|
||||
|
||||
@@ -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<DivPatch, Error>) -> Void
|
||||
|
||||
public func parseDivPatch(_ data: Data) throws -> DivPatch {
|
||||
|
||||
Reference in New Issue
Block a user