LineSDKImageMessage.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // LineSDKImageMessage.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 LineSDKImageMessage: LineSDKMessage {
  23. public let originalContentURL: URL
  24. public let previewImageURL: URL
  25. public var animated: Bool
  26. public var fileExtension: String?
  27. public var sender: LineSDKMessageSender?
  28. convenience init(_ value: ImageMessage) {
  29. self.init(
  30. originalContentURL: value.originalContentURL,
  31. previewImageURL: value.previewImageURL,
  32. animated: value.animated ?? false,
  33. fileExtension: value.fileExtension,
  34. sender: value.sender.map { .init($0) })!
  35. }
  36. public convenience init?(originalContentURL: URL, previewImageURL: URL) {
  37. self.init(
  38. originalContentURL: originalContentURL,
  39. previewImageURL: previewImageURL,
  40. animated: false,
  41. fileExtension: nil,
  42. sender: nil)
  43. }
  44. public init?(
  45. originalContentURL: URL,
  46. previewImageURL: URL,
  47. animated: Bool,
  48. fileExtension: String?,
  49. sender: LineSDKMessageSender?)
  50. {
  51. do {
  52. _ = try ImageMessage(originalContentURL: originalContentURL, previewImageURL: previewImageURL)
  53. self.originalContentURL = originalContentURL
  54. self.previewImageURL = previewImageURL
  55. self.animated = animated
  56. self.fileExtension = fileExtension
  57. self.sender = sender
  58. } catch {
  59. Log.assertionFailure("An error happened: \(error)")
  60. return nil
  61. }
  62. }
  63. override var unwrapped: Message {
  64. return .image(try! .init(
  65. originalContentURL: originalContentURL,
  66. previewImageURL: previewImageURL,
  67. animated: animated,
  68. fileExtension: fileExtension,
  69. sender: sender?.unwrapped
  70. ))
  71. }
  72. }