1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-19 06:55:24 +02:00

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
This commit is contained in:
Kateryna Kostiuk 2023-06-21 16:31:57 -04:00
parent 9fe34c5282
commit 8a7547aaba
2 changed files with 28 additions and 9 deletions

View file

@ -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 <QDateTime>
@ -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)
{

View file

@ -58,4 +58,6 @@ private:
QMap<QString, bool> sectionState_;
QMap<ConferenceableItem, ConferenceableValue> conferenceables_;
ConversationModel::ConversationQueueProxy conversations_;
void updateModels();
};