WebUpdateConnectionInfoResponse.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 WebUpdateConnectionInfoResponse: WebAbstractMessage, NSCoding {
  22. var id: Data
  23. var resume: WebConnection?
  24. init(currentId: Data, previousId: Data?, previousSequenceNumber: UInt32?) {
  25. id = currentId
  26. var tmpData:[AnyHashable:Any?] = ["id": id]
  27. if previousId != nil && previousSequenceNumber != nil {
  28. if previousId!.bytes.count > 0 {
  29. resume = WebConnection.init(connection: ["id": previousId!, "sequenceNumber": previousSequenceNumber!])
  30. }
  31. }
  32. if resume != nil {
  33. tmpData.updateValue(resume!.objectDict(), forKey: "resume")
  34. }
  35. super.init(messageType: "update", messageSubType: "connectionInfo", requestId: nil, ack: nil, args: nil, data: tmpData)
  36. }
  37. required init?(coder aDecoder: NSCoder) {
  38. self.id = aDecoder.decodeObject(forKey: "id") as! Data
  39. self.resume = aDecoder.decodeObject(forKey: "resume") as? WebConnection
  40. super.init(messageType: "update", messageSubType: "connectionInfo", requestId: nil, ack: nil, args: nil, data: aDecoder.decodeObject(forKey: "data"))
  41. }
  42. func encode(with aCoder: NSCoder) {
  43. aCoder.encode(id, forKey: "id")
  44. if resume != nil {
  45. aCoder.encode(resume, forKey: "resume")
  46. }
  47. aCoder.encode(messageType, forKey: "messageType")
  48. if messageSubType != nil {
  49. aCoder.encode(messageSubType, forKey: "messageSubType")
  50. }
  51. if requestId != nil {
  52. aCoder.encode(requestId, forKey: "requestId")
  53. }
  54. if ack != nil {
  55. aCoder.encode(ack, forKey: "ack")
  56. }
  57. if args != nil {
  58. aCoder.encode(args, forKey: "args")
  59. }
  60. if data != nil {
  61. aCoder.encode(data, forKey: "data")
  62. }
  63. }
  64. }