Code review updates for scoping of functions.

Fix continuation leak.
This commit is contained in:
Scott Pfeil 2023-10-20 11:51:14 -04:00
parent d44235bd03
commit def76778e5
2 changed files with 22 additions and 18 deletions

View File

@ -26,12 +26,6 @@ open class ActionShareHandler: MVMCoreActionHandlerProtocol {
if completed { if completed {
// Activity was completed, considered finished. // Activity was completed, considered finished.
continuation.resume() continuation.resume()
} else if let _ = activityType {
// If a specific type of activity failed, the activity controller is still presented, cannot continue yet.
if let error = error,
let errorObject = MVMCoreErrorObject.createErrorObject(for: error, location: MVMCoreActionHandler.getErrorLocation(with: delegateObject?.actionDelegate, actionType: model.actionType)) {
MVMCoreLoggingHandler.addError(toLog: errorObject)
}
} else if let error = error { } else if let error = error {
continuation.resume(throwing: error) continuation.resume(throwing: error)
} else { } else {

View File

@ -66,8 +66,8 @@ public struct ActionShareModel: ActionModelProtocol {
// MARK: - Initializer // MARK: - Initializer
//-------------------------------------------------- //--------------------------------------------------
public init(sharedText: String, sharedType: ActionShareItemModel.SharedType, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) { public init(items: [ActionShareItemModel], _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
items = [ActionShareItemModel(type: sharedType, value: sharedText)] self.items = items
self.extraParameters = extraParameters self.extraParameters = extraParameters
self.analyticsData = analyticsData self.analyticsData = analyticsData
} }
@ -83,24 +83,34 @@ public struct ActionShareModel: ActionModelProtocol {
case sharedText case sharedText
} }
private enum DeprecatedCodingKeys: String, CodingKey {
case sharedType
case sharedText
}
public init(from decoder: Decoder) throws { public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let items = try typeContainer.decodeIfPresent([ActionShareItemModel].self, forKey: .items) { if let items = try typeContainer.decodeIfPresent([ActionShareItemModel].self, forKey: .items) {
self.items = items self.init(items: items)
} else { } else {
// Legacy // Legacy
let type = try typeContainer.decode(ActionShareItemModel.SharedType.self, forKey: .sharedType) try self.init(deprecatedFrom: decoder)
var value: Any
switch type {
case .url:
value = try typeContainer.decode(URL.self, forKey: .sharedText)
default:
value = try typeContainer.decode(String.self, forKey: .sharedText)
}
items = [ActionShareItemModel(type: type, value: value)]
} }
} }
private init(deprecatedFrom decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: DeprecatedCodingKeys.self)
let type = try typeContainer.decode(ActionShareItemModel.SharedType.self, forKey: .sharedType)
var value: Any
switch type {
case .url:
value = try typeContainer.decode(URL.self, forKey: .sharedText)
default:
value = try typeContainer.decode(String.self, forKey: .sharedText)
}
items = [ActionShareItemModel(type: type, value: value)]
}
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self) var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(actionType, forKey: .actionType) try container.encode(actionType, forKey: .actionType)