25 lines
1.6 KiB
JavaScript
25 lines
1.6 KiB
JavaScript
WorkerScript.onMessage = function(msg) {
|
|
if(msg.appendnews!==true){ msg.model.clear()};
|
|
for (var j=0;j<msg.news.length;j++){
|
|
if (msg.news[j]) {
|
|
var newsitemobject=msg.news[j];
|
|
var seconds=(msg.currentTime-newsitemobject.created_at)/1000;
|
|
var timestring="";
|
|
if (seconds<60) {timestring=seconds+" "+qsTr("seconds") +" "+qsTr("ago");}
|
|
else if (seconds<90){timestring=Math.round(seconds/60)+" "+qsTr("minute") +" "+qsTr("ago");}
|
|
else if (seconds<3600){timestring=Math.round(seconds/60)+" "+qsTr("minutes") +" "+qsTr("ago");}
|
|
else if (seconds<5400){timestring=Math.round(seconds/3600)+" "+qsTr("hour") +" "+qsTr("ago");}
|
|
else if (seconds<86400){timestring=Math.round(seconds/3600)+" "+qsTr("hours") +" "+qsTr("ago");}
|
|
else if (seconds<129600){timestring=Math.round(seconds/86400)+" "+qsTr("day") +" "+qsTr("ago");}
|
|
else if (seconds<3888000){timestring=Math.round(seconds/86400)+" "+qsTr("days") +" "+qsTr("ago");}
|
|
else if (seconds<5832000){timestring=Math.round(seconds/3888000)+" "+qsTr("month") +" "+qsTr("ago");}
|
|
else if (seconds<69984000){timestring=Math.round(seconds/3888000)+" "+qsTr("months") +" "+qsTr("ago");}
|
|
else {timestring=Math.round(seconds/69984000)+" "+qsTr("years") +" "+qsTr("ago");}
|
|
var data=({"newsitemobject": newsitemobject,"dateDiff":timestring})}
|
|
// print("News:"+j+msg.news.length+JSON.stringify(data));
|
|
msg.model.append(data);}
|
|
if (j==msg.news.length){
|
|
msg.model.sync()
|
|
};
|
|
}
|