2018-02-19 22:36:00 +01:00
|
|
|
// 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/>.
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
import QtQuick 2.0
|
|
|
|
import QtQuick.Controls 1.2
|
|
|
|
import "qrc:/qml/genericqml"
|
|
|
|
import "qrc:/js/news.js" as Newsjs
|
|
|
|
import "qrc:/js/helper.js" as Helperjs
|
|
|
|
import "qrc:/js/service.js" as Service
|
|
|
|
|
2018-04-11 21:50:43 +02:00
|
|
|
//import AndroidNative 1.0
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
Item {
|
|
|
|
Connections{
|
|
|
|
target:newstab
|
|
|
|
onNewstabstatusChanged:{
|
|
|
|
newstabstatusButton.text= qsTr(newstab.newstabstatus)
|
|
|
|
}
|
|
|
|
}
|
2017-01-29 17:26:09 +01:00
|
|
|
|
|
|
|
Connections{
|
|
|
|
target:xhr
|
2018-02-19 22:36:00 +01:00
|
|
|
// onError:{if (data=="contact"){downloadNotice.text=root.newContacts[root.currentContact].name+"... Error!"}}
|
2017-03-25 23:36:14 +01:00
|
|
|
onSuccess:{replytimer.start() //wait 1 second to load new timeline
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:50:43 +02:00
|
|
|
|
|
|
|
|
2017-03-25 23:36:14 +01:00
|
|
|
Timer {id:replytimer; interval: 1000; running: false; repeat: false
|
2018-02-19 22:36:00 +01:00
|
|
|
onTriggered: {
|
|
|
|
if(newstab.newstabstatus=="Conversation"){
|
|
|
|
showConversation(newsStack.timelineIndex-1,newsModel.get(0).newsitemobject)}
|
|
|
|
else{
|
2017-03-25 23:36:14 +01:00
|
|
|
var onlynew=true;
|
|
|
|
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(rns,rnc){
|
|
|
|
root.contactLoadType="news";
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=rns;root.newContacts=rnc;})
|
|
|
|
}
|
|
|
|
}
|
2017-01-29 17:26:09 +01:00
|
|
|
}
|
|
|
|
|
2017-03-25 23:36:14 +01:00
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
function showNews(newsToShow){
|
2017-03-25 23:36:14 +01:00
|
|
|
try{if (newsStack.depth>1){newsStack.pop()}}catch(e){}
|
2018-04-11 21:50:43 +02:00
|
|
|
newsBusy.running = false;
|
2017-01-26 21:55:31 +01:00
|
|
|
var currentTime= new Date();
|
2017-03-25 23:36:14 +01:00
|
|
|
downloadNotice.text="";
|
2017-01-26 21:55:31 +01:00
|
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsToShow};
|
|
|
|
newsWorker.sendMessage(msg);
|
|
|
|
}
|
|
|
|
|
2017-05-11 22:15:34 +02:00
|
|
|
function showConversation(conversationIndex,newsitemobject){
|
2017-11-07 21:57:40 +01:00
|
|
|
//newsBusy.running=true;
|
2017-03-25 23:36:14 +01:00
|
|
|
root.contactLoadType="conversation";
|
2017-05-11 22:15:34 +02:00
|
|
|
newsStack.conversationIndex= conversationIndex;
|
|
|
|
if(newsitemobject.messagetype==0){
|
|
|
|
Newsjs.requestConversation(root.login,db,newsitemobject.status_id,root.contactlist,root,function(ns,nc){
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=ns;root.newContacts=nc;
|
2017-03-25 23:36:14 +01:00
|
|
|
})}
|
2017-05-11 22:15:34 +02:00
|
|
|
else{Newsjs.conversationfromdb(root.db,root.login.username,newsitemobject.statusnet_conversation_id, function(newsarray){
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=newsarray;root.newContacts=[];
|
2017-05-11 22:15:34 +02:00
|
|
|
})}
|
2017-03-25 23:36:14 +01:00
|
|
|
}
|
|
|
|
|
2017-11-07 21:57:40 +01:00
|
|
|
function showContact(contact){
|
|
|
|
var component = Qt.createComponent("qrc:/qml/contactqml/ContactDetailsComponent.qml");
|
|
|
|
if (component.status== Component.Ready){
|
|
|
|
var contactDetails = component.createObject(newstab,{"contact": contact})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
function onFriendsMessages(friend){
|
2017-01-29 17:26:09 +01:00
|
|
|
newstab.newstabstatus="Contact"
|
2018-02-19 22:36:00 +01:00
|
|
|
Newsjs.newsfromdb(db,root.login.username, function(dbnews){
|
|
|
|
if (dbnews.length==0){
|
|
|
|
Newsjs.newsfromdb(db,login.username,function(forumnews){
|
|
|
|
showNews(forumnews)
|
|
|
|
},friend.url)
|
|
|
|
}
|
|
|
|
else showNews(dbnews)
|
|
|
|
},friend.id)
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function onDirectMessage(friend){
|
|
|
|
newstab.newstabstatus="SendMessage"
|
|
|
|
newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"reply_to_user": friend,"directmessage":1,"login":root.login}});
|
|
|
|
}
|
|
|
|
|
2018-04-11 21:50:43 +02:00
|
|
|
function sendUrls(urls){
|
|
|
|
if((urls.length==1)&&(newsStack.depth<2)){
|
|
|
|
newsStack.push([newslistRectangle,{item:"qrc:/qml/newsqml/MessageSend.qml",properties:{attachImageURLs:urls}}])
|
|
|
|
}
|
|
|
|
}
|
2017-11-07 21:57:40 +01:00
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
StackView{
|
|
|
|
id: newsStack
|
|
|
|
anchors.fill:parent
|
2017-05-11 22:15:34 +02:00
|
|
|
property int conversationIndex: 0
|
2017-03-25 23:36:14 +01:00
|
|
|
|
2017-05-11 22:15:34 +02:00
|
|
|
initialItem:Rectangle {
|
2018-04-11 21:50:43 +02:00
|
|
|
id:newslistRectangle
|
2017-01-26 21:55:31 +01:00
|
|
|
y:1
|
|
|
|
color: "white"
|
|
|
|
|
|
|
|
BlueButton{
|
|
|
|
id:newstabstatusButton
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 0.5*mm
|
|
|
|
text: qsTr(newstab.newstabstatus)
|
|
|
|
onClicked: {newstabmenu.popup()}
|
|
|
|
}
|
|
|
|
|
|
|
|
Row{
|
|
|
|
spacing: mm
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.topMargin: 0.5*mm
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
|
|
|
BlueButton {
|
2017-05-11 22:15:34 +02:00
|
|
|
id: newMessageButton
|
|
|
|
text: "\uf040"
|
|
|
|
onClicked: {
|
|
|
|
var groups=[];
|
|
|
|
Helperjs.readData(root.db,"groups",root.login.username,function(groupobject){
|
|
|
|
groups=groupobject
|
|
|
|
});
|
|
|
|
newstab.newstabstatus="SendMessage";
|
|
|
|
Helperjs.readData(root.db,"contacts",root.login.username,function(friends){
|
|
|
|
newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{"contacts": friends,"login":root.login}})
|
|
|
|
},"isFriend",1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BlueButton {
|
|
|
|
id: quitButton
|
|
|
|
text: "\uf08b"
|
2018-02-19 22:36:00 +01:00
|
|
|
onClicked: {Service.cleanNews(root.db,function(){
|
|
|
|
Service.cleanContacts(root.login,root.db,function(){
|
|
|
|
Qt.quit() })
|
|
|
|
})}
|
2017-05-11 22:15:34 +02:00
|
|
|
}
|
|
|
|
BlueButton {
|
2017-01-26 21:55:31 +01:00
|
|
|
id: update
|
2017-03-25 23:36:14 +01:00
|
|
|
text: "\uf021"
|
2017-01-26 21:55:31 +01:00
|
|
|
onClicked: {
|
|
|
|
newsBusy.running=true;
|
|
|
|
newstab.newstabstatus=login.newsViewType;
|
|
|
|
root.contactLoadType="news";
|
|
|
|
var onlynew=true;
|
2018-02-19 22:36:00 +01:00
|
|
|
//print("newstab "+ JSON.stringify(contactlist));
|
2017-01-26 21:55:31 +01:00
|
|
|
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(ns,nc){
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=ns;root.newContacts=nc;
|
2017-01-26 21:55:31 +01:00
|
|
|
if (ns.length==0){// update last 20 existing news for changes and likes
|
|
|
|
onlynew=false;
|
|
|
|
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(rns,rnc){
|
|
|
|
root.contactLoadType="news";
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=rns;root.newContacts=rnc;})
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
2017-03-25 23:36:14 +01:00
|
|
|
})
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
Component { id:footerComponent
|
|
|
|
Rectangle{
|
|
|
|
border.color: "#EEEEEE"
|
|
|
|
border.width: 1
|
2017-03-25 23:36:14 +01:00
|
|
|
width:newsView.width
|
2017-01-26 21:55:31 +01:00
|
|
|
height:6*mm
|
|
|
|
Text{
|
|
|
|
font.pixelSize: 1.5*mm
|
|
|
|
anchors.centerIn: parent
|
|
|
|
text:qsTr("More")
|
|
|
|
}
|
|
|
|
MouseArea{anchors.fill:parent
|
|
|
|
onClicked:{
|
2017-11-07 21:57:40 +01:00
|
|
|
var currentTime= new Date();
|
|
|
|
var lastnews_id=newsModel.get(newsModel.count-1).newsitemobject.created_at;
|
|
|
|
print("Lastnews ID "+lastnews_id+Qt.atob(newsModel.get(newsModel.count-1).newsitemobject.statusnet_html))
|
|
|
|
if(newstab.newstabstatus=="Timeline"){
|
2017-01-26 21:55:31 +01:00
|
|
|
Newsjs.newsfromdb(root.db,root.login.username, function(news){
|
2017-11-07 21:57:40 +01:00
|
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
|
|
|
newsWorker.sendMessage(msg);
|
|
|
|
},false,lastnews_id)}
|
|
|
|
if(newstab.newstabstatus=="Conversations"){
|
2017-01-26 21:55:31 +01:00
|
|
|
Newsjs.chatsfromdb(root.db,root.login.username, function(news){
|
2017-11-07 21:57:40 +01:00
|
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
|
|
|
newsWorker.sendMessage(msg);
|
|
|
|
},lastnews_id)}
|
|
|
|
else if(newstab.newstabstatus=="Contact"){
|
|
|
|
Newsjs.newsfromdb(root.db,root.login.username, function(news){
|
|
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'appendnews':true};
|
|
|
|
newsWorker.sendMessage(msg);
|
|
|
|
},newsModel.get(newsModel.count-1).newsitemobject.uid,lastnews_id)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
2017-03-25 23:36:14 +01:00
|
|
|
|
2017-01-26 21:55:31 +01:00
|
|
|
ListView {
|
|
|
|
id: newsView
|
|
|
|
anchors.fill: parent
|
2017-05-11 22:15:34 +02:00
|
|
|
anchors.topMargin: 7*root.mm
|
2017-01-26 21:55:31 +01:00
|
|
|
anchors.leftMargin: 3*root.mm; anchors.rightMargin: root.mm
|
|
|
|
anchors.bottomMargin: 1*root.mm
|
|
|
|
clip: true
|
|
|
|
spacing: 0
|
2017-05-11 22:15:34 +02:00
|
|
|
footer: footerComponent
|
2017-01-26 21:55:31 +01:00
|
|
|
model: newsModel
|
|
|
|
delegate: Newsitem{}
|
2017-11-07 21:57:40 +01:00
|
|
|
//onContentYChanged:{if(contentY<-8*mm&&contentY>(-8*mm-1)){print("refreshing");
|
|
|
|
onDragEnded:{if(contentY<-5*mm){//print("refreshing");
|
2017-05-11 22:15:34 +02:00
|
|
|
newsBusy.running=true;
|
|
|
|
newstab.newstabstatus=login.newsViewType;
|
|
|
|
root.contactLoadType="news";
|
|
|
|
var onlynew=true;
|
|
|
|
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(ns,nc){
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=ns;root.newContacts=nc;
|
2017-05-11 22:15:34 +02:00
|
|
|
if (ns.length==0){// update last 20 existing news for changes and likes
|
|
|
|
onlynew=false;
|
|
|
|
Newsjs.getFriendsTimeline(login,db,contactlist,onlynew,newstab,function(rns,rnc){
|
|
|
|
root.contactLoadType="news";
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=rns;root.newContacts=rnc;})
|
2017-05-11 22:15:34 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
|
|
|
|
ListModel{id: newsModel}
|
|
|
|
|
|
|
|
WorkerScript {
|
|
|
|
id: newsWorker
|
|
|
|
source: "qrc:/js/newsworker.js"
|
|
|
|
}
|
|
|
|
|
|
|
|
BusyIndicator{
|
|
|
|
id: newsBusy
|
|
|
|
anchors.horizontalCenter: newsView.horizontalCenter
|
|
|
|
anchors.top:newsView.top
|
|
|
|
anchors.topMargin: 2*mm
|
|
|
|
width:10*mm
|
|
|
|
height: 10*mm
|
|
|
|
}
|
2017-01-29 17:26:09 +01:00
|
|
|
Rectangle{
|
|
|
|
id:downloadNotice
|
|
|
|
property alias text: noticeText.text
|
|
|
|
color:"white"
|
|
|
|
border.color:"grey"
|
|
|
|
z:1
|
|
|
|
anchors.horizontalCenter: newsView.horizontalCenter
|
|
|
|
anchors.bottom:newsView.bottom
|
|
|
|
anchors.bottomMargin: 2*mm
|
|
|
|
width: noticeText.width+2*mm
|
|
|
|
height: noticeText.height+2*mm
|
|
|
|
visible: (downloadNotice.text!="")
|
|
|
|
|
|
|
|
Text{
|
|
|
|
id:noticeText
|
|
|
|
color: "grey"
|
|
|
|
anchors.centerIn: parent
|
|
|
|
width: contentWidth
|
|
|
|
height: contentHeight
|
|
|
|
font.pixelSize: 2*mm
|
|
|
|
text:""
|
|
|
|
}
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
Menu {
|
|
|
|
id:newstabmenu
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Timeline")
|
|
|
|
onTriggered: {
|
|
|
|
newstab.newstabstatus="Timeline";
|
|
|
|
newsModel.clear();
|
2017-03-25 23:36:14 +01:00
|
|
|
try{ Newsjs.newsfromdb(root.db,root.login.username, function(dbnews){
|
2017-01-26 21:55:31 +01:00
|
|
|
showNews(dbnews)
|
2017-03-25 23:36:14 +01:00
|
|
|
})}catch(e){Helperjs.showMessage("Error",e,root)}}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Favorites")
|
|
|
|
onTriggered:{
|
|
|
|
newstab.newstabstatus="Favorites";
|
|
|
|
root.contactLoadType="favorites";
|
|
|
|
newsBusy.running=true;
|
|
|
|
Newsjs.requestFavorites(root.login,db,root.contactlist,root,function(ns,nc){
|
2018-02-19 22:36:00 +01:00
|
|
|
root.news=ns; root.newContacts=nc;
|
2017-01-26 21:55:31 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem {
|
2017-05-11 22:15:34 +02:00
|
|
|
text: qsTr("Conversations")
|
2017-01-26 21:55:31 +01:00
|
|
|
onTriggered:{
|
|
|
|
newsModel.clear();
|
2017-05-11 22:15:34 +02:00
|
|
|
newstab.newstabstatus="Conversations";
|
2017-01-26 21:55:31 +01:00
|
|
|
Newsjs.chatsfromdb(db,root.login.username,function(news){showNews(news)})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Notifications")
|
|
|
|
onTriggered:{
|
|
|
|
newstab.newstabstatus="Notifications";
|
|
|
|
newsBusy.running=true;
|
|
|
|
Newsjs.getNotifications(root.login,db,root,function(news){
|
|
|
|
showNews(news)}
|
|
|
|
)}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
root.messageSignal.connect(onFriendsMessages);
|
|
|
|
root.directmessageSignal.connect(onDirectMessage);
|
|
|
|
root.newsSignal.connect(showNews);
|
2018-04-11 21:50:43 +02:00
|
|
|
root.uploadSignal.connect(sendUrls);
|
2017-01-26 21:55:31 +01:00
|
|
|
try{newsModel.clear()} catch(e){}
|
2018-04-11 21:50:43 +02:00
|
|
|
|
|
|
|
//print("imageUrls "+JSON.stringify(imageUrls)+" newsstack.depth:"+newsStack.depth);
|
|
|
|
//newsStack.push({item:"qrc:/qml/newsqml/MessageSend.qml",properties:{attachImageURLs:[imageUrl]}})
|
|
|
|
// var imagePicker = Qt.createQmlObject('import QtQuick 2.0; import "qrc:/qml/genericqml";'+
|
|
|
|
// osSettings.imagePickQml+'{multiple : true; onReady: {'+
|
|
|
|
// 'if(imageUrls.length==1){root.currentIndex=0;newstab.active=true;root.uploadSignal(imageUrls)} else{'+
|
|
|
|
// ' root.currentIndex=2;fotostab.active=true;'+
|
|
|
|
// 'root.uploadSignal(imageUrls)};}}',newstab,"imagePicker");
|
|
|
|
//SystemDispatcher.setInitialized();
|
|
|
|
if(root.news.length>0){showNews(root.news)}
|
|
|
|
else{ newstab.newstabstatus=login.newsViewType;
|
|
|
|
if(login.newsViewType=="Timeline"){Newsjs.newsfromdb(db,login.username,function(dbnews){showNews(dbnews)})}
|
|
|
|
else{Newsjs.chatsfromdb(db,login.username,function(dbnews){showNews(dbnews)})}
|
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
2018-04-11 21:50:43 +02:00
|
|
|
}
|
2017-01-26 21:55:31 +01:00
|
|
|
}
|
|
|
|
}
|