diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/NostrEventDetailScreen.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/NostrEventDetailScreen.kt index 205f0fb6..845bce53 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/NostrEventDetailScreen.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/NostrEventDetailScreen.kt @@ -39,6 +39,7 @@ fun NostrEventDetailScreen( nostrRepository: NostrRepository, onNavigateBack: () -> Unit, onNavigateToEvent: (Route) -> Unit, + onNavigateToDirectMessage: (Route) -> Unit, onNavigateToEditProfile: () -> Unit, onNavigateToWriteAReply: (String) -> Unit, onNavigateToQuoteNostrEvent: (String) -> Unit, @@ -69,6 +70,7 @@ fun NostrEventDetailScreen( localNostrEvent = feedListUIState.localNostrEvent, onNavigateBack = onNavigateBack, onNavigateToEvent = onNavigateToEvent, + onNavigateToChatRoom = onNavigateToDirectMessage, onNavigateToEditProfile = onNavigateToEditProfile, nostrRepository = nostrRepository ) @@ -167,7 +169,8 @@ It has survived not only five centuries, but also the leap into electronic types onNavigateToEvent = {}, onNavigateToWriteAReply = {}, onNavigateToEditProfile = {}, - onNavigateToQuoteNostrEvent = {} + onNavigateToQuoteNostrEvent = {}, + onNavigateToDirectMessage = {} ) } } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/navigation/AuxNavHost.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/navigation/AuxNavHost.kt index 05d16c05..8e3a90c1 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/navigation/AuxNavHost.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/navigation/AuxNavHost.kt @@ -423,7 +423,12 @@ fun AuxNavHost( quotedEventId = nostrEventId ) ) - } + }, + onNavigateToDirectMessage = { route -> + navController.navigate( + route = route + ) + }, ) } composable { backStackEntry -> diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt index 788473ec..f710aa9e 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/composable/widgets/detail/MetadataEventDetail.kt @@ -4,6 +4,7 @@ import ac.cord.auxiliary.compose.database.model.NostrEvent import ac.cord.auxiliary.compose.database.model.Profile import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent import ac.cord.auxiliary.compose.repository.NostrRepository +import ac.cord.auxiliary.compose.ui.composable.navigation.routes.ImplementationPendingRoute import ac.cord.auxiliary.compose.ui.composable.navigation.routes.Route import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileAvatar import ac.cord.auxiliary.compose.ui.theme.AuxTheme @@ -27,11 +28,11 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBackIosNew import androidx.compose.material.icons.filled.Bolt import androidx.compose.material.icons.filled.Error +import androidx.compose.material.icons.filled.Mail import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi @@ -52,7 +53,6 @@ import androidx.compose.runtime.key import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -69,6 +69,7 @@ fun MetadataEventDetail( onNavigateBack: () -> Unit, onNavigateToEvent: (Route) -> Unit, onNavigateToEditProfile: () -> Unit, + onNavigateToChatRoom: (Route) -> Unit, nostrRepository: NostrRepository ) { val scope = rememberCoroutineScope() @@ -162,6 +163,20 @@ fun MetadataEventDetail( modifier = Modifier.weight(1f) ) + if (!metadataEventDetailViewModel.isActiveUser()) { + IconButton( + onClick = { + onNavigateToChatRoom.invoke( + ImplementationPendingRoute("Direct message") + ) + } + ) { + Icon( + Icons.Default.Mail, + contentDescription = "Direct Message" + ) + } + } when(val metadataEventDetailUIState = metadataEventDetailViewModel.metadataEventDetailUIState) { @@ -383,6 +398,7 @@ private fun MetadataEventEventDetailPreview() { onNavigateBack = {}, onNavigateToEvent = {}, onNavigateToEditProfile = {}, + onNavigateToChatRoom = {}, nostrRepository = NostrRepository.NO_OP_NOSTR_REPOSITORY ) } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt index dcb96625..df70b6bb 100755 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt @@ -74,7 +74,7 @@ class MetadataEventDetailViewModel( logger.d("We found relations: $relations") metadataEventDetailUIState = MetadataEventDetailUIState.Loaded( - isActiveUser = activePublicKey == publicKey, + isActiveUser = isActiveUser(activePublicKey), followingActiveUserConnection = relations.find { connection -> connection.sourcePublicKey == publicKey && connection.destinationPublicKey == activePublicKey }, followedByActiveUserConnection = relations.find { connection -> connection.sourcePublicKey == activePublicKey && connection.destinationPublicKey == publicKey } ) @@ -87,6 +87,18 @@ class MetadataEventDetailViewModel( } } + fun isActiveUser(activePublicKey: HexKey): Boolean { + return activePublicKey == publicKey + } + + fun isActiveUser(): Boolean { + val activePublicKey = SeedManager.activePublicKey().toHexKey() + + return isActiveUser( + activePublicKey = activePublicKey + ) + } + fun getSynchronizationFilter( metadataEventDetailType: MetadataEventDetailType ) = when (metadataEventDetailType) {