Friendiqa/source-linux/js/newsworker.js

83 lines
5 KiB
JavaScript
Raw Normal View History

2017-01-26 21:55:31 +01:00
WorkerScript.onMessage = function(msg) {
2017-11-07 21:57:40 +01:00
if(msg.deleteId)
{msg.model.remove(msg.deleteId);
msg.model.sync()
}
else{
if(msg.appendnews!==true){msg.model.clear()};
msg.model.sync()
2017-01-26 21:55:31 +01:00
for (var j=0;j<msg.news.length;j++){
if (msg.news[j]) {
var newsitemobject=msg.news[j];
2017-03-25 23:36:14 +01:00
//print("Newsitem"+JSON.stringify(newsitemobject.friendica_owner+" userid: "+newsitemobject.user.id));
2017-01-26 21:55:31 +01:00
if (newsitemobject.messagetype==2){
newsitemobject.user={};
newsitemobject.user.profile_image="";
newsitemobject.user.profile_image_url="";
newsitemobject.user.name="";
}
2017-11-07 21:57:40 +01:00
var forumname="";if (newsitemobject.messagetype==0&&((newsitemobject.friendica_owner)!=(newsitemobject.user.url))){forumname=" via "+Qt.atob(newsitemobject.friendica_owner_object.name)}
2017-01-26 21:55:31 +01:00
var likeText="";var dislikeText="";var attendyesText="";var attendnoText="";var attendmaybeText=""; var self={};
if (newsitemobject.messagetype==0){
if (newsitemobject.like.length>0){
if (newsitemobject.like.length==1){likeText= Qt.atob(newsitemobject.like[0].name)+" "+ qsTr("likes this.")}
else {likeText= newsitemobject.like.length+" "+ qsTr("like this.")}
}
if (newsitemobject.dislike.length>0){
2017-05-11 22:15:34 +02:00
if (newsitemobject.dislike.length==1){dislikeText= Qt.atob(newsitemobject.dislike[0].name)+" "+ qsTr("doesn't like this.")}
2017-01-26 21:55:31 +01:00
else {dislikeText= newsitemobject.dislike.length+" "+ qsTr("don't like this.")}
}
if (newsitemobject.attendyes.length>0){
if (newsitemobject.attendyes.length==1){attendyesText= Qt.atob(newsitemobject.attendyes[0].name)+" "+ qsTr("will attend.")}
else {attendyesText= newsitemobject.attendyes.length+" "+ qsTr("persons will attend.")}
}
if (newsitemobject.attendno.length>0){
if (newsitemobject.attendno.length==1){attendnoText= Qt.atob(newsitemobject.attendno[0].name)+" "+ qsTr("will not attend.")}
else {attendnoText= newsitemobject.attendno.length+" "+ qsTr("persons will not attend.")}
}
if (newsitemobject.attendmaybe.length>0){
if (newsitemobject.attendmaybe.length==1){attendmaybeText= Qt.atob(newsitemobject.attendmaybe[0].name)+" "+ qsTr("may attend.")}
else {attendmaybeText= newsitemobject.attendmaybe.length+" "+ qsTr("persons may attend.")}
}
//var friendica_activities_self=JSON.parse(newsitemobject.friendica_activities_self);
if (newsitemobject.friendica_activities_self.indexOf(3)!=-1){self.attending=qsTr("yes")}
if (newsitemobject.friendica_activities_self.indexOf(4)!=-1){self.attending=qsTr("no")}
if (newsitemobject.friendica_activities_self.indexOf(5)!=-1){self.attending=qsTr("maybe")}
if (newsitemobject.friendica_activities_self.indexOf(1)!=-1){self.liked=1}
if (newsitemobject.friendica_activities_self.indexOf(2)!=-1){self.disliked=1}
2017-01-26 21:55:31 +01:00
}
2017-11-07 21:57:40 +01:00
var friendica_activities={likeText:likeText,dislikeText:dislikeText,attendyesText:attendyesText,attendnoText:attendnoText,attendmaybeText:attendmaybeText,self:self}
2017-05-11 22:15:34 +02:00
var attachmentList=[];if(newsitemobject.attachments){
var attachArray=JSON.parse(Qt.atob(newsitemobject.attachments));
for (var image in attachArray){if(attachArray[image].mimetype=="image/gif"){
attachmentList.push(attachArray[image])
}
}
}
newsitemobject.attachmentList=attachmentList;
2017-01-26 21:55:31 +01:00
var seconds=(msg.currentTime-newsitemobject.created_at)/1000;
2017-11-07 21:57:40 +01:00
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/46656000)+" "+qsTr("years") +" "+qsTr("ago");}
var data=({"newsitemobject": newsitemobject,"dateDiff":timestring,"friendica_activities":friendica_activities,"forumname":forumname})}
//print("News:"+j+msg.news.length+JSON.stringify(data));
msg.model.append(data)
}
if (j==msg.news.length){
//print("j: "+j+" msg.model.count: "+msg.model.count);
msg.model.sync()
}
}
2017-01-26 21:55:31 +01:00
}