diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml
index 0889e9ce..09abbd31 100644
--- a/composeApp/src/commonMain/composeResources/values/strings.xml
+++ b/composeApp/src/commonMain/composeResources/values/strings.xml
@@ -794,4 +794,7 @@
Send again
Sent again
The group's admins have changed since this key was made. It changes on its own once an admin's device starts a new ceremony, or you can rotate it now.
+
+ Unread: %1$d
+ Conversations with unread messages: %1$d
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NotificationDao.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NotificationDao.kt
index 089a71fd..cc707fe9 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NotificationDao.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/dao/NotificationDao.kt
@@ -56,7 +56,8 @@ abstract class NotificationDao {
/** Unread lines per room, for every room [userPublicKey] is in and has not left or deleted. */
@Query(
- "SELECT ChatMessage.chatRoomId AS chatRoomId, COUNT(*) AS unread FROM ChatMessage " +
+ "SELECT ChatMessage.chatRoomId AS chatRoomId, COUNT(*) AS unread, " +
+ "ChatRoom.notifications AS notifications FROM ChatMessage " +
"JOIN ChatRoom ON ChatRoom.id = ChatMessage.chatRoomId " +
"WHERE ChatRoom.userPublicKey = :userPublicKey AND ChatRoom.deletedAt IS NULL " +
"AND ChatRoom.leftGroupAt IS NULL AND ChatMessage.isUserMessage = 0 " +
@@ -150,5 +151,11 @@ abstract class NotificationDao {
}
}
-/** One room's unread count. */
-data class RoomUnread(val chatRoomId: String, val unread: Int)
+/** One room's unread count, and whether the room is muted -- a muted room counts, quietly. */
+data class RoomUnread(
+ val chatRoomId: String,
+ val unread: Int,
+ val notifications: String,
+) {
+ val isMuted: Boolean get() = notifications == mobi.giza.compose.database.model.ChatRoom.NOTIFICATIONS_MUTED
+}
diff --git a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
index 23f5ffc2..5977ba25 100644
--- a/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
+++ b/composeApp/src/commonMain/kotlin/mobi/giza/compose/database/repository/DatabaseChatRepository.kt
@@ -44,6 +44,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.map
import mobi.giza.compose.database.GENESIS_AT
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.model.ChatMessage
@@ -187,6 +188,18 @@ class DatabaseChatRepository(
return database.chatRoomDao().observeChatRoomListByUserPublicKey(publicKey)
}
+ override suspend fun markChatRoomRead(chatRoomId: String) {
+ database.notificationDao().markAllRead(chatRoomId)
+ }
+
+ override fun observeUnreadCounts(publicKey: String): Flow