Skip to content
Snippets Groups Projects
Unverified Commit db54e18b authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin
Browse files

displayname: add display name into alias for an incoming call

Change-Id: Ic7c9301f586e0af174e230badd952fbb0ef8bc61
parent 9354ee2c
Branches release/202001
No related tags found
No related merge requests found
...@@ -251,8 +251,9 @@ Q_SIGNALS: ...@@ -251,8 +251,9 @@ Q_SIGNALS:
* Emitted when a call is incoming * Emitted when a call is incoming
* @param callId * @param callId
* @param fromId the peer uri * @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 * Emitted when a call is added to a conference
* @param callId * @param callId
......
...@@ -323,16 +323,22 @@ CallbacksHandler::slotIncomingContactRequest(const QString& accountId, ...@@ -323,16 +323,22 @@ CallbacksHandler::slotIncomingContactRequest(const QString& accountId,
void void
CallbacksHandler::slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri) CallbacksHandler::slotIncomingCall(const QString &accountId, const QString &callId, const QString &fromUri)
{ {
std::string displayname;
if (fromUri.contains("ring.dht")) { 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); auto fromQString = fromUri.right(50);
fromQString = fromQString.left(40); fromQString = fromQString.left(40);
emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString()); emit incomingCall(accountId.toStdString(), callId.toStdString(), fromQString.toStdString(), displayname);
} else { } else {
auto left = fromUri.indexOf("<") + 1; auto left = fromUri.indexOf("<") + 1;
auto right = fromUri.indexOf("@"); auto right = fromUri.indexOf("@");
auto fromQString = fromUri.mid(left, right-left); 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);
} }
} }
......
...@@ -103,10 +103,12 @@ Q_SIGNALS: ...@@ -103,10 +103,12 @@ Q_SIGNALS:
* @param accountId the one who receives the call * @param accountId the one who receives the call
* @param callId the call id * @param callId the call id
* @param fromUri the caller uri * @param fromUri the caller uri
* @param displayName the display name of incoming call
*/ */
void incomingCall(const std::string& accountId, void incomingCall(const std::string& accountId,
const std::string& callId, 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 * Connect this signal to know when a call is updated
* @param callId the call id * @param callId the call id
......
...@@ -82,9 +82,10 @@ public: ...@@ -82,9 +82,10 @@ public:
* @note: the contactId must corresponds to a profile in the database. * @note: the contactId must corresponds to a profile in the database.
* @param contactId * @param contactId
* @param type * @param type
* @param displayName
* @param banned whether contact is banned or not * @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. * Helpers for searchContact. Search for a given RING or SIP contact.
*/ */
...@@ -158,8 +159,9 @@ public Q_SLOTS: ...@@ -158,8 +159,9 @@ public Q_SLOTS:
* Listen from callModel when an incoming call arrives. * Listen from callModel when an incoming call arrives.
* @param fromId * @param fromId
* @param callId * @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 * Listen from callbacksHandler for new account interaction and add pending contact if not present
...@@ -530,7 +532,7 @@ ContactModelPimpl::fillWithJamiContacts() { ...@@ -530,7 +532,7 @@ ContactModelPimpl::fillWithJamiContacts() {
for (auto contact_info : contacts_vector) { for (auto contact_info : contacts_vector) {
std::lock_guard<std::mutex> lk(contactsMtx_); std::lock_guard<std::mutex> lk(contactsMtx_);
bool banned = contact_info["banned"] == "true" ? true : false; 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 // Add pending contacts
...@@ -637,7 +639,7 @@ ContactModelPimpl::slotContactAdded(const std::string& accountId, const std::str ...@@ -637,7 +639,7 @@ ContactModelPimpl::slotContactAdded(const std::string& accountId, const std::str
bannedContacts.erase(it); 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 ...@@ -701,10 +703,10 @@ ContactModelPimpl::slotContactRemoved(const std::string& accountId, const std::s
} }
void 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 // 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); storage::createOrUpdateProfile(linked.owner.id, profileInfo, true);
auto contactInfo = storage::buildContactFromProfile(linked.owner.id, contactUri, type); auto contactInfo = storage::buildContactFromProfile(linked.owner.id, contactUri, type);
...@@ -715,6 +717,8 @@ ContactModelPimpl::addToContacts(const std::string& contactUri, const profile::T ...@@ -715,6 +717,8 @@ ContactModelPimpl::addToContacts(const std::string& contactUri, const profile::T
ConfigurationManager::instance().lookupAddress(QString::fromStdString(linked.owner.id), ConfigurationManager::instance().lookupAddress(QString::fromStdString(linked.owner.id),
"", QString::fromStdString(contactUri)); "", QString::fromStdString(contactUri));
PresenceManager::instance().subscribeBuddy(linked.owner.id.c_str(), contactUri.c_str(), !banned); 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 contactInfo.profileInfo.type = type; // Because PENDING should not be stored in the database
...@@ -811,17 +815,24 @@ ContactModelPimpl::slotIncomingContactRequest(const std::string& accountId, ...@@ -811,17 +815,24 @@ ContactModelPimpl::slotIncomingContactRequest(const std::string& accountId,
} }
void 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; bool emitContactAdded = false;
{ {
std::lock_guard<std::mutex> lk(contactsMtx_); 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. // Contact not found, load profile from database.
// The conversation model will create an entry and link the incomingCall. // 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; 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; 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) { if (emitContactAdded) {
...@@ -851,13 +862,13 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId, ...@@ -851,13 +862,13 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId,
if (linked.owner.profileInfo.type == profile::Type::SIP) { if (linked.owner.profileInfo.type == profile::Type::SIP) {
std::string potentialContact = sipUriReceivedFilter(from); std::string potentialContact = sipUriReceivedFilter(from);
if (potentialContact.empty()) { if (potentialContact.empty()) {
addToContacts(from, profile::Type::SIP, false); addToContacts(from, profile::Type::SIP, "", false);
} else { } else {
// equivalent uri exist, use that uri // equivalent uri exist, use that uri
from = potentialContact; from = potentialContact;
} }
} else { } else {
addToContacts(from, profile::Type::PENDING, false); addToContacts(from, profile::Type::PENDING, "", false);
emitNewTrust = true; emitNewTrust = true;
} }
} }
...@@ -937,7 +948,7 @@ ContactModelPimpl::slotNewAccountTransfer(long long dringId, datatransfer::Info ...@@ -937,7 +948,7 @@ ContactModelPimpl::slotNewAccountTransfer(long long dringId, datatransfer::Info
auto type = (linked.owner.profileInfo.type == profile::Type::RING) auto type = (linked.owner.profileInfo.type == profile::Type::RING)
? profile::Type::PENDING ? profile::Type::PENDING
: profile::Type::SIP; : profile::Type::SIP;
addToContacts(info.peerUri, type, false); addToContacts(info.peerUri, type, "", false);
emitNewTrust = (linked.owner.profileInfo.type == profile::Type::RING); emitNewTrust = (linked.owner.profileInfo.type == profile::Type::RING);
} }
} }
......
...@@ -149,8 +149,9 @@ public Q_SLOTS: ...@@ -149,8 +149,9 @@ public Q_SLOTS:
* @param accountId account which receives the call * @param accountId account which receives the call
* @param callId * @param callId
* @param fromId peer uri * @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 * Listen from CallbacksHandler when a call got a new state
* @param callId * @param callId
...@@ -649,7 +650,7 @@ NewCallModel::hangupCallsAndConferences() ...@@ -649,7 +650,7 @@ NewCallModel::hangupCallsAndConferences()
} }
void 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) { if (linked.owner.id != accountId) {
return; return;
...@@ -674,7 +675,7 @@ NewCallModelPimpl::slotIncomingCall(const std::string& accountId, const std::str ...@@ -674,7 +675,7 @@ NewCallModelPimpl::slotIncomingCall(const std::string& accountId, const std::str
return; return;
} }
emit linked.newIncomingCall(fromId, callId); emit linked.newIncomingCall(fromId, callId, displayname);
// HACK. BECAUSE THE DAEMON DOESN'T HANDLE THIS CASE! // HACK. BECAUSE THE DAEMON DOESN'T HANDLE THIS CASE!
if (linked.owner.confProperties.autoAnswer) { if (linked.owner.confProperties.autoAnswer) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment