Skip to content

Commit

Permalink
fix: snowflake ids can also be of 19 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
dead8309 committed Dec 27, 2024
1 parent 4ce28b5 commit a663c1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions data/src/main/java/com/my/kizzy/data/rpc/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ object Constants {
const val APP_DIRECTORY = "App Directory"
const val DOWNLOADS_DIRECTORY = "Downloads Directory"
const val MAX_ALLOWED_CHARACTER_LENGTH = 32
/*
See https://discord.com/developers/docs/reference#snowflakes
*/
val MAX_APPLICATION_ID_LENGTH_RANGE = 18..19
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import com.my.kizzy.data.rpc.Constants
import com.my.kizzy.data.rpc.Constants.MAX_ALLOWED_CHARACTER_LENGTH
import com.my.kizzy.data.rpc.Constants.MAX_APPLICATION_ID_LENGTH_RANGE
import com.my.kizzy.domain.model.rpc.RpcButtons
import com.my.kizzy.preference.Prefs
import com.my.kizzy.resources.R
Expand Down Expand Up @@ -438,10 +439,10 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
RpcField(
value = customApplicationId,
label = R.string.application_id,
isError = customApplicationId.length != 18 || !customApplicationId.all { it.isDigit() },
isError = customApplicationId.length !in MAX_APPLICATION_ID_LENGTH_RANGE || !customApplicationId.all { it.isDigit() },
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
onValueChange = { newText ->
if (newText.length <= 18 && newText.all { it.isDigit() }) {
if (newText.length in MAX_APPLICATION_ID_LENGTH_RANGE && newText.all { it.isDigit() }) {
customApplicationId = newText
}
}
Expand All @@ -451,7 +452,7 @@ fun RpcSettings(onBackPressed: () -> Boolean) {
confirmButton = {
TextButton(
onClick = {
if (customApplicationId.length != 18 || !customApplicationId.all { it.isDigit() }) {
if (customApplicationId.length !in MAX_APPLICATION_ID_LENGTH_RANGE || !customApplicationId.all { it.isDigit() }) {
Toast.makeText(context, "Please enter a valid Application ID", Toast.LENGTH_SHORT).show()
} else {
Prefs[Prefs.CUSTOM_ACTIVITY_APPLICATION_ID] = customApplicationId
Expand Down

0 comments on commit a663c1d

Please sign in to comment.