feat: Add "Mark all as read" and unread message count indicators (#4720)

This commit is contained in:
James Rich 2026-03-05 12:18:34 -06:00 committed by GitHub
parent 6a1a612c38
commit b0258d0cf1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 131 additions and 26 deletions

View file

@ -158,6 +158,26 @@ class PacketDaoTest {
}
}
@Test
fun test_getUnreadCount_excludesFiltered() = runBlocking {
val filteredContactKey = "0!filteredonly"
val filteredPacket =
Packet(
uuid = 0L,
myNodeNum = myNodeNum,
port_num = 1,
contact_key = filteredContactKey,
received_time = nowMillis,
read = false,
filtered = true,
data = DataPacket(DataPacket.ID_BROADCAST, 0, "Filtered message"),
)
packetDao.insert(filteredPacket)
val unreadCount = packetDao.getUnreadCount(filteredContactKey)
assertEquals(0, unreadCount)
}
@Test
fun test_clearUnreadCount() = runBlocking {
val timestamp = nowMillis

View file

@ -94,16 +94,25 @@ interface PacketDao {
"""
SELECT COUNT(*) FROM packet
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND contact_key = :contact AND read = 0
AND port_num = 1 AND contact_key = :contact AND read = 0 AND filtered = 0
""",
)
suspend fun getUnreadCount(contact: String): Int
@Query(
"""
SELECT COUNT(*) FROM packet
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND contact_key = :contact AND read = 0 AND filtered = 0
""",
)
fun getUnreadCountFlow(contact: String): Flow<Int>
@Query(
"""
SELECT uuid FROM packet
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND contact_key = :contact AND read = 0
AND port_num = 1 AND contact_key = :contact AND read = 0 AND filtered = 0
ORDER BY received_time ASC
LIMIT 1
""",
@ -114,7 +123,7 @@ interface PacketDao {
"""
SELECT COUNT(*) > 0 FROM packet
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND contact_key = :contact AND read = 0
AND port_num = 1 AND contact_key = :contact AND read = 0 AND filtered = 0
""",
)
fun hasUnreadMessages(contact: String): Flow<Boolean>
@ -123,7 +132,7 @@ interface PacketDao {
"""
SELECT COUNT(*) FROM packet
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND read = 0
AND port_num = 1 AND read = 0 AND filtered = 0
""",
)
fun getUnreadCountTotal(): Flow<Int>
@ -133,11 +142,21 @@ interface PacketDao {
UPDATE packet
SET read = 1
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND contact_key = :contact AND read = 0 AND received_time <= :timestamp
AND port_num = 1 AND contact_key = :contact AND read = 0 AND filtered = 0 AND received_time <= :timestamp
""",
)
suspend fun clearUnreadCount(contact: String, timestamp: Long)
@Query(
"""
UPDATE packet
SET read = 1
WHERE (myNodeNum = 0 OR myNodeNum = (SELECT myNodeNum FROM my_node))
AND port_num = 1 AND read = 0 AND filtered = 0
""",
)
suspend fun clearAllUnreadCounts()
@Upsert suspend fun insert(packet: Packet)
@Transaction