feat: save age gate unlock state

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2024-08-10 18:09:48 +02:00
parent 20ca6f4cf5
commit afbdfc6bb4
3 changed files with 30 additions and 1 deletions

View File

@ -531,7 +531,9 @@ fun ChannelScreen(
if (ageGateUnlocked == false) {
ChannelScreenAgeGate(
onAccept = {
viewModel.ageGateUnlocked = true
scope.launch {
viewModel.unlockAgeGate()
}
},
onDeny = {
onToggleDrawer()

View File

@ -49,6 +49,7 @@ import chat.revolt.callbacks.UiCallback
import chat.revolt.callbacks.UiCallbacks
import chat.revolt.persistence.KVStorage
import chat.revolt.screens.chat.ChatRouterDestination
import chat.revolt.settings.providers.AgeGateUnlockedStorageProvider
import dagger.hilt.android.lifecycle.HiltViewModel
import io.ktor.http.ContentType
import kotlinx.coroutines.Dispatchers
@ -113,6 +114,11 @@ class ChannelScreenViewModel @Inject constructor(
this.denyMessageFieldReasonResource = R.string.typing_blank
this.editingMessage = null
this.ageGateUnlocked = channel?.nsfw != true
viewModelScope.launch {
if (ageGateUnlocked != true) {
ageGateUnlocked = AgeGateUnlockedStorageProvider.getAgeGateUnlocked()
}
}
viewModelScope.launch {
draftContent = kvStorage.get("draftContent/$id") ?: ""
@ -129,6 +135,11 @@ class ChannelScreenViewModel @Inject constructor(
this.loadMessages(50)
}
suspend fun unlockAgeGate() {
AgeGateUnlockedStorageProvider.setAgeGateUnlocked(true)
ageGateUnlocked = true
}
private suspend fun ensureSelfHasMember() {
channel?.server?.let { serverId ->
RevoltAPI.selfId?.let { selfId ->

View File

@ -0,0 +1,16 @@
package chat.revolt.settings.providers
import chat.revolt.RevoltApplication
import chat.revolt.persistence.KVStorage
object AgeGateUnlockedStorageProvider {
private val kv = KVStorage(RevoltApplication.instance)
suspend fun setAgeGateUnlocked(unlocked: Boolean) {
kv.set("ageGateUnlocked", unlocked)
}
suspend fun getAgeGateUnlocked(): Boolean {
return kv.getBoolean("ageGateUnlocked") ?: false
}
}