From fc7109950b6d16982227f71c1bd6837d85d07649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Wed, 1 Nov 2023 11:03:21 -0400 Subject: [PATCH] swarm-call: do not create 1:1 conversation for incoming calls in swarm There was no way to differentiate a 1:1 incoming call and a call from a swarm, because username couldn't be checked. Now, create conversation only if it's a 1:1 call Change-Id: I0094967914b4888d083b9adc1d2b11de467d6f48 --- daemon | 2 +- src/libclient/api/callmodel.h | 4 ++- src/libclient/api/contactmodel.h | 3 +- src/libclient/callmodel.cpp | 2 +- src/libclient/contactmodel.cpp | 10 +++--- src/libclient/conversationmodel.cpp | 51 +++++++++++++++-------------- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/daemon b/daemon index a7e2c494d..a5a46c038 160000 --- a/daemon +++ b/daemon @@ -1 +1 @@ -Subproject commit a7e2c494d1d16bec68b7e098734884062a4b2505 +Subproject commit a5a46c0385a224f27456c9b0d271cede9622ea72 diff --git a/src/libclient/api/callmodel.h b/src/libclient/api/callmodel.h index 5ac592021..b3d188673 100644 --- a/src/libclient/api/callmodel.h +++ b/src/libclient/api/callmodel.h @@ -451,11 +451,13 @@ Q_SIGNALS: * @param callId * @param displayname * @param isOutgoing + * @param toUri Generally account's uri for 1:1 calls, rdv uri for swarm-call */ void newCall(const QString& peerId, const QString& callId, const QString& displayname, - bool isOutgoing) const; + bool isOutgoing, + const QString& toUri) const; /** * Emitted when a call is added to a conference * @param callId diff --git a/src/libclient/api/contactmodel.h b/src/libclient/api/contactmodel.h index 9cae1fdca..572e53092 100644 --- a/src/libclient/api/contactmodel.h +++ b/src/libclient/api/contactmodel.h @@ -156,8 +156,9 @@ Q_SIGNALS: * @param fromId peer profile uri * @param callId call id * @param isOutgoing + * @param toUri */ - void newCall(const QString& from, const QString& callId, bool isOutgoing) const; + void newCall(const QString& from, const QString& callId, bool isOutgoing, const QString& toUri) const; /** * Connect this signal to know when a text message arrives for this account * @param accountId diff --git a/src/libclient/callmodel.cpp b/src/libclient/callmodel.cpp index f9c3a4105..cb4cca9e0 100644 --- a/src/libclient/callmodel.cpp +++ b/src/libclient/callmodel.cpp @@ -1440,7 +1440,7 @@ CallModelPimpl::slotCallStateChanged(const QString& accountId, qDebug() << displayname; qDebug() << peerId; - Q_EMIT linked.newCall(peerId, callId, displayname, details["CALL_TYPE"] == "1"); + Q_EMIT linked.newCall(peerId, callId, displayname, details["CALL_TYPE"] == "1", details["TO_USERNAME"]); // NOTE: signal emission order matters, always emit CallStatusChanged before CallEnded Q_EMIT linked.callStatusChanged(callId, code); diff --git a/src/libclient/contactmodel.cpp b/src/libclient/contactmodel.cpp index 22ae05e6a..78893a496 100644 --- a/src/libclient/contactmodel.cpp +++ b/src/libclient/contactmodel.cpp @@ -164,8 +164,9 @@ public Q_SLOTS: * @param callId * @param displayName * @param isOutgoing + * @param toUri */ - void slotNewCall(const QString& fromId, const QString& callId, const QString& displayname, bool isOutgoing); + void slotNewCall(const QString& fromId, const QString& callId, const QString& displayname, bool isOutgoing, const QString& toUri); /** * Listen from callbacksHandler for new account interaction and add pending contact if not present @@ -1022,9 +1023,10 @@ void ContactModelPimpl::slotNewCall(const QString& fromId, const QString& callId, const QString& displayname, - bool isOutgoing) + bool isOutgoing, + const QString& toUri) { - if (!isOutgoing) { + if (!isOutgoing && toUri == linked.owner.profileInfo.uri) { bool emitContactAdded = false; { std::lock_guard<std::mutex> lk(contactsMtx_); @@ -1053,7 +1055,7 @@ ContactModelPimpl::slotNewCall(const QString& fromId, } else Q_EMIT linked.profileUpdated(fromId); } - Q_EMIT linked.newCall(fromId, callId, isOutgoing); + Q_EMIT linked.newCall(fromId, callId, isOutgoing, toUri); } void diff --git a/src/libclient/conversationmodel.cpp b/src/libclient/conversationmodel.cpp index 4031eb97f..831cac57d 100644 --- a/src/libclient/conversationmodel.cpp +++ b/src/libclient/conversationmodel.cpp @@ -271,8 +271,9 @@ public Q_SLOTS: * @param fromId caller uri * @param callId * @param isOutgoing + * @param toUri */ - void slotNewCall(const QString& fromId, const QString& callId, bool isOutgoing = false); + void slotNewCall(const QString& fromId, const QString& callId, bool isOutgoing, const QString& toUri); /** * Listen from callmodel for calls status changed. * @param callId @@ -3367,7 +3368,7 @@ ConversationModelPimpl::getIndicesForContact(const QString& uri) const } void -ConversationModelPimpl::slotNewCall(const QString& fromId, const QString& callId, bool isOutgoing) +ConversationModelPimpl::slotNewCall(const QString& fromId, const QString& callId, bool isOutgoing, const QString& toUri) { if (isOutgoing) { // search contact @@ -3379,33 +3380,35 @@ ConversationModelPimpl::slotNewCall(const QString& fromId, const QString& callId Q_EMIT linked.filterChanged(); } - auto convIds = storage::getConversationsWithPeer(db, fromId); - if (convIds.empty()) { - // in case if we receive call after removing contact add conversation request; - try { - auto contact = linked.owner.contactModel->getContact(fromId); - if (!isOutgoing && !contact.isBanned && fromId != linked.owner.profileInfo.uri) { - addContactRequest(fromId); - } - if (isOutgoing && contact.profileInfo.type == profile::Type::TEMPORARY) { - linked.owner.contactModel->addContact(contact); + if (toUri == linked.owner.profileInfo.uri) { + auto convIds = storage::getConversationsWithPeer(db, fromId); + if (convIds.empty()) { + // in case if we receive call after removing contact add conversation request; + try { + auto contact = linked.owner.contactModel->getContact(fromId); + if (!isOutgoing && !contact.isBanned && fromId != linked.owner.profileInfo.uri) { + addContactRequest(fromId); + } + if (isOutgoing && contact.profileInfo.type == profile::Type::TEMPORARY) { + linked.owner.contactModel->addContact(contact); + } + } catch (const std::out_of_range&) { } - } catch (const std::out_of_range&) { } - } - auto conversationIndices = getIndicesForContact(fromId); - if (conversationIndices.empty()) { - qDebug() << "ConversationModelPimpl::slotNewCall, but conversation not found"; - return; // Not a contact - } + auto conversationIndices = getIndicesForContact(fromId); + if (conversationIndices.empty()) { + qDebug() << "ConversationModelPimpl::slotNewCall, but conversation not found"; + return; // Not a contact + } - auto& conversation = conversations.at(conversationIndices.at(0)); - qDebug() << "Add call to conversation " << conversation.uid << " - " << callId; - conversation.callId = callId; + auto& conversation = conversations.at(conversationIndices.at(0)); + qDebug() << "Add call to conversation " << conversation.uid << " - " << callId; + conversation.callId = callId; - addOrUpdateCallMessage(callId, fromId, true); - Q_EMIT behaviorController.showIncomingCallView(linked.owner.id, conversation.uid); + addOrUpdateCallMessage(callId, fromId, true); + Q_EMIT behaviorController.showIncomingCallView(linked.owner.id, conversation.uid); + } } void -- GitLab