refactor: remove channel disambiguation suffix

pull/923/head^2
andrekir 2024-03-18 08:34:56 -03:00
rodzic a3a914abce
commit ee61b79aa3
3 zmienionych plików z 5 dodań i 20 usunięć

Wyświetl plik

@ -73,21 +73,6 @@ data class Channel(
} }
} }
/**
* Return a name that is formatted as #channename-suffix
*
* Where suffix indicates the hash of the PSK
*/
val humanName: String
get() {
// start with the PSK then xor in the name
val pskCode = xorHash(psk.toByteArray())
val nameCode = xorHash(name.toByteArray())
val suffix = 'A' + ((pskCode xor nameCode) % 26)
return "#${name}-${suffix}"
}
/** /**
* Given a channel name and psk, return the (0 to 255) hash for that channel * Given a channel name and psk, return the (0 to 255) hash for that channel
*/ */

Wyświetl plik

@ -241,11 +241,12 @@ fun ChannelScreen(
fun sendButton() { fun sendButton() {
primaryChannel?.let { primaryChannel -> primaryChannel?.let { primaryChannel ->
val humanName = primaryChannel.humanName
val message = buildString { val message = buildString {
append(context.getString(R.string.are_you_sure_channel)) append(context.getString(R.string.are_you_sure_channel))
if (primaryChannel.settings == Channel.default.settings) if (primaryChannel.settings == Channel.default.settings) {
append("\n\n" + context.getString(R.string.warning_default_psk, humanName)) append("\n\n")
append(context.getString(R.string.warning_default_psk, primaryChannel.name))
}
} }
MaterialAlertDialogBuilder(context) MaterialAlertDialogBuilder(context)
@ -290,7 +291,7 @@ fun ChannelScreen(
if (!showChannelEditor) item { if (!showChannelEditor) item {
ClickableTextField( ClickableTextField(
label = R.string.channel_name, label = R.string.channel_name,
value = primaryChannel?.humanName.orEmpty(), value = primaryChannel?.name.orEmpty(),
onClick = { showChannelEditor = true }, onClick = { showChannelEditor = true },
enabled = enabled, enabled = enabled,
trailingIcon = Icons.TwoTone.Edit, trailingIcon = Icons.TwoTone.Edit,

Wyświetl plik

@ -11,7 +11,6 @@ class ChannelSetTest {
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ") val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ")
val cs = url.toChannelSet() val cs = url.toChannelSet()
Assert.assertEquals("LongFast", cs.primaryChannel!!.name) Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
Assert.assertEquals("#LongFast-I", cs.primaryChannel!!.humanName)
Assert.assertEquals(url, cs.getChannelUrl(false)) Assert.assertEquals(url, cs.getChannelUrl(false))
} }
} }