From 8a7547aaba2eedd724b3ed5d552e05974139e51c Mon Sep 17 00:00:00 2001 From: Kateryna Kostiuk Date: Wed, 21 Jun 2023 16:31:57 -0400 Subject: [PATCH] smartList: update underlying model This patch ensures the underlying model is updated whenever a new conversation is added or removed. This will prevent a possible crash when the model gets invalidated. GitLab: #1210 Change-Id: I2bd6f396a6ea09ddd357a567456a057ac1805734 --- src/app/smartlistmodel.cpp | 35 ++++++++++++++++++++++++++--------- src/app/smartlistmodel.h | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/app/smartlistmodel.cpp b/src/app/smartlistmodel.cpp index 1780ca3d..d61deafa 100644 --- a/src/app/smartlistmodel.cpp +++ b/src/app/smartlistmodel.cpp @@ -21,13 +21,10 @@ #include "smartlistmodel.h" #include "lrcinstance.h" -#include "utils.h" #include "api/account.h" -#include "api/contact.h" #include "api/conversation.h" #include "api/conversationmodel.h" -#include "api/contactmodel.h" #include @@ -37,11 +34,20 @@ SmartListModel::SmartListModel(QObject* parent, : ConversationListModelBase(instance, parent) , listModelType_(listModelType) { - if (listModelType_ == Type::CONFERENCE) { - setConferenceableFilter(); - } else if (listModelType_ == Type::CONVERSATION || listModelType_ == Type::ADDCONVMEMBER) { - fillConversationsList(); - } + connect( + model_, + &ConversationModel::newConversation, + this, + [this] { updateModels(); }, + Qt::DirectConnection); + connect( + model_, + &ConversationModel::conversationRemoved, + this, + [this] { updateModels(); }, + Qt::DirectConnection); + + updateModels(); } int @@ -63,8 +69,9 @@ SmartListModel::rowCount(const QModelIndex& parent) const rowCount += sectionState_[tr("Contacts")] ? contacts.size() : 0; } return rowCount; + } else { + return conversations_.size(); } - return conversations_.size(); } return 0; } @@ -167,6 +174,16 @@ SmartListModel::fillConversationsList() endResetModel(); } +void +SmartListModel::updateModels() +{ + if (listModelType_ == Type::CONFERENCE) { + setConferenceableFilter(); + } else if (listModelType_ == Type::CONVERSATION || listModelType_ == Type::ADDCONVMEMBER) { + fillConversationsList(); + } +} + void SmartListModel::toggleSection(const QString& section) { diff --git a/src/app/smartlistmodel.h b/src/app/smartlistmodel.h index f85e0a0a..fc2dfc9a 100644 --- a/src/app/smartlistmodel.h +++ b/src/app/smartlistmodel.h @@ -58,4 +58,6 @@ private: QMap sectionState_; QMap conferenceables_; ConversationModel::ConversationQueueProxy conversations_; + + void updateModels(); };