This commit is contained in:
Diogo
2025-01-20 16:06:50 +00:00
committed by Evgeny Poberezkin
parent ad7a39b0c7
commit c65cd8ac72
3 changed files with 24 additions and 10 deletions
@@ -190,7 +190,7 @@ fun ChatInfoView(
},
close = close,
onSearchClicked = onSearchClicked,
enabled = remember { derivedStateOf { !progressIndicator.value } }
disabled = progressIndicator
)
if (progressIndicator.value) {
@@ -544,7 +544,7 @@ fun ChatInfoLayout(
verifyClicked: () -> Unit,
close: () -> Unit,
onSearchClicked: () -> Unit,
enabled: State<Boolean>
disabled: State<Boolean>
) {
val cStats = connStats.value
val scrollState = rememberScrollState()
@@ -552,7 +552,7 @@ fun ChatInfoLayout(
KeyChangeEffect(chat.id) {
scope.launch { scrollState.scrollTo(0) }
}
ColumnWithScrollBar(Modifier.alpha(if (enabled.value) 1f else 0.6f)) {
ColumnWithScrollBar(Modifier.alpha(if (disabled.value) 0.6f else 1f)) {
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
@@ -1394,7 +1394,16 @@ private fun afterSetChatTTL(m: ChatModel, chatInfo: ChatInfo, progressIndicator:
withApi {
try {
// this is using current remote host on purpose - if it changes during update, it will load correct chats
apiLoadMessages(m.remoteHostId(), chatInfo.chatType, chatInfo.apiId, contentTag = null, pagination = ChatPagination.Initial(ChatPagination.INITIAL_COUNT), replaceChat = true)
// redirectDisabled is set to true to prevent redirecting the current chat/chat items in case the chat changes while messages were updating
apiLoadMessages(
m.remoteHostId(),
chatInfo.chatType,
chatInfo.apiId,
contentTag = null,
pagination = ChatPagination.Initial(ChatPagination.INITIAL_COUNT),
replaceChat = true,
redirectDisabled = true
)
} catch (e: Exception) {
Log.e(TAG, "apiGetChat error: ${e.message}")
} finally {
@@ -1436,7 +1445,7 @@ fun PreviewChatInfoLayout() {
verifyClicked = {},
close = {},
onSearchClicked = {},
enabled = remember { mutableStateOf(true) }
disabled = remember { mutableStateOf(true) }
)
}
}
@@ -29,7 +29,8 @@ suspend fun apiLoadMessages(
pagination: ChatPagination,
search: String = "",
visibleItemIndexesNonReversed: () -> IntRange = { 0 .. 0 },
replaceChat: Boolean = false
replaceChat: Boolean = false,
redirectDisabled: Boolean = false
) = coroutineScope {
val (chat, navInfo) = chatModel.controller.apiGetChat(rhId, chatType, apiId, contentTag, pagination, search) ?: return@coroutineScope
// For .initial allow the chatItems to be empty as well as chatModel.chatId to not match this chat because these values become set after .initial finishes
@@ -57,6 +58,10 @@ suspend fun apiLoadMessages(
}
}
withChats(contentTag) {
if (redirectDisabled && chatModel.chatId.value != chat.id) {
// redirect is disabled, but the chat is not the current one, so don't update it
return@withChats
}
chatItemStatuses.clear()
chatItems.replaceAll(chat.chatItems)
chatModel.chatId.value = chat.chatInfo.id
@@ -141,7 +141,7 @@ fun ModalData.GroupChatInfoView(chatModel: ChatModel, rhId: Long?, chatId: Strin
ModalManager.end.showModal { GroupLinkView(chatModel, rhId, groupInfo, groupLink, groupLinkMemberRole, onGroupLinkUpdated) }
},
onSearchClicked = onSearchClicked,
enabled = remember { derivedStateOf { !progressIndicator.value } }
disabled = progressIndicator
)
if (progressIndicator.value) {
@@ -323,7 +323,7 @@ fun ModalData.GroupChatInfoLayout(
manageGroupLink: () -> Unit,
close: () -> Unit = { ModalManager.closeAllModalsEverywhere()},
onSearchClicked: () -> Unit,
enabled: State<Boolean>
disabled: State<Boolean>
) {
val listState = remember { appBarHandler.listState }
val scope = rememberCoroutineScope()
@@ -337,7 +337,7 @@ fun ModalData.GroupChatInfoLayout(
if (s.isEmpty()) members else members.filter { m -> m.anyNameContains(s) }
}
}
Box(Modifier.alpha(if (enabled.value) 1f else 0.6f)) {
Box(Modifier.alpha(if (disabled.value) 0.6f else 1f)) {
val oneHandUI = remember { appPrefs.oneHandUI.state }
LazyColumnWithScrollBar(
state = listState,
@@ -811,7 +811,7 @@ fun PreviewGroupChatInfoLayout() {
onLocalAliasChanged = {},
groupLink = null,
scrollToItemId = remember { mutableStateOf(null) },
addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, addOrEditWelcomeMessage = {}, openPreferences = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {}, manageGroupLink = {}, onSearchClicked = {}, enabled = remember { mutableStateOf(true) }
addMembers = {}, showMemberInfo = {}, editGroupProfile = {}, addOrEditWelcomeMessage = {}, openPreferences = {}, deleteGroup = {}, clearChat = {}, leaveGroup = {}, manageGroupLink = {}, onSearchClicked = {}, disabled = remember { mutableStateOf(true) }
)
}
}