Unverified Commit db54e18b authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin

displayname: add display name into alias for an incoming call

Change-Id: Ic7c9301f586e0af174e230badd952fbb0ef8bc61
parent 9354ee2c
......@@ -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
......
......@@ -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);
}
}
......
......@@ -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
......
......@@ -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);
}
}
......
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment