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 @@ ...@@ -21,13 +21,10 @@
#include "smartlistmodel.h" #include "smartlistmodel.h"
#include "lrcinstance.h" #include "lrcinstance.h"
#include "utils.h"
#include "api/account.h" #include "api/account.h"
#include "api/contact.h"
#include "api/conversation.h" #include "api/conversation.h"
#include "api/conversationmodel.h" #include "api/conversationmodel.h"
#include "api/contactmodel.h"
#include <QDateTime> #include <QDateTime>
...@@ -37,11 +34,20 @@ SmartListModel::SmartListModel(QObject* parent, ...@@ -37,11 +34,20 @@ SmartListModel::SmartListModel(QObject* parent,
: ConversationListModelBase(instance, parent) : ConversationListModelBase(instance, parent)
, listModelType_(listModelType) , listModelType_(listModelType)
{ {
if (listModelType_ == Type::CONFERENCE) { connect(
setConferenceableFilter(); model_,
} else if (listModelType_ == Type::CONVERSATION || listModelType_ == Type::ADDCONVMEMBER) { &ConversationModel::newConversation,
fillConversationsList(); this,
} [this] { updateModels(); },
Qt::DirectConnection);
connect(
model_,
&ConversationModel::conversationRemoved,
this,
[this] { updateModels(); },
Qt::DirectConnection);
updateModels();
} }
int int
...@@ -63,8 +69,9 @@ SmartListModel::rowCount(const QModelIndex& parent) const ...@@ -63,8 +69,9 @@ SmartListModel::rowCount(const QModelIndex& parent) const
rowCount += sectionState_[tr("Contacts")] ? contacts.size() : 0; rowCount += sectionState_[tr("Contacts")] ? contacts.size() : 0;
} }
return rowCount; return rowCount;
} else {
return conversations_.size();
} }
return conversations_.size();
} }
return 0; return 0;
} }
...@@ -167,6 +174,16 @@ SmartListModel::fillConversationsList() ...@@ -167,6 +174,16 @@ SmartListModel::fillConversationsList()
endResetModel(); endResetModel();
} }
void
SmartListModel::updateModels()
{
if (listModelType_ == Type::CONFERENCE) {
setConferenceableFilter();
} else if (listModelType_ == Type::CONVERSATION || listModelType_ == Type::ADDCONVMEMBER) {
fillConversationsList();
}
}
void void
SmartListModel::toggleSection(const QString& section) SmartListModel::toggleSection(const QString& section)
{ {
......
...@@ -58,4 +58,6 @@ private: ...@@ -58,4 +58,6 @@ private:
QMap<QString, bool> sectionState_; QMap<QString, bool> sectionState_;
QMap<ConferenceableItem, ConferenceableValue> conferenceables_; QMap<ConferenceableItem, ConferenceableValue> conferenceables_;
ConversationModel::ConversationQueueProxy conversations_; ConversationModel::ConversationQueueProxy conversations_;
void updateModels();
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment