Last active
November 13, 2021 14:35
-
-
Save a914-gowtham/a9b1053483e577aa3cc7a54b7ea5a0f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun initListener(){ | |
val db = FirebaseFirestore.getInstance() | |
val groupMsgCollection= db.collectionGroup("group_messages") | |
groupMsgCollection.whereArrayContains("to", userId!!) | |
.addSnapshotListener { snapshots, error -> | |
if (error != null || snapshots == null || snapshots.metadata.isFromCache) { | |
LogMessage.v("Error ${error?.localizedMessage}") | |
return@addSnapshotListener | |
} | |
onSnapShotChanged(snapshots) | |
} | |
} | |
fun onSnapShotChanged(snapshots: QuerySnapshot){ | |
val messageList= mutableListOf<GroupMessage>() | |
for(snapShot in snapshots){ | |
val message = snapShot.document.data.toDataClass<GroupMessage>() | |
messagesList.add(message) | |
} | |
groupMessageDao.insertMessages(messageList) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment