NCNotificationAction.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
  3. // SPDX-License-Identifier: GPL-3.0-or-later
  4. //
  5. import Foundation
  6. // Documentation at https://github.com/nextcloud/notifications/blob/master/docs/ocs-endpoint-v2.md
  7. // Type "Web" is supposed to do a redirect
  8. @objc enum NCNotificationActionType: Int {
  9. case kNotificationActionTypeUnknown = 0
  10. case kNotificationActionTypeGet
  11. case kNotificationActionTypePost
  12. case kNotificationActionTypeDelete
  13. case kNotificationActionTypePut
  14. case kNotificationActionTypeWeb
  15. }
  16. @objcMembers class NCNotificationAction: NSObject {
  17. public let actionLabel: String?
  18. public var actionLink: String?
  19. public var actionType: NCNotificationActionType = .kNotificationActionTypeUnknown
  20. public var isPrimaryAction: Bool
  21. init(dictionary: [String: Any]) {
  22. self.actionLabel = dictionary["label"] as? String
  23. self.actionLink = dictionary["link"] as? String
  24. self.isPrimaryAction = dictionary["primary"] as? Bool ?? false
  25. if let actionType = dictionary["type"] as? String {
  26. switch actionType.lowercased() {
  27. case "get":
  28. self.actionType = .kNotificationActionTypeGet
  29. case "post":
  30. self.actionType = .kNotificationActionTypePost
  31. case "delete":
  32. self.actionType = .kNotificationActionTypeDelete
  33. case "put":
  34. self.actionType = .kNotificationActionTypePut
  35. case "web":
  36. self.actionType = .kNotificationActionTypeWeb
  37. default:
  38. self.actionType = .kNotificationActionTypeUnknown
  39. }
  40. }
  41. super.init()
  42. }
  43. }