From fa27d11cfe6816e52831422ce7c86e5f53d9c084 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 18 Nov 2026 12:46:17 +0100 Subject: [PATCH 1/3] feat(conversation-list): show unread counts in conversation tag chips Each tag chip shows how many of its conversations have unread messages, like the iOS app does. The number counts conversations, not unread messages. The favorites chip counts unread favorite conversations. The badge uses the same styles as the unread bubble of a conversation: filled for a direct mention or an unread one-to-one conversation, outlined for a group mention and grey otherwise. A chip uses the most important style among its unread conversations. To share the styles, the unread bubble is moved into its own composable. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- .../ui/ConversationListItem.kt | 73 +--------- .../ui/ConversationTagsRow.kt | 72 +++++++++- .../ui/ConversationsListScreen.kt | 8 +- .../conversationlist/ui/UnreadCountBadge.kt | 96 +++++++++++++ app/src/main/res/values/strings.xml | 4 + .../ui/ConversationTagChipsTest.kt | 128 ++++++++++++++++++ 6 files changed, 302 insertions(+), 79 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt create mode 100644 app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt index 2e347f4009c..d1edb06cbd0 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt @@ -15,7 +15,6 @@ import android.widget.ImageView import androidx.annotation.DrawableRes import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background -import androidx.compose.foundation.border import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Box @@ -30,7 +29,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.CircleShape -import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.InlineTextContent import androidx.compose.foundation.text.appendInlineContent import androidx.compose.material3.Icon @@ -102,8 +100,6 @@ private const val ICON_MSG_SIZE_DP = 14 private const val ICON_MSG_SPACING_DP = 2 private const val THREAD_ICON_ID = "threadIcon" private const val THREAD_ICON_SIZE_SP = 14 -private const val UNREAD_THRESHOLD = 1000 -private const val UNREAD_BUBBLE_STROKE_DP = 1.5f private const val MILLIS_PER_SECOND = 1_000L /** Groups the tap callbacks for [ConversationListItem] to keep the parameter count low. */ @@ -517,77 +513,12 @@ private fun ConversationLastMessageRow( @Composable private fun UnreadBubble(model: ConversationModel, currentUser: User) { - if (model.unreadMessages <= 0) return - - val text = if (model.unreadMessages >= UNREAD_THRESHOLD) { - stringResource(R.string.tooManyUnreadMessages) - } else { - model.unreadMessages.toString() - } - - val isOneToOne = model.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL val hasDmFlag = hasSpreedFeatureCapability( currentUser.capabilities?.spreedCapability, SpreedFeatures.DIRECT_MENTION_FLAG ) - val outlined = model.unreadMention && hasDmFlag && !model.unreadMentionDirect && !isOneToOne - - when { - outlined -> OutlinedUnreadChip(text = text) - isOneToOne || model.unreadMention -> FilledUnreadChip(text = text) - else -> GreyUnreadChip(text = text) - } -} - -@Composable -private fun FilledUnreadChip(text: String) { - Box( - modifier = Modifier - .background(MaterialTheme.colorScheme.primary, RoundedCornerShape(12.dp)) - .padding(horizontal = 6.dp, vertical = 2.dp), - contentAlignment = Alignment.Center - ) { - Text( - text = text, - color = MaterialTheme.colorScheme.onPrimary, - style = MaterialTheme.typography.labelSmall, - fontWeight = FontWeight.Bold - ) - } -} - -@Composable -private fun OutlinedUnreadChip(text: String) { - Box( - modifier = Modifier - .border(UNREAD_BUBBLE_STROKE_DP.dp, MaterialTheme.colorScheme.primary, RoundedCornerShape(12.dp)) - .padding(horizontal = 6.dp, vertical = 2.dp), - contentAlignment = Alignment.Center - ) { - Text( - text = text, - color = MaterialTheme.colorScheme.primary, - style = MaterialTheme.typography.labelSmall, - fontWeight = FontWeight.Bold - ) - } -} - -@Composable -private fun GreyUnreadChip(text: String) { - Box( - modifier = Modifier - .background(colorResource(R.color.conversation_unread_bubble), RoundedCornerShape(12.dp)) - .padding(horizontal = 6.dp, vertical = 2.dp), - contentAlignment = Alignment.Center - ) { - Text( - text = text, - color = colorResource(R.color.conversation_unread_bubble_text), - style = MaterialTheme.typography.labelSmall, - fontWeight = FontWeight.Bold - ) - } + val style = unreadBadgeStyle(model, hasDmFlag) ?: return + UnreadCountBadge(count = model.unreadMessages, style = style) } @Suppress("LongMethod", "CyclomaticComplexMethod", "ReturnCount") diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt index bb6d617c731..b7705815c65 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt @@ -28,13 +28,17 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.semantics.clearAndSetSemantics +import androidx.compose.ui.semantics.contentDescription import androidx.compose.ui.hapticfeedback.HapticFeedbackType import androidx.compose.ui.platform.LocalHapticFeedback import androidx.compose.ui.platform.LocalViewConfiguration import androidx.compose.ui.res.dimensionResource +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import com.nextcloud.talk.R +import com.nextcloud.talk.models.domain.ConversationModel import com.nextcloud.talk.models.json.tags.ConversationTagDto import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collectLatest @@ -42,7 +46,7 @@ import kotlinx.coroutines.flow.collectLatest @OptIn(ExperimentalMaterial3Api::class) @Composable fun ConversationTagsRow( - tags: List, + tags: List, selectedTagId: String?, onTagSelected: (String?) -> Unit, onManageTagsClick: () -> Unit, @@ -61,12 +65,13 @@ fun ConversationTagsRow( onLongClick = onManageTagsClick ) } - items(tags, key = { it.id }) { tag -> + items(tags, key = { it.tag.id }) { (tag, unreadInfo) -> val isSelected = tag.id == selectedTagId val isFavorites = tag.type == ConversationTagDto.TYPE_FAVORITES TagFilterChip( selected = isSelected, label = if (isFavorites) stringResource(R.string.nc_conversation_tags_favorites) else tag.name, + unreadInfo = unreadInfo, onClick = { onTagSelected(if (isSelected) null else tag.id) }, onLongClick = onManageTagsClick ) @@ -77,7 +82,13 @@ fun ConversationTagsRow( /** Detects long-press via the chip's own interactionSource so its native ripple stays untouched. */ @OptIn(ExperimentalMaterial3Api::class) @Composable -private fun TagFilterChip(selected: Boolean, label: String, onClick: () -> Unit, onLongClick: () -> Unit) { +private fun TagFilterChip( + selected: Boolean, + label: String, + onClick: () -> Unit, + onLongClick: () -> Unit, + unreadInfo: TagUnreadInfo? = null +) { val interactionSource = remember { MutableInteractionSource() } val hapticFeedback = LocalHapticFeedback.current val longPressTimeoutMillis = LocalViewConfiguration.current.longPressTimeoutMillis @@ -102,16 +113,63 @@ private fun TagFilterChip(selected: Boolean, label: String, onClick: () -> Unit, suppressClick = false }, label = { Text(label) }, + trailingIcon = unreadInfo?.let { info -> + { + val description = pluralStringResource( + R.plurals.nc_conversation_tags_unread_conversations, + info.conversationCount, + info.conversationCount + ) + UnreadCountBadge( + count = info.conversationCount, + style = info.style, + modifier = Modifier.clearAndSetSemantics { contentDescription = description } + ) + } + }, interactionSource = interactionSource ) } +/** + * Unread state of a tag filter chip: [conversationCount] is the number of conversations with this tag + * that have unread messages (not the number of unread messages), [style] is the most important + * badge style among those conversations (direct mention > group mention > plain unread). + */ +data class TagUnreadInfo(val conversationCount: Int, val style: UnreadBadgeStyle) + +/** A tag filter chip; [unreadInfo] is null when no conversation with this tag has unread messages. */ +data class ConversationTagChip(val tag: ConversationTagDto, val unreadInfo: TagUnreadInfo? = null) + +fun buildConversationTagChips( + tags: List, + rooms: List, + hasDirectMentionFlag: Boolean +): List = + tags.map { tag -> + val isFavorites = tag.type == ConversationTagDto.TYPE_FAVORITES + val styles = rooms + .filter { if (isFavorites) it.favorite else it.tagIds.contains(tag.id) } + .mapNotNull { unreadBadgeStyle(it, hasDirectMentionFlag) } + val unreadInfo = styles.maxOrNull()?.let { TagUnreadInfo(conversationCount = styles.size, style = it) } + ConversationTagChip(tag, unreadInfo) + } + private fun previewTags() = listOf( - ConversationTagDto(id = "favorites", name = "", type = ConversationTagDto.TYPE_FAVORITES), - ConversationTagDto(id = "1", name = "Work", sortOrder = 0), - ConversationTagDto(id = "2", name = "Family", sortOrder = 1), - ConversationTagDto(id = "3", name = "Projects", sortOrder = 2) + ConversationTagChip( + ConversationTagDto(id = "favorites", name = "", type = ConversationTagDto.TYPE_FAVORITES), + TagUnreadInfo(conversationCount = 1, style = UnreadBadgeStyle.FILLED) + ), + ConversationTagChip( + ConversationTagDto(id = "1", name = "Work", sortOrder = 0), + TagUnreadInfo(conversationCount = 3, style = UnreadBadgeStyle.OUTLINED) + ), + ConversationTagChip( + ConversationTagDto(id = "2", name = "Family", sortOrder = 1), + TagUnreadInfo(conversationCount = 2, style = UnreadBadgeStyle.GREY) + ), + ConversationTagChip(ConversationTagDto(id = "3", name = "Projects", sortOrder = 2)) ) @Preview(showBackground = true, name = "Light") diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt index b8cfb4d7c11..f6add86b130 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt @@ -195,6 +195,12 @@ fun ConversationsListScreen( } } } + val hasDirectMentionFlag = state.currentUser?.capabilities?.spreedCapability?.let { + CapabilitiesUtil.hasSpreedFeatureCapability(it, SpreedFeatures.DIRECT_MENTION_FLAG) + } == true + val conversationTagChips = remember(nonEmptyConversationTags, visibleRooms, hasDirectMentionFlag) { + buildConversationTagChips(nonEmptyConversationTags, visibleRooms, hasDirectMentionFlag) + } val showConversationTagsRow = hasConversationTagsCapability && nonEmptyConversationTags.isNotEmpty() && !isSearchActive && @@ -342,7 +348,7 @@ fun ConversationsListScreen( tagsRowContent = if (showConversationTagsRow) { { ConversationTagsRow( - tags = nonEmptyConversationTags, + tags = conversationTagChips, selectedTagId = selectedTagFilter, onTagSelected = { tagId -> val isFavorites = conversationTags.any { diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt new file mode 100644 index 00000000000..5927e37b843 --- /dev/null +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt @@ -0,0 +1,96 @@ +/* + * Nextcloud Talk - Android Client + * + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package com.nextcloud.talk.conversationlist.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.colorResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import com.nextcloud.talk.R +import com.nextcloud.talk.models.domain.ConversationModel +import com.nextcloud.talk.models.json.conversations.ConversationEnums + +private const val UNREAD_THRESHOLD = 1000 +private const val UNREAD_BUBBLE_STROKE_DP = 1.5f + +/** Visual emphasis of an unread counter, ordered from lowest to highest priority. */ +enum class UnreadBadgeStyle { + /** Unread messages without a mention. */ + GREY, + + /** Unread group mention (e.g. @all) without a direct mention. */ + OUTLINED, + + /** Unread direct mention, or any unread message in a one-to-one conversation. */ + FILLED +} + +/** Returns the badge style for a conversation's unread counter, or null if it has no unread messages. */ +fun unreadBadgeStyle(model: ConversationModel, hasDirectMentionFlag: Boolean): UnreadBadgeStyle? { + if (model.unreadMessages <= 0) return null + + val isOneToOne = model.type == ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL + val outlined = model.unreadMention && hasDirectMentionFlag && !model.unreadMentionDirect && !isOneToOne + + return when { + outlined -> UnreadBadgeStyle.OUTLINED + isOneToOne || model.unreadMention -> UnreadBadgeStyle.FILLED + else -> UnreadBadgeStyle.GREY + } +} + +@Composable +fun UnreadCountBadge(count: Int, style: UnreadBadgeStyle, modifier: Modifier = Modifier) { + val text = if (count >= UNREAD_THRESHOLD) { + stringResource(R.string.tooManyUnreadMessages) + } else { + count.toString() + } + + val shape = RoundedCornerShape(12.dp) + val (boxModifier, textColor) = when (style) { + UnreadBadgeStyle.FILLED -> + Modifier.background(MaterialTheme.colorScheme.primary, shape) to MaterialTheme.colorScheme.onPrimary + + UnreadBadgeStyle.OUTLINED -> + Modifier.border(UNREAD_BUBBLE_STROKE_DP.dp, MaterialTheme.colorScheme.primary, shape) to + MaterialTheme.colorScheme.primary + + UnreadBadgeStyle.GREY -> + Modifier.background(colorResource(R.color.conversation_unread_bubble), shape) to + colorResource(R.color.conversation_unread_bubble_text) + } + + UnreadBadgeBox(text = text, textColor = textColor, modifier = modifier.then(boxModifier)) +} + +@Composable +private fun UnreadBadgeBox(text: String, textColor: Color, modifier: Modifier) { + Box( + modifier = modifier.padding(horizontal = 6.dp, vertical = 2.dp), + contentAlignment = Alignment.Center + ) { + Text( + text = text, + color = textColor, + style = MaterialTheme.typography.labelSmall, + fontWeight = FontWeight.Bold + ) + } +} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b8aa0a54909..88040fe3c62 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1044,6 +1044,10 @@ How to translate with transifex: Once a conversation is archived, it will be hidden by default. Select the filter \"Archived\" to view archived conversations. Direct mentions will still be received. Once a conversation is unarchived, it will be shown by default again. All + + %d conversation with unread messages + %d conversations with unread messages + Tags Manage tags New tag diff --git a/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt b/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt new file mode 100644 index 00000000000..c14763fcd08 --- /dev/null +++ b/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt @@ -0,0 +1,128 @@ +/* + * Nextcloud Talk - Android Client + * + * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package com.nextcloud.talk.conversationlist.ui + +import com.nextcloud.talk.data.user.model.User +import com.nextcloud.talk.models.domain.ConversationModel +import com.nextcloud.talk.models.json.conversations.ConversationDto +import com.nextcloud.talk.models.json.conversations.ConversationEnums +import com.nextcloud.talk.models.json.tags.ConversationTagDto +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Test + +class ConversationTagChipsTest { + + private val workTag = ConversationTagDto(id = "work", name = "Work") + private val favoritesTag = ConversationTagDto(id = "fav", name = "", type = ConversationTagDto.TYPE_FAVORITES) + + @Test + fun `counts conversations with unread messages, not the unread messages themselves`() { + val rooms = listOf( + conversation("a", tagIds = listOf("work"), unreadMessages = 5), + conversation("b", tagIds = listOf("work"), unreadMessages = 1), + conversation("c", tagIds = listOf("work"), unreadMessages = 0), + conversation("d", tagIds = listOf("other"), unreadMessages = 3) + ) + + val info = chips(listOf(workTag), rooms).single().unreadInfo!! + + assertEquals(2, info.conversationCount) + assertEquals(UnreadBadgeStyle.GREY, info.style) + } + + @Test + fun `no unread info when no tagged conversation is unread`() { + val rooms = listOf(conversation("a", tagIds = listOf("work"), unreadMessages = 0)) + + assertNull(chips(listOf(workTag), rooms).single().unreadInfo) + } + + @Test + fun `favorites tag counts unread favorite conversations`() { + val rooms = listOf( + conversation("a", favorite = true, unreadMessages = 2), + conversation("b", favorite = false, unreadMessages = 2) + ) + + assertEquals(1, chips(listOf(favoritesTag), rooms).single().unreadInfo!!.conversationCount) + } + + @Test + fun `direct mention wins over group mention and plain unread`() { + val rooms = listOf( + conversation("a", tagIds = listOf("work"), unreadMessages = 1), + conversation("b", tagIds = listOf("work"), unreadMessages = 1, unreadMention = true), + conversation( + "c", + tagIds = listOf("work"), + unreadMessages = 1, + unreadMention = true, + unreadMentionDirect = true + ) + ) + + assertEquals(UnreadBadgeStyle.FILLED, chips(listOf(workTag), rooms).single().unreadInfo!!.style) + } + + @Test + fun `group mention is outlined with the direct mention flag`() { + val rooms = listOf( + conversation("a", tagIds = listOf("work"), unreadMessages = 1), + conversation("b", tagIds = listOf("work"), unreadMessages = 1, unreadMention = true) + ) + + assertEquals(UnreadBadgeStyle.OUTLINED, chips(listOf(workTag), rooms).single().unreadInfo!!.style) + assertEquals( + "without the flag every mention is treated as direct", + UnreadBadgeStyle.FILLED, + chips(listOf(workTag), rooms, hasDirectMentionFlag = false).single().unreadInfo!!.style + ) + } + + @Test + fun `unread one-to-one conversation is highlighted like a direct mention`() { + val rooms = listOf( + conversation( + "a", + tagIds = listOf("work"), + unreadMessages = 1, + type = ConversationEnums.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL + ) + ) + + assertEquals(UnreadBadgeStyle.FILLED, chips(listOf(workTag), rooms).single().unreadInfo!!.style) + } + + private fun chips( + tags: List, + rooms: List, + hasDirectMentionFlag: Boolean = true + ) = buildConversationTagChips(tags, rooms, hasDirectMentionFlag) + + @Suppress("LongParameterList") + private fun conversation( + token: String, + tagIds: List = emptyList(), + favorite: Boolean = false, + unreadMessages: Int = 0, + unreadMention: Boolean = false, + unreadMentionDirect: Boolean = false, + type: ConversationEnums.ConversationType = ConversationEnums.ConversationType.ROOM_GROUP_CALL + ): ConversationModel = + ConversationModel.mapToConversationModel( + ConversationDto(token = token, name = token, type = type), + User(id = 1L, userId = "me", username = "me", baseUrl = "https://server.example.com") + ).copy( + tagIds = tagIds, + favorite = favorite, + unreadMessages = unreadMessages, + unreadMention = unreadMention, + unreadMentionDirect = unreadMentionDirect + ) +} From c927e05ec8a41b1f5c8d0fcd28af1ecbc1365b7a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 18 Nov 2026 12:53:01 +0100 Subject: [PATCH 2/3] fix(conversation-list): make unread badges round for single digits The unread badge was a bit wider than tall for single digit numbers. Make it at least as wide as tall and fully rounded, so single digits show as a circle and longer numbers as a pill. This applies to the tag chips and the conversation items. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- .../talk/conversationlist/ui/UnreadCountBadge.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt index 5927e37b843..b0051b6c277 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/UnreadCountBadge.kt @@ -11,13 +11,14 @@ import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.layout import androidx.compose.ui.res.colorResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight @@ -63,7 +64,7 @@ fun UnreadCountBadge(count: Int, style: UnreadBadgeStyle, modifier: Modifier = M count.toString() } - val shape = RoundedCornerShape(12.dp) + val shape = CircleShape val (boxModifier, textColor) = when (style) { UnreadBadgeStyle.FILLED -> Modifier.background(MaterialTheme.colorScheme.primary, shape) to MaterialTheme.colorScheme.onPrimary @@ -77,9 +78,18 @@ fun UnreadCountBadge(count: Int, style: UnreadBadgeStyle, modifier: Modifier = M colorResource(R.color.conversation_unread_bubble_text) } - UnreadBadgeBox(text = text, textColor = textColor, modifier = modifier.then(boxModifier)) + UnreadBadgeBox(text = text, textColor = textColor, modifier = modifier.atLeastAsWideAsTall().then(boxModifier)) } +/** Makes single digit badges a circle, longer numbers stay a pill. */ +private fun Modifier.atLeastAsWideAsTall(): Modifier = + layout { measurable, constraints -> + val height = measurable.minIntrinsicHeight(constraints.maxWidth) + val minWidth = height.coerceIn(constraints.minWidth, constraints.maxWidth) + val placeable = measurable.measure(constraints.copy(minWidth = minWidth)) + layout(placeable.width, placeable.height) { placeable.placeRelative(0, 0) } + } + @Composable private fun UnreadBadgeBox(text: String, textColor: Color, modifier: Modifier) { Box( From 1d4703182dbe68c038437365e26220f8afd87c1e Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 18 Nov 2026 13:08:10 +0100 Subject: [PATCH 3/3] refactor(conversation-list): build tag chips in one pass Count each conversation only once per tag chip, even if the room list contains it twice, so the count matches the filtered list. Hiding tags without conversations is now done while building the chips, instead of in a second pass over all rooms with a copy of the tag matching rule. Skip the capability lookup for the unread bubble of read conversations, and use the nullable capability check in the screen. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marcel Hibbe --- .../ui/ConversationListItem.kt | 2 ++ .../ui/ConversationTagsRow.kt | 14 +++++++----- .../ui/ConversationsListScreen.kt | 22 ++++++------------- .../ui/ConversationTagChipsTest.kt | 14 ++++++++++++ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt index d1edb06cbd0..d270df13b33 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationListItem.kt @@ -513,6 +513,8 @@ private fun ConversationLastMessageRow( @Composable private fun UnreadBubble(model: ConversationModel, currentUser: User) { + if (model.unreadMessages <= 0) return + val hasDmFlag = hasSpreedFeatureCapability( currentUser.capabilities?.spreedCapability, SpreedFeatures.DIRECT_MENTION_FLAG diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt index b7705815c65..484ba5c882e 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationTagsRow.kt @@ -141,19 +141,23 @@ data class TagUnreadInfo(val conversationCount: Int, val style: UnreadBadgeStyle /** A tag filter chip; [unreadInfo] is null when no conversation with this tag has unread messages. */ data class ConversationTagChip(val tag: ConversationTagDto, val unreadInfo: TagUnreadInfo? = null) +/** Builds the chips for all [tags] that have at least one of the given [rooms]. */ fun buildConversationTagChips( tags: List, rooms: List, hasDirectMentionFlag: Boolean -): List = - tags.map { tag -> +): List { + val distinctRooms = rooms.distinctBy { it.token } + return tags.mapNotNull { tag -> val isFavorites = tag.type == ConversationTagDto.TYPE_FAVORITES - val styles = rooms - .filter { if (isFavorites) it.favorite else it.tagIds.contains(tag.id) } - .mapNotNull { unreadBadgeStyle(it, hasDirectMentionFlag) } + val taggedRooms = distinctRooms.filter { if (isFavorites) it.favorite else it.tagIds.contains(tag.id) } + if (taggedRooms.isEmpty()) return@mapNotNull null + + val styles = taggedRooms.mapNotNull { unreadBadgeStyle(it, hasDirectMentionFlag) } val unreadInfo = styles.maxOrNull()?.let { TagUnreadInfo(conversationCount = styles.size, style = it) } ConversationTagChip(tag, unreadInfo) } +} private fun previewTags() = listOf( diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt index f6add86b130..7bb1133e070 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/ui/ConversationsListScreen.kt @@ -186,23 +186,15 @@ fun ConversationsListScreen( val hasConversationTagsCapability = state.currentUser?.capabilities?.spreedCapability?.let { CapabilitiesUtil.hasSpreedFeatureCapability(it, SpreedFeatures.CONVERSATION_TAGS) } == true - val nonEmptyConversationTags = remember(conversationTags, visibleRooms) { - conversationTags.filter { tag -> - if (tag.type == ConversationTagDto.TYPE_FAVORITES) { - visibleRooms.any { it.favorite } - } else { - visibleRooms.any { it.tagIds.contains(tag.id) } - } - } - } - val hasDirectMentionFlag = state.currentUser?.capabilities?.spreedCapability?.let { - CapabilitiesUtil.hasSpreedFeatureCapability(it, SpreedFeatures.DIRECT_MENTION_FLAG) - } == true - val conversationTagChips = remember(nonEmptyConversationTags, visibleRooms, hasDirectMentionFlag) { - buildConversationTagChips(nonEmptyConversationTags, visibleRooms, hasDirectMentionFlag) + val hasDirectMentionFlag = CapabilitiesUtil.hasSpreedFeatureCapability( + state.currentUser?.capabilities?.spreedCapability, + SpreedFeatures.DIRECT_MENTION_FLAG + ) + val conversationTagChips = remember(conversationTags, visibleRooms, hasDirectMentionFlag) { + buildConversationTagChips(conversationTags, visibleRooms, hasDirectMentionFlag) } val showConversationTagsRow = hasConversationTagsCapability && - nonEmptyConversationTags.isNotEmpty() && + conversationTagChips.isNotEmpty() && !isSearchActive && !showShareTo && !isForward diff --git a/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt b/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt index c14763fcd08..25e2d4fce61 100644 --- a/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt +++ b/app/src/test/java/com/nextcloud/talk/conversationlist/ui/ConversationTagChipsTest.kt @@ -43,6 +43,20 @@ class ConversationTagChipsTest { assertNull(chips(listOf(workTag), rooms).single().unreadInfo) } + @Test + fun `tags without conversations get no chip`() { + val rooms = listOf(conversation("a", tagIds = listOf("work"), unreadMessages = 1)) + + assertEquals(listOf(workTag), chips(listOf(workTag, favoritesTag), rooms).map { it.tag }) + } + + @Test + fun `duplicate conversations are counted once`() { + val room = conversation("a", tagIds = listOf("work"), unreadMessages = 1) + + assertEquals(1, chips(listOf(workTag), listOf(room, room.copy())).single().unreadInfo!!.conversationCount) + } + @Test fun `favorites tag counts unread favorite conversations`() { val rooms = listOf(