Merge c1752844ee123871db61ecefff4a417befe22c24 into d615fc9cc07faa8ba243c25bb769fb617ecc38ea

This commit is contained in:
a1denvalu3 2026-07-26 20:30:17 -04:00 committed by GitHub
commit e2114824d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 14 deletions

View File

@ -130,6 +130,10 @@ class GeohashRepository(
return participants.keys.count { !dataManager.isGeohashUserBlocked(it) }
}
private fun formatAnonName(pubkeyHex: String): String {
return "${pubkeyHex.take(8)}..."
}
fun refreshGeohashPeople() {
val geohash = currentGeohash
if (geohash == null) {
@ -153,11 +157,11 @@ class GeohashRepository(
val base = try {
val myHex = currentGeohash?.let { NostrIdentityBridge.deriveIdentity(it, application).publicKeyHex }
if (myHex != null && myHex.equals(pubkeyHex, true)) {
state.getNicknameValue() ?: "anon"
state.getNicknameValue().ifEmpty { formatAnonName(pubkeyHex) }
} else {
getCachedNickname(pubkeyHex) ?: "anon"
getCachedNickname(pubkeyHex) ?: formatAnonName(pubkeyHex)
}
} catch (_: Exception) { getCachedNickname(pubkeyHex) ?: "anon" }
} catch (_: Exception) { getCachedNickname(pubkeyHex) ?: formatAnonName(pubkeyHex) }
GeoPerson(
id = pubkeyHex.lowercase(),
displayName = base, // UI can add #hash if necessary
@ -195,11 +199,12 @@ class GeohashRepository(
try {
val my = NostrIdentityBridge.deriveIdentity(current, application)
if (my.publicKeyHex.equals(lower, true)) {
return "${state.getNicknameValue()}#$suffix"
val selfNick = state.getNicknameValue()
return if (selfNick.isNotEmpty()) "$selfNick#$suffix" else "${formatAnonName(lower)}#$suffix"
}
} catch (_: Exception) {}
}
val nick = geoNicknames[lower] ?: "anon"
val nick = geoNicknames[lower] ?: formatAnonName(lower)
return "$nick#$suffix"
}
@ -211,10 +216,10 @@ class GeohashRepository(
if (current != null) {
val my = NostrIdentityBridge.deriveIdentity(current, application)
if (my.publicKeyHex.equals(lower, true)) {
state.getNicknameValue() ?: "anon"
} else geoNicknames[lower] ?: "anon"
} else geoNicknames[lower] ?: "anon"
} catch (_: Exception) { geoNicknames[lower] ?: "anon" }
state.getNicknameValue().ifEmpty { formatAnonName(lower) }
} else geoNicknames[lower] ?: formatAnonName(lower)
} else geoNicknames[lower] ?: formatAnonName(lower)
} catch (_: Exception) { geoNicknames[lower] ?: formatAnonName(lower) }
if (current == null) return base
return try {
val cutoff = Date(System.currentTimeMillis() - 5 * 60 * 1000)
@ -223,7 +228,7 @@ class GeohashRepository(
for ((k, t) in participants) {
if (dataManager.isGeohashUserBlocked(k)) continue
if (t.before(cutoff)) continue
val name = if (k.equals(lower, true)) base else (geoNicknames[k.lowercase()] ?: "anon")
val name = if (k.equals(lower, true)) base else (geoNicknames[k.lowercase()] ?: formatAnonName(k))
if (name.equals(base, true)) { count++; if (count > 1) break }
}
if (!participants.containsKey(lower)) count += 1
@ -237,7 +242,7 @@ class GeohashRepository(
fun displayNameForGeohashConversation(pubkeyHex: String, sourceGeohash: String): String {
val lower = pubkeyHex.lowercase()
val suffix = pubkeyHex.takeLast(4)
val base = geoNicknames[lower] ?: "anon"
val base = geoNicknames[lower] ?: formatAnonName(lower)
return try {
val cutoff = Date(System.currentTimeMillis() - 5 * 60 * 1000)
val participants = geohashParticipants[sourceGeohash] ?: emptyMap()
@ -245,7 +250,7 @@ class GeohashRepository(
for ((k, t) in participants) {
if (dataManager.isGeohashUserBlocked(k)) continue
if (t.before(cutoff)) continue
val name = if (k.equals(lower, true)) base else (geoNicknames[k.lowercase()] ?: "anon")
val name = if (k.equals(lower, true)) base else (geoNicknames[k.lowercase()] ?: formatAnonName(k))
if (name.equals(base, true)) { count++; if (count > 1) break }
}
if (!participants.containsKey(lower)) count += 1

View File

@ -108,13 +108,24 @@ fun GeohashPeopleList(
}
}
// Sort people: me first, then by lastSeen (matches iOS exactly)
// Sort people: me first, then named users, then anons (by lastSeen within groups)
val orderedPeople = remember(geohashPeople, myHex) {
geohashPeople.sortedWith { a, b ->
// Check if display name indicates an "anon" (shortened hex)
val aIsAnon = a.displayName == "${a.id.take(8)}..."
val bIsAnon = b.displayName == "${b.id.take(8)}..."
when {
// 1. Me always first
myHex != null && a.id == myHex && b.id != myHex -> -1
myHex != null && b.id == myHex && a.id != myHex -> 1
else -> b.lastSeen.compareTo(a.lastSeen) // Most recent first
// 2. Named users before anon users
!aIsAnon && bIsAnon -> -1
aIsAnon && !bIsAnon -> 1
// 3. Otherwise sort by recency
else -> b.lastSeen.compareTo(a.lastSeen)
}
}
}