mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-04-25 12:02:13 +00:00
fix: jump to quoted message in search and content filter (#6721)
* fix: jump to quoted message in search and content filter
When tapping a quoted message during search or content filter,
scrollToItem bailed out silently instead of navigating to the message.
Load around the target without search/filter params using
openAroundItemId, which closes search/filter and positions at the
target.
Fixes the overly broad guard added in 219381f9 (#5315).
* remove logs
---------
Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com>
This commit is contained in:
@@ -813,7 +813,6 @@ fun ChatView(
|
||||
|
||||
fun updateAvailableContent(chatRh: Long?, activeChat: State<Chat?>, availableContent: MutableState<List<ContentFilter>>) {
|
||||
withBGApi {
|
||||
Log.e(TAG, "updateAvailableContent")
|
||||
val chatInfo = activeChat.value?.chatInfo
|
||||
if (chatInfo == null) return@withBGApi
|
||||
val types = chatModel.controller.apiGetChatContentTypes(chatRh, chatInfo.chatType, chatInfo.apiId, null)
|
||||
@@ -822,7 +821,6 @@ fun updateAvailableContent(chatRh: Long?, activeChat: State<Chat?>, availableCon
|
||||
availableContent.value = ContentFilter.entries
|
||||
} else {
|
||||
val typeSet: Set<MsgContentTag> = types.union(ContentFilter.alwaysShow)
|
||||
Log.e(TAG, "updateAvailableContent $typeSet")
|
||||
availableContent.value = ContentFilter.entries.filter { it -> typeSet.contains(it.contentTag) }
|
||||
}
|
||||
}
|
||||
@@ -1826,7 +1824,7 @@ fun BoxScope.ChatItemsList(
|
||||
val chatInfoUpdated = rememberUpdatedState(chatInfo)
|
||||
val scope = rememberCoroutineScope()
|
||||
val scrollToItem: (Long) -> Unit = remember {
|
||||
scrollToItem(searchValue, loadingMoreItems, animatedScrollingInProgress, highlightedItems, chatInfoUpdated, maxHeight, scope, reversedChatItems, mergedItems, listState, loadMessages)
|
||||
scrollToItem(chatsCtx, remoteHostIdUpdated, searchValue, contentFilter, loadingMoreItems, animatedScrollingInProgress, highlightedItems, chatInfoUpdated, maxHeight, scope, reversedChatItems, mergedItems, listState, loadMessages)
|
||||
}
|
||||
val scrollToQuotedItemFromItem: (Long) -> Unit = remember { findQuotedItemFromItem(chatsCtx, remoteHostIdUpdated, chatInfoUpdated, scope, scrollToItem, scrollToItemId) }
|
||||
if (chatsCtx.secondaryContextFilter == null) {
|
||||
@@ -2971,7 +2969,10 @@ private fun lastFullyVisibleIemInListState(topPaddingToContentPx: State<Int>, de
|
||||
}
|
||||
|
||||
private fun scrollToItem(
|
||||
chatsCtx: ChatModel.ChatsContext,
|
||||
remoteHostId: State<Long?>,
|
||||
searchValue: State<String>,
|
||||
contentFilter: State<ContentFilter?>,
|
||||
loadingMoreItems: MutableState<Boolean>,
|
||||
animatedScrollingInProgress: MutableState<Boolean>,
|
||||
highlightedItems: MutableState<Set<Long>>,
|
||||
@@ -2986,8 +2987,13 @@ private fun scrollToItem(
|
||||
withApi {
|
||||
try {
|
||||
var index = mergedItems.value.indexInParentItems[itemId] ?: -1
|
||||
// Don't try to load messages while in search
|
||||
if (index == -1 && searchValue.value.isNotBlank()) return@withApi
|
||||
if (index == -1 && (searchValue.value.isNotBlank() || contentFilter.value != null)) {
|
||||
val ci = chatInfo.value
|
||||
apiLoadMessages(chatsCtx, remoteHostId.value, ci.chatType, ci.apiId,
|
||||
ChatPagination.Around(itemId, ChatPagination.PRELOAD_COUNT * 2),
|
||||
openAroundItemId = itemId)
|
||||
return@withApi
|
||||
}
|
||||
// setting it to 'loading' even if the item is loaded because in rare cases when the resulting item is near the top, scrolling to
|
||||
// it will trigger loading more items and will scroll to incorrect position (because of trimming)
|
||||
loadingMoreItems.value = true
|
||||
|
||||
Reference in New Issue
Block a user