OAuth and bugfixes
This commit is contained in:
parent
e58a1f69dc
commit
d43c18bb76
65 changed files with 1681 additions and 1494 deletions
|
@ -279,7 +279,6 @@ function storeNews(login,database,news,rootwindow){
|
|||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from news where username="'+login.username+'" AND status_id = "'+news[i].id+'" AND messagetype='+news[i].messagetype); // check for news id
|
||||
if(result.rows.length === 1) {// use update
|
||||
//print(news[i].id +' news exists, update it'+'UPDATE news SET username="'+login.username+'", messagetype=0, text="'+Qt.btoa(news[i].text)+'", created_at="'+Date.parse(cleanDate(news[i].created_at))+'", in_reply_to_status_id="'+news[i].in_reply_to_status_id+'", source="'+news[i].source+'", status_id="'+news[i].id+'", in_reply_to_user_id="'+news[i].in_reply_to_user_id+'", geo="'+news[i].geo+'", favorited="'+news[i].favorited+'", uid="'+news[i].user.id+'", statusnet_html="'+Qt.btoa(news[i].status_html)+'", statusnet_conversation_id="'+news[i].statusnet_conversation_id+'",friendica_activities="'+Qt.btoa(JSON.stringify(friendica_activities))+'",attachments="'+attachments+'",friendica_owner="'+news[i].friendica_owner.url+'" where username="'+login.username+'" AND status_id="'+news[i].status_id+'" AND messagetype=0')
|
||||
result = tx.executeSql('UPDATE news SET username="'+login.username+'", messagetype='+news[i].messagetype+', text="'+Qt.btoa(news[i].text)+'", created_at="'+news[i].created_at+'", in_reply_to_status_id="'+news[i].in_reply_to_status_id+'", source="'+news[i].source+'", status_id="'+news[i].id+'", in_reply_to_user_id="'+news[i].in_reply_to_user_id+'", geo="'+news[i].geo+'", favorited="'+news[i].favorited+'", uid="'+news[i].user.id+'", statusnet_html="'+Qt.btoa(news[i].statusnet_html)+'", statusnet_conversation_id="'+news[i].statusnet_conversation_id+'",friendica_activities="'+Qt.btoa(JSON.stringify(friendica_activities))+'",attachments="'+attachments+'",friendica_owner="'+news[i].friendica_author.url+'" where username="'+login.username+'" AND status_id="'+news[i].status_id+'" AND messagetype=0');
|
||||
} else {// use insert
|
||||
result = tx.executeSql('INSERT INTO news (username,messagetype,text,created_at,in_reply_to_status_id,source,status_id,in_reply_to_user_id,geo,favorited,uid,statusnet_html,statusnet_conversation_id,friendica_activities,friendica_activities_self,attachments,friendica_owner) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [login.username,news[i].messagetype,Qt.btoa(news[i].text),news[i].created_at, news[i].in_reply_to_status_id, news[i].source, news[i].id,news[i].in_reply_to_user_id,news[i].geo,news[i].favorited, news[i].user.id,Qt.btoa(news[i].statusnet_html),news[i].statusnet_conversation_id, Qt.btoa(JSON.stringify(friendica_activities)),"[]",attachments,news[i].friendica_author.url])}})
|
||||
|
@ -308,7 +307,6 @@ function newsfromdb(database,login,messagetype,callback,contact,stop_time){
|
|||
else{var stop="<"+stop_time}
|
||||
var contactfilter="";if(contact){contactfilter=" AND (uid='"+contact+"' OR friendica_owner='"+contact+"')"}
|
||||
if (messagetype=="0"){messagetype="0,5"}
|
||||
//print('select * from news WHERE username="'+login.username+'" AND messagetype IN ( '+messagetype+' ) AND created_at'+stop+contactfilter+' ORDER BY created_at DESC LIMIT 20');
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+login.username+'" AND messagetype IN ( '+messagetype+' ) AND created_at'+stop+contactfilter+' ORDER BY created_at DESC LIMIT 20');
|
||||
var newsArray=[];
|
||||
var allcontacts=getAllContacts(database,login.username);
|
||||
|
@ -326,7 +324,7 @@ function newsfromdb(database,login,messagetype,callback,contact,stop_time){
|
|||
}
|
||||
|
||||
|
||||
function fetchUsersForNews(database,username,news,allcontacts){//print("fetchusers "+JSON.stringify(news))
|
||||
function fetchUsersForNews(database,username,news,allcontacts){//print("fetchusers "+JSON.stringify(news));
|
||||
news.user=objFromArray(allcontacts,"id",news.uid);
|
||||
if(news.in_reply_to_user_id){news.reply_user=objFromArray(allcontacts,"id",news.in_reply_to_user_id)}
|
||||
//news.friendica_owner_object=objFromArray(allcontacts,"url",news.friendica_owner);
|
||||
|
@ -382,7 +380,6 @@ function likerequest(login,database,verb,newsid,rootwindow){
|
|||
db.transaction( function(tx) {
|
||||
var currentActivities_rs=tx.executeSql('select friendica_activities_self from news WHERE username="'+login.username+'" AND status_id='+newsid) ;
|
||||
var currentActivities=JSON.parse(currentActivities_rs.rows.item(0).friendica_activities_self);
|
||||
//print(verb+"currentActivities "+JSON.stringify(currentActivities));
|
||||
if ((verb=="like")&&(currentActivities.indexOf(1)==-1)){ currentActivities.push(1);
|
||||
if (currentActivities.indexOf(2)!=-1){currentActivities.splice(currentActivities.indexOf(2),1)}
|
||||
}
|
||||
|
@ -391,7 +388,6 @@ function likerequest(login,database,verb,newsid,rootwindow){
|
|||
}
|
||||
if (verb=="unlike"){ if (currentActivities.indexOf(1)!=-1){currentActivities.splice(currentActivities.indexOf(1),1)}}
|
||||
if (verb=="undislike"){ if (currentActivities.indexOf(2)!=-1){currentActivities.splice(currentActivities.indexOf(2),1)}}
|
||||
//print(JSON.stringify(currentActivities));
|
||||
var result = tx.executeSql('UPDATE news SET friendica_activities_self ="'+JSON.stringify(currentActivities)+'" where username="'+login.username+'" AND status_id ='+newsid);
|
||||
})}
|
||||
else{}})
|
||||
|
@ -408,7 +404,6 @@ function like(login,database,toggle,verb,newsid,rootwindow){
|
|||
|
||||
function attend(login,database,attend,newsid,rootwindow,callback){
|
||||
Helperjs.friendicaPostRequest(login,"/api/friendica/activity/attend"+attend+"?id="+newsid, "","POST",rootwindow,function (obj){
|
||||
//print("attend: "+attend+obj);
|
||||
if (obj=='"ok"')
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
|
@ -418,7 +413,6 @@ function attend(login,database,attend,newsid,rootwindow,callback){
|
|||
currentActivities.push(3);
|
||||
if (currentActivities.indexOf(4)!=-1){currentActivities.splice(currentActivities.indexOf(4),1)}
|
||||
if (currentActivities.indexOf(5)!=-1){currentActivities.splice(currentActivities.indexOf(5),1)}
|
||||
//print(JSON.stringify(currentActivities));
|
||||
}
|
||||
if ((attend=="no")&&(currentActivities.indexOf(4)==-1)){
|
||||
currentActivities.push(4);
|
||||
|
@ -443,26 +437,8 @@ function requestConversation(login,database,newsid,contacts,rootwindow,callback)
|
|||
callback(news,newContacts)
|
||||
})}
|
||||
|
||||
//function conversationfromdb(database,user,conversationId,callback){
|
||||
// var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
// db.transaction( function(tx) {
|
||||
// var newsrs=tx.executeSql('select * from news WHERE username="'+user+'" AND statusnet_conversation_id="'+conversationId+'" ORDER BY created_at ASC');
|
||||
// var newsArray=[];
|
||||
// var allcontacts=getAllContacts(database,user);
|
||||
// for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
// newsArray.push(newsrs.rows.item(i));
|
||||
// newsArray[i].statusnet_html=Qt.atob(newsArray[i].statusnet_html);
|
||||
// newsArray[i].text=Qt.atob(newsArray[i].text);
|
||||
// newsArray[i].id=newsArray[i].status_id;
|
||||
// newsArray[i]=fetchUsersForNews(database,user,newsArray[i],allcontacts);
|
||||
// if (helpernews.attachments!="" && newsArray[i].attachments!==null){newsArray[i].attachments=JSON.parse(Qt.atob(newsArray[i].attachments))};
|
||||
// }
|
||||
// callback(newsArray)})
|
||||
//}
|
||||
|
||||
function requestFavorites(login,database,contacts,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/favorites",rootwindow, function (obj){
|
||||
//print(obj+JSON.stringify(obj));
|
||||
var news=JSON.parse(obj);
|
||||
var newContacts=findNewContacts(news,contacts);
|
||||
// storeNews(login,database,news,rootwindow,callback)
|
||||
|
@ -494,7 +470,6 @@ function chatsfromdb(database,login,messagetype,currentconversations,callback,st
|
|||
|
||||
for(var j = 0; j< conversations.length; j++) {
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+login.username+'" AND statusnet_conversation_id="'+conversations[j] +'" AND messagetype="'+messagetype+'" ORDER BY created_at ASC');
|
||||
//print(JSON.stringify(newsrs.rows.item(0))+JSON.stringify(newsrs.rows.item(1)))
|
||||
var helpernews=newsrs.rows.item(0);
|
||||
helpernews=cleanhelpernews(database,login.username,helpernews,allcontacts)
|
||||
helpernews.currentconversation=[];
|
||||
|
@ -532,17 +507,18 @@ function allchatsfromdb(database,user,callback){
|
|||
for(var j = 0; j< conversationIds.length; j++) {
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+user+'" AND statusnet_conversation_id="'+conversationIds[j] +'" ORDER BY created_at ASC');
|
||||
var helpernews=newsrs.rows.item(0);
|
||||
var helpernews=cleanhelpernews(database,user,helpernews,allcontacts)
|
||||
helpernews.currentconversation=[];
|
||||
for (var h = 0;h<newsrs.rows.length;h++){
|
||||
var helpernews2=newsrs.rows.item(h);
|
||||
if(helpernews.id!=helpernews2.status_id){
|
||||
helpernews2.newscount=0;
|
||||
helpernews2=cleanhelpernews(database,user,helpernews2,allcontacts)
|
||||
helpernews.currentconversation.push(helpernews2)
|
||||
if (helpernews){
|
||||
var helpernews=cleanhelpernews(database,user,helpernews,allcontacts)
|
||||
helpernews.currentconversation=[];
|
||||
for (var h = 0;h<newsrs.rows.length;h++){
|
||||
var helpernews2=newsrs.rows.item(h);
|
||||
if(helpernews.id!=helpernews2.status_id){
|
||||
helpernews2.newscount=0;
|
||||
helpernews2=cleanhelpernews(database,user,helpernews2,allcontacts)
|
||||
helpernews.currentconversation.push(helpernews2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newsArray.push(helpernews);
|
||||
countArray.push(newsrs.rows.length)
|
||||
}
|
||||
|
@ -557,16 +533,10 @@ function allchatsfromdb(database,user,callback){
|
|||
function oldchatfromdb(database,user,conversationId,lastpost,allcontacts,callback){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
// var newsArray=[];
|
||||
// var countArray=[];
|
||||
//var allcontacts=getAllContacts(database,user);
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+user+'" AND statusnet_conversation_id="'+conversationId +'" AND status_id<'+lastpost+' ORDER BY created_at ASC');
|
||||
let conversation=[];
|
||||
var helpernews={currentconversation:conversation}
|
||||
if(newsrs.rows.length>0){
|
||||
//helpernews=newsrs.rows.item(0);
|
||||
//helpernews=cleanhelpernews(database,user,helpernews,allcontacts)
|
||||
//helpernews.currentconversation=[];
|
||||
for (var h = 0;h<newsrs.rows.length;h++){
|
||||
var helpernews2=newsrs.rows.item(h);
|
||||
if(helpernews.id!=helpernews2.status_id){
|
||||
|
@ -579,8 +549,6 @@ function oldchatfromdb(database,user,conversationId,lastpost,allcontacts,callbac
|
|||
}
|
||||
var newscount=newsrs.rows.length;
|
||||
callback(helpernews,newscount);
|
||||
// var conversationobject={news:helpernews,newscount:newscount};
|
||||
// return conversationobject;
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -595,7 +563,6 @@ function cleanhelpernews(database,user,helpernews,allcontacts){
|
|||
return helpernews
|
||||
}
|
||||
|
||||
|
||||
function getAllContacts(database,user){
|
||||
var allcontacts=[];
|
||||
Helperjs.readData(database,"contacts",user,function(obj){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue