feat: save age gate unlock state
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
20ca6f4cf5
commit
afbdfc6bb4
|
|
@ -531,7 +531,9 @@ fun ChannelScreen(
|
||||||
if (ageGateUnlocked == false) {
|
if (ageGateUnlocked == false) {
|
||||||
ChannelScreenAgeGate(
|
ChannelScreenAgeGate(
|
||||||
onAccept = {
|
onAccept = {
|
||||||
viewModel.ageGateUnlocked = true
|
scope.launch {
|
||||||
|
viewModel.unlockAgeGate()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onDeny = {
|
onDeny = {
|
||||||
onToggleDrawer()
|
onToggleDrawer()
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ import chat.revolt.callbacks.UiCallback
|
||||||
import chat.revolt.callbacks.UiCallbacks
|
import chat.revolt.callbacks.UiCallbacks
|
||||||
import chat.revolt.persistence.KVStorage
|
import chat.revolt.persistence.KVStorage
|
||||||
import chat.revolt.screens.chat.ChatRouterDestination
|
import chat.revolt.screens.chat.ChatRouterDestination
|
||||||
|
import chat.revolt.settings.providers.AgeGateUnlockedStorageProvider
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
@ -113,6 +114,11 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
this.denyMessageFieldReasonResource = R.string.typing_blank
|
this.denyMessageFieldReasonResource = R.string.typing_blank
|
||||||
this.editingMessage = null
|
this.editingMessage = null
|
||||||
this.ageGateUnlocked = channel?.nsfw != true
|
this.ageGateUnlocked = channel?.nsfw != true
|
||||||
|
viewModelScope.launch {
|
||||||
|
if (ageGateUnlocked != true) {
|
||||||
|
ageGateUnlocked = AgeGateUnlockedStorageProvider.getAgeGateUnlocked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
draftContent = kvStorage.get("draftContent/$id") ?: ""
|
draftContent = kvStorage.get("draftContent/$id") ?: ""
|
||||||
|
|
@ -129,6 +135,11 @@ class ChannelScreenViewModel @Inject constructor(
|
||||||
this.loadMessages(50)
|
this.loadMessages(50)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun unlockAgeGate() {
|
||||||
|
AgeGateUnlockedStorageProvider.setAgeGateUnlocked(true)
|
||||||
|
ageGateUnlocked = true
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun ensureSelfHasMember() {
|
private suspend fun ensureSelfHasMember() {
|
||||||
channel?.server?.let { serverId ->
|
channel?.server?.let { serverId ->
|
||||||
RevoltAPI.selfId?.let { selfId ->
|
RevoltAPI.selfId?.let { selfId ->
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue