feat: move access control to feature flag
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
769cf99529
commit
fddb926770
|
|
@ -3,20 +3,25 @@ package chat.revolt.api.settings
|
|||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import chat.revolt.api.RevoltAPI
|
||||
|
||||
annotation class FeatureFlag(val name: String)
|
||||
annotation class Treatment(val description: String)
|
||||
|
||||
@FeatureFlag("TiramisuFilePicker")
|
||||
enum class FilePickerFeatureFlagVariates {
|
||||
@Treatment("Use the READ_MEDIA_IMAGES or READ_MEDIA_VIDEO permissions introduced in Android Tiramisu")
|
||||
TiramisuMediaPermissions,
|
||||
@FeatureFlag("ClosedBetaAccessControl")
|
||||
sealed class ClosedBetaAccessControlVariates {
|
||||
@Treatment("Restrict access to the app to users that meet certain or all criteria (implementation-specific)")
|
||||
data class Restricted(val predicate: () -> Boolean) : ClosedBetaAccessControlVariates()
|
||||
|
||||
@Treatment("Use the DocumentsUI picker introduced in Android KitKat")
|
||||
DocumentsUI
|
||||
@Treatment("Allow access to the app to all users")
|
||||
data object Unrestricted : ClosedBetaAccessControlVariates()
|
||||
}
|
||||
|
||||
object FeatureFlags {
|
||||
@FeatureFlag("TiramisuFilePicker")
|
||||
var filePickerType by mutableStateOf(FilePickerFeatureFlagVariates.TiramisuMediaPermissions)
|
||||
}
|
||||
@FeatureFlag("ClosedBetaAccessControl")
|
||||
var closedBetaAccessControl by mutableStateOf<ClosedBetaAccessControlVariates>(
|
||||
ClosedBetaAccessControlVariates.Restricted {
|
||||
RevoltAPI.channelCache.containsKey("01H7X2KRB0CA4QDSMB4N7WGERF")
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,9 @@ import chat.revolt.api.realtime.RealtimeSocket
|
|||
import chat.revolt.api.routes.server.fetchMembers
|
||||
import chat.revolt.api.schemas.ChannelType
|
||||
import chat.revolt.api.schemas.User
|
||||
import chat.revolt.api.settings.ClosedBetaAccessControlVariates
|
||||
import chat.revolt.api.settings.FeatureFlag
|
||||
import chat.revolt.api.settings.FeatureFlags
|
||||
import chat.revolt.api.settings.SyncedSettings
|
||||
import chat.revolt.callbacks.Action
|
||||
import chat.revolt.callbacks.ActionChannel
|
||||
|
|
@ -199,9 +201,13 @@ class ChatRouterViewModel @Inject constructor(
|
|||
fun navigateToChannel(channelId: String, navController: NavController, pure: Boolean = false) {
|
||||
if (!pure) setSaveCurrentChannel(channelId)
|
||||
|
||||
// Only allow access to closed beta users, currently "has access to #beta-chat in Jenvolt"
|
||||
@FeatureFlag("ClosedBetaAccessControl")
|
||||
if (RevoltAPI.channelCache.size > 0 && !RevoltAPI.channelCache.containsKey("01H7X2KRB0CA4QDSMB4N7WGERF")) {
|
||||
if (RevoltAPI.channelCache.size > 0
|
||||
&& FeatureFlags.closedBetaAccessControl is ClosedBetaAccessControlVariates.Restricted
|
||||
&& (FeatureFlags.closedBetaAccessControl as ClosedBetaAccessControlVariates.Restricted)
|
||||
.predicate()
|
||||
.not()
|
||||
) {
|
||||
Pipebomb.incrementHardCrashCounter()
|
||||
|
||||
navController.navigate("no_current_channel") {
|
||||
|
|
|
|||
|
|
@ -72,9 +72,6 @@ import chat.revolt.api.internals.ChannelUtils
|
|||
import chat.revolt.api.routes.microservices.autumn.FileArgs
|
||||
import chat.revolt.api.schemas.Channel
|
||||
import chat.revolt.api.schemas.ChannelType
|
||||
import chat.revolt.api.settings.FeatureFlag
|
||||
import chat.revolt.api.settings.FeatureFlags
|
||||
import chat.revolt.api.settings.FilePickerFeatureFlagVariates
|
||||
import chat.revolt.components.chat.Message
|
||||
import chat.revolt.components.chat.MessageField
|
||||
import chat.revolt.components.chat.SystemMessage
|
||||
|
|
@ -491,10 +488,8 @@ fun ChannelScreen(
|
|||
onAddAttachment = {
|
||||
val isTiramisu = Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
|
||||
|
||||
@FeatureFlag("TiramisuFilePicker")
|
||||
when {
|
||||
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.TiramisuMediaPermissions
|
||||
&& isTiramisu -> {
|
||||
isTiramisu -> {
|
||||
focusManager.clearFocus()
|
||||
if (viewModel.currentBottomPane == BottomPane.InbuiltMediaPicker) {
|
||||
viewModel.currentBottomPane = BottomPane.None
|
||||
|
|
@ -503,8 +498,7 @@ fun ChannelScreen(
|
|||
}
|
||||
}
|
||||
|
||||
FeatureFlags.filePickerType == FilePickerFeatureFlagVariates.DocumentsUI
|
||||
|| !isTiramisu -> {
|
||||
!isTiramisu -> {
|
||||
pickFileLauncher.launch(arrayOf("*/*"))
|
||||
}
|
||||
}
|
||||
|
|
@ -592,7 +586,7 @@ fun ChannelScreen(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AnimatedVisibility(visible = viewModel.currentBottomPane == BottomPane.EmojiPicker) {
|
||||
BackHandler(enabled = viewModel.currentBottomPane == BottomPane.EmojiPicker) {
|
||||
viewModel.currentBottomPane = BottomPane.None
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import chat.revolt.api.routes.server.fetchMember
|
|||
import chat.revolt.api.routes.user.addUserIfUnknown
|
||||
import chat.revolt.api.schemas.Channel
|
||||
import chat.revolt.api.schemas.Message
|
||||
import chat.revolt.api.settings.FeatureFlag
|
||||
import chat.revolt.callbacks.UiCallback
|
||||
import chat.revolt.callbacks.UiCallbacks
|
||||
import io.ktor.http.ContentType
|
||||
|
|
@ -57,8 +56,6 @@ import kotlinx.datetime.Instant
|
|||
|
||||
sealed class BottomPane {
|
||||
data object None : BottomPane()
|
||||
|
||||
@FeatureFlag("TiramisuFilePicker")
|
||||
data object InbuiltMediaPicker : BottomPane()
|
||||
data object EmojiPicker : BottomPane()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue