// This file is part of Friendiqa // https://git.friendi.ca/lubuwest/Friendiqa // Copyright (C) 2020 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 . import QtQuick 2.12 import QtQuick.Controls 2.12 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 // width: parent.width // height: parent.height color: osSettings.backgroundColor property string updateMethodNews: "refresh" property var allchats: ({}) property int lastnewsid:0 property string newstabstatus: "" property bool expectScreenUpdate: false function newstypeHandling(newstype){print("newstype "+newstype) if (!newsBusy.running) { try{newsBusy.running=true}catch(e){print(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": newsStack.updateMethodNews="conversation"; newstab.newstabstatus="Conversations"; Newsjs.chatsfromdb(root.db,root.login,0,[],function(news,lastid){ lastnewsid=lastid; showNews(news)}); break; case "favorites": newsStack.updateMethodNews="refresh"; newstab.newstabstatus="Favorites"; Service.updateView("Favorites"); expectScreenUpdate=true; break; case "replies": newsStack.updateMethodNews="refresh"; newstab.newstabstatus="Replies"; Service.updateView("Replies"); expectScreenUpdate=true; break; case "publictimeline": newsStack.updateMethodNews="refresh"; newstab.newstabstatus="Public Timeline"; Service.updateView("Public Timeline"); expectScreenUpdate=true; break; case "groupnews": newsStack.updateMethodNews="refresh"; newstab.newstabstatus="Groupnews"; Service.showGroups(); expectScreenUpdate=true; break; case "search": newsView.anchors.topMargin=7*mm; newstab.newstabstatus="Search"; newsBusy.running=false; var leftoffset=(osSettings.osType=="Android")?2*root.fontFactor*osSettings.bigFontSize:0 var component = Qt.createComponent("qrc:/qml/genericqml/Search.qml"); var searchItem = component.createObject(newsStack,{y:mm,x:leftoffset,width:root.width-(leftoffset+mm),height: 1.5*root.fontFactor*osSettings.systemFontSize,selfdestroying:true}); break; case "refresh": if (newstab.newstabstatus=="Timeline" || newstabstatus=="Timeline"){ newsStack.updateMethodNews="append" } else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){ newsStack.updateMethodNews="conversation"} else {newsStack.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"){ newsStack.updateMethodNews="append" } else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){ newsStack.updateMethodNews="conversation"} else {newsStack.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",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 = newsStack.updateMethodNews} var msg = {'currentTime': currentTime, 'model': newsModel,'news':newsToShow,'method':method, 'options':globaloptions}; newsWorker.sendMessage(msg); } } function search(term){ if (term!=""){ newstabstatus="Search"; newsBusy.running=true; newsStack.updateMethodNews="refresh"; xhr.setAccount(login); xhr.setApi("/api/search"); xhr.setParam("q",term) xhr.get(); expectScreenUpdate=true; } newsView.anchors.topMargin=mm } function getOldNews(){print("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;c5*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"){ newsStack.updateMethodNews="append" } else if (newstab.newstabstatus=="Conversations" || newstabstatus=="Conversations"){ newsStack.updateMethodNews="conversation"} else {newsStack.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" } Text { id: closeButton //Svisible: !(globaloptions.defaultNewsTypes.indexOf(newsSwipeview.stacktype)>-1) anchors.top: parent.top anchors.topMargin: 1*mm anchors.right: parent.right anchors.rightMargin: 1*mm width: root.fontFactor*osSettings.bigFontSize*2 height: root.fontFactor*osSettings.bigFontSize*2 font.bold: true font.family: fontAwesome.name font.pointSize: osSettings.bigFontSize HoverHandler{id:closehover} ToolTip.visible: closehover.hovered ToolTip.text: qsTr("Close this timeline") text: "\uf057" MouseArea{ anchors.fill: parent onClicked: { newstabitem.newstypes.splice(newsSwipeview.currentIndex,1) newstabbar.removeItem(newstabbar.contentChildren[newstabbar.currentIndex]); newstabbar.currentIndex=0; newsSwipeview.removeItem(newsStack) newsSwipeview.currentIndex=0; } } } 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: { print("globaloptions.defaultNewsTypes.indexOf(newsSwipeview.stacktype)>-1 " +(globaloptions.defaultNewsTypes.indexOf(newsSwipeview.stacktype)>-1)) root.newstypeSignal.connect(newstypeHandling); root.contactdetailsSignal.connect(showContact); 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; loadDBNews() } }