diff --git a/LeStorage/Store.swift b/LeStorage/Store.swift index ece0ab4..5bb20cb 100644 --- a/LeStorage/Store.swift +++ b/LeStorage/Store.swift @@ -71,6 +71,8 @@ public class Store { fileprivate var _failedAPICallsCollection: StoredCollection? = nil + fileprivate var blackListedUserName: [String] = [] + public init() { FileManager.default.createDirectoryInDocuments(directoryName: Store.storageDirectory) } @@ -327,4 +329,16 @@ public class Store { } + public func blackListUserName(_ userName: String) { + self.blackListedUserName.append(userName) + } + + func userIsAllowed() -> Bool { + guard let userName = self.userName() else { + return true + } + let isAllowed = !self.blackListedUserName.contains(where: { $0 == userName } ) + return !self.blackListedUserName.contains(where: { $0 == userName } ) + } + } diff --git a/LeStorage/StoredCollection.swift b/LeStorage/StoredCollection.swift index c14558e..d300e68 100644 --- a/LeStorage/StoredCollection.swift +++ b/LeStorage/StoredCollection.swift @@ -433,7 +433,7 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti /// Sends an insert api call for the provided [instance] fileprivate func _sendInsertionIfNecessary(_ instance: T) { - guard self.synchronized, Store.main.collectionsCanSynchronize else { + guard self.synchronized, self._canSynchronise() else { return } Task { @@ -443,7 +443,7 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti /// Sends an update api call for the provided [instance] fileprivate func _sendUpdateIfNecessary(_ instance: T) { - guard self.synchronized, self._sendsUpdate, Store.main.collectionsCanSynchronize else { + guard self.synchronized, self._sendsUpdate, self._canSynchronise() else { return } Task { @@ -453,7 +453,7 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti /// Sends an delete api call for the provided [instance] fileprivate func _sendDeletionIfNecessary(_ instance: T) { - guard self.synchronized, Store.main.collectionsCanSynchronize else { + guard self.synchronized, self._canSynchronise() else { return } Task { @@ -461,6 +461,10 @@ public class StoredCollection: RandomAccessCollection, SomeCollecti } } + fileprivate func _canSynchronise() -> Bool { + return Store.main.collectionsCanSynchronize && Store.main.userIsAllowed() + } + /// Reschedule the api calls if possible func rescheduleApiCallsIfNecessary() { Task {