Fix/nostr dm bottom sheet (#598)

* nostr in new dm sheets

* open sheet for nostr peers
This commit is contained in:
callebtc
2026-01-14 17:38:47 +07:00
committed by GitHub
parent 216352c39d
commit e769a03634
5 changed files with 45 additions and 12 deletions
@@ -76,7 +76,12 @@ object ConversationAliasResolver {
if (selected != null && keysToMerge.contains(selected)) {
state.setSelectedPrivateChatPeer(targetPeerID)
}
// Switch sheet peer if currently viewing an alias that got merged
val sheetPeer = state.getPrivateChatSheetPeerValue()
if (sheetPeer != null && keysToMerge.contains(sheetPeer)) {
state.setPrivateChatSheetPeer(targetPeerID)
}
}
}
}
@@ -507,6 +507,10 @@ class ChatViewModel(
).also { canonical ->
if (canonical != state.getSelectedPrivateChatPeerValue()) {
privateChatManager.startPrivateChat(canonical, meshService)
// If we're in the private chat sheet, update its active peer too
if (state.getPrivateChatSheetPeerValue() != null) {
showPrivateChatSheet(canonical)
}
}
}
// Send private message
@@ -722,7 +726,7 @@ class ChatViewModel(
}
// MARK: - QR Verification
fun isPeerVerified(peerID: String, verifiedFingerprints: Set<String>): Boolean {
if (peerID.startsWith("nostr_") || peerID.startsWith("nostr:")) return false
val fingerprint = verificationHandler.getPeerFingerprintForDisplay(peerID)
@@ -799,10 +803,6 @@ class ChatViewModel(
fun hideMeshPeerList() {
state.setShowMeshPeerList(false)
if (state.getPrivateChatSheetPeerValue() != null) {
endPrivateChat()
}
hidePrivateChatSheet()
}
fun showPrivateChatSheet(peerID: String) {
@@ -280,6 +280,7 @@ class GeohashViewModel(
}
fun displayNameForNostrPubkeyUI(pubkeyHex: String): String = repo.displayNameForNostrPubkeyUI(pubkeyHex)
fun displayNameForGeohashConversation(pubkeyHex: String, sourceGeohash: String): String = repo.displayNameForGeohashConversation(pubkeyHex, sourceGeohash)
fun colorForNostrPubkey(pubkeyHex: String, isDark: Boolean): androidx.compose.ui.graphics.Color {
val seed = "nostr:${pubkeyHex.lowercase()}"
@@ -29,6 +29,8 @@ import com.bitchat.android.core.ui.component.button.CloseButton
import com.bitchat.android.core.ui.component.sheet.BitchatBottomSheet
import com.bitchat.android.geohash.ChannelID
import com.bitchat.android.ui.theme.BASE_FONT_SIZE
import com.bitchat.android.nostr.GeohashAliasRegistry
import com.bitchat.android.nostr.GeohashConversationRegistry
/**
@@ -122,6 +124,7 @@ fun MeshPeerListSheet(
peerNicknames.entries.firstOrNull { it.value == peerName }?.key
if (peerID != null) {
viewModel.showPrivateChatSheet(peerID)
onDismiss()
}
} else {
// Regular channel switch
@@ -158,9 +161,10 @@ fun MeshPeerListSheet(
colorScheme = colorScheme,
selectedPrivatePeer = selectedPrivatePeer,
viewModel = viewModel,
onPrivateChatStart = { peerID ->
viewModel.showPrivateChatSheet(peerID)
}
onPrivateChatStart = { peerID ->
viewModel.showPrivateChatSheet(peerID)
onDismiss()
}
)
}
}
@@ -785,11 +789,28 @@ fun PrivateChatSheet(
viewModel.startPrivateChat(peerID)
}
val isNostrPeer = peerID.startsWith("nostr_") || peerID.startsWith("nostr:")
// Compute display name and title text reactively
val displayName = peerNicknames[peerID] ?: peerID.take(12)
val titleText = remember(peerID, peerNicknames) {
if (isNostrPeer) {
val gh = GeohashConversationRegistry.get(peerID) ?: "geohash"
val fullPubkey = GeohashAliasRegistry.get(peerID) ?: ""
val name = if (fullPubkey.isNotEmpty()) {
viewModel.geohashViewModel.displayNameForGeohashConversation(fullPubkey, gh)
} else {
peerNicknames[peerID] ?: "unknown"
}
"#$gh/@$name"
} else {
peerNicknames[peerID] ?: peerID.take(12)
}
}
val messages = privateChats[peerID] ?: emptyList()
val isDirect = peerDirectMap[peerID] == true
val isConnected = connectedPeers.contains(peerID) || isDirect
val isNostrPeer = peerID.startsWith("nostr_") || peerID.startsWith("nostr:")
val sessionState = peerSessionStates[peerID]
val fingerprint = peerFingerprints[peerID]
val isFavorite = remember(favoritePeers, fingerprint) {
@@ -945,12 +966,12 @@ fun PrivateChatSheet(
}
Text(
text = displayName,
text = titleText,
style = MaterialTheme.typography.titleMedium.copy(
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.Monospace
),
color = colorScheme.onSurface
color = if (isNostrPeer) Color(0xFFFF9500) else colorScheme.onSurface
)
Row(
@@ -476,6 +476,12 @@ class PrivateChatManager(
unread.add(targetPeerID)
state.setUnreadPrivateMessages(unread)
}
// If we're currently viewing one of the temp aliases in the sheet, switch to the permanent ID
val sheetPeer = state.getPrivateChatSheetPeerValue()
if (sheetPeer != null && tryMergeKeys.contains(sheetPeer)) {
state.setPrivateChatSheetPeer(targetPeerID)
}
}
}