This commit is contained in:
Pfeil, Scott Robert 2020-10-15 16:51:27 -04:00
parent b371cf5e83
commit 44c7476542

View File

@ -40,6 +40,7 @@ public extension MVMCoreUITopAlertView {
MVMCoreAlertHandler.shared()?.checkPagesDependency(for: controller.pageType)
}
/// Decodes the json into a TopNotificationModel
func decodeTopNotification(with json: [AnyHashable: Any], delegateObject: MVMCoreUIDelegateObject?) -> TopNotificationModel? {
do {
return try TopNotificationModel.decode(json: json, delegateObject: delegateObject)
@ -57,6 +58,7 @@ public extension MVMCoreUITopAlertView {
MVMCoreAlertHandler.shared()?.showTopAlert(with: object)
}
/// Updates the current top alert molecule with the new object
@objc func updateMolecule(with topAlertObject: MVMCoreTopAlertObject) {
guard topAlertObject.type == self.topAlertObject?.type else { return }
let delegateObject = getDelegateObject()
@ -67,9 +69,15 @@ public extension MVMCoreUITopAlertView {
let currentModel = decodeTopNotification(with: currentJson, delegateObject: delegateObject),
let currentModelName = MoleculeObjectMapping.shared()?.getMoleculeClass(currentModel.molecule)?.nameForReuse(with: currentModel.molecule, delegateObject),
newModelName == currentModelName,
let molecule = currentAlert as? MoleculeViewProtocol else { return /* Something is not right, revisit */}
// Update molecule
let molecule = currentAlert as? MoleculeViewProtocol else {
// Log that we couldn't update.
if let errorObject = MVMCoreErrorObject(title: nil, message: nil, messageToLog: nil, code: ErrorCode.parsingJSON.rawValue, domain: ErrorDomainNative, location: "TopNotification update \(String(describing: topAlertObject.type))") {
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
}
return
}
MVMCoreDispatchUtility.performBlock(onMainThread: {
// Update molecule
molecule.reset()
molecule.set(with: newModel.molecule, delegateObject, nil)
(molecule as? MVMCoreViewProtocol)?.updateView(self.bounds.width)