kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
refactor: ensure backward compatibility for PKC encryption
rodzic
6e2848a54a
commit
587c6c91f4
|
@ -79,6 +79,8 @@ data class NodeEntity(
|
|||
return (if (brightness > 0.5) Color.BLACK else Color.WHITE) to Color.rgb(r, g, b)
|
||||
}
|
||||
|
||||
val hasPKC get() = !user.publicKey.isEmpty
|
||||
|
||||
val batteryLevel get() = deviceMetrics.batteryLevel
|
||||
val voltage get() = deviceMetrics.voltage
|
||||
val batteryStr get() = if (batteryLevel in 1..100) "$batteryLevel%" else ""
|
||||
|
|
|
@ -474,8 +474,13 @@ class MeshService : Service(), Logging {
|
|||
|
||||
/// Admin channel index
|
||||
private val adminChannelIndex: Int
|
||||
get() = channelSet.settingsList.indexOfFirst { it.name.equals("admin", ignoreCase = true) }
|
||||
.coerceAtLeast(0)
|
||||
get() = if (nodeDBbyNodeNum[myNodeNum]?.hasPKC == true) { // TODO use meta.hasPKC
|
||||
DataPacket.PKC_CHANNEL_INDEX
|
||||
} else {
|
||||
channelSet.settingsList
|
||||
.indexOfFirst { it.name.equals("admin", ignoreCase = true) }
|
||||
.coerceAtLeast(0)
|
||||
}
|
||||
|
||||
/// Generate a new mesh packet builder with our node as the sender, and the specified node num
|
||||
private fun newMeshPacketTo(idNum: Int) = MeshPacket.newBuilder().apply {
|
||||
|
@ -513,7 +518,7 @@ class MeshService : Service(), Logging {
|
|||
decoded = MeshProtos.Data.newBuilder().also {
|
||||
initFn(it)
|
||||
}.build()
|
||||
if (decoded.portnum in setOf(Portnums.PortNum.TEXT_MESSAGE_APP, Portnums.PortNum.ADMIN_APP)) {
|
||||
if (channel == DataPacket.PKC_CHANNEL_INDEX) {
|
||||
nodeDBbyNodeNum[to]?.user?.publicKey?.let { publicKey ->
|
||||
pkiEncrypted = !publicKey.isEmpty
|
||||
this.publicKey = publicKey
|
||||
|
|
|
@ -75,7 +75,6 @@ fun NodeItem(
|
|||
expanded: Boolean = false,
|
||||
currentTimeMillis: Long,
|
||||
) {
|
||||
val hasPublicKey = !thatNode.user.publicKey.isEmpty
|
||||
val isUnknownUser = thatNode.user.hwModel == MeshProtos.HardwareModel.UNSET
|
||||
val unknownShortName = stringResource(id = R.string.unknown_node_short_name)
|
||||
val longName = thatNode.user.longName.ifEmpty { stringResource(id = R.string.unknown_username) }
|
||||
|
@ -163,7 +162,7 @@ fun NodeItem(
|
|||
)
|
||||
Text(
|
||||
modifier = Modifier.weight(1f),
|
||||
text = if (hasPublicKey) "🔒 $longName" else longName,
|
||||
text = if (thatNode.hasPKC) "🔒 $longName" else longName,
|
||||
style = style,
|
||||
textDecoration = TextDecoration.LineThrough.takeIf { isIgnored },
|
||||
softWrap = true,
|
||||
|
|
|
@ -90,7 +90,8 @@ class UsersFragment : ScreenFragment("Users"), Logging {
|
|||
}
|
||||
|
||||
private fun navigateToMessages(node: NodeEntity) = node.user.let { user ->
|
||||
val channel = if (user.publicKey.isEmpty) node.channel else DataPacket.PKC_CHANNEL_INDEX
|
||||
val hasPKC = model.ourNodeInfo.value?.hasPKC == true && node.hasPKC // TODO use meta.hasPKC
|
||||
val channel = if (hasPKC) DataPacket.PKC_CHANNEL_INDEX else node.channel
|
||||
val contactKey = "$channel${user.id}"
|
||||
info("calling MessagesFragment filter: $contactKey")
|
||||
parentFragmentManager.navigateToMessages(contactKey, user.longName)
|
||||
|
|
Ładowanie…
Reference in New Issue