From 83eaebc357b8d2148f42a075d57345fb31be2444 Mon Sep 17 00:00:00 2001 From: Kane Waldo Date: Fri, 31 Jul 2026 11:20:58 +0700 Subject: [PATCH] Fix geohash join channel routing --- .../com/bitchat/android/ui/ChannelManager.kt | 6 +++++- .../com/bitchat/android/ui/ChatViewModel.kt | 12 +++++++++++- .../bitchat/android/ui/CommandProcessorTest.kt | 18 ++++++++++++++++++ gradle/verification-metadata.xml | 6 ++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/bitchat/android/ui/ChannelManager.kt b/app/src/main/java/com/bitchat/android/ui/ChannelManager.kt index 5cc1375c..43bc2085 100644 --- a/app/src/main/java/com/bitchat/android/ui/ChannelManager.kt +++ b/app/src/main/java/com/bitchat/android/ui/ChannelManager.kt @@ -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 -> diff --git a/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt b/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt index 16933537..24346e00 100644 --- a/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt +++ b/app/src/main/java/com/bitchat/android/ui/ChatViewModel.kt @@ -121,7 +121,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 { diff --git a/app/src/test/java/com/bitchat/android/ui/CommandProcessorTest.kt b/app/src/test/java/com/bitchat/android/ui/CommandProcessorTest.kt index 011f80a2..fee53c0d 100644 --- a/app/src/test/java/com/bitchat/android/ui/CommandProcessorTest.kt +++ b/app/src/test/java/com/bitchat/android/ui/CommandProcessorTest.kt @@ -161,4 +161,22 @@ 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) + } } diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index a62cbff6..08eb23c4 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -2147,6 +2147,9 @@ + + + @@ -4903,6 +4906,9 @@ + + +