WebThumbnailResponse.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2018-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import Foundation
  21. class WebThumbnailResponse: WebAbstractMessage {
  22. var id: String
  23. var messageId: String
  24. var type: String
  25. var message: BaseMessage?
  26. init(request: WebThumbnailRequest, imageMessage: BaseMessage) {
  27. id = request.id
  28. type = request.type
  29. messageId = request.messageId.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
  30. let webThumbnail = WebThumbnail.init(imageMessage: imageMessage as! ImageMessage, onlyThumbnail: false)
  31. let tmpArgs:[AnyHashable:Any?] = ["id": id, "messageId": messageId, "type": type]
  32. let tmpAck = request.requestId != nil ? WebAbstractMessageAcknowledgement.init(request.requestId, true, nil) : nil
  33. super.init(messageType: "response", messageSubType: "thumbnail", requestId: nil, ack: tmpAck, args: tmpArgs, data: webThumbnail.image)
  34. }
  35. init(request: WebThumbnailRequest, videoMessage: BaseMessage) {
  36. id = request.id
  37. type = request.type
  38. messageId = request.messageId.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
  39. let webThumbnail = WebThumbnail.init(videoMessage as! VideoMessage, onlyThumbnail: false)
  40. let tmpArgs:[AnyHashable:Any?] = ["id": id, "messageId": messageId, "type": type]
  41. let tmpAck = request.requestId != nil ? WebAbstractMessageAcknowledgement.init(request.requestId, true, nil) : nil
  42. super.init(messageType: "response", messageSubType: "thumbnail", requestId: nil, ack: tmpAck, args: tmpArgs, data: webThumbnail.image)
  43. }
  44. init(request: WebThumbnailRequest, fileMessage: BaseMessage) {
  45. id = request.id
  46. type = request.type
  47. messageId = request.messageId.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
  48. let webThumbnail = WebThumbnail.init(fileMessage as! FileMessage, onlyThumbnail: false)
  49. let tmpArgs:[AnyHashable:Any?] = ["id": id, "messageId": messageId, "type": type]
  50. let tmpAck = request.requestId != nil ? WebAbstractMessageAcknowledgement.init(request.requestId, true, nil) : nil
  51. super.init(messageType: "response", messageSubType: "thumbnail", requestId: nil, ack: tmpAck, args: tmpArgs, data: webThumbnail.image)
  52. }
  53. }