mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 04:05:21 +00:00
Fix/nostr dm bottom sheet (#598)
* nostr in new dm sheets * open sheet for nostr peers
This commit is contained in:
@@ -76,7 +76,12 @@ object ConversationAliasResolver {
|
|||||||
if (selected != null && keysToMerge.contains(selected)) {
|
if (selected != null && keysToMerge.contains(selected)) {
|
||||||
state.setSelectedPrivateChatPeer(targetPeerID)
|
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 ->
|
).also { canonical ->
|
||||||
if (canonical != state.getSelectedPrivateChatPeerValue()) {
|
if (canonical != state.getSelectedPrivateChatPeerValue()) {
|
||||||
privateChatManager.startPrivateChat(canonical, meshService)
|
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
|
// Send private message
|
||||||
@@ -799,10 +803,6 @@ class ChatViewModel(
|
|||||||
|
|
||||||
fun hideMeshPeerList() {
|
fun hideMeshPeerList() {
|
||||||
state.setShowMeshPeerList(false)
|
state.setShowMeshPeerList(false)
|
||||||
if (state.getPrivateChatSheetPeerValue() != null) {
|
|
||||||
endPrivateChat()
|
|
||||||
}
|
|
||||||
hidePrivateChatSheet()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showPrivateChatSheet(peerID: String) {
|
fun showPrivateChatSheet(peerID: String) {
|
||||||
|
|||||||
@@ -280,6 +280,7 @@ class GeohashViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun displayNameForNostrPubkeyUI(pubkeyHex: String): String = repo.displayNameForNostrPubkeyUI(pubkeyHex)
|
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 {
|
fun colorForNostrPubkey(pubkeyHex: String, isDark: Boolean): androidx.compose.ui.graphics.Color {
|
||||||
val seed = "nostr:${pubkeyHex.lowercase()}"
|
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.core.ui.component.sheet.BitchatBottomSheet
|
||||||
import com.bitchat.android.geohash.ChannelID
|
import com.bitchat.android.geohash.ChannelID
|
||||||
import com.bitchat.android.ui.theme.BASE_FONT_SIZE
|
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
|
peerNicknames.entries.firstOrNull { it.value == peerName }?.key
|
||||||
if (peerID != null) {
|
if (peerID != null) {
|
||||||
viewModel.showPrivateChatSheet(peerID)
|
viewModel.showPrivateChatSheet(peerID)
|
||||||
|
onDismiss()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular channel switch
|
// Regular channel switch
|
||||||
@@ -160,6 +163,7 @@ fun MeshPeerListSheet(
|
|||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onPrivateChatStart = { peerID ->
|
onPrivateChatStart = { peerID ->
|
||||||
viewModel.showPrivateChatSheet(peerID)
|
viewModel.showPrivateChatSheet(peerID)
|
||||||
|
onDismiss()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -785,11 +789,28 @@ fun PrivateChatSheet(
|
|||||||
viewModel.startPrivateChat(peerID)
|
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 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 messages = privateChats[peerID] ?: emptyList()
|
||||||
val isDirect = peerDirectMap[peerID] == true
|
val isDirect = peerDirectMap[peerID] == true
|
||||||
val isConnected = connectedPeers.contains(peerID) || isDirect
|
val isConnected = connectedPeers.contains(peerID) || isDirect
|
||||||
val isNostrPeer = peerID.startsWith("nostr_") || peerID.startsWith("nostr:")
|
|
||||||
val sessionState = peerSessionStates[peerID]
|
val sessionState = peerSessionStates[peerID]
|
||||||
val fingerprint = peerFingerprints[peerID]
|
val fingerprint = peerFingerprints[peerID]
|
||||||
val isFavorite = remember(favoritePeers, fingerprint) {
|
val isFavorite = remember(favoritePeers, fingerprint) {
|
||||||
@@ -945,12 +966,12 @@ fun PrivateChatSheet(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = displayName,
|
text = titleText,
|
||||||
style = MaterialTheme.typography.titleMedium.copy(
|
style = MaterialTheme.typography.titleMedium.copy(
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
fontFamily = FontFamily.Monospace
|
fontFamily = FontFamily.Monospace
|
||||||
),
|
),
|
||||||
color = colorScheme.onSurface
|
color = if (isNostrPeer) Color(0xFFFF9500) else colorScheme.onSurface
|
||||||
)
|
)
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -476,6 +476,12 @@ class PrivateChatManager(
|
|||||||
unread.add(targetPeerID)
|
unread.add(targetPeerID)
|
||||||
state.setUnreadPrivateMessages(unread)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user