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
// :entities module | |
dependency { | |
implementation "androidx.room:room-common:2.4.2" | |
} |
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
// :entities module | |
dependency { | |
implementation "androidx.room:room-runtime:2.3.0" | |
} |
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
// :data module | |
dependency { | |
implementation "androidx.room:room-runtime:2.3.0" | |
kapt "androidx.room:room-compiler:2.3.0" | |
} |
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
@Entity(tableName = "user_table") | |
data class User( | |
@PrimaryKey | |
val id: String, | |
val name: String, | |
val age: Int | |
) |
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
val db = FirebaseFirestore.getInstance() | |
db.collectionGroup("group_messages") | |
.whereArrayContains("to", preference.getUserId()) | |
.addSnapshotListener { snapShots, error -> | |
} |
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
@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 |
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) |
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
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> |
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
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 |
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
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!!) |
NewerOlder