// 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 Helperjs.friendicaRequest(login,"/api/statuses/friends?count=9999", rootwindow,function (obj){ var friends=JSON.parse(obj); for (var i=0;i0'+filtertext); var result = tx.executeSql('SELECT * from contacts WHERE username="'+login.username+'" AND isFriend>0'); // check for friends var contactlist=[]; 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){var helpernews=newsrs.rows.item(0); var newscount=newsrs.rows.length; helpernews=fetchUsersForNews(database,user,helpernews,allcontacts); helpernews.statusnet_html=Qt.atob(helpernews.statusnet_html); helpernews.text=Qt.atob(helpernews.text); helpernews.id=helpernews.status_id;helpernews.friendica_author=objFromArray(allcontacts,"url",helpernews.friendica_owner); if (helpernews.attachments!="" && helpernews.attachments!==null){helpernews.attachments=JSON.parse(Qt.atob(helpernews.attachments))}; callback(helpernews,newscount);} // var conversationobject={news:helpernews,newscount:newscount}; // return conversationobject; })} function getAllContacts(database,user){ var allcontacts=[]; Helperjs.readData(database,"contacts",user,function(obj){ allcontacts=obj; for (var n in allcontacts){ allcontacts[n].name=Qt.atob(allcontacts[n].name); allcontacts[n].description=Qt.atob(allcontacts[n].description) } }); return allcontacts; } function inArray(list, prop, val) { if (list.length > 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) }