diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt index c3fed36fb..7ec9b35e1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt @@ -151,6 +151,7 @@ fun AppNavigation( PublicChatChannelScreen( it.id, it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) }, + it.replyTo?.let { hex -> accountViewModel.checkGetOrCreateNote(hex) }, accountViewModel, nav, ) @@ -160,6 +161,7 @@ fun AppNavigation( LiveActivityChannelScreen( Address(it.kind, it.pubKeyHex, it.dTag), draft = it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) }, + replyTo = it.replyTo?.let { hex -> accountViewModel.checkGetOrCreateNote(hex) }, accountViewModel, nav, ) @@ -170,6 +172,7 @@ fun AppNavigation( EphemeralChatScreen( channelId = RoomId(it.id, relay), draft = it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) }, + replyTo = it.replyTo?.let { hex -> accountViewModel.checkGetOrCreateNote(hex) }, accountViewModel = accountViewModel, nav = nav, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/RouteMaker.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/RouteMaker.kt index 8c5e24612..c69bc5e63 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/RouteMaker.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/RouteMaker.kt @@ -215,6 +215,21 @@ fun routeReplyTo( ): Route? { val noteEvent = note.event return when (noteEvent) { + is ChannelMessageEvent -> { + noteEvent.channelId()?.let { channelId -> + Route.PublicChatChannel(channelId, replyTo = note.idHex) + } + } + is LiveActivitiesChatMessageEvent -> { + noteEvent.activityAddress()?.let { + Route.LiveActivityChannel(it.kind, it.pubKeyHex, it.dTag, replyTo = note.idHex) + } + } + is EphemeralChatEvent -> { + noteEvent.roomId()?.let { + Route.EphemeralChat(it.id, it.relayUrl.url, replyTo = note.idHex) + } + } is PublicMessageEvent -> Route.NewPublicMessage( users = noteEvent.groupKeySet() - account.userProfile().pubkeyHex, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt index 9f06f4b15..94b9651db 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/routes/Routes.kt @@ -91,6 +91,7 @@ sealed class Route { @Serializable data class PublicChatChannel( val id: String, val draftId: HexKey? = null, + val replyTo: HexKey? = null, ) : Route() @Serializable data class LiveActivityChannel( @@ -98,6 +99,7 @@ sealed class Route { val pubKeyHex: HexKey, val dTag: String, val draftId: HexKey? = null, + val replyTo: HexKey? = null, ) : Route() @Serializable data class RelayInfo( @@ -108,6 +110,7 @@ sealed class Route { val id: String, val relayUrl: String, val draftId: HexKey? = null, + val replyTo: HexKey? = null, ) : Route() @Serializable object NewEphemeralChat : Route() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt index f6a67ae18..c4e634e7f 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/AccountViewModel.kt @@ -967,7 +967,7 @@ class AccountViewModel( fun getUserIfExists(hex: HexKey): User? = LocalCache.getUserIfExists(hex) - private fun checkGetOrCreateNote(key: HexKey): Note? = LocalCache.checkGetOrCreateNote(key) + fun checkGetOrCreateNote(key: HexKey): Note? = LocalCache.checkGetOrCreateNote(key) override suspend fun getOrCreateNote(key: HexKey): Note = LocalCache.getOrCreateNote(key) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/ChannelView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/ChannelView.kt index dcce16c5c..2a8adefca 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/ChannelView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/ChannelView.kt @@ -47,6 +47,7 @@ import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId fun EphemeralChatChannelView( channelId: RoomId?, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -56,6 +57,7 @@ fun EphemeralChatChannelView( PrepareChannelViewModels( baseChannel = ephem, draft = draft, + replyTo = replyTo, accountViewModel = accountViewModel, nav = nav, ) @@ -66,6 +68,7 @@ fun EphemeralChatChannelView( private fun PrepareChannelViewModels( baseChannel: EphemeralChatChannel, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -89,6 +92,12 @@ private fun PrepareChannelViewModels( } } + if (replyTo != null) { + LaunchedEffect(replyTo, channelScreenModel, accountViewModel) { + channelScreenModel.reply(replyTo) + } + } + ChannelView( channel = baseChannel, feedViewModel = feedViewModel, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/EphemeralChatScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/EphemeralChatScreen.kt index 49144b988..3811b92db 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/EphemeralChatScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/ephemChat/EphemeralChatScreen.kt @@ -36,6 +36,7 @@ import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId fun EphemeralChatScreen( channelId: RoomId, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -49,7 +50,7 @@ fun EphemeralChatScreen( accountViewModel = accountViewModel, ) { Column(Modifier.padding(it).statusBarsPadding()) { - EphemeralChatChannelView(channelId, draft, accountViewModel, nav) + EphemeralChatChannelView(channelId, draft, replyTo, accountViewModel, nav) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/ChannelView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/ChannelView.kt index aa0371fdc..89f03d6b4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/ChannelView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/ChannelView.kt @@ -47,6 +47,7 @@ import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer fun PublicChatChannelView( channelId: String?, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -56,6 +57,7 @@ fun PublicChatChannelView( PrepareChannelViewModels( baseChannel = it, draft = draft, + replyTo = replyTo, accountViewModel = accountViewModel, nav = nav, ) @@ -66,6 +68,7 @@ fun PublicChatChannelView( fun PrepareChannelViewModels( baseChannel: PublicChatChannel, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -89,6 +92,12 @@ fun PrepareChannelViewModels( } } + if (replyTo != null) { + LaunchedEffect(replyTo, channelScreenModel, accountViewModel) { + channelScreenModel.reply(replyTo) + } + } + ChannelView( channel = baseChannel, feedViewModel = feedViewModel, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/PublicChatChannelScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/PublicChatChannelScreen.kt index 1a08e226f..e8c2f8157 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/PublicChatChannelScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip28PublicChat/PublicChatChannelScreen.kt @@ -37,6 +37,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey fun PublicChatChannelScreen( channelId: HexKey?, draft: Note?, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -52,7 +53,7 @@ fun PublicChatChannelScreen( accountViewModel = accountViewModel, ) { Column(Modifier.padding(it).statusBarsPadding()) { - PublicChatChannelView(channelId, draft, accountViewModel, nav) + PublicChatChannelView(channelId, draft, replyTo, accountViewModel, nav) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/ChannelView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/ChannelView.kt index bb54a6f3f..e147ad2c1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/ChannelView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/ChannelView.kt @@ -47,6 +47,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address fun LiveActivityChannelView( channelId: Address?, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -56,6 +57,7 @@ fun LiveActivityChannelView( PrepareChannelViewModels( baseChannel = it, draft = draft, + replyTo = replyTo, accountViewModel = accountViewModel, nav = nav, ) @@ -66,6 +68,7 @@ fun LiveActivityChannelView( fun PrepareChannelViewModels( baseChannel: LiveActivitiesChannel, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -89,6 +92,12 @@ fun PrepareChannelViewModels( } } + if (replyTo != null) { + LaunchedEffect(replyTo, channelScreenModel, accountViewModel) { + channelScreenModel.reply(replyTo) + } + } + LiveActivityChannelView( channel = baseChannel, feedViewModel = feedViewModel, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LiveActivityChannelScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LiveActivityChannelScreen.kt index 4db210440..cef2058a1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LiveActivityChannelScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LiveActivityChannelScreen.kt @@ -38,6 +38,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address fun LiveActivityChannelScreen( channelId: Address?, draft: Note? = null, + replyTo: Note? = null, accountViewModel: AccountViewModel, nav: INav, ) { @@ -58,7 +59,7 @@ fun LiveActivityChannelScreen( accountViewModel = accountViewModel, ) { Column(Modifier.padding(it)) { - LiveActivityChannelView(channelId, draft, accountViewModel, nav) + LiveActivityChannelView(channelId, draft, replyTo, accountViewModel, nav) } } }