fix #3838 : message deletion count on the contacts page. (#3924)

This commit is contained in:
Dane Evans
2025-12-07 23:42:48 +11:00
committed by GitHub
parent c62ab6094c
commit 73f1ff0f1a
2 changed files with 16 additions and 2 deletions

View File

@@ -165,7 +165,11 @@ fun ContactsScreen(
.mapNotNull { pagedContacts[it] }
.filter { it.contactKey in selectedContactKeys }
}
val selectedCount = remember(selectedContacts) { selectedContacts.sumOf { it.messageCount } }
// Get message count directly from repository for selected contacts
var selectedCount by remember { mutableStateOf(0) }
LaunchedEffect(selectedContactKeys.size, selectedContactKeys.joinToString(",")) {
selectedCount = viewModel.getTotalMessageCount(selectedContactKeys.toList())
}
val isAllMuted = remember(selectedContacts) { selectedContacts.all { it.isMuted } }
// Callback functions for item interaction
@@ -398,7 +402,7 @@ private fun DeleteConfirmationDialog(
pluralStringResource(
Res.plurals.delete_messages,
selectedCount,
arrayOf(selectedCount), // Pass the count as a format argument
selectedCount, // Pass the count as a format argument
)
AlertDialog(

View File

@@ -189,5 +189,15 @@ constructor(
fun getContactSettings() = packetRepository.getContactSettings()
/**
* Get the total message count for a list of contact keys. This queries the repository directly, so it works even if
* contacts aren't loaded in the paged list.
*/
suspend fun getTotalMessageCount(contactKeys: List<String>): Int = if (contactKeys.isEmpty()) {
0
} else {
contactKeys.sumOf { contactKey -> packetRepository.getMessageCount(contactKey) }
}
private fun getUser(userId: String?) = nodeRepository.getUser(userId ?: DataPacket.ID_BROADCAST)
}