Skip to content
Snippets Groups Projects
Commit 8a7547aa authored by Kateryna Kostiuk's avatar Kateryna Kostiuk
Browse files

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
parent 9fe34c52
No related branches found
No related tags found
No related merge requests found
......@@ -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,9 +69,10 @@ SmartListModel::rowCount(const QModelIndex& parent) const
rowCount += sectionState_[tr("Contacts")] ? contacts.size() : 0;
}
return rowCount;
}
} else {
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)
{
......
......@@ -58,4 +58,6 @@ private:
QMap<QString, bool> sectionState_;
QMap<ConferenceableItem, ConferenceableValue> conferenceables_;
ConversationModel::ConversationQueueProxy conversations_;
void updateModels();
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment