Merge pull request #1093 from permissionlesstech/fix/network-sheet-swipe-offline-styling

Fix stuck conversation swipe and grey out offline peers
This commit is contained in:
callebtc authored and GitHub committed 2026-11-24 19:12:36 +01:00
commit f6bfceac23
2 files changed
+33 -10

No files matched your search

@@ -1001,6 +1001,7 @@ private fun ConversationSwipeItem(
favoriteRelationship?.theyFavoritedUs == true
val isVerified = fingerprint != null && fingerprint in verifiedFingerprints
val dismissState = rememberSwipeToDismissBoxState()
val swipeScope = rememberCoroutineScope()
val shape = RoundedCornerShape(
topStart = if (isFirst) 14.dp else 0.dp,
topEnd = if (isFirst) 14.dp else 0.dp,
@@ -1008,22 +1009,25 @@ private fun ConversationSwipeItem(
bottomEnd = if (isLast) 14.dp else 0.dp
)
LaunchedEffect(dismissState.currentValue, conversation.conversationID) {
when (dismissState.currentValue) {
// Act only once the swipe has settled at a dismissed anchor (finger lifted, fling done),
// then spring the row back. Keying an effect on `currentValue` instead fires mid-drag as
// soon as the row passes the halfway point; the reset animation then loses to the still
// active drag and the row stays stuck in the dismissed position.
val onSwipeDismissed: (SwipeToDismissBoxValue) -> Unit = { direction ->
when (direction) {
SwipeToDismissBoxValue.StartToEnd -> {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
onReadStateRequested(conversation, conversation.unreadCount > 0)
dismissState.reset()
}
SwipeToDismissBoxValue.EndToStart -> {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
onDeleteRequested(conversation)
dismissState.reset()
}
SwipeToDismissBoxValue.Settled -> Unit
}
swipeScope.launch { dismissState.reset() }
}
Surface(
@@ -1040,6 +1044,7 @@ private fun ConversationSwipeItem(
state = dismissState,
enableDismissFromStartToEnd = true,
enableDismissFromEndToStart = true,
onDismiss = onSwipeDismissed,
backgroundContent = {
val markRead = conversation.unreadCount > 0
val startToEnd =
@@ -1178,7 +1183,13 @@ private fun ConversationRow(
val peerIdentity = conversation.nostrPubkey
?.let(viewModel::peerIdentityForNostrPubkey)
?: viewModel.peerIdentityForMeshPeer(conversation.conversationID)
val assignedColor = colorForPeer(peerIdentity, palette)
// Offline peers lose their identity colour so they read as inactive at a glance.
val isOffline = !conversation.isConnected
val assignedColor = if (isOffline) {
palette.textTertiary
} else {
colorForPeer(peerIdentity, palette)
}
val (baseNameRaw, suffix) = splitSuffix(conversation.displayName)
val relativeTime by produceState(
initialValue = conversationRelativeTime(conversation.latestMessageAt),
@@ -1249,6 +1260,7 @@ private fun ConversationRow(
isFavorite = isFavorite,
theyFavoritedUs = theyFavoritedUs,
isVerified = isVerified,
isOffline = isOffline,
badge = {
when {
conversation.isConnected -> Icon(
@@ -1270,7 +1282,7 @@ private fun ConversationRow(
R.string.offline_reachable_via_nostr
),
modifier = Modifier.size(13.dp),
tint = palette.accentPurple
tint = palette.textTertiary
)
else -> Icon(
@@ -1491,7 +1503,13 @@ private fun PeerItem(
viewModel.peerIdentityForMeshPeer(peerID),
palette
)
val baseColor = if (isMe) palette.accentOrange else assignedColor
// Offline peers lose their identity colour so they read as inactive at a glance.
val isOffline = !isConnected && !isMe
val baseColor = when {
isMe -> palette.accentOrange
isOffline -> palette.textTertiary
else -> assignedColor
}
Row(
modifier = Modifier
@@ -1506,6 +1524,7 @@ private fun PeerItem(
isFavorite = isFavorite,
theyFavoritedUs = theyFavoritedUs,
isVerified = isVerified,
isOffline = isOffline,
badge = {
when {
isConnected -> Icon(
@@ -1525,7 +1544,7 @@ private fun PeerItem(
painter = painterResource(R.drawable.ic_spec_globe),
contentDescription = stringResource(R.string.cd_reachable_via_nostr),
modifier = Modifier.size(13.dp),
tint = palette.accentPurple
tint = palette.textTertiary
)
else -> Icon(
@@ -34,10 +34,14 @@ internal fun PeerAvatar(
isFavorite: Boolean = false,
theyFavoritedUs: Boolean = false,
isVerified: Boolean = false,
isOffline: Boolean = false,
badge: (@Composable () -> Unit)? = null
) {
val palette = LocalBitchatPalette.current
val colorScheme = MaterialTheme.colorScheme
// Offline peers render their badges without accent colours, matching the greyed avatar.
val starTint = if (isOffline) palette.textTertiary else palette.accentOrange
val verifiedTint = if (isOffline) palette.textTertiary else colorScheme.primary
Box(
modifier = modifier.size(42.dp),
@@ -100,7 +104,7 @@ internal fun PeerAvatar(
}
),
modifier = Modifier.size(10.dp),
tint = palette.accentOrange
tint = starTint
)
}
}
@@ -122,7 +126,7 @@ internal fun PeerAvatar(
R.string.fingerprint_verified_label
),
modifier = Modifier.size(12.dp),
tint = colorScheme.primary
tint = verifiedTint
)
}
}