kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: remove channel disambiguation suffix
rodzic
a3a914abce
commit
ee61b79aa3
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -241,11 +241,12 @@ fun ChannelScreen(
|
|||
|
||||
fun sendButton() {
|
||||
primaryChannel?.let { primaryChannel ->
|
||||
val humanName = primaryChannel.humanName
|
||||
val message = buildString {
|
||||
append(context.getString(R.string.are_you_sure_channel))
|
||||
if (primaryChannel.settings == Channel.default.settings)
|
||||
append("\n\n" + context.getString(R.string.warning_default_psk, humanName))
|
||||
if (primaryChannel.settings == Channel.default.settings) {
|
||||
append("\n\n")
|
||||
append(context.getString(R.string.warning_default_psk, primaryChannel.name))
|
||||
}
|
||||
}
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
|
@ -290,7 +291,7 @@ fun ChannelScreen(
|
|||
if (!showChannelEditor) item {
|
||||
ClickableTextField(
|
||||
label = R.string.channel_name,
|
||||
value = primaryChannel?.humanName.orEmpty(),
|
||||
value = primaryChannel?.name.orEmpty(),
|
||||
onClick = { showChannelEditor = true },
|
||||
enabled = enabled,
|
||||
trailingIcon = Icons.TwoTone.Edit,
|
||||
|
|
|
@ -11,7 +11,6 @@ class ChannelSetTest {
|
|||
val url = Uri.parse("https://meshtastic.org/e/#CgMSAQESBggBQANIAQ")
|
||||
val cs = url.toChannelSet()
|
||||
Assert.assertEquals("LongFast", cs.primaryChannel!!.name)
|
||||
Assert.assertEquals("#LongFast-I", cs.primaryChannel!!.humanName)
|
||||
Assert.assertEquals(url, cs.getChannelUrl(false))
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue