feat: add unread message count

This commit is contained in:
andrekir 2024-06-15 12:18:26 -03:00 committed by Andre K
parent e4f5d9b89c
commit d7013e1386
7 changed files with 89 additions and 4 deletions

View file

@ -24,6 +24,14 @@ class PacketRepository @Inject constructor(private val packetDaoLazy: dagger.Laz
packetDao.getMessageCount(contact)
}
suspend fun getUnreadCount(contact: String): Int = withContext(Dispatchers.IO) {
packetDao.getUnreadCount(contact)
}
suspend fun clearUnreadCount(contact: String, timestamp: Long) = withContext(Dispatchers.IO) {
packetDao.clearUnreadCount(contact, timestamp)
}
suspend fun getQueuedPackets(): List<DataPacket>? = withContext(Dispatchers.IO) {
packetDao.getQueuedPackets()
}

View file

@ -45,6 +45,25 @@ interface PacketDao {
)
suspend fun getMessageCount(contact: String): Int
@Query(
"""
SELECT COUNT(*) FROM packet
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM MyNodeInfo))
AND port_num = 1 AND contact_key = :contact AND read = 0
"""
)
suspend fun getUnreadCount(contact: String): Int
@Query(
"""
UPDATE packet
SET read = 1
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM MyNodeInfo))
AND port_num = 1 AND contact_key = :contact AND read = 0 AND received_time <= :timestamp
"""
)
suspend fun clearUnreadCount(contact: String, timestamp: Long)
@Insert
fun insert(packet: Packet)