android/ui: sort self peer first in list of peers

Closes tailscale/corp#19111

Signed-off-by: Percy Wegmann <percy@tailscale.com>
angott/reintroduce-dark-mode
Percy Wegmann 3 weeks ago committed by Percy Wegmann
parent 11f52ad96b
commit 9054264363

@ -101,6 +101,8 @@ class Tailcfg {
val displayName: String
get() = ComputedName ?: Name
fun isSelfNode(netmap: Netmap.NetworkMap): Boolean = StableID == netmap.SelfNode.StableID
fun connectedOrSelfNode(nm: Netmap.NetworkMap?) =
Online == true || StableID == nm?.SelfNode?.StableID

@ -39,7 +39,18 @@ class PeerCategorizer {
grouped
.map { (userId, peers) ->
val profile = netmap.userProfile(userId)
PeerSet(profile, peers.sortedBy { it.ComputedName })
PeerSet(
profile,
peers.sortedWith { a, b ->
when {
a.StableID == b.StableID -> 0
a.isSelfNode(netmap) -> -1
b.isSelfNode(netmap) -> 1
else ->
(a.ComputedName?.lowercase() ?: "").compareTo(
b.ComputedName?.lowercase() ?: "")
}
})
}
.sortedBy {
if (it.user?.ID == me?.ID) {

Loading…
Cancel
Save