feat: use voice icon for voice channels

This commit is contained in:
infi 2026-08-04 12:26:31 +02:00
parent adc73df832
commit c322affde4
8 changed files with 58 additions and 31 deletions

View File

@ -400,9 +400,9 @@ fun MessageField(
},
label = { Text("#${item.channel.name}") },
icon = {
item.channel.channelType?.let { type ->
if (item.channel.channelType != null) {
ChannelIcon(
channelType = type,
channel = item.channel,
modifier = Modifier.size(SuggestionChipDefaults.IconSize)
)
}

View File

@ -61,9 +61,9 @@ fun ChannelHeader(
)
}
channel.channelType?.let {
if (channel.channelType != null) {
ChannelIcon(
channelType = it,
channel = channel,
modifier = Modifier.alpha(0.6f)
)
}

View File

@ -9,10 +9,42 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import chat.stoat.R
import chat.stoat.core.model.schemas.Channel
import chat.stoat.core.model.schemas.ChannelType
@Composable
fun ChannelIcon(channel: Channel, modifier: Modifier = Modifier) {
ChannelIcon(
channelType = channel.channelType ?: ChannelType.TextChannel,
hasVoice = channel.channelType == ChannelType.TextChannel && channel.voice != null,
modifier = modifier
)
}
@Composable
fun ChannelIcon(channelType: ChannelType, modifier: Modifier = Modifier) {
ChannelIcon(
channelType = channelType,
hasVoice = channelType == ChannelType.VoiceChannel,
modifier = modifier
)
}
@Composable
private fun ChannelIcon(
channelType: ChannelType,
hasVoice: Boolean,
modifier: Modifier,
) {
if (hasVoice || channelType == ChannelType.VoiceChannel) {
Icon(
painter = painterResource(R.drawable.ic_volume_up_24dp),
contentDescription = stringResource(R.string.channel_voice),
modifier = modifier
)
return
}
when (channelType) {
ChannelType.TextChannel -> {
Icon(
@ -22,14 +54,6 @@ fun ChannelIcon(channelType: ChannelType, modifier: Modifier = Modifier) {
)
}
ChannelType.VoiceChannel -> {
Icon(
painter = painterResource(R.drawable.ic_volume_up_24dp),
contentDescription = stringResource(R.string.channel_voice),
modifier = modifier
)
}
ChannelType.SavedMessages -> {
Icon(
painter = painterResource(R.drawable.ic_note_stack_24dp),

View File

@ -18,26 +18,28 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import chat.stoat.core.model.schemas.AutumnResource
import chat.stoat.core.model.schemas.ChannelType
import chat.stoat.core.model.schemas.User
import chat.stoat.R
import chat.stoat.api.internals.ChannelUtils
import chat.stoat.composables.generic.RemoteImage
import chat.stoat.composables.generic.UserAvatar
import chat.stoat.composables.markdown.prose.ChatMarkdown
import chat.stoat.core.model.data.STOAT_FILES
import chat.stoat.core.model.schemas.Channel
import chat.stoat.core.model.schemas.ChannelType
import chat.stoat.core.model.schemas.User
@Composable
fun ChannelSheetHeader(
channelName: String,
channelIcon: AutumnResource? = null,
channelType: ChannelType,
channelDescription: String? = null,
serverId: String? = null,
channel: Channel,
dmPartner: User? = null
) {
val channelType = channel.channelType ?: ChannelType.TextChannel
val channelIcon = channel.icon
val channelDescription = channel.description
Row(
verticalAlignment = Alignment.CenterVertically
) {
@ -73,7 +75,7 @@ fun ChannelSheetHeader(
)
} else {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onPrimaryContainer) {
ChannelIcon(channelType = channelType)
ChannelIcon(channel = channel)
}
}
}
@ -82,7 +84,9 @@ fun ChannelSheetHeader(
Column {
Text(
text = channelName,
text = channel.name
?: ChannelUtils.resolveName(channel)
?: stringResource(R.string.unknown),
fontWeight = FontWeight.SemiBold,
maxLines = 1,
overflow = TextOverflow.Ellipsis
@ -90,7 +94,7 @@ fun ChannelSheetHeader(
if (!channelDescription.isNullOrBlank()) {
Spacer(modifier = Modifier.height(8.dp))
ChatMarkdown(channelDescription, serverId = serverId)
ChatMarkdown(channelDescription, serverId = channel.server)
}
}
}

View File

@ -925,6 +925,10 @@ fun ChannelItem(
)
}
channel.channelType == ChannelType.TextChannel && channel.voice != null -> {
ChannelIcon(channel = channel)
}
else -> ChannelIcon(iconType.type)
}
}

View File

@ -703,7 +703,7 @@ fun ChannelScreen(
else -> {
ChannelIcon(
channelType = it.channelType ?: ChannelType.TextChannel,
channel = it,
modifier = Modifier
.size(24.dp)
.alpha(0.8f)

View File

@ -103,13 +103,7 @@ fun ChannelInfoSheet(channelId: String, onHideSheet: suspend () -> Unit) {
modifier = Modifier.padding(top = 16.dp, start = 16.dp, end = 16.dp, bottom = 4.dp),
) {
ChannelSheetHeader(
channelName = channel.name
?: ChannelUtils.resolveName(channel)
?: stringResource(id = R.string.unknown),
channelIcon = channel.icon,
channelType = channel.channelType ?: ChannelType.TextChannel,
channelDescription = channel.description,
serverId = channel.server,
channel = channel,
dmPartner = partner
)
HorizontalDivider()

View File

@ -99,6 +99,7 @@ data class Channel(
rolePermissions = partial.rolePermissions ?: rolePermissions,
defaultPermissions = partial.defaultPermissions ?: defaultPermissions,
nsfw = partial.nsfw ?: nsfw,
voice = partial.voice ?: voice,
slowmode = partial.slowmode ?: slowmode,
type = partial.type ?: type
)