Skip to content

Instantly share code, notes, and snippets.

@yashovardhan99
Last active August 18, 2020 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yashovardhan99/b6be4a1d0b65363c87033bee90260825 to your computer and use it in GitHub Desktop.
Save yashovardhan99/b6be4a1d0b65363c87033bee90260825 to your computer and use it in GitHub Desktop.
Firebase MVVM Profile Service 2
suspend fun getFriends(userId: String): List<User> {
val db = FirebaseFirestore.getInstance()
return try {
db.collection("users")
.document(userId)
.collection("friends").get().await()
.documents.mapNotNull { it.toUser() }
} catch (e: Exception) {
Log.e(TAG, "Error getting user friends", e)
FirebaseCrashlytics.getInstance().log("Error getting user friends")
FirebaseCrashlytics.getInstance().setCustomKey("user id", xpertSlug)
FirebaseCrashlytics.getInstance().recordException(e)
emptyList()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment