diff --git a/LeStorage/Codables/GetSyncData.swift b/LeStorage/Codables/GetSyncData.swift index bd8882e..3c6999b 100644 --- a/LeStorage/Codables/GetSyncData.swift +++ b/LeStorage/Codables/GetSyncData.swift @@ -10,13 +10,19 @@ import Foundation class GetSyncData: SyncedModelObject, SyncedStorable, URLParameterConvertible { var date: String = "" - + + enum CodingKeys: String, CodingKey { + case date + } + override required init() { super.init() } required public init(from decoder: Decoder) throws { - fatalError("init(from:) has not been implemented") + let container = try decoder.container(keyedBy: CodingKeys.self) + date = try container.decode(String.self, forKey: .date) + try super.init(from: decoder) } static func tokenExemptedMethods() -> [HTTPMethod] { return [] } diff --git a/LeStorage/Codables/Log.swift b/LeStorage/Codables/Log.swift index ab9f2a7..665bb18 100644 --- a/LeStorage/Codables/Log.swift +++ b/LeStorage/Codables/Log.swift @@ -30,6 +30,7 @@ class Log: SyncedModelObject, SyncedStorable { } // MARK: - Codable + enum CodingKeys: String, CodingKey { case id case date diff --git a/LeStorage/StoreCenter.swift b/LeStorage/StoreCenter.swift index 5c77c9a..52096aa 100644 --- a/LeStorage/StoreCenter.swift +++ b/LeStorage/StoreCenter.swift @@ -640,6 +640,8 @@ public class StoreCenter { self._syncAddOrUpdate(syncData.sharedRelationshipSets) self._syncRevoke(syncData.sharedRelationshipRemovals) + Logger.log("sync content: updates = \(syncData.updates.count) / deletions = \(syncData.deletions.count), grants = \(syncData.grants.count)") + if let dateString = syncData.date { Logger.log("Sets sync date = \(dateString)") self._settingsStorage.update { settings in @@ -1028,8 +1030,8 @@ public class StoreCenter { return [] } - /// Sets the the list of authorized users for an instance - public func setAuthorizedUsers(for instance: T, users: [String]) throws { + public func setAuthorizedUsersAsync(for instance: T, users: [String]) async throws { + guard let dataAccessCollection = self._dataAccess else { return } @@ -1039,15 +1041,27 @@ public class StoreCenter { if let dataAccess = dataAccessCollection.first(where: { $0.modelId == instance.stringId }) { if users.isEmpty { - dataAccessCollection.delete(instance: dataAccess) + await dataAccessCollection.deleteAsync(instance: dataAccess) } else { dataAccess.sharedWith.removeAll() dataAccess.sharedWith = users - dataAccessCollection.addOrUpdate(instance: dataAccess) + await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) } } else { let dataAccess = DataAccess(owner: userId, sharedWith: users, modelName: String(describing: type(of: instance)), modelId: instance.stringId) - dataAccessCollection.addOrUpdate(instance: dataAccess) + await dataAccessCollection.addOrUpdateAsync(instance: dataAccess) + } + + } + + /// Sets the the list of authorized users for an instance + public func setAuthorizedUsers(for instance: T, users: [String]) throws { + Task { + do { + try await self.setAuthorizedUsersAsync(for: instance, users: users) + } catch { + Logger.error(error) + } } }