ChatCore: wait for deleted state before emitting deleted signal

fix chats selection and remove useless signal
This commit is contained in:
Gaelle Braud 2025-12-02 14:26:07 +01:00
parent 60517741a2
commit 21e8e2aaba
10 changed files with 54 additions and 99 deletions

View file

@ -163,14 +163,13 @@ void ChatCore::setSelf(QSharedPointer<ChatCore> me) {
mChatModelConnection->makeConnectToCore(&ChatCore::lDelete, [this]() {
mChatModelConnection->invokeToModel([this]() { mChatModel->deleteChatRoom(); });
});
mChatModelConnection->makeConnectToModel(
&ChatModel::deleted, [this]() { mChatModelConnection->invokeToCore([this]() { emit deleted(); }); });
mChatModelConnection->makeConnectToModel(
&ChatModel::stateChanged,
[this](const std::shared_ptr<linphone::ChatRoom> &chatRoom, linphone::ChatRoom::State newState) {
auto state = LinphoneEnums::fromLinphone(newState);
bool isReadOnly = chatRoom->isReadOnly();
if (newState == linphone::ChatRoom::State::Deleted) emit deleted();
mChatModelConnection->invokeToCore([this, state, isReadOnly]() {
setChatRoomState(state);
setIsReadOnly(isReadOnly);

View file

@ -54,13 +54,15 @@ ChatList::~ChatList() {
}
void ChatList::connectItem(QSharedPointer<ChatCore> chat) {
connect(chat.get(), &ChatCore::deleted, this, [this, chat] {
disconnect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::lastMessageChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::deleted, this, nullptr);
remove(chat);
});
connect(
chat.get(), &ChatCore::deleted, this,
[this, chat] {
disconnect(chat.get(), &ChatCore::unreadMessagesCountChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::lastUpdatedTimeChanged, this, nullptr);
disconnect(chat.get(), &ChatCore::lastMessageChanged, this, nullptr);
remove(chat);
},
Qt::SingleShotConnection);
auto dataChange = [this, chat] {
int i = -1;
get(chat.get(), &i);
@ -167,30 +169,6 @@ void ChatList::setSelf(QSharedPointer<ChatList> me) {
addChatToList(core, room, message);
});
mModelConnection->makeConnectToModel(
&CoreModel::chatRoomStateChanged,
[this](const std::shared_ptr<linphone::Core> &core, const std::shared_ptr<linphone::ChatRoom> &chatRoom,
linphone::ChatRoom::State state) {
auto chatRoomAccount = chatRoom->getAccount();
auto currentAccount = CoreModel::getInstance()->getCore()->getDefaultAccount();
if (!chatRoomAccount || !currentAccount || !chatRoomAccount->getParams() || !currentAccount->getParams() ||
!chatRoomAccount->getParams()->getIdentityAddress()->weakEqual(
currentAccount->getParams()->getIdentityAddress())) {
lInfo() << "ChatRoom state of another account changed, return";
return;
}
if (chatRoom->getState() == linphone::ChatRoom::State::Created) {
lInfo() << "ChatRoom created, add it to the list" << chatRoom.get();
auto chatCore = ChatCore::create(chatRoom);
if (chatCore) {
mModelConnection->invokeToCore([this, chatCore] {
bool added = addChatInList(chatCore);
if (added) emit chatCreated(new ChatGui(chatCore));
});
}
}
});
connect(this, &ChatList::filterChanged, [this](QString filter) {
mFilter = filter;
lUpdate();
@ -212,8 +190,7 @@ bool ChatList::addChatInList(QSharedPointer<ChatCore> chatCore) {
mustBeInMainThread(log().arg(Q_FUNC_INFO));
auto chatList = getSharedList<ChatCore>();
auto it = std::find_if(chatList.begin(), chatList.end(), [chatCore](const QSharedPointer<ChatCore> item) {
return item && chatCore && item->getModel() && chatCore->getModel() &&
item->getModel()->getMonitor() == chatCore->getModel()->getMonitor();
return item && chatCore && item->getIdentifier() == chatCore->getIdentifier();
});
if (it == chatList.end()) {
connectItem(chatCore);

View file

@ -50,9 +50,6 @@ signals:
void filterChanged(QString filter);
void chatAdded();
void chatUpdated();
// emit this signal to force selection when
// newly created chat added to the list
void chatCreated(ChatGui *chatGui);
private:
QString mFilter;

View file

@ -46,10 +46,6 @@ void ChatProxy::setSourceModel(QAbstractItemModel *model) {
connect(this, &ChatProxy::filterTextChanged, newChatList,
[this, newChatList] { emit newChatList->filterChanged(getFilterText()); });
connect(newChatList, &ChatList::chatAdded, this, [this] { invalidate(); });
connect(newChatList, &ChatList::chatCreated, this, [this](ChatGui *chatGui) {
invalidate();
emit chatCreated(chatGui);
});
connect(newChatList, &ChatList::dataChanged, this, [this] { invalidate(); });
}
QSortFilterProxyModel::setSourceModel(newChatList);

View file

@ -41,8 +41,6 @@ public:
Q_INVOKABLE int findChatIndex(ChatGui *chatGui);
Q_INVOKABLE bool addChatInList(ChatGui *chatGui);
signals:
void chatCreated(ChatGui *chatGui);
protected:
QSharedPointer<ChatList> mList;

View file

@ -2099,65 +2099,65 @@
<context>
<name>ChatListView</name>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="264"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="253"/>
<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="266"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="255"/>
<source>chat_message_draft_sending_text</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="411"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="400"/>
<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="350"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="339"/>
<source>chat_room_mute</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="349"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="338"/>
<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="363"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="352"/>
<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="382"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="371"/>
<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="388"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="377"/>
<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="390"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="379"/>
<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="417"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="406"/>
<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="419"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="408"/>
<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>
@ -2723,19 +2723,19 @@ Error</extracomment>
<translation type="vanished">Fehler</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="150"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="164"/>
<source>information_popup_error_title</source>
<extracomment>Erreur</extracomment>
<translation>Fehler</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="152"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="166"/>
<source>information_popup_voicemail_address_undefined_message</source>
<extracomment>L&apos;URI de messagerie vocale n&apos;est pas définie.</extracomment>
<translation>Die Voicemail-URI ist nicht definiert.</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="166"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="180"/>
<source>account_settings_name_accessible_name</source>
<extracomment>Account settings of %1</extracomment>
<translation type="unfinished"></translation>

View file

@ -2086,65 +2086,65 @@
<context>
<name>ChatListView</name>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="264"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="253"/>
<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="266"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="255"/>
<source>chat_message_draft_sending_text</source>
<translation>Draft : %1</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="411"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="400"/>
<source>chat_room_delete</source>
<extracomment>&quot;Delete&quot;</extracomment>
<translation>Delete</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="350"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="339"/>
<source>chat_room_mute</source>
<translation>Mute</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="349"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="338"/>
<source>chat_room_unmute</source>
<extracomment>&quot;Mute&quot;</extracomment>
<translation>Unmute</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="363"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="352"/>
<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="382"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="371"/>
<source>chat_room_leave</source>
<extracomment>&quot;leave&quot;</extracomment>
<translation>Leave</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="388"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="377"/>
<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="390"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="379"/>
<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="417"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="406"/>
<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="419"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="408"/>
<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>
@ -2682,19 +2682,19 @@ Only your correspondent can decrypt them.</translation>
<context>
<name>Contact</name>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="150"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="164"/>
<source>information_popup_error_title</source>
<extracomment>Erreur</extracomment>
<translation>Error</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="152"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="166"/>
<source>information_popup_voicemail_address_undefined_message</source>
<extracomment>L&apos;URI de messagerie vocale n&apos;est pas définie.</extracomment>
<translation>The voicemail URI is not defined.</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="166"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="180"/>
<source>account_settings_name_accessible_name</source>
<extracomment>Account settings of %1</extracomment>
<translation>Account settings of %1</translation>

View file

@ -2086,65 +2086,65 @@
<context>
<name>ChatListView</name>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="264"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="253"/>
<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="266"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="255"/>
<source>chat_message_draft_sending_text</source>
<translation>Brouillon : %1</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="411"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="400"/>
<source>chat_room_delete</source>
<extracomment>&quot;Delete&quot;</extracomment>
<translation>Supprimer</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="350"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="339"/>
<source>chat_room_mute</source>
<translation>Mettre en sourdine</translation>
</message>
<message>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="349"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="338"/>
<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="363"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="352"/>
<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="382"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="371"/>
<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="388"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="377"/>
<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="390"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="379"/>
<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="417"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="406"/>
<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="419"/>
<location filename="../../view/Control/Display/Chat/ChatListView.qml" line="408"/>
<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>
@ -2682,19 +2682,19 @@ en bout. Seul votre correspondant peut les déchiffrer.</translation>
<context>
<name>Contact</name>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="150"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="164"/>
<source>information_popup_error_title</source>
<extracomment>Erreur</extracomment>
<translation>Erreur</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="152"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="166"/>
<source>information_popup_voicemail_address_undefined_message</source>
<extracomment>L&apos;URI de messagerie vocale n&apos;est pas définie.</extracomment>
<translation>L&apos;URI de messagerie vocale n&apos;est pas définie.</translation>
</message>
<message>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="166"/>
<location filename="../../view/Control/Display/Contact/Contact.qml" line="180"/>
<source>account_settings_name_accessible_name</source>
<extracomment>Account settings of %1</extracomment>
<translation>Paramaètres de compte de %1</translation>

View file

@ -44,7 +44,7 @@ ChatModel::ChatModel(const std::shared_ptr<linphone::ChatRoom> &chatroom, QObjec
ChatModel::~ChatModel() {
mustBeInLinphoneThread("~" + getClassName());
disconnect(CoreModel::getInstance().get(), &CoreModel::messageReadInChatRoom, this, nullptr);
disconnect(CoreModel::getInstance().get(), &CoreModel::chatRoomRead, this, nullptr);
}
QDateTime ChatModel::getLastUpdateTime() {
@ -173,7 +173,6 @@ void ChatModel::leave() {
void ChatModel::deleteChatRoom() {
CoreModel::getInstance()->getCore()->deleteChatRoom(mMonitor);
emit deleted();
}
std::shared_ptr<linphone::ChatMessage>

View file

@ -18,13 +18,11 @@ ListView {
property real busyIndicatorSize: Utils.getSizeWithScreenRatio(60)
property ChatGui currentChatGui: model.getAt(currentIndex) || null
onCurrentIndexChanged: console.log("current index changed", currentIndex)
onCurrentChatGuiChanged: positionViewAtIndex(currentIndex, ListView.Center)
property ChatGui chatToSelect: null
property ChatGui chatToSelectLater: null
onChatToSelectChanged: {
if (chatToSelect) {
console.log("chat to select changed, select", (chatToSelect ? chatToSelect.core.title : "NULL"))
// first clear the chatToSelect property in case we need to
// force adding the chat to the list and the layout changes
var toselect = chatToSelect
@ -72,9 +70,6 @@ ListView {
selectChat(mainItem.currentChatGui)
}
}
onChatCreated: (chat) => {
selectChat(chat)
}
}
// flickDeceleration: 10000
spacing: Utils.getSizeWithScreenRatio(10)
@ -100,12 +95,6 @@ ListView {
onActiveFocusChanged: if (activeFocus && currentIndex < 0 && count > 0)
currentIndex = 0
onAtYEndChanged: {
if (atYEnd && count > 0) {
chatProxy.displayMore()
}
}
//----------------------------------------------------------------
function moveToCurrentItem() {
if (mainItem.currentIndex >= 0)