mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 06:25:21 +00:00
Debug button (#377)
* feat(debug): add DebugSettingsManager + DebugSettingsSheet scaffold and AboutSheet entry; groundwork for verbose logging, GATT controls, relay stats, device/scan views * fix(debug): wire debug sheet launch via onShowDebug in AboutSheet from ChatScreen; add public start/stop server/client methods} * fix(about): remove misplaced debug item block inside PoW section; keep debug launcher managed by ChatScreen only * feat(debug): wire DebugSettingsSheet role switches to explicit startServer/stopServer and startClient/stopClient; expose role controls + disconnectAll on BluetoothConnectionManager; fix syntax error; build passes * feat(debug): add connect/disconnect helpers; wire DebugSettingsSheet connect/disconnect actions to BluetoothConnectionManager * feat(debug): add debug settings button at bottom of AboutSheet; wire onShowDebug callback to open DebugSettingsSheet from ChatScreen * feat(debug): wire verbose logging into chat view via DebugSettingsManager; add rolling relay stats; push connected devices and scan results; ensure GATT role stop closes connections; log incoming packets and relay events; add UI polling for devices; build passes * chore(debug-branch): remove unrelated files that were mistakenly added in first commit; keep only intended debug settings changes * fix(chat): prevent mesh→geohash leak Root cause: - DebugSettingsManager→chat bridge appended system logs to the global timeline regardless of active channel - MeshDelegateHandler added public mesh messages to UI unconditionally Fixes: - Only inject debug system messages when selected location channel is Mesh - Only add public mesh messages to UI when Mesh is selected (still send notifications) Build: ./gradlew assembleDebug } * fix(timeline): restore message persistence across channel switches Root cause: - NostrGeohashService.switchLocationChannel() called messageManager.clearMessages() which wiped ALL messages (mesh + debug + geohash) from main timeline - Geohash events were adding to main timeline, causing cross-contamination Fixes: - Remove messageManager.clearMessages() from channel switching - ChatScreen displayMessages now routes to separate storage: - Mesh: messages (main timeline, includes debug logs when Mesh selected) - Geohash: viewModel.getGeohashMessages(geohash) from separate history - Private: privateChats[peerID] - Channels: channelMessages[channel] - Geohash events no longer add to main timeline, only to geohash history - Mesh messages always stored to preserve history when switching away Result: Each chat type has persistent separate storage, no message loss * Debug/relay logs: use MessageType names; include device route in verbose packet logs. * Verbose device-peer assignment and connection/disconnection logs with peerId, deviceId, nickname; packet relay log uses MessageType names.} * Debug logs API: include nickname and deviceId for incoming/relay; update callers.} * Fix compile: import MessageType; correct debug manager API usage and remove stray insertion; build.} * Respect relay toggle; helper to log relay with deviceId.} * PacketRelayManager: add relay toggle and unified logging helper; clean file header comments; build fixes.} * changes * Geohash local echo: do not add to mesh timeline; rely on geohash history and ChatScreen display for location channels. * persisting * persist debug settings * gitignore * gatt server / client controls * debugger * max connection settings and graph * more graph * better logging * refactor logging
This commit is contained in:
@@ -258,11 +258,12 @@ class NostrGeohashService(
|
||||
powDifficulty = if (powSettingsLocal.enabled) powSettingsLocal.difficulty else null
|
||||
)
|
||||
|
||||
// Store and display the message immediately
|
||||
// Store immediately; UI will display from geohash history (not main mesh timeline)
|
||||
storeGeohashMessage(channel.geohash, localMessage)
|
||||
messageManager.addMessage(localMessage)
|
||||
// IMPORTANT: Do not add to main mesh timeline to avoid duplication in mesh chat view
|
||||
// messageManager.addMessage(localMessage)
|
||||
|
||||
Log.d(TAG, "📝 Added message immediately with temp ID: $tempMessageId")
|
||||
Log.d(TAG, "📝 Added geohash local echo with temp ID: $tempMessageId (not shown in mesh timeline)")
|
||||
|
||||
// Check if PoW is enabled before starting animation
|
||||
val powSettings = PoWPreferenceManager.getCurrentSettings()
|
||||
@@ -726,6 +727,13 @@ class NostrGeohashService(
|
||||
messageManager.addMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get stored messages for a geohash without mutating UI state
|
||||
*/
|
||||
fun getGeohashMessages(geohash: String): List<BitchatMessage> {
|
||||
return geohashMessageHistory[geohash]?.toList() ?: emptyList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear geohash message history
|
||||
@@ -986,9 +994,8 @@ class NostrGeohashService(
|
||||
private fun switchLocationChannel(channel: com.bitchat.android.geohash.ChannelID?) {
|
||||
// STEP 1: Immediate UI updates (synchronous, no blocking)
|
||||
try {
|
||||
// Clear all displayed messages and load stored messages for the new channel
|
||||
messageManager.clearMessages()
|
||||
Log.d(TAG, "🗑️ Cleared all messages for channel switch")
|
||||
// NOTE: Don't clear messages here - let ChatScreen's displayMessages logic handle what to show
|
||||
// This preserves mesh message history when switching between views
|
||||
|
||||
when (channel) {
|
||||
is com.bitchat.android.geohash.ChannelID.Mesh -> {
|
||||
@@ -1013,9 +1020,7 @@ class NostrGeohashService(
|
||||
// Clear notifications for this geohash since user is now viewing it
|
||||
notificationManager.clearNotificationsForGeohash(channel.channel.geohash)
|
||||
// Note: Don't clear geoNicknames - they contain cached nicknames for all geohashes
|
||||
|
||||
// Load stored messages for this geohash immediately
|
||||
loadGeohashMessages(channel.channel.geohash)
|
||||
// Note: Don't load messages here - ChatScreen will get them via getGeohashMessages()
|
||||
|
||||
// Immediate self-registration for instant UI feedback
|
||||
try {
|
||||
@@ -1298,16 +1303,8 @@ class NostrGeohashService(
|
||||
// Store in geohash history for persistence across channel switches
|
||||
storeGeohashMessage(geohash, message)
|
||||
|
||||
// CRITICAL BUG FIX: Add to message timeline if we're viewing this geohash OR if it matches our selected location channel
|
||||
// This prevents messages from being lost during channel switching race conditions
|
||||
val selectedLocationChannel = state.selectedLocationChannel.value
|
||||
val shouldShowMessage = currentGeohash == geohash ||
|
||||
(selectedLocationChannel is com.bitchat.android.geohash.ChannelID.Location &&
|
||||
selectedLocationChannel.channel.geohash == geohash)
|
||||
|
||||
if (shouldShowMessage) {
|
||||
withContext(Dispatchers.Main) { messageManager.addMessage(message) }
|
||||
}
|
||||
// NOTE: Don't add to main message timeline here - ChatScreen will display geohash messages
|
||||
// from the separate geohash history via getGeohashMessages()
|
||||
|
||||
// NOTIFICATION LOGIC: Check for mentions and first messages
|
||||
checkAndTriggerGeohashNotifications(geohash, senderName, content, message)
|
||||
|
||||
Reference in New Issue
Block a user