WebGroupSyncRequest.swift 2.0 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 WebGroupSyncRequest: WebAbstractMessage {
  22. let id: Data
  23. // var success: Bool = false
  24. // var error: String?
  25. override init(message:WebAbstractMessage) {
  26. let idString = message.args!["id"] as! String
  27. id = idString.hexadecimal()!
  28. super.init(message: message)
  29. }
  30. func syncGroup() {
  31. ack = WebAbstractMessageAcknowledgement.init(requestId, false, nil)
  32. let entityManager = EntityManager()
  33. let conversation = entityManager.entityFetcher.conversation(forGroupId: id)
  34. if conversation == nil {
  35. ack!.success = false
  36. ack!.error = "invalidGroup"
  37. return
  38. }
  39. let groupProxy = GroupProxy.init(for: conversation, entityManager: entityManager)
  40. if groupProxy == nil {
  41. ack!.success = false
  42. ack!.error = "invalidGroup"
  43. return
  44. }
  45. if !groupProxy!.isOwnGroup() {
  46. ack!.success = false
  47. ack!.error = "notAllowed"
  48. return
  49. }
  50. DispatchQueue.main.async {
  51. groupProxy?.syncGroupInfoToAll()
  52. }
  53. ack!.success = true
  54. }
  55. }