mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 05:05:20 +00:00
fix nostr private messages processing (#563)
* fix nostr private messages processing * persisted geohash registry --------- Co-authored-by: a1denvalu3 <>
This commit is contained in:
co-authored by
a1denvalu3 <>
parent
cbe7a2fc95
commit
c7e20a9590
@@ -1,17 +1,40 @@
|
||||
package com.bitchat.android.nostr
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* GeohashAliasRegistry
|
||||
* - Global, thread-safe registry for alias->Nostr pubkey mappings (e.g., nostr_<pub16> -> pubkeyHex)
|
||||
* - Allows non-UI components (e.g., MessageRouter) to resolve geohash DM aliases without depending on UI ViewModels
|
||||
* - Persisted to SharedPreferences to survive app restarts.
|
||||
*/
|
||||
object GeohashAliasRegistry {
|
||||
private val map: MutableMap<String, String> = ConcurrentHashMap()
|
||||
private const val PREFS_NAME = "geohash_alias_registry"
|
||||
private var prefs: SharedPreferences? = null
|
||||
|
||||
fun initialize(context: Context) {
|
||||
if (prefs == null) {
|
||||
prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
loadFromPrefs()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadFromPrefs() {
|
||||
prefs?.let { p ->
|
||||
val allEntries = p.all
|
||||
for ((key, value) in allEntries) {
|
||||
if (key is String && value is String) {
|
||||
map[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun put(alias: String, pubkeyHex: String) {
|
||||
map[alias] = pubkeyHex
|
||||
prefs?.edit()?.putString(alias, pubkeyHex)?.apply()
|
||||
}
|
||||
|
||||
fun get(alias: String): String? = map[alias]
|
||||
@@ -20,5 +43,8 @@ object GeohashAliasRegistry {
|
||||
|
||||
fun snapshot(): Map<String, String> = HashMap(map)
|
||||
|
||||
fun clear() { map.clear() }
|
||||
fun clear() {
|
||||
map.clear()
|
||||
prefs?.edit()?.clear()?.apply()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,51 @@
|
||||
package com.bitchat.android.nostr
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* GeohashConversationRegistry
|
||||
* - Global, thread-safe registry of conversationKey (e.g., "nostr_<pub16>") -> source geohash
|
||||
* - Enables routing geohash DMs from anywhere by providing the correct geohash identity
|
||||
* - Persisted to SharedPreferences to survive app restarts.
|
||||
*/
|
||||
object GeohashConversationRegistry {
|
||||
private val map = ConcurrentHashMap<String, String>()
|
||||
private const val PREFS_NAME = "geohash_conversation_registry"
|
||||
private var prefs: SharedPreferences? = null
|
||||
|
||||
fun initialize(context: Context) {
|
||||
if (prefs == null) {
|
||||
prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
loadFromPrefs()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadFromPrefs() {
|
||||
prefs?.let { p ->
|
||||
val allEntries = p.all
|
||||
for ((key, value) in allEntries) {
|
||||
if (key is String && value is String) {
|
||||
map[key] = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun set(convKey: String, geohash: String) {
|
||||
if (geohash.isNotEmpty()) map[convKey] = geohash
|
||||
if (geohash.isNotEmpty()) {
|
||||
map[convKey] = geohash
|
||||
prefs?.edit()?.putString(convKey, geohash)?.apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun get(convKey: String): String? = map[convKey]
|
||||
|
||||
fun snapshot(): Map<String, String> = map.toMap()
|
||||
|
||||
fun clear() = map.clear()
|
||||
fun clear() {
|
||||
map.clear()
|
||||
prefs?.edit()?.clear()?.apply()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user