mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-24 23:25:19 +00:00
fix: unconditionally update mesh reference in MessageRouter.getInstance
This commit is contained in:
@@ -19,23 +19,22 @@ class MessageRouter private constructor(
|
|||||||
@Volatile private var INSTANCE: MessageRouter? = null
|
@Volatile private var INSTANCE: MessageRouter? = null
|
||||||
fun tryGetInstance(): MessageRouter? = INSTANCE
|
fun tryGetInstance(): MessageRouter? = INSTANCE
|
||||||
fun getInstance(context: Context, mesh: BluetoothMeshService): MessageRouter {
|
fun getInstance(context: Context, mesh: BluetoothMeshService): MessageRouter {
|
||||||
return INSTANCE ?: synchronized(this) {
|
val instance = INSTANCE ?: synchronized(this) {
|
||||||
val nostr = NostrTransport.getInstance(context)
|
INSTANCE ?: run {
|
||||||
INSTANCE?.also {
|
val nostr = NostrTransport.getInstance(context)
|
||||||
// Update mesh reference if needed and keep senderPeerID in sync
|
MessageRouter(context.applicationContext, mesh, nostr).also { instance ->
|
||||||
it.mesh = mesh
|
// Register for favorites changes to flush outbox
|
||||||
it.nostr.senderPeerID = mesh.myPeerID
|
try {
|
||||||
return it
|
com.bitchat.android.favorites.FavoritesPersistenceService.shared.addListener(instance.favoriteListener)
|
||||||
}
|
} catch (_: Exception) {}
|
||||||
MessageRouter(context.applicationContext, mesh, nostr).also { instance ->
|
INSTANCE = instance
|
||||||
instance.nostr.senderPeerID = mesh.myPeerID
|
}
|
||||||
// Register for favorites changes to flush outbox
|
|
||||||
try {
|
|
||||||
com.bitchat.android.favorites.FavoritesPersistenceService.shared.addListener(instance.favoriteListener)
|
|
||||||
} catch (_: Exception) {}
|
|
||||||
INSTANCE = instance
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Always update mesh reference and sync peer ID
|
||||||
|
instance.mesh = mesh
|
||||||
|
instance.nostr.senderPeerID = mesh.myPeerID
|
||||||
|
return instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user