fix chatroom selection when filter change #LINQT-2199

This commit is contained in:
Gaelle Braud 2025-11-21 12:48:43 +01:00 committed by gaelle.braud
parent fea9a1b7be
commit 514c337192
6 changed files with 79 additions and 87 deletions

View file

@ -81,45 +81,32 @@ void EventLogList::connectItem(const QSharedPointer<EventLogCore> &item) {
}
void EventLogList::setChatCore(QSharedPointer<ChatCore> core) {
auto updateChatCore = [this](QSharedPointer<ChatCore> core) {
if (mChatCore != core) {
if (mChatCore) {
disconnect(mChatCore.get(), &ChatCore::eventsInserted, this, nullptr);
disconnect(mChatCore.get(), &ChatCore::eventListCleared, this, nullptr);
}
mChatCore = core;
if (mChatCore) {
connect(mChatCore.get(), &ChatCore::eventListCleared, this, [this] { resetData(); });
connect(mChatCore.get(), &ChatCore::eventsInserted, this,
[this](QList<QSharedPointer<EventLogCore>> list) {
auto eventsList = getSharedList<EventLogCore>();
for (auto &event : list) {
auto it = std::find_if(
eventsList.begin(), eventsList.end(),
[event](const QSharedPointer<EventLogCore> item) { return item == event; });
if (it == eventsList.end()) {
connectItem(event);
add(event);
int index;
get(event.get(), &index);
emit eventInserted(index, new EventLogGui(event));
}
}
});
}
lUpdate();
emit chatGuiChanged();
if (mChatCore != core) {
if (mChatCore) {
disconnect(mChatCore.get(), &ChatCore::eventsInserted, this, nullptr);
disconnect(mChatCore.get(), &ChatCore::eventListCleared, this, nullptr);
}
};
if (mIsUpdating) {
connect(this, &EventLogList::isUpdatingChanged, this, [this, core, updateChatCore] {
if (!mIsUpdating) {
updateChatCore(core);
disconnect(this, &EventLogList::isUpdatingChanged, this, nullptr);
}
});
} else {
updateChatCore(core);
mChatCore = core;
if (mChatCore) {
connect(mChatCore.get(), &ChatCore::eventListCleared, this, [this] { resetData(); });
connect(mChatCore.get(), &ChatCore::eventsInserted, this, [this](QList<QSharedPointer<EventLogCore>> list) {
auto eventsList = getSharedList<EventLogCore>();
for (auto &event : list) {
auto it = std::find_if(eventsList.begin(), eventsList.end(),
[event](const QSharedPointer<EventLogCore> item) { return item == event; });
if (it == eventsList.end()) {
connectItem(event);
add(event);
int index;
get(event.get(), &index);
emit eventInserted(index, new EventLogGui(event));
}
}
});
}
lUpdate();
// setIsUpdating(false);
emit chatGuiChanged();
}
}

View file

@ -2112,65 +2112,65 @@
<context>
<name>ChatListView</name>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="280"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="287"/>
<source>chat_message_is_writing_info</source>
<extracomment>%1 is writing</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="282"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="289"/>
<source>chat_message_draft_sending_text</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="425"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="432"/>
<source>chat_room_delete</source>
<extracomment>&quot;Delete&quot;</extracomment>
<translation>Löschen</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="364"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="371"/>
<source>chat_room_mute</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="363"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="370"/>
<source>chat_room_unmute</source>
<extracomment>&quot;Mute&quot;</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="377"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="384"/>
<source>chat_room_mark_as_read</source>
<extracomment>&quot;Mark as read&quot;</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="396"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="403"/>
<source>chat_room_leave</source>
<extracomment>&quot;leave&quot;</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="402"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="409"/>
<source>chat_list_leave_chat_popup_title</source>
<extracomment>leave the conversation ?</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="404"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="411"/>
<source>chat_list_leave_chat_popup_message</source>
<extracomment>You will not be able to send or receive messages in this conversation anymore. Do You want to continue ?</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="431"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="438"/>
<source>chat_list_delete_chat_popup_title</source>
<extracomment>Delete the conversation ?</extracomment>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="433"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="440"/>
<source>chat_list_delete_chat_popup_message</source>
<extracomment>This conversation and all its messages will be deleted. Do You want to continue ?</extracomment>
<translation type="unfinished"></translation>

View file

@ -2089,65 +2089,65 @@
<context>
<name>ChatListView</name>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="280"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="287"/>
<source>chat_message_is_writing_info</source>
<extracomment>%1 is writing</extracomment>
<translation>%1 is writing</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="282"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="289"/>
<source>chat_message_draft_sending_text</source>
<translation>Draft : %1</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="425"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="432"/>
<source>chat_room_delete</source>
<extracomment>&quot;Delete&quot;</extracomment>
<translation>Delete</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="364"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="371"/>
<source>chat_room_mute</source>
<translation>Mute</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="363"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="370"/>
<source>chat_room_unmute</source>
<extracomment>&quot;Mute&quot;</extracomment>
<translation>Unmute</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="377"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="384"/>
<source>chat_room_mark_as_read</source>
<extracomment>&quot;Mark as read&quot;</extracomment>
<translation>Mark as read</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="396"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="403"/>
<source>chat_room_leave</source>
<extracomment>&quot;leave&quot;</extracomment>
<translation>Leave</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="402"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="409"/>
<source>chat_list_leave_chat_popup_title</source>
<extracomment>leave the conversation ?</extracomment>
<translation>Leave the conversation ?</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="404"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="411"/>
<source>chat_list_leave_chat_popup_message</source>
<extracomment>You will not be able to send or receive messages in this conversation anymore. Do You want to continue ?</extracomment>
<translation>You will not be able to send or receive messages in this conversation anymore. Do You want to continue ?</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="431"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="438"/>
<source>chat_list_delete_chat_popup_title</source>
<extracomment>Delete the conversation ?</extracomment>
<translation>Delete the conversation ?</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="433"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="440"/>
<source>chat_list_delete_chat_popup_message</source>
<extracomment>This conversation and all its messages will be deleted. Do You want to continue ?</extracomment>
<translation>This conversation and all its messages will be deleted. Do You want to continue ?</translation>

View file

@ -2089,65 +2089,65 @@
<context>
<name>ChatListView</name>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="280"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="287"/>
<source>chat_message_is_writing_info</source>
<extracomment>%1 is writing</extracomment>
<translation>%1 est en train d&apos;écrire</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="282"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="289"/>
<source>chat_message_draft_sending_text</source>
<translation>Brouillon : %1</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="425"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="432"/>
<source>chat_room_delete</source>
<extracomment>&quot;Delete&quot;</extracomment>
<translation>Supprimer</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="364"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="371"/>
<source>chat_room_mute</source>
<translation>Mettre en sourdine</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="363"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="370"/>
<source>chat_room_unmute</source>
<extracomment>&quot;Mute&quot;</extracomment>
<translation>Enlever la sourdine </translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="377"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="384"/>
<source>chat_room_mark_as_read</source>
<extracomment>&quot;Mark as read&quot;</extracomment>
<translation>Marquer comme lu</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="396"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="403"/>
<source>chat_room_leave</source>
<extracomment>&quot;leave&quot;</extracomment>
<translation>Quitter la conversation</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="402"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="409"/>
<source>chat_list_leave_chat_popup_title</source>
<extracomment>leave the conversation ?</extracomment>
<translation>Quitter la conversation ?</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="404"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="411"/>
<source>chat_list_leave_chat_popup_message</source>
<extracomment>You will not be able to send or receive messages in this conversation anymore. Do You want to continue ?</extracomment>
<translation>Vous ne pourrez plus envoyer ou recevoir de messages dans cette conversation. Souhaitez-vous continuer ?</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="431"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="438"/>
<source>chat_list_delete_chat_popup_title</source>
<extracomment>Delete the conversation ?</extracomment>
<translation>Supprimer la conversation ?</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="433"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="440"/>
<source>chat_list_delete_chat_popup_message</source>
<extracomment>This conversation and all its messages will be deleted. Do You want to continue ?</extracomment>
<translation>La conversation et tous ses messages seront supprimés. Souhaitez-vous continuer ?</translation>

View file

@ -18,7 +18,9 @@ ListView {
property real busyIndicatorSize: Utils.getSizeWithScreenRatio(60)
property ChatGui currentChatGui: model.getAt(currentIndex) || null
onCurrentChatGuiChanged: positionViewAtIndex(currentIndex, ListView.Center)
property ChatGui chatToSelect: null
property ChatGui chatToSelectLater: null
onChatToSelectChanged: {
var index = chatProxy.findChatIndex(chatToSelect)
if (index != -1) {
@ -28,10 +30,7 @@ ListView {
}
onChatClicked: (chat) => {selectChat(chat)}
onCountChanged: {
selectChat(currentChatGui)
}
signal markAllAsRead()
signal chatClicked(ChatGui chat)
@ -41,14 +40,11 @@ ListView {
loading = true
}
filterText: mainItem.searchText
onFilterTextChanged: {
chatToSelectLater = currentChatGui
}
initialDisplayItems: Math.max(20, Math.round(2 * mainItem.height / Utils.getSizeWithScreenRatio(56)))
displayItemsStep: 3 * initialDisplayItems / 2
onModelReset: {
loading = false
if (mainItem.chatToSelect) {
selectChat(mainItem.chatToSelect)
}
}
onModelAboutToBeReset: {
loading = true
}
@ -58,7 +54,18 @@ ListView {
mainItem.currentIndex = index
}
onLayoutChanged: {
selectChat(mainItem.currentChatGui)
loading = false
if (mainItem.chatToSelectLater) {
selectChat(mainItem.chatToSelectLater)
mainItem.chatToSelectLater = null
}
else if (mainItem.chatToSelect) {
selectChat(mainItem.chatToSelect)
mainItem.chatToSelect = null
}
else {
selectChat(mainItem.currentChatGui)
}
}
onChatCreated: (chat) => {
selectChat(chat)

View file

@ -267,7 +267,7 @@ AbstractMainPage {
Layout.rightMargin: Utils.getSizeWithScreenRatio(8)
Layout.topMargin: Utils.getSizeWithScreenRatio(18)
onGroupCreationRequested: {
console.log("groupe call requetsed")
console.log("groupe call requested")
listStackView.push(groupChatItem)
}
onContactClicked: (contact) => {
@ -371,9 +371,7 @@ AbstractMainPage {
visible: chat != undefined //&& (chat.core.isBasic || chat.core.conferenceJoined)
anchors.fill: parent
chat: mainItem.selectedChatGui ? mainItem.selectedChatGui : null
onChatChanged: {
if (mainItem.selectedChatGui !== chat) mainItem.selectedChatGui = chat
}
// Reset current chat when switching account, otherwise the binding makes
// the last chat from last account the current chat for the new default account
Connections {
@ -387,7 +385,7 @@ AbstractMainPage {
Connections {
target: mainItem
function onSelectedChatGuiChanged() {
if (mainItem.selectedChatGui) selectedChatView.chat = mainItem.selectedChatGui
selectedChatView.chat = mainItem.selectedChatGui ? mainItem.selectedChatGui : null
}
}
Binding {