fix(regression/cs2): ack channels on view, dont show agegate for sfw channels

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-06-05 14:59:11 +02:00
parent 39433efb15
commit e9c3b8ec95
2 changed files with 26 additions and 4 deletions

View File

@ -31,6 +31,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.ime
@ -514,7 +515,7 @@ fun ChannelScreen(
targetState = viewModel.ageGateUnlocked,
label = "ageGateUnlocked"
) { ageGateUnlocked ->
if (!ageGateUnlocked) {
if (ageGateUnlocked == false) {
ChannelScreenAgeGate(
onAccept = {
viewModel.ageGateUnlocked = true
@ -523,7 +524,11 @@ fun ChannelScreen(
onToggleDrawer()
}
)
} else {
} else if (ageGateUnlocked == null) {
Box(Modifier.fillMaxSize()) {
CircularProgressIndicator(modifier = Modifier.size(48.dp))
}
} else if (ageGateUnlocked == true) {
Column(
modifier = Modifier
.padding(pv)

View File

@ -92,7 +92,7 @@ class ChannelScreenViewModel @Inject constructor(
var editingMessage by mutableStateOf<String?>(null)
var ageGateUnlocked by mutableStateOf(false)
var ageGateUnlocked by mutableStateOf<Boolean?>(null)
init {
viewModelScope.launch {
@ -405,7 +405,11 @@ class ChannelScreenViewModel @Inject constructor(
}
}
if (!didInitialChannelFetch) didInitialChannelFetch = true
val ackNewest: Boolean
if (!didInitialChannelFetch) {
didInitialChannelFetch = true
ackNewest = true
} else ackNewest = false
val newItems = messages.filter {
if (ignoreExisting) {
@ -438,6 +442,19 @@ class ChannelScreenViewModel @Inject constructor(
}
updateItems(newItemsWithPosition)
// If ackNewest is true, we ack the newest (first, as initial fetch is newest to oldest) message.
if (ackNewest) {
ackMessage(newItemsWithPosition.first {
it is ChannelScreenItem.RegularMessage || it is ChannelScreenItem.SystemMessage
}.let {
when (it) {
is ChannelScreenItem.RegularMessage -> it.message.id
is ChannelScreenItem.SystemMessage -> it.message.id
else -> null
}
} ?: return@launch)
}
} catch (e: Exception) {
Log.e("ChannelScreenViewModel", "Failed to fetch messages", e)
}