forked from lubuwest/Friendiqa
568 lines
22 KiB
QML
568 lines
22 KiB
QML
// This file is part of Friendiqa
|
|
// https://git.friendi.ca/lubuwest/Friendiqa
|
|
// Copyright (C) 2020 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/>.
|
|
|
|
import QtQuick 6.3
|
|
import QtQuick.Controls 6.3
|
|
import "qrc:/js/news.js" as Newsjs
|
|
import "qrc:/js/helper.js" as Helperjs
|
|
import "qrc:/js/service.js" as Service
|
|
import "qrc:/qml/genericqml"
|
|
|
|
Rectangle{
|
|
id: newsStack
|
|
color: osSettings.backgroundColor
|
|
property string updateMethodNews: "refresh"
|
|
property var allchats: ({})
|
|
property int lastnewsid:0
|
|
property string newstabstatus: ""
|
|
|
|
function newstypeHandling(newstype){
|
|
newsModel.clear();
|
|
//if (!newsBusy.running) {
|
|
try{newsBusy.running=true}catch(e){print("newsBusy.running=true " + e)};
|
|
//root.replySignal("");
|
|
switch(newstype){
|
|
case "timeline":
|
|
newstab.newstabstatus="Timeline";
|
|
try{ Newsjs.newsfromdb(root.db,root.login,0, function(dbnews,lastid){
|
|
lastnewsid=lastid;
|
|
showNews(dbnews)
|
|
})}catch(e){//Helperjs.showMessage("Error",e,root)
|
|
};
|
|
break;
|
|
case "conversation":
|
|
updateMethodNews="conversation";
|
|
newstab.newstabstatus="Conversations";
|
|
Newsjs.chatsfromdb(root.db,root.login,0,[],function(news,lastid){
|
|
lastnewsid=lastid;
|
|
showNews(news)});
|
|
break;
|
|
case "favorites":
|
|
updateMethodNews="refresh";
|
|
newstab.newstabstatus="Favorites";
|
|
Service.updateView("Favorites");
|
|
expectScreenUpdate=true;
|
|
break;
|
|
case "replies":
|
|
updateMethodNews="refresh";
|
|
newstab.newstabstatus="Replies";
|
|
Service.updateView("Replies");
|
|
expectScreenUpdate=true;
|
|
break;
|
|
case "publictimeline":
|
|
updateMethodNews="refresh";
|
|
newstab.newstabstatus="Public Timeline";
|
|
Service.updateView("Public Timeline");
|
|
expectScreenUpdate=true;
|
|
break;
|
|
case "groupnews":
|
|
updateMethodNews="refresh";
|
|
newstab.newstabstatus="Groupnews";
|
|
Service.showGroups();
|
|
expectScreenUpdate=true;
|
|
break;
|
|
case "search":
|
|
newsView.anchors.topMargin=root.fontFactor*osSettings.bigFontSize*3;
|
|
newstab.newstabstatus="Search";
|
|
newsBusy.running=false;
|
|
searchBox.visible=true;
|
|
break;
|
|
case "refresh":
|
|
if (newstab.newstabstatus=="Timeline" || newstabstatus=="Timeline"){
|
|
updateMethodNews="append"
|
|
} else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){
|
|
updateMethodNews="conversation"}
|
|
else {updateMethodNews="refresh"}
|
|
//root.contactLoadType="news";
|
|
if (newsSwipeview.stacktype=="Home"){
|
|
Service.updateView(newstab.newstabstatus,lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Directmessage"){
|
|
Service.updateView("Direct Messages",lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Notifications"){
|
|
Service.updateView("Notifications")
|
|
}
|
|
expectScreenUpdate=true;
|
|
break;
|
|
default:
|
|
if (newstab.newstabstatus=="Timeline" || newstabstatus=="Timeline"){
|
|
updateMethodNews="append"
|
|
} else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){
|
|
updateMethodNews="conversation"}
|
|
else {updateMethodNews="refresh"}
|
|
//root.contactLoadType="news";
|
|
if (newsSwipeview.stacktype=="Home"){
|
|
Service.updateView(newstab.newstabstatus,lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="DirectMessages"){
|
|
Service.updateView("Direct Messages",lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Notifications"){
|
|
Service.updateView("Notifications",lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Favorites"){
|
|
Service.updateView("Favorites",lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Replies"){
|
|
Service.updateView("Replies",lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Public Timeline"){
|
|
Service.updateView("Public Timeline",lastnewsid)
|
|
}
|
|
else if (newsSwipeview.stacktype=="Search"){
|
|
Service.updateView("Search",lastnewsid)
|
|
}
|
|
else{
|
|
Service.updateView(newstab.newstabstatus,lastnewsid)
|
|
}
|
|
expectScreenUpdate=true;
|
|
//}
|
|
}
|
|
}
|
|
|
|
function showNews(newsToShow){
|
|
try{if (rootstackView.depth>1){rootstackView.pop()}}catch(e){}
|
|
newsBusy.running=false;
|
|
if(newsToShow.length>0){
|
|
var currentTime= new Date()
|
|
// downloadNotice.text=downloadNotice.text + "\n shownews start "+ Date.now();
|
|
if (newsToShow.length==1){var method="refresh"}else{var method = updateMethodNews}
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsToShow,'method':method, 'options':globaloptions};
|
|
newsWorker.sendMessage(msg);
|
|
}
|
|
}
|
|
|
|
function search(term){
|
|
if (term!=""){
|
|
newsBusy.running=true;
|
|
newsSwipeview.stacktype="Search";
|
|
updateMethodNews="refresh";
|
|
xhr.setAccount(login);
|
|
xhr.setApi("/api/search/tweets");
|
|
xhr.setParam("q",term)
|
|
xhr.get();
|
|
expectScreenUpdate=true;
|
|
}
|
|
newsView.anchors.topMargin=mm
|
|
}
|
|
|
|
function getOldNews(){
|
|
var currentTime= new Date();
|
|
|
|
try{var oldnewsitemobject=newsModel.get(newsModel.count-1).newsitemobject;
|
|
if(oldnewsitemobject.hasOwnProperty("lastcomment")){
|
|
var lastnews_id=oldnewsitemobject.lastcomment.created_at;
|
|
}else{
|
|
var lastnews_id=oldnewsitemobject.created_at;
|
|
}
|
|
} catch(e){print(e);var lastnews_id=99999999999999}
|
|
var messagetype=0;
|
|
switch(newsSwipeview.stacktype){
|
|
case "Home":messagetype=0;break;
|
|
case "DirectMessages": messagetype=1;break;
|
|
case "Notifications":messagetype=2;break;
|
|
case "Replies":messagetype=3;break;
|
|
default:messagetype=0;
|
|
}
|
|
|
|
if(newsSwipeview.stacktype!="Home"|| newstab.newstabstatus=="Timeline" || newstabstatus=="Timeline" ){
|
|
Newsjs.newsfromdb(root.db,root.login, messagetype,function(news){
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'method':"", 'options':globaloptions};
|
|
newsWorker.sendMessage(msg);
|
|
},false,lastnews_id)}
|
|
|
|
else if(newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){
|
|
var currentconversations=[];
|
|
for (let c=0;c<newsModel.count;c++){
|
|
currentconversations.push(parseInt(newsModel.get(c).newsitemobject.statusnet_conversation_id))
|
|
}
|
|
|
|
Newsjs.chatsfromdb(root.db,root.login, messagetype,currentconversations,function(news){
|
|
var msg = {'currentTime': currentTime, 'model': newsModel,'news':news,'method':"", 'options':globaloptions};
|
|
newsWorker.sendMessage(msg);
|
|
},lastnews_id)}
|
|
|
|
else if (newstab.newstabstatus=="Notifications" || newstabstatus=="Notifications"){}
|
|
else{
|
|
// switch(newsSwipeview.stacktype){
|
|
// case "Home":messagetype=0;break;
|
|
// case "DirectMessages": messagetype=1;break;
|
|
// case "Notifications":messagetype=2;break;
|
|
// case "Replies":messagetype=3;break;
|
|
// default:messagetype=0;
|
|
// }
|
|
|
|
try{xhr.setParam("max_id",newsModel.get(newsModel.count-1).newsitemobject.id-1);}catch(e){}
|
|
xhr.get()
|
|
expectScreenUpdate=true;
|
|
}
|
|
}
|
|
|
|
|
|
function loadDBNews(){
|
|
var messagetype=99;
|
|
switch(newsSwipeview.stacktype){
|
|
case "Home":messagetype=0;break;
|
|
case "DirectMessages": messagetype=1;break;
|
|
case "Notifications":messagetype=2;break;
|
|
case "Replies":messagetype=3;break;
|
|
default:messagetype=99;
|
|
}
|
|
if((newstabstatus=="Conversations")&&(newsSwipeview.stacktype=="Home")){
|
|
Newsjs.chatsfromdb(db,login,messagetype,[],function(dbnews,lastid){
|
|
lastnewsid=lastid;
|
|
if (dbnews.length==0){
|
|
newstypeHandling()
|
|
}
|
|
else{
|
|
showNews(dbnews);
|
|
}
|
|
})
|
|
}
|
|
else if (messagetype==99){
|
|
//newstypeHandling()
|
|
}
|
|
else{
|
|
Newsjs.newsfromdb(db,login,messagetype,function(dbnews,lastid){
|
|
lastnewsid=lastid;
|
|
if (dbnews.length==0){
|
|
newstypeHandling()
|
|
}
|
|
else{
|
|
showNews(dbnews);
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
Connections{
|
|
target:xhr
|
|
function onError(data,url,api,code){print("api "+api+" code "+code)
|
|
newsBusy.running=false;
|
|
expectScreenUpdate=false;
|
|
}
|
|
function onSuccess(data,api){
|
|
const newsApiArray=["/api/statuses/friends_timeline",
|
|
"/api/direct_messages/all",
|
|
"/api/direct_messages/conversation",
|
|
"/api/direct_messages/new",
|
|
"/api/friendica/notification",
|
|
"/api/statuses/user_timeline",
|
|
"/api/conversation/show",
|
|
"/api/search",
|
|
"/api/statuses/public_timeline",
|
|
"/api/favorites",
|
|
"/api/statuses/replies",
|
|
"/api/lists/statuses",
|
|
"/api/statuses/update",
|
|
"/api/direct_messages/new"
|
|
];
|
|
if(newsApiArray.includes(api) && expectScreenUpdate==true){
|
|
expectScreenUpdate=false;
|
|
Service.processNews(api,data)
|
|
//root.replySignal("")
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections{
|
|
target:updatenews
|
|
function onError(api,data){
|
|
newsBusy.running=false;
|
|
}
|
|
function onSuccess(api){
|
|
if(expectScreenUpdate){
|
|
loadDBNews();
|
|
newsBusy.running=false;
|
|
expectScreenUpdate=false;
|
|
}
|
|
}
|
|
}
|
|
|
|
Connections{
|
|
target: root
|
|
function onNewstypeSignal(type){newstypeHandling(type)}
|
|
}
|
|
|
|
Timer {id:replytimer; interval: 1000; running: false; repeat: false
|
|
onTriggered: {//print("replytimer")
|
|
newsBusy.running=true;
|
|
if(newstab.newstabstatus=="Conversation"){
|
|
showConversation(newsStack.timelineIndex-1,newsModel.get(0).newsitemobject)}
|
|
else{
|
|
if (newstab.newstabstatus=="Timeline" || newstabstatus=="Timeline"){
|
|
updateMethodNews="append"
|
|
} else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){
|
|
updateMethodNews="conversation"}
|
|
else {updateMethodNews="refresh"}
|
|
if (newsSwipeview.stacktype=="Home"){
|
|
Service.updateView(newstab.newstabstatus)
|
|
}
|
|
else if (newsSwipeview.stacktype=="DirectMessages"){
|
|
Service.updateView("Direct Messages")
|
|
}
|
|
else if (newsSwipeview.stacktype=="Replies"){
|
|
Service.updateView("Replies")
|
|
}
|
|
expectScreenUpdate=true;
|
|
root.replySignal("")
|
|
}
|
|
}
|
|
}
|
|
|
|
Component {
|
|
id:footerComponent
|
|
Rectangle{
|
|
border.color: "#EEEEEE"
|
|
color: osSettings.dialogColor
|
|
border.width: 1
|
|
width:newsView.width
|
|
height:6*mm
|
|
Text{
|
|
color: osSettings.primaryTextColor
|
|
font.pointSize: osSettings.systemFontSize
|
|
anchors.centerIn: parent
|
|
text:qsTr("More")
|
|
}
|
|
MouseArea{
|
|
anchors.fill:parent
|
|
onClicked:{
|
|
if (newsModel.count==0){
|
|
expectScreenUpdate=true;
|
|
if (newsSwipeview.stacktype=="Home"){
|
|
Service.updateView(newstab.newstabstatus)
|
|
}
|
|
else if (newsSwipeview.stacktype=="DirectMessages"){
|
|
Service.updateView("Direct Messages")
|
|
}
|
|
else if (newsSwipeview.stacktype=="Notifications"){
|
|
Service.updateView("Notifications")
|
|
}
|
|
else if (newsSwipeview.stacktype=="Replies"){
|
|
Service.updateView("Replies")
|
|
}
|
|
}
|
|
else {getOldNews();}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
BusyIndicator{
|
|
id: newsBusy
|
|
anchors.horizontalCenter: newsStack.horizontalCenter
|
|
anchors.top: newsStack.top
|
|
anchors.topMargin: 2*root.fontFactor*osSettings.bigFontSize
|
|
width: 2*root.fontFactor*osSettings.bigFontSize
|
|
height: 2*root.fontFactor*osSettings.bigFontSize
|
|
z:2
|
|
running: false
|
|
}
|
|
|
|
TextInput{
|
|
id:searchBox
|
|
visible: false
|
|
anchors.top: parent.top
|
|
anchors.margins: 0.5*root.fontFactor*osSettings.bigFontSize
|
|
x: searchCloseButton.width+0.5*root.fontFactor*osSettings.bigFontSize
|
|
width: parent.width-root.fontFactor*osSettings.bigFontSize*7
|
|
height: root.fontFactor*osSettings.bigFontSize*3
|
|
font.pointSize: osSettings.bigFontSize
|
|
onVisibleChanged:{
|
|
if (visible){searchBox.forceActiveFocus()}
|
|
else{newsView.anchors.topMargin=0.5*mm;}}
|
|
onAccepted: searchButton.onClicked()
|
|
}
|
|
|
|
MButton {
|
|
id: searchButton
|
|
visible: searchBox.visible
|
|
anchors.left: searchBox.right
|
|
anchors.leftMargin: 0.5*root.fontFactor*osSettings.bigFontSize
|
|
icon.name: "search"
|
|
icon.source: "qrc:/assets/icons/search.svg"
|
|
text: qsTr("Close")
|
|
display: AbstractButton.IconOnly
|
|
onClicked: {search(searchBox.text); searchBox.visible=false}
|
|
}
|
|
MButton {
|
|
id: searchCloseButton
|
|
visible: searchBox.visible
|
|
anchors.right: searchBox.left
|
|
anchors.rightMargin: 0.5*root.fontFactor*osSettings.bigFontSize
|
|
font.bold: true
|
|
font.pointSize: osSettings.bigFontSize
|
|
text: qsTr("Close")
|
|
display: AbstractButton.IconOnly
|
|
icon.name: "dialog-close"
|
|
icon.source: "qrc:/assets/icons/times-circle.svg"
|
|
onClicked: {searchBox.text=""; searchBox.visible=false}
|
|
}
|
|
ListView {
|
|
id: newsView
|
|
property real oldContentY:0
|
|
property bool viewdragged: false
|
|
property bool viewdraggedpositive: false
|
|
property string viewtype: "news"
|
|
anchors.fill:parent
|
|
anchors.margins: 0.5*mm
|
|
clip: true
|
|
spacing: 0
|
|
footer: footerComponent
|
|
model: newsModel
|
|
delegate: Newsitem{}
|
|
onDragStarted: oldContentY=contentY
|
|
onDragEnded: {
|
|
if(verticalOvershoot<-5*mm){
|
|
viewdragged=true
|
|
}
|
|
else if (verticalOvershoot>5*mm){
|
|
viewdraggedpositive=true
|
|
}
|
|
else{
|
|
if((contentY-oldContentY)>15*mm){
|
|
//swipeIndicator.visible=false;
|
|
//newsSwipeview.height=rootstack.height;
|
|
//newsSwipeview.y=0;
|
|
//rootStackItem.state="fullscreen"
|
|
}
|
|
else if ((contentY-oldContentY)<-15*mm){
|
|
//swipeIndicator.visible=true;
|
|
//newsSwipeview.height=rootstack.height-12*mm;
|
|
//newsSwipeview.y=5*mm;
|
|
//rootStackItem.state=""
|
|
}
|
|
}
|
|
}
|
|
onViewdraggedChanged: {
|
|
if (viewdragged){
|
|
var onlynew=true;
|
|
newsBusy.running=true;
|
|
viewdragged=false
|
|
if (newstab.newstabstatus=="Timeline" || newstabstatus=="Timeline"){
|
|
updateMethodNews="append"
|
|
} else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){
|
|
updateMethodNews="conversation"}
|
|
else {updateMethodNews="refresh"}
|
|
let currentnewstabstatus="Conversations";
|
|
if (newstab.newstabstatus!=""){
|
|
currentnewstabstatus=newstab.newstabstatus
|
|
}else if (newstabstatus!=""){
|
|
currentnewstabstatus=newstabstatus
|
|
}
|
|
|
|
if (newsSwipeview.stacktype=="Home"){
|
|
Newsjs.getLastNews(root.login,root.db,function(currentlastnews){
|
|
if (currentlastnews>lastnewsid){
|
|
if(currentnewstabstatus=="Timeline"){
|
|
try{ Newsjs.newsfromdb(root.db,root.login,0, function(dbnews,lastid){
|
|
lastnewsid=lastid;
|
|
showNews(dbnews)
|
|
})}catch(e){Helperjs.showMessage("Error",e,root)};
|
|
}
|
|
if(currentnewstabstatus=="Conversations"){
|
|
Newsjs.chatsfromdb(db,root.login,0,[],function(news,lastid){
|
|
lastnewsid=lastid;
|
|
showNews(news)});
|
|
}
|
|
} else {
|
|
expectScreenUpdate=true;
|
|
Service.updateView(currentnewstabstatus,currentlastnews)
|
|
}
|
|
});
|
|
}
|
|
else if (newsSwipeview.stacktype=="DirectMessages"){
|
|
Service.updateView("Direct Messages")
|
|
expectScreenUpdate=true;
|
|
}
|
|
else if (newsSwipeview.stacktype=="Notifications"){
|
|
Service.updateView("Notifications")
|
|
expectScreenUpdate=true;
|
|
}
|
|
else if (newsSwipeview.stacktype=="Replies"){
|
|
Service.updateView("Replies")
|
|
expectScreenUpdate=true;
|
|
}
|
|
|
|
}
|
|
}
|
|
onViewdraggedpositiveChanged: {
|
|
if (viewdraggedpositive){
|
|
getOldNews();
|
|
viewdraggedpositive=false
|
|
}
|
|
}
|
|
ScrollBar.vertical: ScrollBar { }
|
|
}
|
|
|
|
ListModel{id: newsModel}
|
|
|
|
WorkerScript {
|
|
id: newsWorker
|
|
source: "qrc:/js/newsworker.js"
|
|
}
|
|
|
|
Rectangle{
|
|
id:downloadNotice
|
|
property alias text: noticeText.text
|
|
color:"white"
|
|
border.color:"grey"
|
|
z:1
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.bottom:parent.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.pointSize: osSettings.systemFontSize
|
|
text:""
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
root.newsSignal.connect(showNews);
|
|
root.searchSignal.connect(search);
|
|
try{newsModel.clear()} catch(e){}
|
|
swipeIndicator.visible=true;
|
|
root.globaloptions.hasOwnProperty("newsViewType")?newstab.newstabstatus=root.globaloptions.newsViewType:newstab.newstabstatus="Conversations";
|
|
newstabstatus=newstab.newstabstatus;
|
|
if(newsSwipeview.stacktype=="Search"){searchBox.visible=true} //else if (newsSwipeview.stacktype=="Group News"){newstypeHandling("groupnews")}
|
|
if(["Home","DirectMessages","Notifications","Replies"].indexOf(newsSwipeview.stacktype)>-1){loadDBNews()}
|
|
}
|
|
}
|