LineSDKOpenChatCreatingController.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // LineSDKOpenChatCreatingController.swift
  3. //
  4. // Copyright (c) 2016-present, LY Corporation. All rights reserved.
  5. //
  6. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  7. // copy and distribute this software in source code or binary form for use
  8. // in connection with the web services and APIs provided by LY Corporation.
  9. //
  10. // As with any software that integrates with the LY Corporation platform, your use of this software
  11. // is subject to the LINE Developers Agreement [http://terms2.line.me/LINE_Developers_Agreement].
  12. // This copyright notice shall be included in all copies or substantial portions of the software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  15. // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. //
  21. @objcMembers
  22. public class LineSDKOpenChatCreatingController: NSObject {
  23. let _value: OpenChatCreatingController
  24. public override init() {
  25. _value = OpenChatCreatingController()
  26. }
  27. var delegateProxy: LineSDKOpenChatCreatingControllerDelegateProxy?
  28. public var delegate: LineSDKOpenChatCreatingControllerDelegate? {
  29. get { return delegateProxy?.proxy }
  30. set {
  31. delegateProxy = newValue.map { .init(proxy: $0, owner: self) }
  32. _value.delegate = delegateProxy
  33. }
  34. }
  35. public var suggestedCategory: Int {
  36. get { return _value.suggestedCategory.rawValue }
  37. set {
  38. guard let category = OpenChatCategory(rawValue: newValue) else {
  39. return
  40. }
  41. _value.suggestedCategory = category
  42. }
  43. }
  44. public func loadAndPresent(
  45. in viewController: UIViewController,
  46. presentedHandler handler: @escaping (UIViewController?, Error?) -> Void
  47. )
  48. {
  49. _value.loadAndPresent(in: viewController) { result in
  50. result.match(with: handler)
  51. }
  52. }
  53. public static func localAuthorizationStatusForCreatingOpenChat() -> LineSDKAuthorizationStatus
  54. {
  55. return LineSDKAuthorizationStatus.status(
  56. from: OpenChatCreatingController.localAuthorizationStatusForCreatingOpenChat()
  57. )
  58. }
  59. }
  60. class LineSDKOpenChatCreatingControllerDelegateProxy: OpenChatCreatingControllerDelegate {
  61. weak var proxy: LineSDKOpenChatCreatingControllerDelegate?
  62. unowned var owner: LineSDKOpenChatCreatingController
  63. init(proxy: LineSDKOpenChatCreatingControllerDelegate, owner: LineSDKOpenChatCreatingController) {
  64. self.proxy = proxy
  65. self.owner = owner
  66. }
  67. func openChatCreatingController(
  68. _ controller: OpenChatCreatingController,
  69. didCreateChatRoom room: OpenChatRoomInfo,
  70. withCreatingItem item: OpenChatRoomCreatingItem
  71. )
  72. {
  73. proxy?.openChatCreatingController?(owner, didCreateChatRoom: .init(room), withCreatingItem: .init(item))
  74. }
  75. func openChatCreatingController(
  76. _ controller: OpenChatCreatingController,
  77. didFailWithError error: LineSDKError,
  78. withCreatingItem item: OpenChatRoomCreatingItem,
  79. presentingViewController: UIViewController
  80. )
  81. {
  82. proxy?.openChatCreatingController?(
  83. owner,
  84. didFailWithError: error,
  85. withCreatingItem: .init(item),
  86. presentingViewController: presentingViewController
  87. )
  88. }
  89. func openChatCreatingController(
  90. _ controller: OpenChatCreatingController,
  91. shouldPreventUserTermAlertFrom presentingViewController: UIViewController
  92. ) -> Bool {
  93. return proxy?.openChatCreatingController?(owner, shouldPreventUserTermAlertFrom: presentingViewController)
  94. ?? false
  95. }
  96. func openChatCreatingControllerDidCancelCreating(_ controller: OpenChatCreatingController) {
  97. proxy?.openChatCreatingControllerDidCancelCreating?(owner)
  98. }
  99. func openChatCreatingController(
  100. _ controller: OpenChatCreatingController,
  101. willPresentCreatingNavigationController navigationController: OpenChatCreatingNavigationController)
  102. {
  103. proxy?.openChatCreatingController?(owner, willPresentCreatingNavigationController: navigationController)
  104. }
  105. }