Merge pull request #841 from phuctoan123/codex-fix-geohash-join-channel-routing

Fix geohash join channel routing
This commit is contained in:
callebtc 2026-08-17 19:09:26 +02:00 committed by GitHub
commit 35ed4417f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.bitchat.android.ui
import com.bitchat.android.geohash.ChannelID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import java.security.MessageDigest
@ -16,7 +17,8 @@ class ChannelManager(
private val state: ChatState,
private val messageManager: MessageManager,
private val dataManager: DataManager,
private val coroutineScope: CoroutineScope
private val coroutineScope: CoroutineScope,
private val onSwitchToMeshLocation: () -> Unit = {}
) {
// Channel encryption and security
@ -109,6 +111,8 @@ class ChannelManager(
fun switchToChannel(channel: String?) {
state.setCurrentChannel(channel)
state.setSelectedPrivateChatPeer(null)
state.setSelectedLocationChannel(ChannelID.Mesh)
onSwitchToMeshLocation()
// Clear unread count
channel?.let { ch ->

View File

@ -140,7 +140,17 @@ class ChatViewModel(
private val conversationListPreferences =
com.bitchat.android.services.ConversationListPreferences.getInstance(getApplication())
private val messageManager = MessageManager(state)
private val channelManager = ChannelManager(state, messageManager, dataManager, viewModelScope)
private val channelManager = ChannelManager(
state,
messageManager,
dataManager,
viewModelScope,
onSwitchToMeshLocation = {
com.bitchat.android.geohash.LocationChannelManager
.getInstance(getApplication())
.select(com.bitchat.android.geohash.ChannelID.Mesh)
}
)
// Create Noise session delegate for clean dependency injection
private val noiseSessionDelegate = object : NoiseSessionDelegate {

View File

@ -24,11 +24,12 @@ import org.robolectric.RobolectricTestRunner
import java.util.Date
@RunWith(RobolectricTestRunner::class)
class CommandProcessorTest() {
class CommandProcessorTest {
private val context: Context = ApplicationProvider.getApplicationContext()
@OptIn(ExperimentalCoroutinesApi::class)
private val testDispatcher = UnconfinedTestDispatcher()
private val testScope = TestScope(testDispatcher)
@OptIn(ExperimentalCoroutinesApi::class)
private val testDispatcher = UnconfinedTestDispatcher()
private val testScope = TestScope(testDispatcher)
private val chatState = ChatState(scope = testScope)
private lateinit var commandProcessor: CommandProcessor
@ -63,11 +64,11 @@ class CommandProcessorTest() {
val channel = "channel-1"
val result = commandProcessor.processCommand(
command = "/j $channel",
meshService = meshService,
myPeerID = "peer-id",
onSendMessage = { a, b, c -> { } },
viewModel = null
command = "/j $channel",
meshService = meshService,
myPeerID = "peer-id",
onSendMessage = { a, b, c -> { } },
viewModel = null
)
assertEquals(result, true)
@ -163,6 +164,23 @@ class CommandProcessorTest() {
assertEquals(0, chatState.getMessagesValue().size)
}
@Test
fun `join command leaves active geohash selection for mesh channel routing`() {
chatState.setSelectedLocationChannel(
ChannelID.Location(GeohashChannel(GeohashChannelLevel.REGION, "9q"))
)
commandProcessor.processCommand(
command = "/join backchannel",
meshService = meshService,
myPeerID = "peer-id",
onSendMessage = { _, _, _ -> },
viewModel = null
)
assertEquals("#backchannel", chatState.getCurrentChannelValue())
assertEquals(ChannelID.Mesh, chatState.selectedLocationChannel.value)
@Test
fun `clearSuggestions hides the command suggestion popup`() {
// Typing "/" opens the command popup.
@ -187,5 +205,6 @@ class CommandProcessorTest() {
commandProcessor.clearSuggestions()
assertFalse(chatState.getShowMentionSuggestionsValue())
assertTrue(chatState.getMentionSuggestionsValue().isEmpty())
}
}
}

View File

@ -2147,6 +2147,9 @@
<artifact name="aapt2-9.3.1-15703166-osx.jar">
<sha256 value="1e35bc2ce18c3aae840be2a29659ce50d6043e907a44d98ee1cf375d044fa29c" origin="Generated by Gradle"/>
</artifact>
<artifact name="aapt2-9.3.1-15703166-windows.jar">
<sha256 value="b1006ecec7e5936257e95e97f3eba7ef439d3e44178967cc048f86c9119fb231" origin="Generated by Gradle"/>
</artifact>
<artifact name="aapt2-9.3.1-15703166.pom">
<sha256 value="edb82dcbe738ca78b31612cb307bf99e5f02f25c8125048f933e792fd7778beb" origin="Generated by Gradle"/>
</artifact>
@ -4911,6 +4914,9 @@
</artifact>
</component>
<component group="org.junit" name="junit-bom" version="5.9.2">
<artifact name="junit-bom-5.9.2.module">
<sha256 value="ab137ba5a8e32c9b066bf9126a1c76dd5614b724ba5c0b02549772b5e9f4cf1f" origin="Generated by Gradle"/>
</artifact>
<artifact name="junit-bom-5.9.2.pom">
<sha256 value="2ed07d65845131f5336a86476c9a4056b59d0b58b9815ab3679bb0f36f35f705" origin="Generated by Gradle"/>
</artifact>