mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-09-10 03:53:23 +02:00
conversationsadapter: replace signal reconnect with unique connect
Change-Id: I34b1dca62ad5b28b49ddf319c4ea9724efd66b21
This commit is contained in:
parent
8152db585c
commit
946491a596
2 changed files with 80 additions and 92 deletions
|
@ -155,7 +155,6 @@ ConversationsAdapter::deselectConversation()
|
|||
void
|
||||
ConversationsAdapter::onCurrentAccountIdChanged()
|
||||
{
|
||||
disconnectConversationModel();
|
||||
connectConversationModel();
|
||||
|
||||
setProperty("currentTypeFilter",
|
||||
|
@ -265,8 +264,11 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
|
|||
// Signal connections
|
||||
auto currentConversationModel = lrcInstance_->getCurrentConversationModel();
|
||||
|
||||
modelSortedConnection_ = QObject::connect(
|
||||
currentConversationModel, &lrc::api::ConversationModel::modelChanged, [this]() {
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::modelChanged,
|
||||
this,
|
||||
[this]() {
|
||||
conversationSmartListModel_->fillConversationsList();
|
||||
updateConversationsFilterWidget();
|
||||
|
||||
|
@ -284,76 +286,94 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
|
|||
return;
|
||||
}
|
||||
Q_EMIT modelSorted(QVariant::fromValue(convInfo.uid));
|
||||
});
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
contactProfileUpdatedConnection_
|
||||
= QObject::connect(lrcInstance_->getCurrentAccountInfo().contactModel.get(),
|
||||
&lrc::api::ContactModel::profileUpdated,
|
||||
[this](const QString& contactUri) {
|
||||
conversationSmartListModel_->updateContactAvatarUid(contactUri);
|
||||
Q_EMIT updateListViewRequested();
|
||||
});
|
||||
QObject::connect(
|
||||
lrcInstance_->getCurrentAccountInfo().contactModel.get(),
|
||||
&lrc::api::ContactModel::profileUpdated,
|
||||
this,
|
||||
[this](const QString& contactUri) {
|
||||
conversationSmartListModel_->updateContactAvatarUid(contactUri);
|
||||
Q_EMIT updateListViewRequested();
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
modelUpdatedConnection_ = QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::conversationUpdated,
|
||||
[this](const QString&) {
|
||||
updateConversationsFilterWidget();
|
||||
Q_EMIT updateListViewRequested();
|
||||
});
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::conversationUpdated,
|
||||
this,
|
||||
[this](const QString&) {
|
||||
updateConversationsFilterWidget();
|
||||
Q_EMIT updateListViewRequested();
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
filterChangedConnection_
|
||||
= QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::filterChanged,
|
||||
[this]() {
|
||||
conversationSmartListModel_->fillConversationsList();
|
||||
updateConversationsFilterWidget();
|
||||
if (!lrcInstance_->get_selectedConvUid().isEmpty())
|
||||
Q_EMIT indexRepositionRequested();
|
||||
Q_EMIT updateListViewRequested();
|
||||
});
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::filterChanged,
|
||||
this,
|
||||
[this]() {
|
||||
conversationSmartListModel_->fillConversationsList();
|
||||
updateConversationsFilterWidget();
|
||||
if (!lrcInstance_->get_selectedConvUid().isEmpty())
|
||||
Q_EMIT indexRepositionRequested();
|
||||
Q_EMIT updateListViewRequested();
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
newConversationConnection_ = QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::newConversation,
|
||||
[this](const QString& convUid) {
|
||||
conversationSmartListModel_
|
||||
->fillConversationsList();
|
||||
updateConversationForNewContact(convUid);
|
||||
});
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::newConversation,
|
||||
this,
|
||||
[this](const QString& convUid) {
|
||||
conversationSmartListModel_->fillConversationsList();
|
||||
updateConversationForNewContact(convUid);
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
conversationRemovedConnection_
|
||||
= QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::conversationRemoved,
|
||||
[this]() { backToWelcomePage(); });
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::conversationRemoved,
|
||||
this,
|
||||
[this]() { backToWelcomePage(); },
|
||||
Qt::UniqueConnection);
|
||||
|
||||
conversationClearedConnection
|
||||
= QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::conversationCleared,
|
||||
[this](const QString& convUid) {
|
||||
// If currently selected, switch to welcome screen (deselecting
|
||||
// current smartlist item).
|
||||
if (convUid != lrcInstance_->get_selectedConvUid()) {
|
||||
return;
|
||||
}
|
||||
backToWelcomePage();
|
||||
});
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::conversationCleared,
|
||||
this,
|
||||
[this](const QString& convUid) {
|
||||
// If currently selected, switch to welcome screen (deselecting
|
||||
// current smartlist item).
|
||||
if (convUid != lrcInstance_->get_selectedConvUid()) {
|
||||
return;
|
||||
}
|
||||
backToWelcomePage();
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
searchStatusChangedConnection_
|
||||
= QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::searchStatusChanged,
|
||||
[this](const QString& status) { Q_EMIT showSearchStatus(status); });
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::searchStatusChanged,
|
||||
this,
|
||||
[this](const QString& status) { Q_EMIT showSearchStatus(status); },
|
||||
Qt::UniqueConnection);
|
||||
|
||||
// This connection is ideal when separated search results list.
|
||||
// This signal is guaranteed to fire just after filterChanged during a search if results are
|
||||
// changed, and once before filterChanged when calling setFilter.
|
||||
// NOTE: Currently, when searching, the entire conversation list will be copied 2-3 times each
|
||||
// keystroke :/.
|
||||
searchResultUpdatedConnection_
|
||||
= QObject::connect(currentConversationModel,
|
||||
&lrc::api::ConversationModel::searchResultUpdated,
|
||||
[this]() {
|
||||
conversationSmartListModel_->fillConversationsList();
|
||||
Q_EMIT updateListViewRequested();
|
||||
});
|
||||
QObject::connect(
|
||||
currentConversationModel,
|
||||
&lrc::api::ConversationModel::searchResultUpdated,
|
||||
this,
|
||||
[this]() {
|
||||
conversationSmartListModel_->fillConversationsList();
|
||||
Q_EMIT updateListViewRequested();
|
||||
},
|
||||
Qt::UniqueConnection);
|
||||
|
||||
if (updateFilter) {
|
||||
currentTypeFilter_ = lrc::api::profile::Type::INVALID;
|
||||
|
@ -361,23 +381,6 @@ ConversationsAdapter::connectConversationModel(bool updateFilter)
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
ConversationsAdapter::disconnectConversationModel()
|
||||
{
|
||||
QObject::disconnect(modelSortedConnection_);
|
||||
QObject::disconnect(modelUpdatedConnection_);
|
||||
QObject::disconnect(filterChangedConnection_);
|
||||
QObject::disconnect(newConversationConnection_);
|
||||
QObject::disconnect(conversationRemovedConnection_);
|
||||
QObject::disconnect(conversationClearedConnection);
|
||||
QObject::disconnect(selectedCallChanged_);
|
||||
QObject::disconnect(smartlistSelectionConnection_);
|
||||
QObject::disconnect(interactionRemovedConnection_);
|
||||
QObject::disconnect(searchStatusChangedConnection_);
|
||||
QObject::disconnect(searchResultUpdatedConnection_);
|
||||
QObject::disconnect(contactProfileUpdatedConnection_);
|
||||
}
|
||||
|
||||
void
|
||||
ConversationsAdapter::updateConversationForNewContact(const QString& convUid)
|
||||
{
|
||||
|
|
|
@ -44,7 +44,6 @@ protected:
|
|||
|
||||
public:
|
||||
Q_INVOKABLE bool connectConversationModel(bool updateFilter = true);
|
||||
Q_INVOKABLE void disconnectConversationModel();
|
||||
Q_INVOKABLE void selectConversation(const QString& accountId, const QString& uid);
|
||||
Q_INVOKABLE void deselectConversation();
|
||||
Q_INVOKABLE void refill();
|
||||
|
@ -82,19 +81,5 @@ private:
|
|||
|
||||
lrc::api::profile::Type currentTypeFilter_ {};
|
||||
|
||||
// Connections.
|
||||
QMetaObject::Connection modelSortedConnection_;
|
||||
QMetaObject::Connection modelUpdatedConnection_;
|
||||
QMetaObject::Connection filterChangedConnection_;
|
||||
QMetaObject::Connection newConversationConnection_;
|
||||
QMetaObject::Connection conversationRemovedConnection_;
|
||||
QMetaObject::Connection conversationClearedConnection;
|
||||
QMetaObject::Connection contactProfileUpdatedConnection_;
|
||||
QMetaObject::Connection selectedCallChanged_;
|
||||
QMetaObject::Connection smartlistSelectionConnection_;
|
||||
QMetaObject::Connection interactionRemovedConnection_;
|
||||
QMetaObject::Connection searchStatusChangedConnection_;
|
||||
QMetaObject::Connection searchResultUpdatedConnection_;
|
||||
|
||||
SystemTray* systemTray_;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue