// This file is part of Friendiqa // https://git.friendi.ca/lubuwest/Friendiqa // Copyright (C) 2020 Marco R. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // In addition, as a special exception, the copyright holders give // permission to link the code of portions of this program with the // OpenSSL library under certain conditions as described in each // individual source file, and distribute linked combinations including // the two. // // You must obey the GNU General Public License in all respects for all // of the code used other than OpenSSL. If you modify file(s) with this // exception, you may extend this exception to your version of the // file(s), but you are not obligated to do so. If you do not wish to do // so, delete this exception statement from your version. If you delete // this exception statement from all source files in the program, then // also delete it here. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . .pragma library .import QtQuick.LocalStorage 2.0 as Sql .import "qrc:/js/helper.js" as Helperjs function requestFriends(login,database,rootwindow,callback){ // return array of friends var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); db.transaction( function(tx) { var result = tx.executeSql('UPDATE contacts SET isFriend=0 where username="'+login.username+'"'); // clean old friends var result2 = tx.executeSql('DELETE from groups where username="'+login.username+'"'); // clean old groups }) // /api/statuses/friends not working in Friendica 2/2022 , switching to api/v1/lists and download of all list members // Helperjs.friendicaRequest(login,"/api/statuses/friends?count=9999", rootwindow,function (obj){ var allfriends=[]; Helperjs.friendicaRequest(login,"/api/v1/lists",rootwindow,function(listsobj){ var lists=JSON.parse(listsobj) for (var list in lists){ Helperjs.friendicaRequest(login,"/api/v1/lists/"+lists[list].id+"/accounts?limit=0", rootwindow,function (obj){ var friends=JSON.parse(obj); var memberarray=[]; for (var i=0;i'+isFriend+' ORDER BY screen_name'); // check for friends var contactlist=[]; for (var i=0;i 0) {// use update result = tx.executeSql('UPDATE hashtags SET tag="'+'", date='+curDate+', ownership=0 where username="'+login.username+'" AND tag="'+Qt.btoa(hashtags[tag])+'"'); } else {// use insert result = tx.executeSql('INSERT INTO hashtags (username,tag,date,statuses,ownership) VALUES (?,?,?,?,?)', [login.username,Qt.btoa(hashtags[tag]),curDate,"[]",0]) } }) } } function deleteGroup(login,database,rootwindow,group, callback){ var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); Helperjs.friendicaPostRequest(login,"/api/friendica/group_delete?gid="+group.gid+"&name="+group.groupname,"","POST",rootwindow, function (obj){ var deletereturn=JSON.parse(obj); if(deletereturn.success){ db.transaction( function(tx) { var result = tx.executeSql('DELETE from groups where username="'+login.username+'" AND groupname="'+group.name+'"'); // delete group callback() }); }})} function getLastNews(login,database,callback){ var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); var lastnewsid=0; db.transaction( function(tx) { var result = tx.executeSql('SELECT status_id from news WHERE username="'+login.username+'" AND messagetype=0 ORDER BY status_id DESC LIMIT 1'); try{lastnewsid=result.rows.item(0).status_id;}catch(e){lastnewsid=0}; callback(lastnewsid) }) } //function getFriendsTimeline(login,database,contacts,onlynew,rootwindow,callback){ // // retrieve and return timeline since last news, return contacts which are not friends and older than 2 days for update (friends can be updated in Contactstab) // var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); // var parameter = "?count=50"; // if(onlynew){db.transaction( function(tx) { // var result = tx.executeSql('SELECT status_id from news WHERE username="'+login.username+'" AND messagetype=0 ORDER BY status_id DESC LIMIT 1'); // check for last news id // try{parameter=parameter+"&since_id="+result.rows.item(0).status_id;}catch(e){};})} // var newContacts=[]; // Helperjs.friendicaRequest(login,"/api/statuses/friends_timeline"+parameter, rootwindow,function (obj){ // var news=JSON.parse(obj); // if (news.hasOwnProperty('status')){ // Helperjs.showMessage(qsTr("Error"),"API:\n" +login.server+"/api/statuses/friends_timeline"+parameter+"\n Return: \n"+obj,rootwindow) // } // var newContacts=findNewContacts(news,contacts); // callback(news,newContacts) //})} function getCurrentContacts(login,database,callback){ var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); var contactlist=[]; db.transaction( function(tx) { var result = tx.executeSql('SELECT url from contacts WHERE username="'+login.username+'" AND isFriend=1'); // check for friends for (var i=0;i'+lastDate); var result2 = tx.executeSql('SELECT url from contacts WHERE username="'+login.username+'" AND isFriend=0 AND imageAge > '+lastDate); for (var j=0;j0){ for (var j=0;j0){ for (var k=0;j

"+news[i].friendica_html;} //else{ news[i].statusnet_html=news[i].friendica_html//} 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])}}) } } function getActivitiesUserData(allcontacts,userUrlArray){//print(JSON.stringify(userUrlArray)); var helpArray=[]; for (var i=0;i0){conversationfilter="AND statusnet_conversation_id NOT IN ("+currentconversations.toString()+") "} var conversationsrs=tx.executeSql('select DISTINCT statusnet_conversation_id from news WHERE username="'+login.username+'" AND status_id'+stop+' AND messagetype IN ( "'+messagetype+'" ) '+ conversationfilter +'ORDER BY created_at DESC LIMIT 20'); //+' ORDER BY created_at DESC LIMIT 20'); var result = tx.executeSql('SELECT status_id from news WHERE username="'+login.username+'" AND messagetype=0 ORDER BY status_id DESC LIMIT 1'); try{var lastid=result.rows.item(0).status_id;}catch(e){var lastid=0}; var conversations=[]; for(var i = 0; i < conversationsrs.rows.length; i++) { conversations.push(conversationsrs.rows.item(i).statusnet_conversation_id); } var newsArray=[]; var allcontacts=getAllContacts(database,login.username); 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=[]; for (var h = 0;h0){ //helpernews=newsrs.rows.item(0); //helpernews=cleanhelpernews(database,user,helpernews,allcontacts) //helpernews.currentconversation=[]; for (var h = 0;h 0 ) { for (var i in list) {if (list[i][prop] == val) { return true; } } } return false; } function objFromArray(list, prop, val) { if (list.length > 0 ) { for (var i in list) {if (list[i][prop] == val) { return list[i]; } } } return false; } function cleanDate(date){ var cleanedDate= date.slice(0,3)+", "+date.slice(8,11)+date.slice(4,7)+date.slice(25,30)+date.slice(10,25); return cleanedDate } function findTags(fulltext){ return fulltext.match(/\s+[#]+[A-Za-z0-9-_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF]+/g) }