Fixes reply routes when clicking in the Conversations tab when the event is a PublicChat, LiveStream or Ephemeral Chat

This commit is contained in:
Vitor Pamplona
2025-09-09 10:28:49 -04:00
parent d25e6cd07b
commit f00207d53c
10 changed files with 55 additions and 4 deletions

View File

@@ -151,6 +151,7 @@ fun AppNavigation(
PublicChatChannelScreen( PublicChatChannelScreen(
it.id, it.id,
it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) }, it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) },
it.replyTo?.let { hex -> accountViewModel.checkGetOrCreateNote(hex) },
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -160,6 +161,7 @@ fun AppNavigation(
LiveActivityChannelScreen( LiveActivityChannelScreen(
Address(it.kind, it.pubKeyHex, it.dTag), Address(it.kind, it.pubKeyHex, it.dTag),
draft = it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) }, draft = it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) },
replyTo = it.replyTo?.let { hex -> accountViewModel.checkGetOrCreateNote(hex) },
accountViewModel, accountViewModel,
nav, nav,
) )
@@ -170,6 +172,7 @@ fun AppNavigation(
EphemeralChatScreen( EphemeralChatScreen(
channelId = RoomId(it.id, relay), channelId = RoomId(it.id, relay),
draft = it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) }, draft = it.draftId?.let { hex -> accountViewModel.getNoteIfExists(hex) },
replyTo = it.replyTo?.let { hex -> accountViewModel.checkGetOrCreateNote(hex) },
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )

View File

@@ -215,6 +215,21 @@ fun routeReplyTo(
): Route? { ): Route? {
val noteEvent = note.event val noteEvent = note.event
return when (noteEvent) { 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 -> is PublicMessageEvent ->
Route.NewPublicMessage( Route.NewPublicMessage(
users = noteEvent.groupKeySet() - account.userProfile().pubkeyHex, users = noteEvent.groupKeySet() - account.userProfile().pubkeyHex,

View File

@@ -91,6 +91,7 @@ sealed class Route {
@Serializable data class PublicChatChannel( @Serializable data class PublicChatChannel(
val id: String, val id: String,
val draftId: HexKey? = null, val draftId: HexKey? = null,
val replyTo: HexKey? = null,
) : Route() ) : Route()
@Serializable data class LiveActivityChannel( @Serializable data class LiveActivityChannel(
@@ -98,6 +99,7 @@ sealed class Route {
val pubKeyHex: HexKey, val pubKeyHex: HexKey,
val dTag: String, val dTag: String,
val draftId: HexKey? = null, val draftId: HexKey? = null,
val replyTo: HexKey? = null,
) : Route() ) : Route()
@Serializable data class RelayInfo( @Serializable data class RelayInfo(
@@ -108,6 +110,7 @@ sealed class Route {
val id: String, val id: String,
val relayUrl: String, val relayUrl: String,
val draftId: HexKey? = null, val draftId: HexKey? = null,
val replyTo: HexKey? = null,
) : Route() ) : Route()
@Serializable object NewEphemeralChat : Route() @Serializable object NewEphemeralChat : Route()

View File

@@ -967,7 +967,7 @@ class AccountViewModel(
fun getUserIfExists(hex: HexKey): User? = LocalCache.getUserIfExists(hex) 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) override suspend fun getOrCreateNote(key: HexKey): Note = LocalCache.getOrCreateNote(key)

View File

@@ -47,6 +47,7 @@ import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
fun EphemeralChatChannelView( fun EphemeralChatChannelView(
channelId: RoomId?, channelId: RoomId?,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -56,6 +57,7 @@ fun EphemeralChatChannelView(
PrepareChannelViewModels( PrepareChannelViewModels(
baseChannel = ephem, baseChannel = ephem,
draft = draft, draft = draft,
replyTo = replyTo,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -66,6 +68,7 @@ fun EphemeralChatChannelView(
private fun PrepareChannelViewModels( private fun PrepareChannelViewModels(
baseChannel: EphemeralChatChannel, baseChannel: EphemeralChatChannel,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -89,6 +92,12 @@ private fun PrepareChannelViewModels(
} }
} }
if (replyTo != null) {
LaunchedEffect(replyTo, channelScreenModel, accountViewModel) {
channelScreenModel.reply(replyTo)
}
}
ChannelView( ChannelView(
channel = baseChannel, channel = baseChannel,
feedViewModel = feedViewModel, feedViewModel = feedViewModel,

View File

@@ -36,6 +36,7 @@ import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
fun EphemeralChatScreen( fun EphemeralChatScreen(
channelId: RoomId, channelId: RoomId,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -49,7 +50,7 @@ fun EphemeralChatScreen(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) { ) {
Column(Modifier.padding(it).statusBarsPadding()) { Column(Modifier.padding(it).statusBarsPadding()) {
EphemeralChatChannelView(channelId, draft, accountViewModel, nav) EphemeralChatChannelView(channelId, draft, replyTo, accountViewModel, nav)
} }
} }
} }

View File

@@ -47,6 +47,7 @@ import com.vitorpamplona.amethyst.ui.theme.DoubleVertSpacer
fun PublicChatChannelView( fun PublicChatChannelView(
channelId: String?, channelId: String?,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -56,6 +57,7 @@ fun PublicChatChannelView(
PrepareChannelViewModels( PrepareChannelViewModels(
baseChannel = it, baseChannel = it,
draft = draft, draft = draft,
replyTo = replyTo,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -66,6 +68,7 @@ fun PublicChatChannelView(
fun PrepareChannelViewModels( fun PrepareChannelViewModels(
baseChannel: PublicChatChannel, baseChannel: PublicChatChannel,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -89,6 +92,12 @@ fun PrepareChannelViewModels(
} }
} }
if (replyTo != null) {
LaunchedEffect(replyTo, channelScreenModel, accountViewModel) {
channelScreenModel.reply(replyTo)
}
}
ChannelView( ChannelView(
channel = baseChannel, channel = baseChannel,
feedViewModel = feedViewModel, feedViewModel = feedViewModel,

View File

@@ -37,6 +37,7 @@ import com.vitorpamplona.quartz.nip01Core.core.HexKey
fun PublicChatChannelScreen( fun PublicChatChannelScreen(
channelId: HexKey?, channelId: HexKey?,
draft: Note?, draft: Note?,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -52,7 +53,7 @@ fun PublicChatChannelScreen(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) { ) {
Column(Modifier.padding(it).statusBarsPadding()) { Column(Modifier.padding(it).statusBarsPadding()) {
PublicChatChannelView(channelId, draft, accountViewModel, nav) PublicChatChannelView(channelId, draft, replyTo, accountViewModel, nav)
} }
} }
} }

View File

@@ -47,6 +47,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
fun LiveActivityChannelView( fun LiveActivityChannelView(
channelId: Address?, channelId: Address?,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -56,6 +57,7 @@ fun LiveActivityChannelView(
PrepareChannelViewModels( PrepareChannelViewModels(
baseChannel = it, baseChannel = it,
draft = draft, draft = draft,
replyTo = replyTo,
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
nav = nav, nav = nav,
) )
@@ -66,6 +68,7 @@ fun LiveActivityChannelView(
fun PrepareChannelViewModels( fun PrepareChannelViewModels(
baseChannel: LiveActivitiesChannel, baseChannel: LiveActivitiesChannel,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -89,6 +92,12 @@ fun PrepareChannelViewModels(
} }
} }
if (replyTo != null) {
LaunchedEffect(replyTo, channelScreenModel, accountViewModel) {
channelScreenModel.reply(replyTo)
}
}
LiveActivityChannelView( LiveActivityChannelView(
channel = baseChannel, channel = baseChannel,
feedViewModel = feedViewModel, feedViewModel = feedViewModel,

View File

@@ -38,6 +38,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
fun LiveActivityChannelScreen( fun LiveActivityChannelScreen(
channelId: Address?, channelId: Address?,
draft: Note? = null, draft: Note? = null,
replyTo: Note? = null,
accountViewModel: AccountViewModel, accountViewModel: AccountViewModel,
nav: INav, nav: INav,
) { ) {
@@ -58,7 +59,7 @@ fun LiveActivityChannelScreen(
accountViewModel = accountViewModel, accountViewModel = accountViewModel,
) { ) {
Column(Modifier.padding(it)) { Column(Modifier.padding(it)) {
LiveActivityChannelView(channelId, draft, accountViewModel, nav) LiveActivityChannelView(channelId, draft, replyTo, accountViewModel, nav)
} }
} }
} }