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

Closes tailscale/corp#19111

Signed-off-by: Percy Wegmann <percy@tailscale.com>
pull/315/head
Percy Wegmann 1 month ago committed by Percy Wegmann
parent 11f52ad96b
commit 9054264363

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

@ -39,7 +39,18 @@ class PeerCategorizer {
grouped grouped
.map { (userId, peers) -> .map { (userId, peers) ->
val profile = netmap.userProfile(userId) 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 { .sortedBy {
if (it.user?.ID == me?.ID) { if (it.user?.ID == me?.ID) {

Loading…
Cancel
Save