Commit 01634109 authored by Anthony Léonard's avatar Anthony Léonard Committed by Kateryna Kostiuk

improve ConversationModel signal handling

Two signals were not handled in client and could have led to incorrect
display in conversation list and errors in conversation view behavior.

Change-Id: Idbf0a43fa99028ae75f0bdfdd465f44d5c9cd991
Reviewed-by: Kateryna Kostiuk's avatarKateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
parent 72128c9c
......@@ -62,10 +62,10 @@
const lrc::api::conversation::Info* cachedConv_;
lrc::api::ConversationModel* convModel_;
// Both are needed to invalidate cached conversation as pointer
// All those connections are needed to invalidate cached conversation as pointer
// may not be referencing the same conversation anymore
QMetaObject::Connection modelSortedSignal_;
QMetaObject::Connection filterChangedSignal_;
QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_;
}
......@@ -106,16 +106,26 @@
// Signals tracking changes in conversation list, we need them as cached conversation can be invalid
// after a reordering.
QObject::disconnect(modelSortedSignal_);
QObject::disconnect(filterChangedSignal_);
modelSortedSignal_ = QObject::connect(convModel_, &lrc::api::ConversationModel::modelSorted,
QObject::disconnect(modelSortedConnection_);
QObject::disconnect(filterChangedConnection_);
QObject::disconnect(newConversationConnection_);
QObject::disconnect(conversationRemovedConnection_);
modelSortedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::modelSorted,
[self](){
cachedConv_ = nil;
});
filterChangedSignal_ = QObject::connect(convModel_, &lrc::api::ConversationModel::filterChanged,
filterChangedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::filterChanged,
[self](){
cachedConv_ = nil;
});
filterChangedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::newConversation,
[self](){
cachedConv_ = nil;
});
filterChangedConnection_ = QObject::connect(convModel_, &lrc::api::ConversationModel::conversationRemoved,
[self](){
cachedConv_ = nil;
});
auto* conv = [self getCurrentConversation];
......
......@@ -53,8 +53,7 @@
__unsafe_unretained IBOutlet RingTableView* smartView;
__unsafe_unretained IBOutlet NSSearchField* searchField;
/* Pending ring usernames lookup for the search entry */
QMetaObject::Connection usernameLookupConnection, modelSortedConnection_, filterChangedConnection_;
QMetaObject::Connection modelSortedConnection_, filterChangedConnection_, newConversationConnection_, conversationRemovedConnection_;
lrc::api::ConversationModel* model_;
std::string selectedUid_;
......@@ -142,6 +141,8 @@ NSInteger const PRESENCE_TAG = 800;
[self reloadData];
QObject::disconnect(modelSortedConnection_);
QObject::disconnect(filterChangedConnection_);
QObject::disconnect(newConversationConnection_);
QObject::disconnect(conversationRemovedConnection_);
if (model_ != nil) {
modelSortedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::modelSorted,
[self] (){
......@@ -151,6 +152,14 @@ NSInteger const PRESENCE_TAG = 800;
[self] (){
[self reloadData];
});
newConversationConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::newConversation,
[self] (){
[self reloadData];
});
conversationRemovedConnection_ = QObject::connect(model_, &lrc::api::ConversationModel::conversationRemoved,
[self] (){
[self reloadData];
});
model_->setFilter(""); // Reset the filter
}
[searchField setStringValue:@""];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment