android: fix for node sorting and details on current node

updates ENG-2859

Moves your current node to the top of the list and fixes fetching peer details for the current node.
pull/185/head
Jonathan Nobels 3 months ago
parent ff757cf2db
commit af40ecd732

@ -32,6 +32,13 @@ class Netmap {
return UserProfiles[id.toString()]
}
fun getPeer(id: StableNodeID): Tailcfg.Node? {
if(id == SelfNode.StableID) {
return SelfNode
}
return Peers?.find { it.StableID == id }
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is NetworkMap) return false

@ -28,10 +28,16 @@ class PeerCategorizer(val model: IpnModel) {
}
grouped[userId]?.add(peer)
}
val selfPeers = grouped[selfNode.User] ?: emptyList()
var selfPeers = (grouped[selfNode.User] ?: emptyList()).sortedBy { it.ComputedName }
grouped.remove(selfNode.User)
var sorted = grouped.map { (userId, peers) ->
val currentNode = selfPeers.first { it.ID == selfNode.ID }
currentNode.let {
selfPeers = selfPeers.filter { it.ID != currentNode.ID }
selfPeers = listOf(currentNode) + selfPeers
}
val sorted = grouped.map { (userId, peers) ->
val profile = netmap.userProfile(userId)
PeerSet(profile, peers)
}.sortedBy {

@ -6,13 +6,14 @@ package com.tailscale.ipn.ui.viewModel
import androidx.compose.ui.graphics.Color
import androidx.lifecycle.ViewModel
import com.tailscale.ipn.ui.model.StableNodeID
import com.tailscale.ipn.ui.service.IpnModel
import com.tailscale.ipn.ui.util.DisplayAddress
import com.tailscale.ipn.ui.util.TimeUtil
data class PeerSettingInfo(val title:String, val value: String)
class PeerDetailsViewModel(val model: IpnModel, val nodeId: String): ViewModel() {
class PeerDetailsViewModel(val model: IpnModel, val nodeId: StableNodeID): ViewModel() {
var addresses: List<DisplayAddress> = emptyList()
var info: List<PeerSettingInfo> = emptyList()
@ -22,7 +23,7 @@ class PeerDetailsViewModel(val model: IpnModel, val nodeId: String): ViewModel()
val connectedColor: Color
init {
val peer = model.netmap.value?.Peers?.find { it.StableID == nodeId }
val peer = model.netmap.value?.getPeer(nodeId)
peer?.Addresses?.let {
addresses = it.map { addr ->
DisplayAddress(addr)}

Loading…
Cancel
Save