mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-24 22:25:19 +00:00
fix: exclude self from nickname disambiguation suffix
This commit is contained in:
@@ -47,7 +47,7 @@ class BluetoothMeshService(private val context: Context) {
|
||||
|
||||
// My peer identification - derived from persisted Noise identity fingerprint (first 16 hex chars)
|
||||
val myPeerID: String = encryptionService.getIdentityFingerprint().take(16)
|
||||
private val peerManager = PeerManager()
|
||||
private val peerManager = PeerManager().apply { myPeerID = this@BluetoothMeshService.myPeerID }
|
||||
private val fragmentManager = FragmentManager()
|
||||
private val securityManager = SecurityManager(encryptionService, myPeerID)
|
||||
private val storeForwardManager = StoreForwardManager()
|
||||
|
||||
@@ -89,6 +89,9 @@ class PeerManager {
|
||||
// Callback to check if a peer is directly connected (injected by BluetoothMeshService)
|
||||
var isPeerDirectlyConnected: ((String) -> Boolean)? = null
|
||||
|
||||
// My own Peer ID (to treat specially in disambiguation and cleanup)
|
||||
var myPeerID: String? = null
|
||||
|
||||
// Coroutines
|
||||
private val managerScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
@@ -305,7 +308,9 @@ class PeerManager {
|
||||
val info = peers[peerID] ?: return peerID
|
||||
val nick = info.nickname.trim()
|
||||
val isAmbiguous = peers.values.count { it.nickname.trim().equals(nick, ignoreCase = true) } > 1
|
||||
return if (isAmbiguous) "$nick#${peerID.takeLast(4)}" else nick
|
||||
|
||||
// Suffix is appended if ambiguous, UNLESS this is our own Peer ID
|
||||
return if (isAmbiguous && peerID != myPeerID) "$nick#${peerID.takeLast(4)}" else nick
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,7 +433,9 @@ class PeerManager {
|
||||
private fun cleanupStalePeers() {
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
val peersToRemove = peers.filterValues { (now - it.lastSeen) > stalePeerTimeoutMs }
|
||||
val peersToRemove = peers.filterValues {
|
||||
it.id != myPeerID && (now - it.lastSeen) > stalePeerTimeoutMs
|
||||
}
|
||||
.keys
|
||||
.toList()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user