Files
iOS/Sources/Shared/API/Models/NotificationAction.swift
Zac West 640cca884b Add SwiftFormat to project (#1463)
Adds new fastlane lanes:
- `fastlane lint` which checks the linters
- `fastlane autocorrect` which applies the linters which can autocorrect (Rubocop, SwiftFormat)

Adds a build step to the Codegen abstract target which runs SwiftFormat in lint mode, pointing out what it's going to change when run.

Applies SwiftFormat to nearly all code -- exempts a few externally-sourced files and generated code.
2021-02-05 22:06:25 -08:00

76 lines
2.6 KiB
Swift

import Foundation
import RealmSwift
import UserNotifications
public class NotificationAction: Object {
@objc public dynamic var uuid: String = UUID().uuidString
@objc public dynamic var Identifier: String = ""
@objc public dynamic var Title: String = ""
@objc public dynamic var TextInput: Bool = false
@objc public dynamic var isServerControlled: Bool = false
// Options
@objc public dynamic var Foreground: Bool = false
@objc public dynamic var Destructive: Bool = false
@objc public dynamic var AuthenticationRequired: Bool = false
// Text Input Options
@objc public dynamic var TextInputButtonTitle: String = L10n.NotificationsConfigurator.Action.Rows
.TextInputButtonTitle.title
@objc public dynamic var TextInputPlaceholder: String = L10n.NotificationsConfigurator.Action.Rows
.TextInputPlaceholder.title
// swiftlint:enable line_length
override public static func primaryKey() -> String? {
"uuid"
}
public let categories = LinkingObjects(fromType: NotificationCategory.self, property: "Actions")
public var options: UNNotificationActionOptions {
var actionOptions = UNNotificationActionOptions([])
if AuthenticationRequired { actionOptions.insert(.authenticationRequired) }
if Destructive { actionOptions.insert(.destructive) }
if Foreground { actionOptions.insert(.foreground) }
return actionOptions
}
public var action: UNNotificationAction {
if TextInput {
return UNTextInputNotificationAction(
identifier: Identifier,
title: Title,
options: options,
textInputButtonTitle: TextInputButtonTitle,
textInputPlaceholder: TextInputPlaceholder
)
}
return UNNotificationAction(identifier: Identifier, title: Title, options: options)
}
public class func exampleTrigger(
identifier: String,
category: String?,
textInput: Bool
) -> String {
let data = HomeAssistantAPI.notificationActionEvent(
identifier: identifier,
category: category,
actionData: "# value of action_data in notify call",
textInput: textInput ? "# text you input" : nil
)
let eventDataStrings = data.eventData.map { $0 + ": " + String(describing: $1) }.sorted()
let indentation = "\n "
return """
- platform: event
event_type: \(data.eventType)
event_data:
\(eventDataStrings.joined(separator: indentation))
"""
}
}