feat: scroll to replied message when clicking reply preview in chat
When a user clicks on the reply preview (inner quote) in a chat message, the chat feed now scrolls to the original replied-to message in the same screen instead of doing nothing. https://claude.ai/code/session_01UF4VxoWGvvvwtLYBLBYw9w
This commit is contained in:
+13
@@ -28,6 +28,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.vitorpamplona.amethyst.commons.ui.feeds.FeedContentState
|
import com.vitorpamplona.amethyst.commons.ui.feeds.FeedContentState
|
||||||
@@ -43,6 +44,7 @@ import com.vitorpamplona.amethyst.ui.screen.SaveableFeedState
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
import com.vitorpamplona.amethyst.ui.theme.FeedPadding
|
||||||
import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent
|
import com.vitorpamplona.quartz.nip37Drafts.DraftWrapEvent
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RefreshingChatroomFeedView(
|
fun RefreshingChatroomFeedView(
|
||||||
@@ -131,6 +133,16 @@ fun ChatFeedLoaded(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val onScrollToNote: (Note) -> Unit = { note ->
|
||||||
|
val index = items.list.indexOfFirst { it.idHex == note.idHex }
|
||||||
|
if (index >= 0) {
|
||||||
|
scope.launch {
|
||||||
|
listState.animateScrollToItem(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
contentPadding = FeedPadding,
|
contentPadding = FeedPadding,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
@@ -147,6 +159,7 @@ fun ChatFeedLoaded(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
onWantsToReply = onWantsToReply,
|
onWantsToReply = onWantsToReply,
|
||||||
onWantsToEditDraft = onWantsToEditDraft,
|
onWantsToEditDraft = onWantsToEditDraft,
|
||||||
|
onScrollToNote = onScrollToNote,
|
||||||
)
|
)
|
||||||
|
|
||||||
NewDateOrSubjectDivisor(items.list.getOrNull(index + 1), item)
|
NewDateOrSubjectDivisor(items.list.getOrNull(index + 1), item)
|
||||||
|
|||||||
+13
-1
@@ -95,6 +95,7 @@ fun ChatroomMessageCompose(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
onWantsToReply: (Note) -> Unit,
|
onWantsToReply: (Note) -> Unit,
|
||||||
onWantsToEditDraft: (Note) -> Unit,
|
onWantsToEditDraft: (Note) -> Unit,
|
||||||
|
onScrollToNote: ((Note) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
WatchNoteEvent(baseNote = baseNote, accountViewModel = accountViewModel, nav) {
|
WatchNoteEvent(baseNote = baseNote, accountViewModel = accountViewModel, nav) {
|
||||||
WatchBlockAndReport(
|
WatchBlockAndReport(
|
||||||
@@ -114,6 +115,7 @@ fun ChatroomMessageCompose(
|
|||||||
nav,
|
nav,
|
||||||
onWantsToReply,
|
onWantsToReply,
|
||||||
onWantsToEditDraft,
|
onWantsToEditDraft,
|
||||||
|
onScrollToNote,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,6 +132,7 @@ fun NormalChatNote(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
onWantsToReply: (Note) -> Unit,
|
onWantsToReply: (Note) -> Unit,
|
||||||
onWantsToEditDraft: (Note) -> Unit,
|
onWantsToEditDraft: (Note) -> Unit,
|
||||||
|
onScrollToNote: ((Note) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val isLoggedInUser =
|
val isLoggedInUser =
|
||||||
remember(note.author) {
|
remember(note.author) {
|
||||||
@@ -171,6 +174,9 @@ fun NormalChatNote(
|
|||||||
if (note.event is ChannelCreateEvent) {
|
if (note.event is ChannelCreateEvent) {
|
||||||
nav.nav(Route.PublicChatChannel(note.idHex))
|
nav.nav(Route.PublicChatChannel(note.idHex))
|
||||||
true
|
true
|
||||||
|
} else if (innerQuote && onScrollToNote != null) {
|
||||||
|
onScrollToNote(note)
|
||||||
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
@@ -253,6 +259,7 @@ fun NormalChatNote(
|
|||||||
canPreview,
|
canPreview,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
nav,
|
nav,
|
||||||
|
onScrollToNote,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -288,6 +295,7 @@ private fun MessageBubbleLines(
|
|||||||
canPreview: Boolean,
|
canPreview: Boolean,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: INav,
|
nav: INav,
|
||||||
|
onScrollToNote: ((Note) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (baseNote.event !is DraftWrapEvent) {
|
if (baseNote.event !is DraftWrapEvent) {
|
||||||
RenderReplyRow(
|
RenderReplyRow(
|
||||||
@@ -298,6 +306,7 @@ private fun MessageBubbleLines(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
onWantsToReply = onWantsToReply,
|
onWantsToReply = onWantsToReply,
|
||||||
onWantsToEditDraft = onWantsToEditDraft,
|
onWantsToEditDraft = onWantsToEditDraft,
|
||||||
|
onScrollToNote = onScrollToNote,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -334,9 +343,10 @@ fun RenderReplyRow(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
onWantsToReply: (Note) -> Unit,
|
onWantsToReply: (Note) -> Unit,
|
||||||
onWantsToEditDraft: (Note) -> Unit,
|
onWantsToEditDraft: (Note) -> Unit,
|
||||||
|
onScrollToNote: ((Note) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (!innerQuote && note.replyTo?.lastOrNull() != null) {
|
if (!innerQuote && note.replyTo?.lastOrNull() != null) {
|
||||||
RenderReply(note, bgColor, accountViewModel, nav, onWantsToReply, onWantsToEditDraft)
|
RenderReply(note, bgColor, accountViewModel, nav, onWantsToReply, onWantsToEditDraft, onScrollToNote)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,6 +358,7 @@ private fun RenderReply(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
onWantsToReply: (Note) -> Unit,
|
onWantsToReply: (Note) -> Unit,
|
||||||
onWantsToEditDraft: (Note) -> Unit,
|
onWantsToEditDraft: (Note) -> Unit,
|
||||||
|
onScrollToNote: ((Note) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
@Suppress("ProduceStateDoesNotAssignValue")
|
@Suppress("ProduceStateDoesNotAssignValue")
|
||||||
@@ -368,6 +379,7 @@ private fun RenderReply(
|
|||||||
nav = nav,
|
nav = nav,
|
||||||
onWantsToReply = onWantsToReply,
|
onWantsToReply = onWantsToReply,
|
||||||
onWantsToEditDraft = onWantsToEditDraft,
|
onWantsToEditDraft = onWantsToEditDraft,
|
||||||
|
onScrollToNote = onScrollToNote,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user