Skip to content

Commit

Permalink
refactor: add shortName to traceroute response
Browse files Browse the repository at this point in the history
closes #1164
  • Loading branch information
andrekir committed Aug 18, 2024
1 parent ddad40a commit 3a11ca9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/src/main/java/com/geeksville/mesh/service/MeshService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,12 @@ class MeshService : Service(), Logging {
}
}

private fun getLongName(num: Int) =
nodeDBbyNodeNum[num]?.user?.longName ?: getString(R.string.unknown_username)
private fun getUserName(num: Int): String {
val user = nodeDBbyNodeNum[num]?.user
val longName = user?.longName ?: getString(R.string.unknown_username)
val shortName = user?.shortName ?: DataPacket.nodeNumToDefaultId(num)
return "$longName ($shortName)"
}

private val numNodes get() = nodeDBbyNodeNum.size

Expand Down Expand Up @@ -733,9 +737,9 @@ class MeshService : Service(), Logging {
if (data.wantResponse) return // ignore data from traceroute requests
val parsed = MeshProtos.RouteDiscovery.parseFrom(data.payload)
radioConfigRepository.setTracerouteResponse(buildString {
append("${getLongName(packet.to)} --> ")
parsed.routeList.forEach { num -> append("${getLongName(num)} --> ") }
append(getLongName(packet.from))
append("${getUserName(packet.to)} --> ")
parsed.routeList.forEach { num -> append("${getUserName(num)} --> ") }
append(getUserName(packet.from))
})
}

Expand Down

0 comments on commit 3a11ca9

Please sign in to comment.