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

contactmodel: add sip uri filter

- to verify if equivalent sip uri contacts exists in the contact list

Change-Id: I19be6ce2ab1f470fdbc6f485d52914025c055862
parent 3287c36d
No related branches found
No related tags found
No related merge requests found
...@@ -95,6 +95,11 @@ public: ...@@ -95,6 +95,11 @@ public:
*/ */
void updateTemporaryMessage(const std::string& mes, const std::string& uri); void updateTemporaryMessage(const std::string& mes, const std::string& uri);
/**
* Check if equivalent uri exist in contact
*/
std::string sipUriReceivedFilter(const std::string& uri);
// Helpers // Helpers
const BehaviorController& behaviorController; const BehaviorController& behaviorController;
const ContactModel& linked; const ContactModel& linked;
...@@ -834,11 +839,19 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId, ...@@ -834,11 +839,19 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId,
if (contacts.find(from) == contacts.end()) { if (contacts.find(from) == 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 if (linked.owner.profileInfo.type == profile::Type::SIP) {
: profile::Type::SIP; std::string potentialContact = sipUriReceivedFilter(from);
addToContacts(from, type, false); if (potentialContact.empty()) {
emitNewTrust = (linked.owner.profileInfo.type == profile::Type::RING); addToContacts(from, profile::Type::SIP, false);
} else {
// equivalent uri exist, use that uri
from = potentialContact;
}
} else {
addToContacts(from, profile::Type::PENDING, false);
emitNewTrust = true;
}
} }
} }
if (emitNewTrust) { if (emitNewTrust) {
...@@ -847,6 +860,61 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId, ...@@ -847,6 +860,61 @@ ContactModelPimpl::slotNewAccountMessage(std::string& accountId,
emit linked.newAccountMessage(accountId, from, payloads); emit linked.newAccountMessage(accountId, from, payloads);
} }
std::string
ContactModelPimpl::sipUriReceivedFilter(const std::string& uri)
{
// this function serves when the uri is not found in the contact list
// return "" means need to add new contact, else means equivalent uri exist
std::string uriCopy = uri;
auto pos = uriCopy.find("@");
auto ownerHostName = linked.owner.confProperties.hostname;
if (pos != std::string::npos) {
// "@" is found, separate username and hostname
std::string hostName = uriCopy.substr(pos + 1);
uriCopy.erase(uriCopy.begin() + pos, uriCopy.end());
std::string remoteUser = std::move(uriCopy);
if (hostName.compare(ownerHostName) == 0) {
if (contacts.find(remoteUser) != contacts.end()) {
return remoteUser;
}
if (remoteUser.at(0) == '+') {
// "+" - country dial-in codes
// maximum 3 digits
for (int i = 2; i <= 4; i++) {
std::string tempUserName = remoteUser.substr(i);
if (contacts.find(tempUserName) != contacts.end()) {
return tempUserName;
}
}
return "";
} else {
// if not "+" from incoming
// sub "+" char from contacts to see if user exit
for (auto& i : contacts) {
if (!i.first.empty()) {
for (int j = 2; j <= 4; j++) {
std::string tempUserName = i.first.substr(j);
if (tempUserName == remoteUser) {
return i.first;
}
}
}
}
return "";
}
}
// different hostname means not a phone number
// no need to check country dial-in codes
return "";
}
// "@" is not found -> not possible since all response uri has one
return "";
}
void void
ContactModelPimpl::slotNewAccountTransfer(long long dringId, datatransfer::Info info) ContactModelPimpl::slotNewAccountTransfer(long long dringId, datatransfer::Info info)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment