I'm implementing post liking and commenting functionality in Firestore using transactions. I use transaction because I need to add new field in likes/comments subcollection and update counter on the post, and also add post id to the user liked/commented post collection.
I noticed that if I'm offline and I request my post like this everything is OK:
val postDocRef = FirebaseUtil.postsColRef.document(postId)
postDocRef.get().addOnSuccessListener { doc ->
val post = doc.toObject(Post::class.java)
Timber.e(post.toString())
}
But if I do the same in transaction exception is thrown:
val postDocRef = FirebaseUtil.postsColRef.document(postId)
FirebaseUtil.firestore.runTransaction(Transaction.Function<Void> { transaction ->
val post = transaction.get(postDocRef).toObject(Post::class.java)
}
Exception is:
com.google.firebase.firestore.FirebaseFirestoreException: UNAVAILABLE
Why offline mode is not working in transaction? Is it possible to implement this functionality (adding entry in subcollection and updating fields in different objects) in offline?
What could be drawbacks in replacing transaction with continueWithTask()
call chain?