Friendiqa v0.2
This commit is contained in:
parent
74fb551755
commit
a3be940192
123 changed files with 9156 additions and 2455 deletions
|
@ -1,3 +1,34 @@
|
|||
// This file is part of Friendiqa
|
||||
// https://github.com/lubuwest/Friendiqa
|
||||
// Copyright (C) 2017 Marco R. <thomasschmidt45@gmx.net>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
.pragma library
|
||||
.import QtQuick.LocalStorage 2.0 as Sql
|
||||
.import "qrc:/js/helper.js" as Helperjs
|
||||
|
@ -10,14 +41,18 @@ function requestFriends(login,database,rootwindow,callback){
|
|||
Helperjs.friendicaRequest(login,"/api/statuses/friends", rootwindow,function (obj){
|
||||
var friends=JSON.parse(obj);
|
||||
for (var i=0;i<friends.length;i++){ friends[i].isFriend=1}
|
||||
callback(friends)
|
||||
//try{requestProfile(login,friends,rootwindow,function(friends_profile){callback(friends_profile)})}
|
||||
//catch(e){
|
||||
callback(friends)//}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
function requestGroups(login,database,rootwindow,callback){
|
||||
// retrieve, save and return groups. Other features currently not implemented
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/group_show",rootwindow, function (obj){print(obj);
|
||||
Helperjs.friendicaRequest(login,"/api/friendica/group_show",rootwindow, function (obj){
|
||||
var groups=JSON.parse(obj);
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('DELETE from groups where username="'+login.username+'"'); // clean old groups
|
||||
|
@ -32,7 +67,7 @@ function requestGroups(login,database,rootwindow,callback){
|
|||
function listFriends(login,database,callback){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
var result = tx.executeSql('SELECT * from contacts WHERE username="'+login.username+'" AND isFriend=1'); // check for friends
|
||||
var result = tx.executeSql('SELECT * from contacts WHERE username="'+login.username+'" AND isFriend>0'); // check for friends
|
||||
var contactlist=[];
|
||||
for (var i=0;i<result.rows.length;i++){
|
||||
contactlist.push(result.rows.item(i))
|
||||
|
@ -61,7 +96,7 @@ function getFriendsTimeline(login,database,contacts,onlynew,rootwindow,callback)
|
|||
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){print(obj);
|
||||
Helperjs.friendicaRequest(login,"/api/statuses/friends_timeline"+parameter, rootwindow,function (obj){
|
||||
var news=JSON.parse(obj);
|
||||
var newContacts=findNewContacts(news,contacts);
|
||||
callback(news,newContacts)
|
||||
|
@ -86,7 +121,7 @@ function getCurrentContacts(login,database,callback){
|
|||
callback(contactlist)
|
||||
}
|
||||
|
||||
function findNewContacts(news,contacts){//print("contacts: "+JSON.stringify(news))
|
||||
function findNewContacts(news,contacts){
|
||||
var newContacts=[];
|
||||
for (var i=0;i<news.length;i++){
|
||||
var url=news[i].user.url;
|
||||
|
@ -112,11 +147,12 @@ function findNewContacts(news,contacts){//print("contacts: "+JSON.stringify(news
|
|||
}
|
||||
}
|
||||
}
|
||||
// var owner_id=parseInt(news[i].friendica_owner.id);
|
||||
// if(contacts.indexOf(owner_id)==-1 && !(inArray(newContacts,"id",owner_id))){
|
||||
// news[i].friendica_owner.isFriend=0;
|
||||
// newContacts.push(news[i].friendica_owner);
|
||||
// }
|
||||
|
||||
var owner_url=news[i].friendica_owner.url;
|
||||
if(contacts.indexOf(owner_url)==-1 && !(inArray(newContacts,"url",owner_url))){
|
||||
news[i].friendica_owner.isFriend=0;
|
||||
newContacts.push(news[i].friendica_owner);
|
||||
}
|
||||
}
|
||||
return newContacts
|
||||
}
|
||||
|
@ -165,8 +201,9 @@ function getDirectMessage(login,database,rootwindow,callback){
|
|||
});
|
||||
}
|
||||
})
|
||||
if(login.newsViewType=="Timeline"){newsfromdb(database,login.username,callback)}
|
||||
else{chatsfromdb(database,login.username,callback)}
|
||||
callback()
|
||||
// if(login.newsViewType=="Timeline"){newsfromdb(database,login.username,callback)}
|
||||
// else{chatsfromdb(database,login.username,callback)}
|
||||
}
|
||||
|
||||
function getNotifications(login,database,rootwindow,callback){
|
||||
|
@ -194,12 +231,14 @@ function getNotifications(login,database,rootwindow,callback){
|
|||
})
|
||||
})}
|
||||
|
||||
function getActivitiesUserData(database,username,userUrlArray){//print(JSON.stringify(userUrlArray));
|
||||
function getActivitiesUserData(database,username,allcontacts,userUrlArray){//print(JSON.stringify(userUrlArray));
|
||||
|
||||
var helpArray=[];
|
||||
for (var i=0;i<userUrlArray.length;i++){
|
||||
Helperjs.readData(database,"contacts",username,function(userdata){
|
||||
helpArray.push(userdata[0]);
|
||||
},"url",userUrlArray[i]);
|
||||
helpArray.push(objFromArray(allcontacts,"url",userUrlArray[i]));
|
||||
// Helperjs.readData(database,"contacts",username,function(userdata){
|
||||
// helpArray.push(userdata[0]);
|
||||
// },"url",userUrlArray[i]);
|
||||
}
|
||||
return helpArray
|
||||
}
|
||||
|
@ -212,42 +251,47 @@ function newsfromdb(database,username,callback,contact,stop_time){
|
|||
try{var rs = tx.executeSql('select created_at from news WHERE username="'+username+'" ORDER BY created_at DESC LIMIT 1');
|
||||
stop="<="+rs.rows.item(0).created_at}catch(e){stop="<99999999999999"}}
|
||||
else{var stop="<"+stop_time}
|
||||
var contactfilter="";if(contact){contactfilter=" AND uid='"+contact+"'"}
|
||||
var contactfilter="";if(contact){contactfilter=" AND (uid='"+contact+"' OR friendica_owner='"+contact+"')"}
|
||||
//print('select * from news WHERE username="'+username+'" AND created_at'+stop+contactfilter+' ORDER BY created_at DESC LIMIT 20');
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+username+'" AND created_at'+stop+contactfilter+' ORDER BY created_at DESC LIMIT 20');
|
||||
var newsArray=[];
|
||||
var allcontacts=[];
|
||||
Helperjs.readData(database,"contacts",username,function(obj){allcontacts=obj});
|
||||
for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
newsArray.push(newsrs.rows.item(i));
|
||||
newsArray[i]=fetchUsersForNews(database,username,newsArray[i])
|
||||
newsArray[i]=fetchUsersForNews(database,username,newsArray[i],allcontacts)
|
||||
}
|
||||
callback(newsArray)});
|
||||
}
|
||||
|
||||
function fetchUsersForNews(database,username,news){//print(JSON.stringify(news))
|
||||
Helperjs.readData(database,"contacts",username,function(userdata){
|
||||
news.user=userdata[0];
|
||||
//print("Fetch user"+JSON.stringify(news.user));
|
||||
},"id",news.uid);
|
||||
if(news.in_reply_to_user_id){
|
||||
Helperjs.readData(database,"contacts",username,function(replytodata){
|
||||
news.reply_user=replytodata[0];
|
||||
//print("Fetch reply to"+JSON.stringify(news.reply_user));
|
||||
},"id",news.in_reply_to_user_id);
|
||||
}
|
||||
function fetchUsersForNews(database,username,news,allcontacts){//print(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);
|
||||
// Helperjs.readData(database,"contacts",username,function(userdata){
|
||||
// news.user=userdata[0];
|
||||
// //print("Fetch user"+JSON.stringify(news.user));
|
||||
// },"id",news.uid);
|
||||
// if(news.in_reply_to_user_id){
|
||||
// Helperjs.readData(database,"contacts",username,function(replytodata){
|
||||
// news.reply_user=replytodata[0];
|
||||
// //print("Fetch reply to"+JSON.stringify(news.reply_user));
|
||||
// },"id",news.in_reply_to_user_id);
|
||||
// }
|
||||
if (news.messagetype==0){
|
||||
for(var j=0;j<news.friendica_activities.length;j++)
|
||||
{var friendicaArray=JSON.parse(Qt.atob(news.friendica_activities));
|
||||
// print("Array: "+friendicaArray[1]);
|
||||
news.like=getActivitiesUserData(database,username,friendicaArray[0]);
|
||||
news.dislike=getActivitiesUserData(database,username,friendicaArray[1]);
|
||||
news.attendyes=getActivitiesUserData(database,username,friendicaArray[2]);
|
||||
news.attendno=getActivitiesUserData(database,username,friendicaArray[3]);
|
||||
news.attendmaybe=getActivitiesUserData(database,username,friendicaArray[4]);
|
||||
news.like=getActivitiesUserData(database,username,allcontacts,friendicaArray[0]);
|
||||
news.dislike=getActivitiesUserData(database,username,allcontacts,friendicaArray[1]);
|
||||
news.attendyes=getActivitiesUserData(database,username,allcontacts,friendicaArray[2]);
|
||||
news.attendno=getActivitiesUserData(database,username,allcontacts,friendicaArray[3]);
|
||||
news.attendmaybe=getActivitiesUserData(database,username,allcontacts,friendicaArray[4]);
|
||||
}
|
||||
Helperjs.readData(database,"contacts",username,function(friendica_owner_data){
|
||||
news.friendica_owner_object=friendica_owner_data[0];
|
||||
//print("Fetch friendica_owner"+JSON.stringify(news.friendica_owner));
|
||||
},"url",news.friendica_owner);
|
||||
// Helperjs.readData(database,"contacts",username,function(friendica_owner_data){
|
||||
// news.friendica_owner_object=friendica_owner_data[0];
|
||||
// //print("Fetch friendica_owner"+JSON.stringify(news.friendica_owner));
|
||||
// },"url",news.friendica_owner);
|
||||
}
|
||||
return news
|
||||
}
|
||||
|
@ -265,19 +309,19 @@ function deleteNews(login,database,newsid,messagetype,rootwindow,callback){
|
|||
})}
|
||||
|
||||
function retweetNews(login,database,newsid,rootwindow,callback){
|
||||
Helperjs.friendicaPostRequest(login,"/api/statuses/retweet?id="+newsid,"","POST", rootwindow,function (obj){
|
||||
Helperjs.friendicaPostRequest(login,"/api/statuses/retweet?id="+newsid,"","POST", rootwindow,function (obj){
|
||||
var answer=JSON.parse(obj);
|
||||
if(answer.status.error){Helperjs.showMessage("Repost",answer.status.code,rootwindow);}
|
||||
else{Helperjs.showMessage("Repost",obj,rootwindow)}
|
||||
})}
|
||||
if(answer.hasOwnProperty('status'))//('error' in answer.status)
|
||||
{Helperjs.showMessage("Repost",answer.status.code,rootwindow);}
|
||||
else{Helperjs.showMessage("Repost",answer.text,rootwindow)}
|
||||
})
|
||||
}
|
||||
|
||||
function favorite(login,favorite,newsid,rootwindow){
|
||||
// toggle favorites
|
||||
if(favorite){ Helperjs.friendicaPostRequest(login,"/api/favorites/create?id="+newsid,"","POST", rootwindow,function (obj){
|
||||
print("Favorite "+obj);
|
||||
})}
|
||||
else {Helperjs.friendicaPostRequest(login,"/api/favorites/destroy?id="+newsid, "POST",rootwindow,function (obj){
|
||||
print("Favorite destroyed "+obj);
|
||||
})}
|
||||
}
|
||||
|
||||
|
@ -300,7 +344,7 @@ function likerequest(login,database,verb,newsid,rootwindow){
|
|||
//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{print("likerequest"+obj)}})
|
||||
else{}})
|
||||
}
|
||||
|
||||
function like(login,database,toggle,verb,newsid,rootwindow){
|
||||
|
@ -352,13 +396,16 @@ function requestConversation(login,database,newsid,contacts,rootwindow,callback)
|
|||
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=[];
|
||||
for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
newsArray.push(newsrs.rows.item(i));
|
||||
newsArray[i]=fetchUsersForNews(database,user,newsArray[i])
|
||||
}
|
||||
callback(newsArray);} )}
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+user+'" AND statusnet_conversation_id="'+conversationId+'" ORDER BY created_at ASC');
|
||||
var newsArray=[];
|
||||
var allcontacts=[];
|
||||
Helperjs.readData(database,"contacts",user,function(obj){allcontacts=obj});
|
||||
for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
newsArray.push(newsrs.rows.item(i));
|
||||
newsArray[i]=fetchUsersForNews(database,user,newsArray[i],allcontacts)
|
||||
}
|
||||
callback(newsArray)})
|
||||
}
|
||||
|
||||
function requestFavorites(login,database,contacts,rootwindow,callback){
|
||||
Helperjs.friendicaRequest(login,"/api/favorites",rootwindow, function (obj){
|
||||
|
@ -375,9 +422,11 @@ function favoritesfromdb(database,user,callback){
|
|||
//print('select * from news WHERE username="'+user+'" AND favorited=1 ORDER BY status_id DESC');
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+user+'" AND favorited=1 ORDER BY status_id DESC');
|
||||
var newsArray=[];
|
||||
var allcontacts=[];
|
||||
Helperjs.readData(database,"contacts",user,function(obj){allcontacts=obj});
|
||||
for(var i = 0; i < newsrs.rows.length; i++) {
|
||||
newsArray.push(newsrs.rows.item(i));
|
||||
newsArray[i]=fetchUsersForNews(database,user,newsArray[i]);
|
||||
newsArray[i]=fetchUsersForNews(database,user,newsArray[i],allcontacts);
|
||||
callback(newsArray);
|
||||
}})}
|
||||
|
||||
|
@ -394,11 +443,13 @@ function chatsfromdb(database,user,callback,stop_time){
|
|||
conversations.push(conversationsrs.rows.item(i).statusnet_conversation_id);
|
||||
}
|
||||
var newsArray=[];
|
||||
var allcontacts=[];
|
||||
Helperjs.readData(database,"contacts",user,function(obj){allcontacts=obj});
|
||||
for(var j = 0; j< conversations.length; j++) {
|
||||
var newsrs=tx.executeSql('select * from news WHERE username="'+user+'" AND statusnet_conversation_id="'+conversations[j] +'" ORDER BY created_at ASC');
|
||||
var helpernews=newsrs.rows.item(0);
|
||||
helpernews.newscount=newsrs.rows.length;
|
||||
helpernews=fetchUsersForNews(database,user,helpernews);
|
||||
helpernews=fetchUsersForNews(database,user,helpernews,allcontacts);
|
||||
//var chatArray=[];
|
||||
// for (var k=0;k<newsrs.rows.length;k++){
|
||||
// var helperchat=newsrs.rows.item(k);
|
||||
|
@ -420,7 +471,16 @@ function inArray(list, prop, val) {
|
|||
} 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 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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue