diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h index 3f6f606c49b2eb2beb5628b93611c4936b0c6562..ad6bf4e11d82f35df8eac86251f0e483af740713 100644 --- a/src/api/newcallmodel.h +++ b/src/api/newcallmodel.h @@ -251,8 +251,9 @@ Q_SIGNALS: * Emitted when a call is incoming * @param callId * @param fromId the peer uri + * @param displayname */ - void newIncomingCall(const std::string& fromId, const std::string& callId) const; + void newIncomingCall(const std::string& fromId, const std::string& callId, const std::string& displayname) const; /** * Emitted when a call is added to a conference * @param callId diff --git a/src/callbackshandler.cpp b/src/callbackshandler.cpp index 245e89556429f397f86b55f3797b1a1759d2260d..4beb9a1bfa5af318331c130200315d1b8458882a 100644 --- a/src/callbackshandler.cpp +++ b/src/callbackshandler.cpp @@ -323,16 +323,22 @@ CallbacksHandler::slotIncomingContactRequest(const QString& accountId, void CallbacksHandler::slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri) { + std::string displayname; if (fromUri.contains("ring.dht")) { + auto qDisplayname = fromUri.left(fromUri.indexOf("<") + 1); + if (qDisplayname.size() > 2) { + displayname = qDisplayname.left(qDisplayname.indexOf("<") - 1).toStdString(); + } auto fromQString = fromUri.right(50); fromQString = fromQString.left(40); - emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString()); + emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString(), displayname); } else { - auto left = fromUri.indexOf("<")+1; + auto left = fromUri.indexOf("<") + 1; auto right = fromUri.indexOf("@"); auto fromQString = fromUri.mid(left, right-left); + displayname = fromUri.left(fromUri.indexOf("<") - 1).toStdString(); - emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString()); + emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString(), displayname); } } diff --git a/src/callbackshandler.h b/src/callbackshandler.h index 385ccb216cb3d7c2ade57ead60ca26b7d028d4ca..19f18b03777ce3ab99619f0da7a1c2b54325a74f 100644 --- a/src/callbackshandler.h +++ b/src/callbackshandler.h @@ -103,10 +103,12 @@ Q_SIGNALS: * @param accountId the one who receives the call * @param callId the call id * @param fromUri the caller uri + * @param displayName the display name of incoming call */ void incomingCall(const std::string& accountId, const std::string& callId, - const std::string& fromUri); + const std::string& fromUri, + const std::string& displayName); /** * Connect this signal to know when a call is updated * @param callId the call id diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index 71ba7bc899cd0c5786d0ded9cd149b8d2f577f2f..723b0d1bcb6d2e31d87d26c1dda2f18184079062 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -82,9 +82,10 @@ public: * @note: the contactId must corresponds to a profile in the database. * @param contactId * @param type + * @param displayName * @param banned whether contact is banned or not */ - void addToContacts(const std::string& contactId, const profile::Type& type, bool banned = false); + void addToContacts(const std::string& contactId, const profile::Type& type, const std::string& displayName = "", bool banned = false); /** * Helpers for searchContact. Search for a given RING or SIP contact. */ @@ -158,8 +159,9 @@ public Q_SLOTS: * Listen from callModel when an incoming call arrives. * @param fromId * @param callId + * @param displayName */ - void slotIncomingCall(const std::string& fromId, const std::string& callId); + void slotIncomingCall(const std::string& fromId, const std::string& callId, const std::string& displayname); /** * Listen from callbacksHandler for new account interaction and add pending contact if not present @@ -530,7 +532,7 @@ ContactModelPimpl::fillWithJamiContacts() { for (auto contact_info : contacts_vector) { std::lock_guard<std::mutex> lk(contactsMtx_); bool banned = contact_info["banned"] == "true" ? true : false; - addToContacts(contact_info["id"].toStdString(), linked.owner.profileInfo.type, banned); + addToContacts(contact_info["id"].toStdString(), linked.owner.profileInfo.type, "", banned); } // Add pending contacts @@ -637,7 +639,7 @@ ContactModelPimpl::slotContactAdded(const std::string& accountId, const std::str bannedContacts.erase(it); } - addToContacts(contactUri, linked.owner.profileInfo.type, false); + addToContacts(contactUri, linked.owner.profileInfo.type, "", false); } } @@ -701,10 +703,10 @@ ContactModelPimpl::slotContactRemoved(const std::string& accountId, const std::s } void -ContactModelPimpl::addToContacts(const std::string& contactUri, const profile::Type& type, bool banned) +ContactModelPimpl::addToContacts(const std::string& contactUri, const profile::Type& type, const std::string& displayName, bool banned) { // create a vcard if necessary - profile::Info profileInfo{ contactUri, {}, {}, linked.owner.profileInfo.type }; + profile::Info profileInfo{ contactUri, displayName, {}, linked.owner.profileInfo.type }; storage::createOrUpdateProfile(linked.owner.id, profileInfo, true); auto contactInfo = storage::buildContactFromProfile(linked.owner.id, contactUri, type); @@ -715,6 +717,8 @@ ContactModelPimpl::addToContacts(const std::string& contactUri, const profile::T ConfigurationManager::instance().lookupAddress(QString::fromStdString(linked.owner.id), "", QString::fromStdString(contactUri)); PresenceManager::instance().subscribeBuddy(linked.owner.id.c_str(), contactUri.c_str(), !banned); + } else { + contactInfo.profileInfo.alias = displayName; } contactInfo.profileInfo.type = type; // Because PENDING should not be stored in the database @@ -811,17 +815,24 @@ ContactModelPimpl::slotIncomingContactRequest(const std::string& accountId, } void -ContactModelPimpl::slotIncomingCall(const std::string& fromId, const std::string& callId) +ContactModelPimpl::slotIncomingCall(const std::string& fromId, const std::string& callId, const std::string& displayname) { bool emitContactAdded = false; { std::lock_guard<std::mutex> lk(contactsMtx_); - if (contacts.find(fromId) == contacts.end()) { + auto it = contacts.find(fromId); + if (it == contacts.end()) { // Contact not found, load profile from database. // The conversation model will create an entry and link the incomingCall. auto type = (linked.owner.profileInfo.type == profile::Type::RING) ? profile::Type::PENDING : profile::Type::SIP; - addToContacts(fromId, type, false); + addToContacts(fromId, type, displayname, false); emitContactAdded = true; + } else { + // Update the display name + if (!displayname.empty()) { + it->second.profileInfo.alias = displayname; + storage::createOrUpdateProfile(linked.owner.id, it->second.profileInfo, true); + } } } if (emitContactAdded) { @@ -851,13 +862,13 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId, if (linked.owner.profileInfo.type == profile::Type::SIP) { std::string potentialContact = sipUriReceivedFilter(from); if (potentialContact.empty()) { - addToContacts(from, profile::Type::SIP, false); + addToContacts(from, profile::Type::SIP, "", false); } else { // equivalent uri exist, use that uri from = potentialContact; } } else { - addToContacts(from, profile::Type::PENDING, false); + addToContacts(from, profile::Type::PENDING, "", false); emitNewTrust = true; } } @@ -937,7 +948,7 @@ ContactModelPimpl::slotNewAccountTransfer(long long dringId, datatransfer::Info auto type = (linked.owner.profileInfo.type == profile::Type::RING) ? profile::Type::PENDING : profile::Type::SIP; - addToContacts(info.peerUri, type, false); + addToContacts(info.peerUri, type, "", false); emitNewTrust = (linked.owner.profileInfo.type == profile::Type::RING); } } diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp index 84f81cdc5e9737197e6413564663b3de9caa0826..620e6b9a07b436ba989300a0b926e49d321a9bb8 100644 --- a/src/newcallmodel.cpp +++ b/src/newcallmodel.cpp @@ -149,8 +149,9 @@ public Q_SLOTS: * @param accountId account which receives the call * @param callId * @param fromId peer uri + * @param displayname */ - void slotIncomingCall(const std::string& accountId, const std::string& callId, const std::string& fromId); + void slotIncomingCall(const std::string& accountId, const std::string& callId, const std::string& fromId, const std::string& displayname); /** * Listen from CallbacksHandler when a call got a new state * @param callId @@ -649,7 +650,7 @@ NewCallModel::hangupCallsAndConferences() } void -NewCallModelPimpl::slotIncomingCall(const std::string& accountId, const std::string& callId, const std::string& fromId) +NewCallModelPimpl::slotIncomingCall(const std::string& accountId, const std::string& callId, const std::string& fromId, const std::string& displayname) { if (linked.owner.id != accountId) { return; @@ -674,7 +675,7 @@ NewCallModelPimpl::slotIncomingCall(const std::string& accountId, const std::str return; } - emit linked.newIncomingCall(fromId, callId); + emit linked.newIncomingCall(fromId, callId, displayname); // HACK. BECAUSE THE DAEMON DOESN'T HANDLE THIS CASE! if (linked.owner.confProperties.autoAnswer) {