Skip to content

Instantly share code, notes, and snippets.

View a914-gowtham's full-sized avatar
🛠️
Building

Gowtham a914-gowtham

🛠️
Building
View GitHub Profile
// :entities module
dependency {
implementation "androidx.room:room-common:2.4.2"
}
// :entities module
dependency {
implementation "androidx.room:room-runtime:2.3.0"
}
// :data module
dependency {
implementation "androidx.room:room-runtime:2.3.0"
kapt "androidx.room:room-compiler:2.3.0"
}
@Entity(tableName = "user_table")
data class User(
@PrimaryKey
val id: String,
val name: String,
val age: Int
)
val db = FirebaseFirestore.getInstance()
db.collectionGroup("group_messages")
.whereArrayContains("to", preference.getUserId())
.addSnapshotListener { snapShots, error ->
}
@Transaction
@Query("SELECT * FROM `Group`")
fun getGroupWithMessagesList(): List<GroupWithMessages>
\\ chathandler.kt
val groupsWithMsgs = dbRepository.getGroupWithMessagesList()
for (groupWithMsg in groupsWithMsgs) {
val unreadCount = groupWithMsg.messages.filter {
val myMessageStatus = Utils.myMsgStatus(userId.toString(), it)
it.from != userId && myMessageStatus < 3
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)
private fun addGroupListener() {
val fireStore= FirebaseFirestore.getInstance()
val userCollection= fireStore.collection("Users")
val groupCollection= fireStore.collection("Groups")
userCollection.document(myUserId).addSnapshotListener { snapshot, error ->
if (error == null) {
val groups = snapshot?.get("groups")
val groupsIds =
if (groups == null) ArrayList() else groups as ArrayList<String>
class GroupMsgStatusUpdater {
fun updateToDeliveryOrSeen(myUserId: String, messageList: List<GroupMessage>,isSeen: Boolean, vararg groupId: String){
try {
val batch= firestore.batch()
val db = FirebaseFirestore.getInstance()
val groupCollection= db.collection("Groups")
for (id in groupId){
val msgSubCollection=groupCollection.document(id).collection("group_messages")
val filterList= messageList
class GroupHandler(){
private val messagesList = mutableListOf<GroupMessage>()
private val groupIds = ArrayList<String>()
fun initListener(){
val db = FirebaseFirestore.getInstance()
val groupMsgCollection= db.collectionGroup("group_messages")
groupMsgCollection.whereArrayContains("to", userId!!)