Skip to content

Instantly share code, notes, and snippets.

@a914-gowtham
Created September 26, 2021 17:14
Show Gist options
  • Save a914-gowtham/61e22b121562da9c2526b10507f3cfc3 to your computer and use it in GitHub Desktop.
Save a914-gowtham/61e22b121562da9c2526b10507f3cfc3 to your computer and use it in GitHub Desktop.
@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
}.size
groupWithMsg.group.unRead = unreadCount
}
dbRepository.insertMultipleGroup(groups)
```utils.kt
fun myMsgStatus(myUserId: String, msg: GroupMessage): Int{
val indexOfMyStatus=msg.to.indexOf(myUserId)
return msg.status[indexOfMyStatus]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment