From c99b409d461c276c04d20b52ca0b248a489f6a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Mon, 18 Jul 2022 16:49:09 -0400 Subject: [PATCH] conversationmodel: listen for profile changes Change-Id: I76b0fe1d35fa38ffe82812bc1c97b2565ceb9318 --- src/libclient/callbackshandler.cpp | 13 ++ src/libclient/callbackshandler.h | 6 + src/libclient/conversationmodel.cpp | 41 +++-- .../qtwrapper/configurationmanager_wrap.h | 161 ++++++++++++++---- 4 files changed, 180 insertions(+), 41 deletions(-) diff --git a/src/libclient/callbackshandler.cpp b/src/libclient/callbackshandler.cpp index 481f093b3..9d7e184c1 100644 --- a/src/libclient/callbackshandler.cpp +++ b/src/libclient/callbackshandler.cpp @@ -308,6 +308,11 @@ CallbacksHandler::CallbacksHandler(const Lrc& parent) this, &CallbacksHandler::slotMessageReceived, Qt::QueuedConnection); + connect(&ConfigurationManager::instance(), + &ConfigurationManagerInterface::conversationProfileUpdated, + this, + &CallbacksHandler::slotConversationProfileUpdated, + Qt::QueuedConnection); connect(&ConfigurationManager::instance(), &ConfigurationManagerInterface::conversationRequestReceived, this, @@ -743,6 +748,14 @@ CallbacksHandler::slotMessageReceived(const QString& accountId, Q_EMIT messageReceived(accountId, conversationId, message); } +void +CallbacksHandler::slotConversationProfileUpdated(const QString& accountId, + const QString& conversationId, + const MapStringString& profile) +{ + Q_EMIT conversationProfileUpdated(accountId, conversationId, profile); +} + void CallbacksHandler::slotConversationRequestReceived(const QString& accountId, const QString& conversationId, diff --git a/src/libclient/callbackshandler.h b/src/libclient/callbackshandler.h index 3417bf947..133d4ca72 100644 --- a/src/libclient/callbackshandler.h +++ b/src/libclient/callbackshandler.h @@ -353,6 +353,9 @@ Q_SIGNALS: void messageReceived(const QString& accountId, const QString& conversationId, const MapStringString& message); + void conversationProfileUpdated(const QString& accountId, + const QString& conversationId, + const MapStringString& profile); void conversationRequestReceived(const QString& accountId, const QString& conversationId, const MapStringString& metadatas); @@ -661,6 +664,9 @@ private Q_SLOTS: void slotMessageReceived(const QString& accountId, const QString& conversationId, const MapStringString& message); + void slotConversationProfileUpdated(const QString& accountId, + const QString& conversationId, + const MapStringString& message); void slotConversationRequestReceived(const QString& accountId, const QString& conversationId, const MapStringString& metadatas); diff --git a/src/libclient/conversationmodel.cpp b/src/libclient/conversationmodel.cpp index 3c7429619..d3a79ddad 100644 --- a/src/libclient/conversationmodel.cpp +++ b/src/libclient/conversationmodel.cpp @@ -363,6 +363,9 @@ public Q_SLOTS: void slotMessageReceived(const QString& accountId, const QString& conversationId, const MapStringString& message); + void slotConversationProfileUpdated(const QString& accountId, + const QString& conversationId, + const MapStringString& profile); void slotConversationRequestReceived(const QString& accountId, const QString& conversationId, const MapStringString& metadatas); @@ -1804,6 +1807,10 @@ ConversationModelPimpl::ConversationModelPimpl(const ConversationModel& linked, &CallbacksHandler::messageReceived, this, &ConversationModelPimpl::slotMessageReceived); + connect(&callbacksHandler, + &CallbacksHandler::conversationProfileUpdated, + this, + &ConversationModelPimpl::slotConversationProfileUpdated); connect(&callbacksHandler, &CallbacksHandler::conversationRequestReceived, this, @@ -1940,6 +1947,10 @@ ConversationModelPimpl::~ConversationModelPimpl() &CallbacksHandler::messageReceived, this, &ConversationModelPimpl::slotMessageReceived); + disconnect(&callbacksHandler, + &CallbacksHandler::conversationProfileUpdated, + this, + &ConversationModelPimpl::slotConversationProfileUpdated); disconnect(&callbacksHandler, &CallbacksHandler::conversationRequestReceived, this, @@ -2340,15 +2351,7 @@ ConversationModelPimpl::slotMessageReceived(const QString& accountId, } try { auto& conversation = getConversationForUid(conversationId).get(); - if (message["type"].isEmpty()) { - return; - } - if (message["type"] == "application/update-profile") { - // Refresh infos - MapStringString details = ConfigurationManager::instance() - .conversationInfos(linked.owner.id, conversationId); - conversation.infos = details; - Q_EMIT linked.profileUpdated(conversationId); + if (message["type"].isEmpty() || message["type"] == "application/update-profile") { return; } if (message["type"] == "initial") { @@ -2428,6 +2431,22 @@ ConversationModelPimpl::slotMessageReceived(const QString& accountId, } } +void +ConversationModelPimpl::slotConversationProfileUpdated(const QString& accountId, + const QString& conversationId, + const MapStringString& profile) +{ + if (accountId != linked.owner.id) { + return; + } + try { + auto& conversation = getConversationForUid(conversationId).get(); + conversation.infos = profile; + Q_EMIT linked.profileUpdated(conversationId); + } catch (...) { + } +} + bool ConversationModelPimpl::insertSwarmInteraction(const QString& interactionId, const interaction::Info& interaction, @@ -2583,14 +2602,14 @@ ConversationModelPimpl::slotConversationRemoved(const QString& accountId, removeConversation(); if (conversation.mode == conversation::Mode::ONE_TO_ONE) { - // If it's a 1:1 conversation and we don't have any more conversation // we can remove the contact auto contactRemoved = true; try { auto& conv = getConversationForPeerUri(contactUri).get(); contactRemoved = !conv.isSwarm(); - } catch (...) {} + } catch (...) { + } if (contact.isBanned && contactRemoved) { // Add 1:1 conv for banned diff --git a/src/libclient/qtwrapper/configurationmanager_wrap.h b/src/libclient/qtwrapper/configurationmanager_wrap.h index 51207de56..d4b1d19f2 100644 --- a/src/libclient/qtwrapper/configurationmanager_wrap.h +++ b/src/libclient/qtwrapper/configurationmanager_wrap.h @@ -288,6 +288,14 @@ public: QString(conversationId.c_str()), convertMap(message)); }), + exportable_callback<ConversationSignal::ConversationProfileUpdated>( + [this](const std::string& accountId, + const std::string& conversationId, + const std::map<std::string, std::string>& profile) { + Q_EMIT conversationProfileUpdated(QString(accountId.c_str()), + QString(conversationId.c_str()), + convertMap(profile)); + }), exportable_callback<ConversationSignal::ConversationRequestReceived>( [this](const std::string& accountId, const std::string& conversationId, @@ -508,11 +516,20 @@ public Q_SLOTS: // METHODS return temp; } - int getHistoryLimit() { return DRing::getHistoryLimit(); } + int getHistoryLimit() + { + return DRing::getHistoryLimit(); + } - bool getIsAlwaysRecording() { return DRing::getIsAlwaysRecording(); } + bool getIsAlwaysRecording() + { + return DRing::getIsAlwaysRecording(); + } - bool getNoiseSuppressState() { return DRing::getNoiseSuppressState(); } + bool getNoiseSuppressState() + { + return DRing::getNoiseSuppressState(); + } QString getRecordPath() { @@ -520,9 +537,15 @@ public Q_SLOTS: // METHODS return temp; } - bool getRecordPreview() { return DRing::getRecordPreview(); } + bool getRecordPreview() + { + return DRing::getRecordPreview(); + } - int getRecordQuality() { return DRing::getRecordQuality(); } + int getRecordQuality() + { + return DRing::getRecordQuality(); + } QStringList getSupportedAudioManagers() { @@ -580,27 +603,60 @@ public Q_SLOTS: // METHODS return temp; } - double getVolume(const QString& device) { return DRing::getVolume(device.toStdString()); } + double getVolume(const QString& device) + { + return DRing::getVolume(device.toStdString()); + } - bool isAgcEnabled() { return DRing::isAgcEnabled(); } + bool isAgcEnabled() + { + return DRing::isAgcEnabled(); + } - bool isCaptureMuted() { return DRing::isCaptureMuted(); } + bool isCaptureMuted() + { + return DRing::isCaptureMuted(); + } - bool isDtmfMuted() { return DRing::isDtmfMuted(); } + bool isDtmfMuted() + { + return DRing::isDtmfMuted(); + } - bool isPlaybackMuted() { return DRing::isPlaybackMuted(); } + bool isPlaybackMuted() + { + return DRing::isPlaybackMuted(); + } - void muteCapture(bool mute) { DRing::muteCapture(mute); } + void muteCapture(bool mute) + { + DRing::muteCapture(mute); + } - void muteDtmf(bool mute) { DRing::muteDtmf(mute); } + void muteDtmf(bool mute) + { + DRing::muteDtmf(mute); + } - void mutePlayback(bool mute) { DRing::mutePlayback(mute); } + void mutePlayback(bool mute) + { + DRing::mutePlayback(mute); + } - void registerAllAccounts() { DRing::registerAllAccounts(); } + void registerAllAccounts() + { + DRing::registerAllAccounts(); + } - void monitor(bool continuous) { DRing::monitor(continuous); } + void monitor(bool continuous) + { + DRing::monitor(continuous); + } - void removeAccount(const QString& accountID) { DRing::removeAccount(accountID.toStdString()); } + void removeAccount(const QString& accountID) + { + DRing::removeAccount(accountID.toStdString()); + } bool changeAccountPassword(const QString& id, const QString& currentPassword, @@ -621,7 +677,10 @@ public Q_SLOTS: // METHODS DRing::setAccountDetails(accountID.toStdString(), convertMap(details)); } - void setAccountsOrder(const QString& order) { DRing::setAccountsOrder(order.toStdString()); } + void setAccountsOrder(const QString& order) + { + DRing::setAccountsOrder(order.toStdString()); + } void setActiveCodecList(const QString& accountID, VectorUInt& list) { @@ -630,20 +689,35 @@ public Q_SLOTS: // METHODS std::vector<unsigned>(list.begin(), list.end())); } - void setAgcState(bool enabled) { DRing::setAgcState(enabled); } + void setAgcState(bool enabled) + { + DRing::setAgcState(enabled); + } - void setAudioInputDevice(int index) { DRing::setAudioInputDevice(index); } + void setAudioInputDevice(int index) + { + DRing::setAudioInputDevice(index); + } - bool setAudioManager(const QString& api) { return DRing::setAudioManager(api.toStdString()); } + bool setAudioManager(const QString& api) + { + return DRing::setAudioManager(api.toStdString()); + } - void setAudioOutputDevice(int index) { DRing::setAudioOutputDevice(index); } + void setAudioOutputDevice(int index) + { + DRing::setAudioOutputDevice(index); + } void setAudioPlugin(const QString& audioPlugin) { DRing::setAudioPlugin(audioPlugin.toStdString()); } - void setAudioRingtoneDevice(int index) { DRing::setAudioRingtoneDevice(index); } + void setAudioRingtoneDevice(int index) + { + DRing::setAudioRingtoneDevice(index); + } void setCredentials(const QString& accountID, VectorMapStringString credentialInformation) { @@ -654,11 +728,20 @@ public Q_SLOTS: // METHODS DRing::setCredentials(accountID.toStdString(), temp); } - void setHistoryLimit(int days) { DRing::setHistoryLimit(days); } + void setHistoryLimit(int days) + { + DRing::setHistoryLimit(days); + } - void setIsAlwaysRecording(bool enabled) { DRing::setIsAlwaysRecording(enabled); } + void setIsAlwaysRecording(bool enabled) + { + DRing::setIsAlwaysRecording(enabled); + } - void setNoiseSuppressState(bool state) { DRing::setNoiseSuppressState(state); } + void setNoiseSuppressState(bool state) + { + DRing::setNoiseSuppressState(state); + } bool isAudioMeterActive(const QString& id) { @@ -670,11 +753,20 @@ public Q_SLOTS: // METHODS DRing::setAudioMeterState(id.toStdString(), state); } - void setRecordPath(const QString& rec) { DRing::setRecordPath(rec.toStdString()); } + void setRecordPath(const QString& rec) + { + DRing::setRecordPath(rec.toStdString()); + } - void setRecordPreview(const bool& rec) { DRing::setRecordPreview(rec); } + void setRecordPreview(const bool& rec) + { + DRing::setRecordPreview(rec); + } - void setRecordQuality(const int& quality) { DRing::setRecordQuality(quality); } + void setRecordQuality(const int& quality) + { + DRing::setRecordQuality(quality); + } void setVolume(const QString& device, double value) { @@ -795,14 +887,20 @@ public Q_SLOTS: // METHODS return DRing::setCodecDetails(accountId.toStdString(), codecId, convertMap(details)); } - int getMessageStatus(uint64_t id) { return DRing::getMessageStatus(id); } + int getMessageStatus(uint64_t id) + { + return DRing::getMessageStatus(id); + } MapStringString getNearbyPeers(const QString& accountID) { return convertMap(DRing::getNearbyPeers(accountID.toStdString())); } - void connectivityChanged() { DRing::connectivityChanged(); } + void connectivityChanged() + { + DRing::connectivityChanged(); + } MapStringString getContactDetails(const QString& accountID, const QString& uri) { @@ -1121,6 +1219,9 @@ Q_SIGNALS: // SIGNALS void messageReceived(const QString& accountId, const QString& conversationId, const MapStringString& message); + void conversationProfileUpdated(const QString& accountId, + const QString& conversationId, + const MapStringString& profile); void conversationRequestReceived(const QString& accountId, const QString& conversationId, const MapStringString& metadatas); -- GitLab