getting dispatch to main thread as close to the listener as possible to allow quickest change

This commit is contained in:
talksik
2021-12-21 00:12:59 -08:00
parent 46ccd91335
commit 158b7277b0
2 changed files with 12 additions and 12 deletions
@@ -28,6 +28,7 @@ class FirestoreService {
return return
} }
DispatchQueue.main.async {
guard let updatedOrNewUser = try? document.data(as: User.self) guard let updatedOrNewUser = try? document.data(as: User.self)
else { else {
completion(nil) completion(nil)
@@ -38,6 +39,7 @@ class FirestoreService {
completion(updatedOrNewUser) completion(updatedOrNewUser)
} }
} }
}
func getUser(userId: String, completion: @escaping((_ user: User?) -> ())) { func getUser(userId: String, completion: @escaping((_ user: User?) -> ())) {
let docRef = db.collection(Collection.users.rawValue).document(userId) let docRef = db.collection(Collection.users.rawValue).document(userId)
@@ -136,13 +136,11 @@ final class AuthSessionStore: ObservableObject, SessionStore {
// when we have a user get signed in, we can activate the listener for fetching the user's data to keep our auth session store always up to date for all of the ui // when we have a user get signed in, we can activate the listener for fetching the user's data to keep our auth session store always up to date for all of the ui
self.firestoreService.getUserRealtime(userId: uid) {[weak self] realtimeUpdatedUser in self.firestoreService.getUserRealtime(userId: uid) {[weak self] realtimeUpdatedUser in
DispatchQueue.main.async {
if realtimeUpdatedUser != nil { if realtimeUpdatedUser != nil {
print("up to date user: \(realtimeUpdatedUser)") print("up to date user: \(realtimeUpdatedUser)")
self?.user = realtimeUpdatedUser self?.user = realtimeUpdatedUser
} }
} }
}
// TODO: listener for getting user's sent and received messages // TODO: listener for getting user's sent and received messages