Adds blacklist system for sync

multistore
Laurent 1 year ago
parent 7c640d5157
commit e23c81306c
  1. 14
      LeStorage/Store.swift
  2. 10
      LeStorage/StoredCollection.swift

@ -71,6 +71,8 @@ public class Store {
fileprivate var _failedAPICallsCollection: StoredCollection<FailedAPICall>? = 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 } )
}
}

@ -433,7 +433,7 @@ public class StoredCollection<T: Storable>: 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<T: Storable>: 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<T: Storable>: 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<T: Storable>: RandomAccessCollection, SomeCollecti
}
}
fileprivate func _canSynchronise() -> Bool {
return Store.main.collectionsCanSynchronize && Store.main.userIsAllowed()
}
/// Reschedule the api calls if possible
func rescheduleApiCallsIfNecessary() {
Task {

Loading…
Cancel
Save