WebCreateTextMessageResponse.swift 2.5 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 WebCreateTextMessageResponse: WebAbstractMessage {
  22. var message: BaseMessage?
  23. var type: String
  24. var id: String
  25. var messageId: String?
  26. init(message:BaseMessage, request: WebCreateTextMessageRequest) {
  27. self.message = message
  28. type = request.type
  29. if request.groupId != nil {
  30. id = request.groupId!.hexEncodedString()
  31. } else {
  32. id = request.id!
  33. }
  34. messageId = message.id.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
  35. let tmpArgs:[AnyHashable:Any?] = ["type": type, "id": id]
  36. let tmpData:[AnyHashable:Any?] = ["messageId": messageId!] as [String : Any]
  37. let success: Bool = request.tmpError == nil
  38. let error: String? = request.tmpError
  39. let tmpAck = WebAbstractMessageAcknowledgement.init(request.requestId, success, error)
  40. super.init(messageType: "create", messageSubType: "textMessage", requestId: nil, ack: tmpAck, args: tmpArgs, data: tmpData)
  41. }
  42. init(request: WebCreateTextMessageRequest) {
  43. type = request.type
  44. if request.groupId != nil {
  45. id = request.groupId!.hexEncodedString()
  46. } else {
  47. id = request.id!
  48. }
  49. let tmpArgs:[AnyHashable:Any?] = ["type": type, "id": id]
  50. let success: Bool = request.tmpError == nil
  51. let error: String? = request.tmpError
  52. let tmpAck = WebAbstractMessageAcknowledgement.init(request.requestId, success, error)
  53. super.init(messageType: "create", messageSubType: "textMessage", requestId: nil, ack: tmpAck, args: tmpArgs, data: nil)
  54. }
  55. }