Florian
12/05/2020, 2:16 PMsuspend fun
but also returns a Flow. And the first line can't be caught like this because it's not inside the Flow.
suspend fun getChatUserFlow(uid: String): Flow<ChatUser?> {
val results = userCollection.whereEqualTo(FieldPath.documentId(), uid).get().await()
return if (!results.isEmpty) {
results.documents[0].reference.asFlow<ChatUser>()
} else {
flowOf(null)
}
}
fun getChatUserFlow(uid: String): Flow<ChatUser?> =
userCollection.whereEqualTo(FieldPath.documentId(), uid).asFlow<ChatUser>().flatMapLatest { result ->
if (!result.isEmpty()) {
userCollection.document(result[0].uid!!).asFlow()
} else {
flowOf(null)
}
}
gildor
12/06/2020, 12:24 AMFlorian
12/06/2020, 7:23 AM