fix: issue where active channel indicator may not update

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-10-30 13:07:56 +01:00
parent 55e8d184f4
commit 73be3d56ee
2 changed files with 34 additions and 11 deletions

View File

@ -221,7 +221,7 @@ fun RowScope.ChannelList(
DrawerChannel(
name = stringResource(R.string.channel_notes),
iconType = DrawerChannelIconType.Channel(ChannelType.SavedMessages),
selected = currentDestination == "channel/{channelId}" && currentChannel == notesChannelId,
selected = currentDestination == "channel/$notesChannelId",
hasUnread = false,
onClick = {
onChannelClick(notesChannelId ?: return@DrawerChannel)
@ -268,7 +268,7 @@ fun RowScope.ChannelList(
iconType = DrawerChannelIconType.Channel(
channel.channelType ?: ChannelType.TextChannel
),
selected = currentDestination == "channel/{channelId}" && currentChannel == channel.id,
selected = currentDestination == "channel/${channel.id}",
hasUnread = channel.lastMessageID?.let { lastMessageID ->
RevoltAPI.unreads.hasUnread(
channel.id!!,
@ -534,7 +534,7 @@ fun RowScope.ChannelList(
iconType = DrawerChannelIconType.Channel(
channel.channelType ?: ChannelType.TextChannel
),
selected = currentDestination == "channel/{channelId}" && currentChannel == channel.id,
selected = currentDestination == "channel/${channel.id}",
hasUnread = channel.lastMessageID?.let { lastMessageID ->
RevoltAPI.unreads.hasUnread(
channel.id!!,

View File

@ -125,6 +125,7 @@ class ChatRouterViewModel @Inject constructor(
) : ViewModel() {
var currentServer by mutableStateOf("home")
var currentChannel by mutableStateOf<String?>(null)
var currentRoute by mutableStateOf("home")
var sidebarSparkDisplayed by mutableStateOf(true)
var latestChangelogRead by mutableStateOf(true)
var latestChangelog by mutableStateOf("")
@ -135,6 +136,7 @@ class ChatRouterViewModel @Inject constructor(
viewModelScope.launch {
currentServer = kvStorage.get("currentServer") ?: "home"
currentChannel = kvStorage.get("currentChannel")
currentRoute = kvStorage.get("currentRoute") ?: "home"
sidebarSparkDisplayed = if (kvStorage.getBoolean("sidebarSpark") == null) {
false
@ -150,14 +152,22 @@ class ChatRouterViewModel @Inject constructor(
}
}
private suspend fun setCurrentServer(serverId: String, save: Boolean = true) {
private suspend fun setSaveCurrentServer(serverId: String) {
currentServer = serverId
if (save) kvStorage.set("currentServer", serverId)
kvStorage.set("currentServer", serverId)
if (serverId != "home") fetchMembers(serverId, includeOffline = false, pure = false)
}
private fun setSaveCurrentRoute(route: String) {
currentRoute = route
viewModelScope.launch {
kvStorage.set("currentRoute", route)
}
}
private fun setSaveCurrentChannel(channelId: String) {
currentChannel = channelId
@ -179,7 +189,8 @@ class ChatRouterViewModel @Inject constructor(
}
}
viewModelScope.launch {
setCurrentServer("home")
setSaveCurrentServer("home")
setSaveCurrentRoute("home")
}
return
}
@ -187,7 +198,7 @@ class ChatRouterViewModel @Inject constructor(
val channelId = RevoltAPI.serverCache[serverId]?.channels?.firstOrNull()
viewModelScope.launch {
setCurrentServer(serverId, channelId != null)
setSaveCurrentServer(serverId)
}
if (channelId != null) {
@ -198,6 +209,10 @@ class ChatRouterViewModel @Inject constructor(
popUpTo(route)
}
}
viewModelScope.launch {
setSaveCurrentRoute("no_current_channel")
}
}
}
@ -245,6 +260,10 @@ class ChatRouterViewModel @Inject constructor(
popUpTo(route)
}
}
viewModelScope.launch {
setSaveCurrentRoute("channel/$channelId")
}
}
}
@ -254,6 +273,10 @@ class ChatRouterViewModel @Inject constructor(
popUpTo(route)
}
}
viewModelScope.launch {
setSaveCurrentRoute(destination)
}
}
}
@ -305,7 +328,7 @@ fun ChatRouterScreen(
var useTabletAwareUI by remember { mutableStateOf(false) }
val toggleDrawerLda = remember {
val toggleDrawerLambda = remember {
{
scope.launch {
if (drawerState.isOpen) {
@ -682,7 +705,7 @@ fun ChatRouterScreen(
topNav = topNav,
useDrawer = false,
toggleDrawer = {
toggleDrawerLda()
toggleDrawerLambda()
},
onShowUserContextSheet = { target, server ->
userContextSheetTarget = target
@ -722,7 +745,7 @@ fun ChatRouterScreen(
topNav = topNav,
useDrawer = true,
toggleDrawer = {
toggleDrawerLda()
toggleDrawerLambda()
},
drawerState = drawerState,
onShowUserContextSheet = { target, server ->
@ -912,7 +935,7 @@ fun Sidebar(
) {
ChannelList(
serverId = it,
currentDestination = navController.currentDestination?.route,
currentDestination = viewModel.currentRoute,
currentChannel = viewModel.currentChannel,
onChannelClick = { channelId ->
viewModel.navigateToChannel(channelId, navController)