// Message List page webphone_api._message = (function () { var mAction = ''; var msgSent = false; var textarea = null; var mMessage = ''; var mContent = ''; var sendrec = false; // if at least one message was sent or received in this session var placeholderhidden = false; var enablepres = false; var composePlaceHolder = '' + webphone_api.stringres.get('messagepl') + ''; function onCreate (event) // called only once - bind events here { try{ webphone_api.common.PutToDebugLog(4, "EVENT, _message: onCreate"); webphone_api.$( window ).resize(function() // window resize handling { if (webphone_api.$.mobile.activePage.attr('id') === 'page_message') { MeasureMessage(); } }); webphone_api.$('#message_menu_ul').on('click', 'li', function(event) { MenuItemSelected(webphone_api.$(this).attr('id')); }); webphone_api.$("#msg_textarea").on("click", function() { RemovePlaceHolder(); }); webphone_api.$("#btn_message_menu").on("click", function() { CreateOptionsMenu('#message_menu_ul'); }); webphone_api.$("#btn_message_menu").attr("title", webphone_api.stringres.get("hint_menu")); var lastiscomposingsenttick = 0; //milliseconds. reset to 0 at every chat send and chatreport recv var reportforlastchatmessagereceived= 0; //0=not needed,1=needed,2=received success,3=received fail (set state on chat send to 1 and chatreport recv to 2 or 3) webphone_api.$("#msg_textarea").keyup(function() { // character count webphone_api.$("#msg_charcount").text(webphone_api.$(this).html().length); //don’t send if previous msg is pending if (reportforlastchatmessagereceived === 1) { return; } if (lastiscomposingsenttick === 0 || webphone_api.common.GetTickCount() - lastiscomposingsenttick > 10000) //send in every 10 second on typing { lastiscomposingsenttick = webphone_api.common.GetTickCount(); webphone_api.sendchatiscomposing(webphone_api.global.mto); } }); webphone_api.$( "#msg_textarea" ).keypress(function( event ) { // handle placeholder in div /* if (placeholderhidden === false) { placeholderhidden = true; var mtmp = webphone_api.$("#msg_textarea").html(); if (!webphone_api.common.isNull(mtmp) && mtmp.length > 0) { var pos = mtmp.indexOf(''); if (pos > 0) { mtmp = mtmp.substring(pos + 7); webphone_api.$("#msg_textarea").html(mtmp); } } } */ RemovePlaceHolder(); //-- // handle delete in content ediatble in Firefox //-- if (webphone_api.common.GetBrowser() === 'Firefox') //-- { //-- var charCode = (event.keyCode) ? event.keyCode : event.which; // workaround for firefox //-- if (charCode === 46) // delete //-- { //-- var cpos = GetCursorPosition(document.getElementById('msg_textarea')); //-- var htmlc = webphone_api.$("#msg_textarea").html(); //-- if (webphone_api.common.isNull(cpos) || cpos < 0 || webphone_api.common.isNull(htmlc) || htmlc.length < cpos) { return; } //-- alert(htmlc); //-- var delidx = 0; //-- var insidetag = false; // don't count characters if we are inside of a html tag //-- for (var i = 0; i < htmlc.length; i++) //-- { //-- if (delidx === cpos) //-- { //-- var begin = htmlc.substring(0, i); //-- var end = htmlc.substring(i + 1, htmlc.length); //-- webphone_api.$("#msg_textarea").html(begin + end); //-- break; //-- } //-- if (htmlc.charCodeAt(i) === '<') { insidetag = true; } //-- if (insidetag === true && htmlc.charCodeAt(i - 1) === '>') { insidetag = false; } //-- if (insidetag === false) //-- { //-- delidx++; //-- } //-- } //-- } //-- } if (webphone_api.common.GetParameter2('sendchatonenter') !== 'false') { if ( event.which === 13) { event.preventDefault(); webphone_api.$("#btn_msgsend").click(); }else { return; } }else { return; } }); webphone_api.$("#status_message").attr("title", webphone_api.stringres.get("hint_status")); webphone_api.$("#curr_user_message").attr("title", webphone_api.stringres.get("hint_curr_user")); webphone_api.$("#btn_msgsend").on("click", function() { SendMessage(); lastiscomposingsenttick = 0; }); webphone_api.$("#msg_btn_sendfile").on("click", function() { webphone_api.common.FileTransfer(webphone_api.$("#msgpick_input").val()); }); webphone_api.$("#msg_btn_sendfile").attr("title", webphone_api.stringres.get("hint_filetranf")); webphone_api.$("#btn_msgsend").attr("title", webphone_api.stringres.get('hint_sendmsg')); webphone_api.$("#msg_btn_smiley").on("click", function() { OpenSmileys(); }); webphone_api.$("#msg_btn_smiley").attr("title", webphone_api.stringres.get('hint_smiley')); webphone_api.$("#btn_msgpick").on("click", function() { webphone_api.common.PickContact(PickContactResult); }); webphone_api.$("#btn_msgpick").attr("title", webphone_api.stringres.get('hint_choosect')); webphone_api.$("#msg_btnback").attr("title", webphone_api.stringres.get("hint_btnback")); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: onCreate", err); } } function GetCursorPosition(element) { try{ var caretOffset = 0; var doc = element.ownerDocument || element.document; var win = doc.defaultView || doc.parentWindow; var sel; if (typeof win.getSelection != "undefined") { sel = win.getSelection(); if (sel.rangeCount > 0) { var range = win.getSelection().getRangeAt(0); var preCaretRange = range.cloneRange(); preCaretRange.selectNodeContents(element); preCaretRange.setEnd(range.endContainer, range.endOffset); caretOffset = preCaretRange.toString().length; } } else if ( (sel = doc.selection) && sel.type != "Control") { var textRange = sel.createRange(); var preCaretTextRange = doc.body.createTextRange(); preCaretTextRange.moveToElementText(element); preCaretTextRange.setEndPoint("EndToEnd", textRange); caretOffset = preCaretTextRange.text.length; } return caretOffset; } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: GetCursorPosition", err); } return 0; } function onStart(event) { try{ webphone_api.common.PutToDebugLog(4, "EVENT, _message: onStart"); webphone_api.global.isMessageStarted = true; //-- webphone_api.$("#phone_number").attr("placeholder", webphone_api.stringres.get("phone_nr")); //-- document.getElementById("app_name_message").innerHTML = webphone_api.common.GetBrandName(); webphone_api.$(".separator_line_thick").css( 'background-color', webphone_api.common.HoverCalc(webphone_api.common.getBgColor('#page_message'), -30) ); // add placeholder on page start webphone_api.$( "#msg_textarea" ).html(composePlaceHolder); // needed for proper display and scrolling of listview MeasureMessage(); if (webphone_api.common.UsePresence2() === true) { enablepres = true; } // fix for IE 10 //-- if (webphone_api.common.IsIeVersion(10)) { webphone_api.$("#messagelist_list").children().css('line-height', 'normal'); } mAction = webphone_api.common.GetIntentParam(webphone_api.global.intentmsg, 'action'); webphone_api.global.mto = webphone_api.common.GetIntentParam(webphone_api.global.intentmsg, 'to'); mMessage = webphone_api.common.GetIntentParam(webphone_api.global.intentmsg, 'message'); if (!webphone_api.common.isNull(document.getElementById('msg_title')) && !webphone_api.common.isNull(mAction)) { if (mAction === 'sms') { document.getElementById('msg_title').innerHTML = webphone_api.stringres.get("msg_title_sms"); }else { document.getElementById('msg_title').innerHTML = webphone_api.stringres.get("msg_title_chat"); } } webphone_api.$("#msg_title").attr("title", webphone_api.stringres.get("hint_page")); if (!webphone_api.common.isNull(document.getElementById('msg_btnback'))) { document.getElementById('msg_btnback').innerHTML = '< ' + webphone_api.stringres.get("go_back_btn_txt"); } if (webphone_api.common.isNull(webphone_api.global.mto)) { webphone_api.global.mto = ''; } if (webphone_api.common.isNull(mMessage)) { mMessage = ''; } webphone_api.$("#msgpick_input").attr("placeholder", webphone_api.stringres.get("chat_nr")); webphone_api.$('#msgpick_input').keyup(function() { HandleChatSms(); }); webphone_api.$('#msgpick_input').on('input',function(e){ HandleChatSms(); }); // set focus on destination or message compose area setTimeout(function () { var tovalTmp = webphone_api.$("#msgpick_input").val(); if (webphone_api.common.isNull(tovalTmp) || (webphone_api.common.Trim(tovalTmp)).length < 1) { webphone_api.$("#msgpick_input").focus(); }else { webphone_api.$("#msg_textarea").focus(); } }, 100); LoadMessage(); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: onStart", err); } } // decice whether is chat or sms, based on input number function HandleChatSms() { try{ //-- !!!NOT NEEDED if (webphone_api.common.GetParameterBool('customizedversion', true) === false) { return; } var sms = webphone_api.common.GetParameter('sms'); if (webphone_api.common.isNull(sms) || sms.length < 3) { return; } /* var textmessaging = webphone_api.common.GetParameterInt('textmessaging',-2); if(textmessaging < -1) { var chatsms = webphone_api.common.GetParameterInt('chatsms',-2); switch(chatsms) { case 0: textmessaging = -1; break; case 1: textmessaging = 3; break; case 2: textmessaging = 6; break; case 3: textmessaging = 0; break; } if(textmessaging < -1) { var haschat = webphone_api.common.GetParameterInt('haschat'); switch(haschat) { case 0: textmessaging = 0; break; case 1: textmessaging = 3; break; case 2: textmessaging = 5; break; case 3: textmessaging = 6; break; case 4: textmessaging = -1; break; } } } */ var nr = webphone_api.$("#msgpick_input").val(); if (webphone_api.common.isNull(nr) || webphone_api.common.Trim(nr).length < 1) { return; } nr = webphone_api.common.Trim(nr); /* if (textmessaging < 0) // if (chatsms === '0') // Ask / Automatic !!!! Treat as automatic (Istvan) { var tmpNumber = nr; if (tmpNumber.indexOf('+') >= 0) { tmpNumber = tmpNumber.substring(tmpNumber.indexOf('+') + 1, tmpNumber.length); } //if (!tmpNumber.match('^[0-9 ]{6,20}$')) if (webphone_api.common.IsNumber(tmpNumber) && tmpNumber.length > 6 && tmpNumber.length < 20) { mAction = 'sms'; document.getElementById('msg_title').innerHTML = webphone_api.stringres.get("msg_title_sms"); }else { mAction = 'chat'; document.getElementById('msg_title').innerHTML = webphone_api.stringres.get("msg_title_chat"); // This was used for "Ask" // PutToDebugLog(4, 'EVENT, StartMsg called action: ' + action + '; number: ' + number + '; fromclass: ' + fromclass + ' (4)'); // ChooseChatOrSms(number, msg); } } */ } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: HandleChatSms", err); } } function MeasureMessage() // resolve window height size change { try{ //-- var pgh = webphone_api.common.GetDeviceHeight() - 1; webphone_api.$('#page_message').css('min-height', pgh + 'px'); // must be set when softphone is skin in div webphone_api.$('#page_message').css('min-height', 'auto'); // must be set when softphone is skin in div var heightTemp = webphone_api.common.GetDeviceHeight() - webphone_api.$("#message_header").height() /*- webphone_api.$('#msg_spacer').height()*/ - webphone_api.$('#msg_textarea_container').height(); if (document.getElementById('msgpick_container').style.display === 'block') { heightTemp = heightTemp - webphone_api.$("#msgpick_container").height(); } var curruser = webphone_api.common.GetCallerid(); if (!webphone_api.common.isNull(curruser) && curruser.length > 0) { webphone_api.$('#curr_user_message').html(curruser); } // set status width so it's uses all space to curr_user var statwidth = webphone_api.common.GetDeviceWidth() - webphone_api.$('#curr_user_message').width() - 25; if (!webphone_api.common.isNull(statwidth) && webphone_api.common.IsNumber(statwidth)) { webphone_api.$('#status_message').width(statwidth); } heightTemp = Math.floor( heightTemp - 6 ); webphone_api.$("#msg_list").height(heightTemp); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: MeasureMessage", err); } } function LoadMessage() { try{ // if file exists, read content and populateit if (!webphone_api.common.isNull(webphone_api.global.mto) && webphone_api.global.mto.length > 0) { document.getElementById('msgpick_input').value = webphone_api.global.mto; // filenames: sms/chat_username_number var currfile = mAction + '_' + webphone_api.common.GetSipusername(true) + '_' + webphone_api.global.mto; webphone_api.File.ReadFile(currfile, webphone_api.global.STORAGE_LOCAL, function (content) { if ( webphone_api.common.isNull(content) || webphone_api.common.Trim(content).length < 1 ) { webphone_api.common.PutToDebugLog(2, 'ERROR, _message: LoadMessage no content'); content = ''; document.getElementById('msgpick_container').style.display = 'block'; MeasureMessage(); } mContent = content; if (!webphone_api.common.isNull(mMessage) && mMessage.length > 0 && mContent.indexOf('
' + mMessage + '
') < 0) { AddMessage('1', true); } PopulateData(); }); }else { document.getElementById('msgpick_container').style.display = 'block'; MeasureMessage(); if (!webphone_api.common.isNull(mMessage) && mMessage.length > 0 && mContent.indexOf('' + mMessage + '
') < 0) { AddMessage('1', true); } PopulateData(); } } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: LoadMessage", err); } } function PopulateData() // :no return value { try{ if ( webphone_api.common.isNull(document.getElementById('page_message_content')) ) { webphone_api.common.PutToDebugLog(2, "ERROR, _message: PopulateList listelement is null"); return; } // filenames: sms/chat_username_number webphone_api.$('#msg_list').html(''); webphone_api.$('#msg_list').append(mContent); ScrollToBottom(); RemoveNotification(); // show presence status in title, if we have username/contact if (!webphone_api.common.isNull(webphone_api.global.mto) && webphone_api.global.mto.length > 0 && enablepres === true) { var presencequery = []; var presence = '-1'; var presobj = webphone_api.global.presenceHM[webphone_api.global.mto]; if (!webphone_api.common.isNull(presobj)) { presence = presobj[webphone_api.common.PRES_STATUS]; } // -1=not exists(undefined), 0=offline, 1=invisible, 2=idle, 3=pending, 4=DND, 5=online if (webphone_api.common.isNull(presence) || presence.length < 1 || presence === '-1') { webphone_api.common.PresenceGet2(webphone_api.global.mto); }else { DisplayPresence(presence); } } } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: LoadMessage", err); } } function RefreshPresence() { webphone_api.common.PresenceGet2(webphone_api.global.mto); } var lastpres_stat = ''; function DisplayPresence(presence) { try{ if (enablepres !== true || webphone_api.common.isNull(presence) || presence.length < 1) { return; } lastpres_stat = presence; if (!webphone_api.common.isNull(document.getElementById('msg_title')) && !webphone_api.common.isNull(mAction)) { var ptitle = ''; if (mAction === 'sms') { ptitle = webphone_api.stringres.get("msg_title_sms"); } else { ptitle = webphone_api.stringres.get("msg_title_chat"); } var presenceimg = ''; if (webphone_api.common.isNull(presence) || presence.length < 1) { presenceimg = ''; } else if (presence === '0') // offline { presenceimg = '
';
}
else if (presence === '1') // invisible
{
presenceimg = '
';
}
else if (presence === '2') // idle
{
presenceimg = '
';
}
else if (presence === '3') // pending
{
presenceimg = '
';
}
else if (presence === '4') // DND
{
presenceimg = '
';
}
else if (presence === '5') // online
{
presenceimg = '
';
}
else
{
presenceimg = '';
}
if (!webphone_api.common.isNull(presenceimg) && presenceimg.length > 0 && !webphone_api.common.isNull(webphone_api.global.mto) && webphone_api.global.mto.length > 0)
{
ptitle = ptitle + ' ' + webphone_api.global.mto + ' ' + presenceimg;
document.getElementById('msg_title').innerHTML = ptitle;
}
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: DisplayPresence", err); }
}
function RemoveNotification() // remove new message notification (number) from filenames list for the opened message thread
{
try{
var files = webphone_api.common.GetParameter('messagefiles');
if (webphone_api.common.isNull(files) || files.length < 3)
{
webphone_api.common.PutToDebugLog(3, 'EVENT, _message: RemoveNotification no message files');
return;
}
var msglist = [];
if (!webphone_api.common.isNull(files) && files.length > 0)
{
msglist = files.split(',');
}
var currfile = mAction + '_' + webphone_api.common.GetSipusername(true) + '_' + webphone_api.global.mto + '[#';
for (var i = 0; i < msglist.length; i++)
{
if (webphone_api.common.isNull(msglist[i]) || msglist[i].length < 3) { continue; }
if (msglist[i].indexOf(currfile) === 0)
{
var pos = msglist[i].indexOf('[#');
msglist[i] = msglist[i].substring(0, pos);
// save list
files = '';
for (var j = 0; j < msglist.length; j++)
{
files = files + ',' + msglist[j];
}
if (files.indexOf(',') === 0) { files = files.substring(1); } // cut off first comma ,
if (files.lastIndexOf(',') === files.length - 1) { files = files.substring(0, files.length - 1); } // cut off last comma ,
webphone_api.common.SaveParameter('messagefiles', files);
break;
}
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: RemoveNotification", err); }
}
function PickContactResult(number)
{
try{
document.getElementById('msgpick_input').value = number;
webphone_api.$("#msg_textarea").focus();
HandleChatSms();
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: PickContactResult", err); }
}
function AddToGroupChat(dest)
{
try{
if (webphone_api.common.isNull(dest) || webphone_api.common.Trim(dest).length < 1)
{
webphone_api.common.PutToDebugLog(2, 'ERROR, _message: AddToGroupChat invalid destination: ' + dest);
return;
}
var inp = document.getElementById('msgpick_input');
var currval = inp.value;
if (webphone_api.common.isNull(currval)) { currval = ''; }
currval = webphone_api.common.Trim(currval);
// send special message
if (sendrec === true)
{
if (mAction === 'chat')
{
var dstlist = currval.split(',');
for (var i = 0; i < dstlist.length; i++)
{
if (webphone_api.common.isNull(dstlist[i]) || webphone_api.common.Trim(dstlist[i]).length < 1) { continue; }
// send special message about group chat on first message
var joined = dest + ' ' + webphone_api.stringres.get('gc_message2');
webphone_api.sendchat(webphone_api.common.Trim(dstlist[i]), joined);
}
// send special message about group chat on first message
var chatwith = '[' + webphone_api.stringres.get('gc_message') + ': ' + currval + ']';
webphone_api.sendchat(dest, chatwith);
}
}
if (currval.length > 0) { currval = currval + ','; }
currval = currval + dest;
inp.value = currval;
webphone_api.common.PutToDebugLog(2, 'EVENT, _message: AddToGroupChat: ' + dest);
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: AddToGroupChat", err); }
}
function RemovePlaceHolder()
{
if (placeholderhidden === true) return;
try{
placeholderhidden = true;
var mtmp = webphone_api.$("#msg_textarea").html();
if (!webphone_api.common.isNull(mtmp) && mtmp.length > 0)
{
var pos = mtmp.indexOf('');
if (pos > 0)
{
mtmp = mtmp.substring(pos + 7);
webphone_api.$("#msg_textarea").html(mtmp);
}
}
if (webphone_api.common.isNull(textarea))
{
textarea = document.getElementById('msg_textarea');
if (webphone_api.common.isNull(textarea))
{
return;
}
}
var mMessageTmp = textarea.innerHTML;
if(mMessageTmp.length < 1) return;
if (!webphone_api.common.isNull(mMessageTmp) && mMessageTmp.indexOf(composePlaceHolder))
{
mMessageTmp = mMessageTmp.replace(composePlaceHolder, '');
textarea.innerHTML = mMessageTmp;
}
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: RemovePlaceHolder", err); }
}
function SendMessage() // validate and send chat/sms
{
try{
webphone_api.common.PutToDebugLog(5, 'EVENT, _message: SendMessage onclick');
if (webphone_api.common.isNull(textarea))
{
textarea = document.getElementById('msg_textarea');
if (webphone_api.common.isNull(textarea))
{
webphone_api.common.PutToDebugLog(2, 'ERROR, _message: SendMessage textarea is NULL');
return;
}
}
//-- mMessage = textarea.value;
RemovePlaceHolder();
mMessage = textarea.innerHTML;
// if (!webphone_api.common.isNull(mMessage)) { mMessage = mMessage.replace(composePlaceHolder, ''); }
//-- if (webphone_api.common.isNull(webphone_api.global.mto) || webphone_api.global.mto.length < 1)
//-- {
var tofrom = document.getElementById('msgpick_input').value;
if ( webphone_api.common.isNull(tofrom) || (webphone_api.common.Trim(tofrom)).length < 1 )
{
if (mAction === 'sms')
{
webphone_api.common.ShowToast(webphone_api.stringres.get('err_msg_5'));
}else
{
webphone_api.common.ShowToast(webphone_api.stringres.get('err_msg_6'));
}
return;
}else
{
webphone_api.global.mto = tofrom;
}
//-- }
if ( webphone_api.common.isNull(mMessage) || (webphone_api.common.Trim(mMessage)).length < 1 )
{
//textarea.value = '';
textarea.innerHTML = '';
return;
}
mMessage = RemoveEmoticon(mMessage);
SendAction(webphone_api.global.mto, mMessage);
//-- textarea.value = '';
textarea.innerHTML = '';
if (msgSent)
{
AddMessage('1', false);
//-- // show that message is sent after 1500 ms (FAKE)
//-- setTimeout(function ()
//-- {
//-- webphone_api.common.ShowToast(webphone_api.stringres.get('message_sent'));
//-- // request focus after toast closes
//-- setTimeout(function ()
//-- {
//-- textarea.focus();
//-- }, 3500);
//-- }, 1500);
}else
{
AddMessage('0', false);
}
textarea.focus();
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: SendMessage", err); }
}
function SendAction(to, msg) // actually send the message
{
try{
var smsapi = webphone_api.common.GetParameter('sms');
if (mAction === 'sms' && !webphone_api.common.isNull(smsapi) && smsapi.length > 0)
{
webphone_api.common.PutToDebugLog(5,"EVENT, _message SMS SendMessage to: " + webphone_api.global.mto + '; message: ' + mMessage);
var toLocal = webphone_api.common.Trim(webphone_api.global.mto);
var msgLocal = webphone_api.common.StripXML(mMessage);
// handle groupchat
if (webphone_api.global.mto.indexOf(',') > 0)
{
var dstlist = webphone_api.global.mto.split(',');
for (var i = 0; i < dstlist.length; i++)
{
if (webphone_api.common.isNull(dstlist[i]) || webphone_api.common.Trim(dstlist[i]).length < 1) { continue; }
// send special message about group chat on first message
if (sendrec === false)
{
var chatwith = dstlist.toString();
chatwith = chatwith.replace(',' + dstlist[i], '');
chatwith = chatwith.replace(dstlist[i] + ',', '');
chatwith = chatwith.replace(dstlist[i], '');
chatwith = '[' + webphone_api.stringres.get('gc_message') + ': ' + chatwith + ']';
webphone_api.common.UriParser(smsapi, '', webphone_api.common.GetSipusername(true), webphone_api.common.Trim(dstlist[i]), chatwith, 'sendsms');
}
webphone_api.common.UriParser(smsapi, '', webphone_api.common.GetSipusername(true), webphone_api.common.Trim(dstlist[i]), msgLocal, 'sendsms');
}
}else
{
webphone_api.common.UriParser(smsapi, '', webphone_api.common.GetSipusername(true), toLocal, msgLocal, 'sendsms');
}
msgSent = true;
}else
{
if (webphone_api.global.mto.indexOf(',') > 0 && sendrec === false)
{
var dstlist = webphone_api.global.mto.split(',');
for (var i = 0; i < dstlist.length; i++)
{
if (webphone_api.common.isNull(dstlist[i]) || webphone_api.common.Trim(dstlist[i]).length < 1) { continue; }
// send special message about group chat on first message
var chatwith = dstlist.toString();
chatwith = chatwith.replace(',' + dstlist[i], '');
chatwith = chatwith.replace(dstlist[i] + ',', '');
chatwith = chatwith.replace(dstlist[i], '');
chatwith = '[' + webphone_api.stringres.get('gc_message') + ': ' + chatwith + ']';
webphone_api.sendchat(webphone_api.common.Trim(dstlist[i]), chatwith);
}
}
webphone_api.sendchat(webphone_api.global.mto, mMessage);
msgSent = true;
}
sendrec = true;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: SendAction", err); }
}
var month = new Array();
month[0] = 'Jan';
month[1] = 'Feb';
month[2] = 'Mar';
month[3] = 'Apr';
month[4] = 'May';
month[5] = 'Jun';
month[6] = 'Jul';
month[7] = 'Aug';
month[8] = 'Sep';
month[9] = 'Oct';
month[10] = 'Nov';
month[11] = 'Dec';
function GetDateForMessage()
{
try{
var date = new Date();
var minutes = date.getMinutes();
if (minutes < 10) { minutes = '0' + minutes; }
var day = date.getDate(); //-- getDay returns the day of the week
if (day < 10) { day = '0' + day; }
var datestr = month[date.getMonth()] + ', ' + day + ' ' + date.getFullYear()+ ' '
+ date.getHours() + ':' + minutes;
return datestr;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: GetDateForMessage", err); }
return '';
}
var lastmsg = '';
var lasttickmsg = 0;
var climit = -1;
// add message to UI and save it in List' + formattedmsg + '
' + GetDateForMessage() + '
' + msg + '
' + GetDateForMessage() + '
'; // filenames: sms/chat_username_number[#nrofmissedmessage if (webphone_api.common.isNull(from) || from.length < 1) { webphone_api.common.PutToDebugLog(2, 'ERROR, _message: SaveMissedIncomingMessage source number is NULL'); return; } var currfile = action + '_' + webphone_api.common.GetSipusername(true) + '_' + from; var files = webphone_api.common.GetParameter('messagefiles'); var msglist = []; if (!webphone_api.common.isNull(files) && files.length > 0) { msglist = files.split(','); } var filenameAdded = false; var nrmissed = 0; // number of missed messages //check if filename exists is msglist and make it the first element (last used - first in msg listview) for (var i = 0; i < msglist.length; i++) { if (webphone_api.common.isNull(msglist[i])) { continue; } // cut off number of missed messages from file names var tempmsgfile = msglist[i]; var pos = tempmsgfile.indexOf('[#'); if (pos > 0) { tempmsgfile = tempmsgfile.substring(0, pos); } if (tempmsgfile === currfile) { if (pos > 0) { var temp = webphone_api.common.Trim( msglist[i].substring(pos + 2) ); if (temp.length > 0) { try{ nrmissed = webphone_api.common.StrToInt(temp); } catch(err) { } } } nrmissed = nrmissed + 1; msglist.splice(i, 1); msglist.unshift(currfile + '[#' + nrmissed); // save list files = ''; for (var j = 0; j < msglist.length; j++) { files = files + ',' + msglist[j]; } if (files.indexOf(',') === 0) { files = files.substring(1); } // cut off first comma , if (files.lastIndexOf(',') === files.length - 1) { files = files.substring(0, files.length - 1); } // cut off last comma , webphone_api.common.SaveParameter('messagefiles', files); filenameAdded = true; break; } } if (!filenameAdded) { if (files.length > 0) { files = currfile + '[#1' + ',' + files; }else { files = currfile + '[#1'; } webphone_api.common.SaveParameter('messagefiles', files); } // first read file, then save it if (webphone_api.common.IsWindowsSoftphone()) { webphone_api.common.ApiWinLoadFile(currfile, function (content) { if ( webphone_api.common.isNull(content) ) { content = ''; } content = content + item; webphone_api.common.ApiWinSaveFile(currfile, content, function (success) { if (!success) { webphone_api.common.PutToDebugLog(2, 'ERROR, _message: SaveMissedIncomingMessage cannot save message file (1) WinApi'); } }); }); }else { webphone_api.File.ReadFile(currfile, webphone_api.global.STORAGE_LOCAL, function (content) { if ( webphone_api.common.isNull(content) ) { content = ''; } content = content + item; webphone_api.File.SaveFile(currfile, content, webphone_api.global.STORAGE_LOCAL, function (success) { if (!success) { webphone_api.common.PutToDebugLog(2, 'ERROR, _message: SaveMissedIncomingMessage cannot save message file (1)'); } }); }); } } catch(err) { webphone_api.common.PutToDebugLogException(2, '_message: SaveMissedIncomingMessage', err); } } function ShowIncomingMessage(action, from, msg) { try{ // if received message, then set status to online if it was offline if (enablepres === true) { webphone_api.global.msg_presence_timer = 0; if (!webphone_api.common.isNull(lastpres_stat) && lastpres_stat !== '0') { DisplayPresence('5'); // set to online } } sendrec = true; //-- if (from === webphone_api.global.mto) if (webphone_api.global.mto.indexOf(from) >= 0) { msg = webphone_api.common.ReplaceAll(msg, "\\<.*?>", ""); mMessage = msg; AddMessage("1", true); if (webphone_api.global.mto.indexOf(',') > 0) { var dstlist = webphone_api.global.mto.split(','); for (var i = 0; i < dstlist.length; i++) { if (webphone_api.common.isNull(dstlist[i]) || webphone_api.common.Trim(dstlist[i]).length < 1) { continue; } if (dstlist[i] === from) { continue; } if (mAction === 'sms' && !webphone_api.common.isNull(webphone_api.common.GetParameter('sms')) && webphone_api.common.GetParameter('sms').length > 0) { webphone_api.common.UriParser(webphone_api.common.GetParameter('sms'), '', webphone_api.common.GetSipusername(true), webphone_api.common.Trim(dstlist[i]), msg, 'sendsms'); }else { webphone_api.sendchat(webphone_api.common.Trim(dstlist[i]), msg); } } } }else { var name = webphone_api.common.GetContactNameFromNumber(from); webphone_api.common.PutNotifications2('1', '', name + ' - ' + from, 0); SaveMissedIncomingMessage(action, from, name, msg); } } catch(err) { webphone_api.common.PutToDebugLogException(2, '_message: ShowIncomingMessage', err); } } function ScrollToBottom() { try{ var d = webphone_api.$('#msg_list'); d.scrollTop(d.prop("scrollHeight")); } catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: ScrollToBottom", err); } } var MENUITEM_MESSAGE_DELETE = '#menuitem_message_delete'; var MENUITEM_MESSAGE_FILETRANSFER = '#menuitem_message_filetransfer'; var MENUITEM_MESSAGE_CALL = '#menuitem_message_call'; var MENUITEM_MESSAGE_GROUPCHAT = '#menuitem_message_groupchat'; function CreateOptionsMenu (menuId) // adding items to menu, called from html { try{ // remove data transition for windows softphone, because it's slow if (webphone_api.common.IsWindowsSoftphone()) { webphone_api.$( "#btn_message_menu" ).removeAttr('data-transition'); } if ( webphone_api.common.isNull(menuId) || menuId.length < 1 ) { webphone_api.common.PutToDebugLog(2, "ERROR, _message: CreateOptionsMenu menuid null"); return; } if (webphone_api.$(menuId).length <= 0) { webphone_api.common.PutToDebugLog(2, "ERROR, _message: CreateOptionsMenu can't get reference to Menu"); return; } if (menuId.charAt(0) !== '#') { menuId = '#' + menuId; } webphone_api.$(menuId).html(''); webphone_api.$(menuId).append( '
';
var img = '
';
var txta = document.getElementById('msg_textarea');
//-- txta.value = txta.value + ' ' + img + ' ';
txta.innerHTML = txta.innerHTML + ' ' + img + ' ';
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: AddSmiley", err); }
};
webphone_api.$("#btn_emoti_smiling").on("click", function() { AddSmiley('Smiling'); });
webphone_api.$("#btn_emoti_sad").on("click", function() { AddSmiley('Sad'); });
webphone_api.$("#btn_emoti_laughing").on("click", function() { AddSmiley('Laughing'); });
webphone_api.$("#btn_emoti_winking").on("click", function() { AddSmiley('Winking'); });
webphone_api.$("#btn_emoti_surprised").on("click", function() { AddSmiley('Surprised'); });
webphone_api.$("#btn_emoti_straightface").on("click", function() { AddSmiley('StraightFace'); });
webphone_api.$("#btn_emoti_worried").on("click", function() { AddSmiley('Worried'); });
webphone_api.$("#btn_emoti_crying").on("click", function() { AddSmiley('Crying'); });
webphone_api.$("#btn_emoti_cool").on("click", function() { AddSmiley('Cool'); });
webphone_api.$("#btn_emoti_angel").on("click", function() { AddSmiley('Angel'); });
webphone_api.$("#btn_emoti_kiss").on("click", function() { AddSmiley('Kiss'); });
webphone_api.$("#btn_emoti_idea").on("click", function() { AddSmiley('Idea'); });
webphone_api.$("#btn_emoti_thinking").on("click", function() { AddSmiley('Thinking'); });
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: OpenSmileys", err); }
}
function AddEmoticon(txtin) // convert emoticon text to image: :) => image
{
try{
if (webphone_api.common.isNull(txtin) || txtin.length < 1) { return txtin; }
var txt = txtin;
txt = webphone_api.common.ReplaceAll(txt, ':))', '
');
txt = webphone_api.common.ReplaceAll(txt, ':((', '
');
txt = webphone_api.common.ReplaceAll(txt, ':)', '
');
txt = webphone_api.common.ReplaceAll(txt, ':(', '
');
txt = webphone_api.common.ReplaceAll(txt, ';)', '
');
txt = webphone_api.common.ReplaceAll(txt, ':-O', '
');
txt = webphone_api.common.ReplaceAll(txt, ':|', '
');
txt = webphone_api.common.ReplaceAll(txt, ':-S', '
');
txt = webphone_api.common.ReplaceAll(txt, 'B-)', '
');
txt = webphone_api.common.ReplaceAll(txt, ':-O)', '
');
txt = webphone_api.common.ReplaceAll(txt, ':x', '
');
txt = webphone_api.common.ReplaceAll(txt, ':-I', '
');
txt = webphone_api.common.ReplaceAll(txt, ':-?', '
');
return txt;
} catch(err) { webphone_api.common.PutToDebugLogException(2, "_message: AddEmoticon", err); }
return txtin;
}
function RemoveEmoticon(txtin) // convert emoticon image to text: image => :)
{
try{
if (webphone_api.common.isNull(txtin) || txtin.length < 1 || txtin.indexOf('