You are on page 1of 3

function insert(item, user, request) {

var ackFlag=0;
if(item.chat==""){// it's an ACK
ackFlag=1;
// dlflag=item.is_dl_flag;
}
var dlflag=item.is_dl_flag;
var server_message_id=0;
var dl_message="";
if(dlflag!=0&&ackFlag==0){//a dl
server_message_id=dlflag;
dl_message=item.chat;
item.chat=dlflag.toString(); //replace message with server_message_id o
f dl_messgae table in case of a dl
dlflag=1;
}
request.execute({
success: function() {
if(ackFlag==1){//it's an ack
doAck();
mssql.query("delete from koyojs.message where chat like ''");
if(dlflag==0)sendRawNotifications(item.to_email_id,item.message_
id);
}
else{
console.log("in message part ?: ",item);
if(item.status!=999)sendNotifications();
/*
if(dlflag==0){//individual chat
sendNotifications();
}
else{//a dl
sendNotificationsToDls()
}*/
}
request.respond();
//console.log("abhishek:", item.text);
}
});
function doAck(){
console.log("in ack part ?: ",item);
mssql.query("update koyojs.message set status=999 where from_email_id='
"+item.to_email_id+"' and message_id='"+item.message_id+"'"+" and to_email_id='"
+item.from_email_id+"'");
}
function sendNotifications() {
var payload;
if(dlflag==0)
payload = '<?xml version="1.0" encoding="utf-8"?><toast><visual><binding
template="ToastText01">' +
'<text id="1">'+item.chat+'</text><text id="2">'+item.from_email_id+'</t
ext><text id="3">'+item.timestamp+'</text><text id="4">'+item.message_id+'</text
><text id="5">'+item.from_username+'</text></binding></visual></toast>';

item).timestamp+'</text><text id="4">'+item. var payload = '<?xml version="1. pushRes ponse).log("payload is=:".wns.msg) { console. //var payload = '<?xml version="1.//<?xml version="1.timestamp+'</text></binding></visual></toast>'.email_id). {//put wns/toast for t oast success: function(pushResponse) { console.from_email_id+'< /text><text id="3">'+item. payload).0" encoding="utf-8"?><toast><visual><binding template="ToastText01">' + '<text id="1">'+dl_message+'</text><text id="2">'+item.dl_name+ '</dlname></binding></visual></toast>'.send(email_id. } }). push.from_username+ '</text><dl_email>'+item.message_id+'</tex t><text id="5">'+item.dl_email_id+'</dl_email><dlname>'+item. pu shResponse).chat:dl_message)).0" encoding="utf-8"?>'+"<message_id>"+m sg+"</message_id>".log("in sendRawNotifications part ?: ".to_email_id }).wns.where({ dl_email_id: item.dl_email_id+'</dl_email><dlname>'+item.read({ success: function(records){ records.to_email_id.from_email_id+'</t ext><text id="3">'+item.payload. var id=0.message_id+'</text ><text id="5">'+item. push.timestamp+'</text></binding></visual></toast>'.forEach(function(record) {//only 1 record . console. } function sendRawNotifications(email_id. var payloadToast = '<?xml version="1.timestamp+'</text><text id="4">'+item.from_username+ '</text><dl_email>'+item.log("chat is=:".log("Sent push in message sending:".0" encoding="utf-8"?><toast><visual><bin ding template="ToastText01">' + '<text id="1">'+item.chat+'</text><text id="2">'+item.chat+'</text><text id="2">'+item.item).log("notification item=". var payloadRaw='<?xml version="1.'wns/raw'.else// a dl message payload = '<?xml version="1.0" encoding="utf-8"?><toast><visual><b inding template="ToastText01">' + //'<text id="1">'+item. console. var dl_detailsTable = tables.0" encoding="utf-8"?><payload>blah!!</payl oad> console.'wns/raw'.payloadRaw. item). console.dl_name+ '</dlname></binding></visual></toast>'.getTable('dl_details').send(item.0" encoding="utf-8"?><toast><visual ><binding template="ToastText01">' + '<text id="1">'+"ack test:: "+'</text><text id="2">'+"ack test"+'</text> <text id="3">'+item. } }). dl_detailsTable.from_email_id+'</ text><text id="3">'+item. ((dlflag==0)?item.log("to email id=:".log("Sent push in ack pushnotification:". } function sendNotificationsToDls() { console.log("in sendRawNotifications part ?: ". { success: function(pushResponse) { console.

} }). } }).wns. push.log("the record is:".getTable('dl_member_details' ).IDD.send(registration.registration. id). { success: function(pushResponse) { // console. } }).forEach(function(registration) { if(registration. pushRe sponse).member_email_id.//console.p ayload.log("the dl id is:".from_email _id){ console.member_email_id).read({ success: function(registrations) { registrations. var dl_member_detailsTable = tables.log("Sent push:".where({ dl_idd: id }). id=record. record). dl_member_detailsTable. } }).'wns/raw'. } } . }) // console.member_email_id!=item.log("in sendRawNotifications part e mail id== ?: ".