|
|
|
|
@ -22,8 +22,8 @@ public class DataStore: ObservableObject { |
|
|
|
|
if self.user.id != self.userStorage.item()?.id { |
|
|
|
|
self.userStorage.setItemNoSync(self.user) |
|
|
|
|
StoreCenter.main.initialSynchronization(clear: false) |
|
|
|
|
self._fixMissingClubCreatorIfNecessary(self.clubs) |
|
|
|
|
self._fixMissingEventCreatorIfNecessary(self.events) |
|
|
|
|
self._fixMissingClubCreatorIfNecessary() |
|
|
|
|
self._fixMissingEventCreatorIfNecessary() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
self._temporaryLocalUser.item = self.user |
|
|
|
|
@ -96,12 +96,12 @@ public class DataStore: ObservableObject { |
|
|
|
|
|
|
|
|
|
@objc func collectionDidLoad(notification: Notification) { |
|
|
|
|
|
|
|
|
|
if let userSingleton: StoredSingleton<CustomUser> = notification.object as? StoredSingleton<CustomUser> { |
|
|
|
|
self.user = userSingleton.item() ?? self._temporaryLocalUser.item ?? CustomUser.placeHolder() |
|
|
|
|
} else if let clubsCollection: SyncedCollection<Club> = notification.object as? SyncedCollection<Club> { |
|
|
|
|
self._fixMissingClubCreatorIfNecessary(clubsCollection) |
|
|
|
|
} else if let eventsCollection: SyncedCollection<Event> = notification.object as? SyncedCollection<Event> { |
|
|
|
|
self._fixMissingEventCreatorIfNecessary(eventsCollection) |
|
|
|
|
if let userSingleton: StoredCollection<CustomUser> = notification.object as? StoredCollection<CustomUser> { |
|
|
|
|
self.user = userSingleton.first ?? self._temporaryLocalUser.item ?? CustomUser.placeHolder() |
|
|
|
|
} else if let clubsCollection: StoredCollection<Club> = notification.object as? StoredCollection<Club> { |
|
|
|
|
self._fixMissingClubCreatorIfNecessary() |
|
|
|
|
} else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> { |
|
|
|
|
self._fixMissingEventCreatorIfNecessary() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if Store.main.fileCollectionsAllLoaded() { |
|
|
|
|
@ -110,10 +110,11 @@ public class DataStore: ObservableObject { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: SyncedCollection<Club>) { |
|
|
|
|
fileprivate func _fixMissingClubCreatorIfNecessary() { |
|
|
|
|
|
|
|
|
|
if self.user.clubs.count > 0 { return } |
|
|
|
|
|
|
|
|
|
let clubsCollection = DataStore.shared.clubs |
|
|
|
|
for club in clubsCollection { |
|
|
|
|
if let userId = StoreCenter.main.userId, club.creator == nil { |
|
|
|
|
club.creator = userId |
|
|
|
|
@ -124,7 +125,8 @@ public class DataStore: ObservableObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _fixMissingEventCreatorIfNecessary(_ eventsCollection: SyncedCollection<Event>) { |
|
|
|
|
fileprivate func _fixMissingEventCreatorIfNecessary() { |
|
|
|
|
let eventsCollection = DataStore.shared.events |
|
|
|
|
for event in eventsCollection { |
|
|
|
|
if let userId = StoreCenter.main.userId, event.creator == nil { |
|
|
|
|
event.creator = userId |
|
|
|
|
|