iOS/Sources/Shared/API/Responses/MobileAppConfig/MobileAppConfigPushCategory.swift
mat1th 113d4fe18f
Update dependecy and cleanup code (#2581)
## Summary
This pr intruduces the following changes: 
- Upgrades the [Alomofire
dependecy](142efae0cc).
- Removes not needed [available
anotations](a4e71a3c88)
and split up code in multiple files; The anotations are not needed since
https://github.com/home-assistant/iOS/pull/2469.

## Screenshots
No user faceing changes

## Link to pull request in Documentation repository
NA

## Any other notes
NA
2024-02-23 15:04:00 +01:00

56 lines
2.3 KiB
Swift

import Foundation
import ObjectMapper
public struct MobileAppConfigPushCategory: ImmutableMappable, UpdatableModelSource {
public struct Action: ImmutableMappable {
public var title: String
public var identifier: String
public var authenticationRequired: Bool
public var behavior: String
public var activationMode: String
public var destructive: Bool
public var textInputButtonTitle: String?
public var textInputPlaceholder: String?
public var url: String?
public var icon: String?
public init(map: Map) throws {
self.title = try map.value("title", default: "Missing title")
// we fall back to 'action' for android-style dynamic actions
self.identifier = try map.value("identifier", default: map.value("action", default: "missing"))
self.authenticationRequired = try map.value("authenticationRequired", default: false)
self.behavior = try map.value("behavior", default: "default")
self.activationMode = try map.value("activationMode", default: "background")
self.destructive = try map.value("destructive", default: false)
self.textInputButtonTitle = try? map.value("textInputButtonTitle")
self.textInputPlaceholder = try? map.value("textInputPlaceholder")
self.icon = try? map.value("icon")
for urlKey in ["url", "uri"] {
if let value: String = try? map.value(urlKey) {
// a url is set, which means this is likely coming from an actionable notification
// so assume that it wants activation for it
self.url = value
self.activationMode = "foreground"
}
}
if identifier.lowercased() == "reply" {
// matching Android behavior
self.behavior = "textinput"
}
}
}
public var name: String
public var identifier: String
public var actions: [Action]
public init(map: Map) throws {
self.name = try map.value("name")
self.identifier = try map.value("identifier", default: name)
self.actions = map.value("actions", default: [])
}
public var primaryKey: String { identifier.uppercased() }
}