Skip to content
Snippets Groups Projects
Commit 67339fe4 authored by Johannes Goderbauer's avatar Johannes Goderbauer
Browse files

cti: search localAddress within the usermodel

parent 4ceef83d
No related branches found
No related tags found
No related merge requests found
......@@ -18,12 +18,14 @@ function IncomingCallExecutor(pCallData)
this.callData.stateName = IncomingCallExecutor._callstateToText(this.callData.state);
//collect contact and user data from *US*
this.contactsLocal = IncomingCallExecutor._getContactsFromNumber(this.callData.localAddress);
this.usersLocal = IncomingCallExecutor._getUsersFromContacts(this.contactsLocal);
this.contactsLocal = null;
this.usersLocal = null;
this.collectDataFromLocalInfo();
//collect contact and user data from *THEM*
this.contactsCall = IncomingCallExecutor._getContactsFromNumber(this.callData.callAddress);
this.usersCall = IncomingCallExecutor._getUsersFromContacts(this.contactsCall);
this.contactsCall = null;
this.usersCall = null;
this.collectDataFromCallInfo();
//key-value pairs of states-functions
this._handlerFunctions = {};
......@@ -55,6 +57,32 @@ IncomingCallExecutor.prototype.processPrivateData = function()
}
};
IncomingCallExecutor.prototype.collectDataFromLocalInfo = function()
{
this.usersLocal = [];
var users = tools.getUsersByAttribute(tools.PHONE_ADDRESS, [this.callData.localAddress], tools.PROFILE_DEFAULT);
var userContactIds = [];
for (var i = 0, l = users.length; i < l; i++)
{
var user = users[i];
if (user[tools.PARAMS][tools.ISACTIVE] == "true")
{
this.usersLocal.push(user);
if (user[tools.PARAMS][tools.CONTACTID])
userContactIds.push(user[tools.PARAMS][tools.CONTACTID]);
}
}
this.contactsLocal = IncomingCallExecutor._getContactsFromNumber(null, userContactIds);
};
IncomingCallExecutor.prototype.collectDataFromCallInfo = function()
{
this.contactsCall = IncomingCallExecutor._getContactsFromNumber(this.callData.callAddress);
this.usersCall = IncomingCallExecutor._getUsersFromContacts(this.contactsCall);
};
IncomingCallExecutor.prototype.logData = function()
{
logging.log("ctiServerEvents");
......@@ -62,7 +90,7 @@ IncomingCallExecutor.prototype.logData = function()
logging.log("contactsLocal>>" + JSON.stringify(this.contactsLocal));
logging.log("usersLocal>>" + JSON.stringify(this.usersLocal));
logging.log("contactsCall>>" + JSON.stringify(this.contactsCall));
}
};
IncomingCallExecutor.prototype.getNotificationBaseConfig = function(pUserName)
{
......@@ -149,10 +177,10 @@ IncomingCallExecutor._callstateToText = function(pCallstate)
return callstateName;
};
IncomingCallExecutor._getContactsFromNumber = function(pNumber)
IncomingCallExecutor._getContactsFromNumber = function(pNumber, pContactIds)
{
var phoneNumber = pNumber;
if (!phoneNumber)
if (!phoneNumber && !pContactIds)
return [];
/*
var config = entities.createConfigForLoadingRows().entity("Communication_entity")
......@@ -172,12 +200,14 @@ IncomingCallExecutor._getContactsFromNumber = function(pNumber)
*/
//load entities does not work here, so use instead a traditional sql-query:
var contactSql = SqlCondition.begin()
.andPrepare("COMMUNICATION.ADDR", phoneNumber)
.andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active())
.buildSql("select CONTACT.CONTACTID, CONTACT.ORGANISATION_ID, ORGANISATION.NAME, CONTACT.PERSON_ID, CONTACT.ISOLANGUAGE, PERSON.LASTNAME, PERSON.FIRSTNAME from CONTACT \n\
join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID \n\
left join PERSON on CONTACT.PERSON_ID = PERSON.PERSONID \n\
join COMMUNICATION on COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID");
.andPrepareIfSet("COMMUNICATION.ADDR", phoneNumber)
.andIn("COMMUNICATION.CONTACT_ID", pContactIds)//this is automatically only added if pContactIds is truely
.andPrepare("CONTACT.STATUS", $KeywordRegistry.contactStatus$active())
.buildSql("select CONTACT.CONTACTID, CONTACT.ORGANISATION_ID, ORGANISATION.NAME, CONTACT.PERSON_ID, \n\
CONTACT.ISOLANGUAGE, PERSON.LASTNAME, PERSON.FIRSTNAME from CONTACT \n\
join ORGANISATION on ORGANISATION.ORGANISATIONID = CONTACT.ORGANISATION_ID \n\
left join PERSON on CONTACT.PERSON_ID = PERSON.PERSONID \n\
join COMMUNICATION on COMMUNICATION.CONTACT_ID = CONTACT.CONTACTID");
var contacts = db.table(contactSql);
......@@ -219,12 +249,16 @@ IncomingCallExecutor.prototype.getLocaleFromUser = function(pUserObject)
IncomingCallExecutor.prototype.getFormattedLocalAddress = function()
{
return this.callData.localAddress;
return IncomingCallExecutor.formatAddress(this.callData.localAddress);
}
IncomingCallExecutor.prototype.getFormattedCallAddress = function()
{
return this.callData.callAddress;
return IncomingCallExecutor.formatAddress(this.callData.callAddress);
}
IncomingCallExecutor.formatAddress = function (pAddress)
{
return cti.formatPhoneNumber(pAddress.replace(/P?J?SIP\//, ""), true, null);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment