Files
bitchat-android/app/src/main/java/com/bitchat/android/geohash/LocationChannel.kt
T
callebtcandGitHub 7243d841a3 Nostr geohash (#276)
* first nostr build

* add test file

* internet access

* fix relay manager

* fix serialization

* demo service - remove later

* fix nostr

* event dedupe

* dedupe

* ui wip

* can send messages

* subscription works

* works

* favs

* works

* delete chat on change

* fix mentions

* remove autojoin channels

* styling

* adjust colors

* ui changes

* live updates working

* use local timestamp

* message history in background

* robust

* fixes

* nicknames refresh optimization

* nostr service

* refactor nostr

* style

* geohash works

* centralize colors

* refactoring

* disable DMs for now: click on peer nickname doesnt open chat list in geohash mode

* use local time

* less logging

* robustness

* scroll nickname

* adjust some text
2025-08-22 19:09:18 +02:00

73 lines
1.8 KiB
Kotlin

package com.bitchat.android.geohash
/**
* Levels of location channels mapped to geohash precisions.
* Direct port from iOS implementation for 100% compatibility
*/
enum class GeohashChannelLevel(val precision: Int, val displayName: String) {
BLOCK(7, "Block"),
NEIGHBORHOOD(6, "Neighborhood"),
CITY(5, "City"),
REGION(4, "Region"),
COUNTRY(2, "Country");
companion object {
fun allCases(): List<GeohashChannelLevel> = values().toList()
}
}
/**
* A computed geohash channel option.
* Direct port from iOS implementation
*/
data class GeohashChannel(
val level: GeohashChannelLevel,
val geohash: String
) {
val id: String get() = "${level.name}-$geohash"
val displayName: String get() = "${level.displayName}$geohash"
}
/**
* Identifier for current public chat channel (mesh or a location geohash).
* Direct port from iOS implementation
*/
sealed class ChannelID {
object Mesh : ChannelID()
data class Location(val channel: GeohashChannel) : ChannelID()
/**
* Human readable name for UI.
*/
val displayName: String
get() = when (this) {
is Mesh -> "Mesh"
is Location -> channel.displayName
}
/**
* Nostr tag value for scoping (geohash), if applicable.
*/
val nostrGeohashTag: String?
get() = when (this) {
is Mesh -> null
is Location -> channel.geohash
}
override fun equals(other: Any?): Boolean {
return when {
this is Mesh && other is Mesh -> true
this is Location && other is Location -> this.channel == other.channel
else -> false
}
}
override fun hashCode(): Int {
return when (this) {
is Mesh -> "mesh".hashCode()
is Location -> channel.hashCode()
}
}
}