// This file is part of Friendiqa // https://git.friendi.ca/lubuwest/Friendiqa // Copyright (C) 2017 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 .import "qrc:/js/news.js" as Newsjs // CONFIG FUNCTIONS function initDatabase(database) { // initialize the database object var db =Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); //print('initDatabase()'+database[0]+database[1]+database[2]+database[3]) db.transaction( function(tx) { //var version=tx.executeSql('PRAGMA user_version');print(JSON.stringify(version.rows.item(0))) tx.executeSql('CREATE TABLE IF NOT EXISTS imageData(username TEXT,id INT, created TEXT,edited TEXT, title TEXT, desc TEXT, album TEXT,filename TEXT, type TEXT, height INT, width INT, profile INT, link TEXT,location TEXT)'); tx.executeSql('CREATE TABLE IF NOT EXISTS config(server TEXT, username TEXT, password TEXT, imagestore TEXT, maxnews INT, timerInterval INT, newsViewType TEXT,isActive INT, permissions TEXT,maxContactAge INT,APIVersion TEXT,layout TEXT, addons TEXT)'); tx.executeSql('CREATE TABLE IF NOT EXISTS news(username TEXT, messagetype INT, text TEXT, created_at INT, in_reply_to_status_id INT, source TEXT, status_id INT, in_reply_to_user_id INT, geo TEXT,favorited TEXT, uid INT, statusnet_html TEXT, statusnet_conversation_id TEXT,friendica_activities TEXT, friendica_activities_self TEXT, attachments TEXT, friendica_owner TEXT)'); tx.executeSql('CREATE TABLE IF NOT EXISTS contacts(username TEXT, id INT, name TEXT, screen_name TEXT, location TEXT,imageAge INT, profile_image_url TEXT, description TEXT, profile_image BLOB, url TEXT, protected TEXT, followers_count INT, friends_count INT, created_at INT, favourites_count TEXT, utc_offset TEXT, time_zone TEXT, statuses_count INT, following TEXT, verified TEXT, statusnet_blocking TEXT, notifications TEXT, statusnet_profile_url TEXT, cid INT, network TEXT, isFriend INT, timestamp INT)'); // tx.executeSql('CREATE INDEX IF NOT EXISTS contact_id ON contacts(id)'); tx.executeSql('CREATE TABLE IF NOT EXISTS profiles(username TEXT, id INT, profiledata TEXT)'); tx.executeSql('CREATE TABLE IF NOT EXISTS groups(username TEXT, groupname TEXT, gid INT, members TEXT)'); tx.executeSql('CREATE TABLE IF NOT EXISTS events(username TEXT, id INT, start INT, end INT, allday INT, title TEXT, j INT, d TEXT, isFirst INT, uid INT, cid INT, uri TEXT, created INT, edited INT, desc TEXT, location TEXT, type TEXT, nofinish TEXT, adjust INT, ignore INT, permissions TEXT, guid INT, itemid INT, plink TEXT, authorName TEXT, authorAvatar TEXT, authorLink TEXT, html TEXT)'); tx.executeSql('CREATE TABLE IF NOT EXISTS globaloptions(k TEXT, v TEXT)') })} function cleanPermissions(oldperms){ var newperms=oldperms.replace("<","");newperms=newperms.replace(">","");newperms="["+newperms+"]"; var newpermArray=JSON.parse(newperms); return (newpermArray) } function getEvents(database,login,rootwindow,callback){ var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); Helperjs.friendicaWebRequest(login.server+"/cal/"+login.username+"/json",rootwindow,function(obj){ //Helperjs.friendicaRemoteAuthRequest(login,login.server+"/cal/"+login.username+"/json",login.server+"/profile/"+login.username,rootwindow,function(obj){ var events = JSON.parse(obj); db.transaction( function(tx) { for (var i=0;i0){ for(var i = 0; i < rs.rows.length; i++) { rsArray.push(rs.rows.item(i)) } var rsObject={server:rsArray[0].server,username:rsArray[0].username, password:rsArray[0].password,imagestore:rsArray[0].imagestore,isActive:rsArray[0].isActive, newsViewType:rsArray[0].newsViewType,permissions:JSON.parse(rsArray[0].permissions),maxContactAge:rsArray[0].maxContactAge,APIVersion:rsArray[0].APIVersion,addons:rsArray[0].addons}; } else {var rsObject=""} callback(rsObject)}} ) } function readActiveConfig(database){ var obj; readConfig(database,function(config){obj=config},"isActive", 0); return obj; } function readGlobaloptions(database,callback){ var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); var go=({}); db.transaction( function(tx) { var rs = tx.executeSql('select * from globaloptions'); for (var r=0; r0){ maxnews=maxnewsrs.rows.item(0).v}; var newscountrs = tx.executeSql('SELECT COUNT(*) from news'); var newscount = newscountrs.rows.item(0)["COUNT(*)"];//print("newscount "+newscount) if (newscount>maxnews){ var lastvalidtimers= tx.executeSql('SELECT DISTINCT created_at FROM news ORDER BY created_at ASC LIMIT ' +(newscount-maxnews)); var lastvalidtime=lastvalidtimers.rows.item(newscount-maxnews-1).created_at; var deleters = tx.executeSql('DELETE from news WHERE created_at<='+lastvalidtime)} callback() }) } function cleanContacts(login,database,callback){ var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]); db.transaction( function(tx) { var oldestnewsrs= tx.executeSql('SELECT created_at FROM news WHERE username="'+login.username+'" AND messagetype=0 ORDER BY created_at ASC LIMIT 1'); if (oldestnewsrs.rows.length>0){ var oldestnewsTime=oldestnewsrs.rows.item(0).created_at- 604800000;} else{var oldestnewsTime=0} //contacts can be 7 days old //print(login.username+" älteste news: "+ oldestnewsTime); var result = tx.executeSql('SELECT * from contacts WHERE username="'+login.username+'" AND isFriend=0 AND imageAge<'+oldestnewsTime); // check for friends //print ("Contact result length: "+ result.rows.length) for (var i=0;i-1){contacttimer.start()} } } function cleanUser(user){ user.created_at=Date.parse(Newsjs.cleanDate(user.created_at)); var imagehelper1=user.profile_image_url.split("?"); var imagehelper2=imagehelper1[0].substring(imagehelper1[0].lastIndexOf("/")+1,imagehelper1[0].length); var imagehelper3=login.imagestore+"contacts/"+user.screen_name+"-"+imagehelper2 if(filesystem.fileexist(imagehelper3)){user.profile_image=imagehelper3}else {user.profile_image=""} return user } function updateView(viewtype){ //messageSend.state=""; //newsBusy.running=true; //downloadNotice.text="xhr start "+Date.now() switch(viewtype){ case "Conversations": Newsjs.getLastNews(login,db,function(lastnews){ xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/statuses/friends_timeline"); xhr.clearParams(); xhr.setParam("since_id",lastnews); xhr.setParam("count",50)}); break; case "Timeline": var lastnews=Newsjs.getLastNews(login,db,function(lastnews){ xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/statuses/friends_timeline"); xhr.clearParams(); xhr.setParam("since_id",lastnews); xhr.setParam("count",50) }); break; case "Search": xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/search"); break; case "Notifications": xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/friendica/notifications"); xhr.clearParams(); break; case "Direct Messages": xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/direct_messages/all"); xhr.clearParams(); break; case "Public Timeline": xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/statuses/public_timeline"); xhr.clearParams(); break; case "Favorites": xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/favorites"); xhr.clearParams(); break; case "Replies": xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/statuses/replies"); xhr.clearParams(); break; default: Newsjs.getLastNews(login,db,function(lastnews){ xhr.setLogin(login.username+":"+Qt.atob(login.password)); xhr.setUrl(login.server); xhr.setApi("/api/statuses/friends_timeline"); xhr.clearParams(); xhr.setParam("since_id",lastnews); xhr.setParam("count",50) newstab.newstabstatus="Conversations"; }); } xhr.get(); if (viewtype==="Conversations"){Newsjs.allchatsfromdb(db,login.username,function(temp){ newsStack.allchats=temp })} } function showGroups(){ Helperjs.readData(db,"groups",login.username,function(groups){ var groupitems=""; for (var i=0;i