Skip to content

Commit

Permalink
refactor: remove channel disambiguation suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Mar 18, 2024
1 parent a3a914a commit ee61b79
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
15 changes: 0 additions & 15 deletions app/src/main/java/com/geeksville/mesh/model/Channel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/com/geeksville/mesh/ui/ChannelFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

0 comments on commit ee61b79

Please sign in to comment.