v.0.5
This commit is contained in:
parent
63dfb9b197
commit
d48847d183
135 changed files with 8879 additions and 3693 deletions
|
@ -38,7 +38,7 @@
|
|||
|
||||
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])
|
||||
//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)');
|
||||
|
@ -194,13 +194,11 @@ function storeConfig(database,obj) { // stores config to DB
|
|||
//print(JSON.stringify(obj));
|
||||
var result = tx.executeSql('SELECT * from config WHERE username="'+obj.username+'"');
|
||||
if(result.rows.length === 1) {// use update
|
||||
var result2 = tx.executeSql('UPDATE config SET server="'+obj.server+'",password="'+obj.password+'", imagestore="'+obj.imagestore+'", maxnews='+obj.maxnews+', timerInterval='+obj.interval+', newsViewType="'+obj.newsViewType+'", isActive=0 WHERE username="'+obj.username +'"');
|
||||
var result2 = tx.executeSql('UPDATE config SET server="'+obj.server+'",password="'+obj.password+'", imagestore="'+obj.imagestore+'", maxnews=0, timerInterval=0, newsViewType="'+obj.newsViewType+'", isActive=0 WHERE username="'+obj.username +'"');
|
||||
var result3 = tx.executeSql('UPDATE config SET isActive=1 WHERE username !="'+obj.username +'"');
|
||||
var result4 = tx.executeSql('UPDATE config SET maxnews='+obj.maxnews);
|
||||
} else {// use insert print('... does not exists, create it')
|
||||
var result2 = tx.executeSql('INSERT INTO config VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', [obj.server, obj.username, obj.password, obj.imagestore, obj.maxnews, obj.interval,obj.newsViewType,0,"[[],[],[],[]]",0,"","",""]);
|
||||
var result2 = tx.executeSql('INSERT INTO config VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)', [obj.server, obj.username, obj.password, obj.imagestore, 0, 0,obj.newsViewType,0,"[[],[],[],[]]",0,"","",""]);
|
||||
var result3 = tx.executeSql('UPDATE config SET isActive=1 WHERE username !="'+obj.username +'"');
|
||||
var result4 = tx.executeSql('UPDATE config SET maxnews='+obj.maxnews);
|
||||
}
|
||||
})}
|
||||
|
||||
|
@ -283,7 +281,7 @@ function readConfig(database,callback,filter,filtervalue) { // reads config
|
|||
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,maxnews:rsArray[0].maxnews,isActive:rsArray[0].isActive,timerInterval:rsArray[0].timerInterval, newsViewType:rsArray[0].newsViewType,permissions:JSON.parse(rsArray[0].permissions),maxContactAge:rsArray[0].maxContactAge,APIVersion:rsArray[0].APIVersion,addons:rsArray[0].addons};
|
||||
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)}}
|
||||
)
|
||||
|
@ -318,6 +316,7 @@ function updateglobaloptions(database,key,value){
|
|||
result = tx.executeSql('INSERT INTO globaloptions (k,v) VALUES (?,?)', [key,value])
|
||||
}
|
||||
})
|
||||
root.globaloptions[key]=value;
|
||||
}
|
||||
|
||||
function deleteConfig(database,userobj,callback) { // delete user data from DB
|
||||
|
@ -338,8 +337,9 @@ function deleteConfig(database,userobj,callback) { // delete user data from DB
|
|||
function cleanNews(database,callback){
|
||||
var db=Sql.LocalStorage.openDatabaseSync(database[0],database[1],database[2],database[3]);
|
||||
db.transaction( function(tx) {
|
||||
var maxnewsrs = tx.executeSql("SELECT DISTINCT maxnews FROM config");
|
||||
var maxnews=maxnewsrs.rows.item(0).maxnews;
|
||||
//var maxnewsrs = tx.executeSql("SELECT DISTINCT maxnews FROM config");
|
||||
var maxnewsrs = tx.executeSql("SELECT v FROM globaloptions WHERE k='max_news'");
|
||||
var maxnews=1000; if(maxnewsrs.rows.length>0){ 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){
|
||||
|
@ -384,6 +384,7 @@ function updateContactInDB(login,database,isFriend,contact){// for newstab and f
|
|||
}
|
||||
|
||||
function processNews(api,data){
|
||||
//print(api + data);
|
||||
try{var newslist=JSON.parse(data)} catch(e){newsBusy.running=false;};
|
||||
if (data==""){}
|
||||
else if (typeof(newslist)=='undefined'){
|
||||
|
@ -393,6 +394,7 @@ function processNews(api,data){
|
|||
Helperjs.showMessage(qsTr("JSON status Error"),"API:\n" +login.server+api+"\n Return: \n"+data,root)
|
||||
}
|
||||
else if (!(Array.isArray(newslist))){
|
||||
//print("processNews not array"+newslist+JSON.stringify(newslist));
|
||||
replytimer.restart()
|
||||
}
|
||||
else {
|
||||
|
@ -407,6 +409,8 @@ function processNews(api,data){
|
|||
newslist[n].uid=newslist[n].sender.id;
|
||||
newslist[n].statusnet_conversation_id=newslist[n].friendica_parent_uri;
|
||||
newslist[n].user=cleanUser(newslist[n].sender);
|
||||
newslist[n].friendica_owner=newslist[n].user;
|
||||
newslist[n].friendica_author=newslist[n].user;
|
||||
newslist[n].statusnet_html=newslist[n].text;
|
||||
}}
|
||||
else if (api=="/api/friendica/notifications"){
|
||||
|
@ -418,6 +422,8 @@ function processNews(api,data){
|
|||
newslist[n].user={"profile_image_url": newslist[n].photo,"name": newslist[n].name," url":newslist[n].url, "created_at":newslist[n].date};
|
||||
newslist[n].user=cleanUser(newslist[n].user);
|
||||
}
|
||||
newslist[n].friendica_author=newslist[n].user;
|
||||
newslist[n].friendica_owner=newslist[n].user;
|
||||
newslist[n].statusnet_html=newslist[n].msg_html;
|
||||
newslist[n].text=newslist[n].msg;
|
||||
}
|
||||
|
@ -427,8 +433,9 @@ function processNews(api,data){
|
|||
var commentCount=[];
|
||||
for (var n in newslist){
|
||||
newslist[n].created_at=Date.parse(Newsjs.cleanDate(newslist[n].created_at));
|
||||
newslist[n].messagetype=0;
|
||||
newslist[n].user=cleanUser(newslist[n].user)
|
||||
if (api=="/api/statuses/replies"){newslist[n].messagetype=3}else{newslist[n].messagetype=0;}
|
||||
newslist[n].friendica_author=cleanUser(newslist[n].friendica_author);
|
||||
newslist[n].user=cleanUser(newslist[n].user);
|
||||
if(newslist[n].in_reply_to_user_id){newslist[n].reply_user=Newsjs.objFromArray(allcontacts,"id",newslist[n].in_reply_to_user_id)}
|
||||
//print (JSON.stringify(newslist[n].user))
|
||||
if(newslist[n].hasOwnProperty('friendica_activities')){
|
||||
|
@ -448,8 +455,8 @@ function processNews(api,data){
|
|||
newslist[n].friendica_activities.attendmaybe[r]=cleanUser(newslist[n].friendica_activities.attendmaybe[r]);
|
||||
}
|
||||
}
|
||||
if(!(newslist[n].hasOwnProperty('friendica_owner'))){
|
||||
newslist[n].friendica_owner=newslist[n].user
|
||||
if(!(newslist[n].hasOwnProperty('friendica_author'))){
|
||||
newslist[n].friendica_author=newslist[n].user
|
||||
}
|
||||
var conversationindex=conversationIds.indexOf(newslist[n].statusnet_conversation_id);
|
||||
|
||||
|
@ -488,11 +495,13 @@ function processNews(api,data){
|
|||
else if (api=="/api/statuses/user_timeline"){
|
||||
newstab.contactposts=newslist
|
||||
}
|
||||
else if (newstab.newstabstatus==="Conversations"){
|
||||
showNews(chatlist);root.news=newslist}
|
||||
else {showNews(newslist);root.news=newslist};
|
||||
else if ((api!="/api/direct_messages/all")&&(api!="/api/friendica/notifications")&&(newstab.newstabstatus==="Conversations")){
|
||||
showNews(chatlist);root.news=newslist
|
||||
}
|
||||
else {
|
||||
showNews(newslist);root.news=newslist};
|
||||
|
||||
var newstabarray=["Conversations","Favorites","Timeline","DirectMessage"];
|
||||
var newstabarray=["Conversations","Favorites","Timeline","DirectMessage","Replies"];
|
||||
if (newstabarray.indexOf(newstab.newstabstatus)>-1){contacttimer.start()}
|
||||
}
|
||||
|
||||
|
@ -509,26 +518,28 @@ function cleanUser(user){
|
|||
}
|
||||
|
||||
function updateView(viewtype){
|
||||
newsBusy.running=true;
|
||||
//messageSend.state="";
|
||||
//newsBusy.running=true;
|
||||
//downloadNotice.text="xhr start "+Date.now()
|
||||
switch(viewtype){
|
||||
case "Conversations":
|
||||
var lastnews=Newsjs.getLastNews(login,db);
|
||||
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)
|
||||
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);
|
||||
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)
|
||||
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));
|
||||
|
@ -566,14 +577,15 @@ function updateView(viewtype){
|
|||
xhr.clearParams();
|
||||
break;
|
||||
default:
|
||||
var lastnews=Newsjs.getLastNews(login,db);
|
||||
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";
|
||||
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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue