2017-06-22 15:49:39 +03:00
|
|
|
import QtQuick 2.2
|
2017-06-07 08:56:42 +03:00
|
|
|
import Sailfish.Silica 1.0
|
|
|
|
import "../../lib/API.js" as Logic
|
|
|
|
import "."
|
|
|
|
|
2020-05-29 21:05:05 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
SilicaListView {
|
|
|
|
id: myList
|
2020-06-04 12:17:06 +03:00
|
|
|
|
2023-01-03 16:13:23 +03:00
|
|
|
property bool debug: true
|
2020-05-29 21:05:05 +03:00
|
|
|
property string type
|
2017-06-07 08:56:42 +03:00
|
|
|
property string title
|
|
|
|
property string description
|
|
|
|
property ListModel mdl: []
|
|
|
|
property variant params: []
|
|
|
|
property var locale: Qt.locale()
|
2020-05-29 21:05:05 +03:00
|
|
|
property bool autoLoadMore: true
|
|
|
|
property bool loadStarted: false
|
|
|
|
property int scrollOffset
|
2017-06-07 08:56:42 +03:00
|
|
|
property string action: ""
|
2023-01-03 20:45:22 +03:00
|
|
|
property string linkprev: ""
|
2017-06-07 08:56:42 +03:00
|
|
|
property variant vars
|
|
|
|
property variant conf
|
2020-05-29 21:05:05 +03:00
|
|
|
property bool notifier: false
|
2022-12-16 21:20:07 +03:00
|
|
|
property bool deduping: false
|
|
|
|
property variant uniqueIds: []
|
2020-06-04 20:44:12 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
model: mdl
|
2020-06-04 12:17:06 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
signal notify (string what, int num)
|
|
|
|
onNotify: {
|
2022-11-30 18:50:50 +03:00
|
|
|
if(debug) console.log(what + " - " + num)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
signal openDrawer (bool setDrawer)
|
|
|
|
onOpenDrawer: {
|
|
|
|
//console.log("Open drawer: " + setDrawer)
|
|
|
|
}
|
|
|
|
signal send (string notice)
|
|
|
|
onSend: {
|
2022-11-30 18:50:50 +03:00
|
|
|
if (debug) console.log("LIST send signal emitted with notice: " + notice)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
header: PageHeader {
|
|
|
|
title: myList.title
|
|
|
|
description: myList.description
|
|
|
|
}
|
|
|
|
|
2020-07-06 11:28:42 +03:00
|
|
|
BusyLabel {
|
2020-07-12 10:12:34 +03:00
|
|
|
id: myListBusyLabel
|
2020-07-06 11:28:42 +03:00
|
|
|
running: model.count === 0
|
|
|
|
anchors {
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
}
|
2020-07-12 10:12:34 +03:00
|
|
|
|
|
|
|
Timer {
|
|
|
|
interval: 5000
|
|
|
|
running: true
|
|
|
|
onTriggered: {
|
|
|
|
myListBusyLabel.visible = false
|
|
|
|
loadStatusPlaceholder.visible = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewPlaceholder {
|
|
|
|
id: loadStatusPlaceholder
|
|
|
|
visible: false
|
|
|
|
enabled: model.count === 0
|
|
|
|
text: qsTr("Nothing found")
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PullDownMenu {
|
2020-07-12 10:12:34 +03:00
|
|
|
id: mainPulleyMenu
|
2017-06-07 08:56:42 +03:00
|
|
|
MenuItem {
|
2017-07-20 13:14:16 +03:00
|
|
|
text: qsTr("Settings")
|
2020-06-29 11:48:06 +03:00
|
|
|
visible: !profilePage
|
2017-06-07 08:56:42 +03:00
|
|
|
onClicked: {
|
2020-05-29 21:05:05 +03:00
|
|
|
pageStack.push(Qt.resolvedUrl("../SettingsPage.qml"), {})
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-05 19:38:15 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("New Toot")
|
2020-06-29 11:48:06 +03:00
|
|
|
visible: !profilePage
|
2020-06-05 19:38:15 +03:00
|
|
|
onClicked: {
|
|
|
|
pageStack.push(Qt.resolvedUrl("../ConversationPage.qml"), {
|
2020-06-15 11:42:10 +03:00
|
|
|
headerTitle: qsTr("New Toot"),
|
2020-06-05 19:38:15 +03:00
|
|
|
type: "new"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 11:48:06 +03:00
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Open in Browser")
|
|
|
|
visible: !mainPage
|
|
|
|
onClicked: {
|
|
|
|
Qt.openUrlExternally(url)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
MenuItem {
|
2020-06-22 21:13:05 +03:00
|
|
|
text: qsTr("Reload")
|
2017-06-07 08:56:42 +03:00
|
|
|
onClicked: {
|
|
|
|
loadData("prepend")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 11:16:13 +03:00
|
|
|
delegate: VisualContainer {}
|
2017-06-07 08:56:42 +03:00
|
|
|
|
|
|
|
add: Transition {
|
|
|
|
NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 800 }
|
|
|
|
NumberAnimation { property: "x"; duration: 800; easing.type: Easing.InOutBack }
|
|
|
|
}
|
|
|
|
|
2017-07-06 17:15:12 +03:00
|
|
|
remove: Transition {
|
2017-06-07 08:56:42 +03:00
|
|
|
NumberAnimation { properties: "x,y"; duration: 800; easing.type: Easing.InOutBack }
|
|
|
|
}
|
|
|
|
|
|
|
|
onCountChanged: {
|
2022-12-20 16:33:10 +03:00
|
|
|
if (debug) console.log("count changed on: " + title)
|
2022-12-16 21:20:07 +03:00
|
|
|
//deDouble()
|
2022-12-20 16:33:10 +03:00
|
|
|
//loadStarted = false
|
2022-12-16 21:20:07 +03:00
|
|
|
|
2017-06-16 17:45:04 +03:00
|
|
|
/*contentY = scrollOffset
|
|
|
|
console.log("CountChanged!")*/
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2017-10-26 00:45:15 +03:00
|
|
|
|
2020-06-22 21:13:05 +03:00
|
|
|
footer: Item {
|
2017-11-01 02:27:48 +03:00
|
|
|
visible: autoLoadMore
|
2017-06-16 17:45:04 +03:00
|
|
|
width: parent.width
|
|
|
|
height: Theme.itemSizeLarge
|
|
|
|
Button {
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
anchors.margins: Theme.paddingSmall
|
|
|
|
anchors.bottomMargin: Theme.paddingLarge
|
|
|
|
visible: false
|
|
|
|
onClicked: {
|
2022-12-16 21:20:07 +03:00
|
|
|
if (!loadStarted && !deduping) loadData("append")
|
2017-10-25 01:37:33 +03:00
|
|
|
}
|
2017-06-16 17:45:04 +03:00
|
|
|
}
|
2020-06-04 12:17:06 +03:00
|
|
|
|
2017-06-16 17:45:04 +03:00
|
|
|
BusyIndicator {
|
2020-07-06 11:28:42 +03:00
|
|
|
running: loadStarted
|
2020-07-12 10:12:34 +03:00
|
|
|
visible: myListBusyLabel.running ? false : true
|
2017-06-16 17:45:04 +03:00
|
|
|
size: BusyIndicatorSize.Small
|
2020-07-06 11:28:42 +03:00
|
|
|
anchors {
|
|
|
|
verticalCenter: parent.verticalCenter
|
|
|
|
horizontalCenter: parent.horizontalCenter
|
|
|
|
}
|
2017-06-16 17:45:04 +03:00
|
|
|
}
|
|
|
|
}
|
2020-06-04 12:17:06 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
onContentYChanged: {
|
2017-07-04 17:57:50 +03:00
|
|
|
if (Math.abs(contentY - scrollOffset) > Theme.itemSizeMedium) {
|
|
|
|
openDrawer(contentY - scrollOffset > 0 ? false : true )
|
|
|
|
scrollOffset = contentY
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2022-12-22 23:32:49 +03:00
|
|
|
if(contentY+height > footerItem.y && !deduping && !loadStarted && autoLoadMore) {
|
2022-12-16 21:20:07 +03:00
|
|
|
loadStarted = true
|
2022-12-22 23:32:49 +03:00
|
|
|
loadData("append")
|
2017-06-16 17:45:04 +03:00
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2020-05-29 21:05:05 +03:00
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
VerticalScrollDecorator {}
|
|
|
|
|
|
|
|
WorkerScript {
|
|
|
|
id: worker
|
|
|
|
source: "../../lib/Worker.js"
|
|
|
|
onMessage: {
|
|
|
|
if (messageObject.error){
|
2022-12-01 12:40:37 +03:00
|
|
|
if (debug) console.log(JSON.stringify(messageObject))
|
2022-12-20 16:33:10 +03:00
|
|
|
} else {
|
2023-01-03 16:13:23 +03:00
|
|
|
if (debug) console.log(JSON.stringify(messageObject))
|
2022-12-20 16:33:10 +03:00
|
|
|
loadStarted = false
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2022-12-20 16:33:10 +03:00
|
|
|
|
2017-06-14 17:42:28 +03:00
|
|
|
if (messageObject.fireNotification && notifier){
|
2017-10-26 00:45:15 +03:00
|
|
|
Logic.notifier(messageObject.data)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2023-01-03 20:45:22 +03:00
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
// temporary debugging measure
|
|
|
|
if (messageObject.updatedAll){
|
2022-12-22 23:32:49 +03:00
|
|
|
if (debug) console.log("Got em all.")
|
2023-01-03 20:45:22 +03:00
|
|
|
if (model.count > 20) deDouble()
|
2022-12-20 16:33:10 +03:00
|
|
|
loadStarted = false
|
2022-12-16 21:20:07 +03:00
|
|
|
}
|
2023-01-03 20:45:22 +03:00
|
|
|
if (messageObject.Header) {
|
|
|
|
//if (debug) console.log(JSON.stringify(messageObject))
|
|
|
|
var matches = /max_id=([0-9]+)/.exec(messageObject.Header);
|
|
|
|
var link = matches[0].split("=")[1];
|
|
|
|
if (debug) console.log("link: " + link)
|
|
|
|
linkprev = link
|
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
2017-06-22 15:49:39 +03:00
|
|
|
loadData("prepend")
|
2022-12-20 16:33:10 +03:00
|
|
|
if (debug) console.log("MyList completed: " + title)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2017-06-14 17:42:28 +03:00
|
|
|
|
|
|
|
Timer {
|
2022-12-22 23:32:49 +03:00
|
|
|
triggeredOnStart: false;
|
|
|
|
interval: {
|
2023-01-03 20:45:22 +03:00
|
|
|
|
|
|
|
/* this is hamfisted */
|
2022-12-22 23:32:49 +03:00
|
|
|
var listInterval = Math.floor(Math.random() * 60)*10*1000
|
|
|
|
if( title === "Home" ) listInterval = 20*60*1000
|
|
|
|
if( title === "Local" ) listInterval = 10*60*1000
|
|
|
|
if( title === "Federated" ) listInterval = 30*60*1000
|
|
|
|
if( title === "Bookmarks" ) listInterval = 40*60*1000
|
|
|
|
if( title === "Notifications" ) listInterval = 12*60*1000
|
|
|
|
|
|
|
|
if(debug) console.log(title + ' interval: ' + listInterval)
|
2023-01-03 20:45:22 +03:00
|
|
|
|
2022-12-22 23:32:49 +03:00
|
|
|
return listInterval
|
|
|
|
}
|
|
|
|
running: true;
|
|
|
|
repeat: true
|
2017-06-14 17:42:28 +03:00
|
|
|
onTriggered: {
|
2022-12-22 23:32:49 +03:00
|
|
|
if(debug) console.log(title + ' ' + Date().toString())
|
2022-12-16 21:20:07 +03:00
|
|
|
// let's avoid pre and appending at the same time!
|
|
|
|
if ( ! loadStarted && ! deduping ) loadData("prepend")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2022-12-22 23:32:49 +03:00
|
|
|
* NOT actually doing deduping :)
|
2022-12-16 21:20:07 +03:00
|
|
|
* utility called on updates to model to remove remove Duplicates:
|
|
|
|
* the dupes are probably a result of improper syncing of the models
|
|
|
|
* this is temporary and can probaly be removed because of the
|
|
|
|
* loadData method passing in to the WorkerScript
|
|
|
|
*/
|
|
|
|
function deDouble(){
|
|
|
|
|
|
|
|
deduping = true
|
|
|
|
var ids = []
|
|
|
|
var uniqueItems = []
|
|
|
|
var i
|
|
|
|
var j
|
|
|
|
var seenIt = 0
|
|
|
|
|
|
|
|
if (debug) console.log(model.count)
|
|
|
|
|
|
|
|
for(i = 0 ; i < model.count ; i++) {
|
|
|
|
ids.push(model.get(i).id)
|
|
|
|
uniqueItems = removeDuplicates(ids)
|
|
|
|
|
2022-12-20 16:33:10 +03:00
|
|
|
}
|
|
|
|
//if (debug) console.log(ids)
|
2022-12-16 21:20:07 +03:00
|
|
|
if (debug) console.log(uniqueItems.length)
|
2022-12-22 23:32:49 +03:00
|
|
|
if (debug) console.log( "maxminusone?:" + model.get(model.count - 2).id )
|
|
|
|
if (debug) console.log( "max?:" + model.get(model.count - 1).id )
|
2022-12-16 21:20:07 +03:00
|
|
|
|
|
|
|
if ( uniqueItems.length < model.count) {
|
2022-12-22 23:32:49 +03:00
|
|
|
|
|
|
|
// it seems that only the last one, is an issue
|
|
|
|
/*if (model.get(model.count - 1).id > model.get(model.count - 2).id){
|
|
|
|
model.remove(model.count - 1,1)
|
|
|
|
}*/
|
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
if (debug) console.log(model.count)
|
|
|
|
for(j = 0; j <= uniqueItems.length - 1 ; j++) {
|
|
|
|
seenIt = 0
|
|
|
|
for(i = 0 ; i < model.count - 1 ; i++) {
|
|
|
|
if (model.get(i).id === uniqueItems[j]){
|
|
|
|
seenIt = seenIt+1
|
|
|
|
if (seenIt > 1) {
|
|
|
|
if (debug) console.log(uniqueItems[j] + " - " + seenIt)
|
|
|
|
|
|
|
|
// model.remove(i,1) // (model.get(i))
|
|
|
|
seenIt = seenIt-1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-14 17:42:28 +03:00
|
|
|
}
|
2022-12-16 21:20:07 +03:00
|
|
|
|
|
|
|
deduping = false
|
|
|
|
}
|
2022-12-20 16:33:10 +03:00
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
/* utility function because this version of qt doesn't support modern javascript
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function removeDuplicates(arr) {
|
|
|
|
var unique = [];
|
|
|
|
for(var i=0; i < arr.length; i++){
|
|
|
|
if(unique.indexOf(arr[i]) === -1) {
|
|
|
|
unique.push(arr[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return unique;
|
2017-06-14 17:42:28 +03:00
|
|
|
}
|
2020-06-04 12:17:06 +03:00
|
|
|
|
2022-12-22 23:32:49 +03:00
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
/* Principle load function, uses websocket's worker.js
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-06-18 09:32:52 +03:00
|
|
|
function loadData(mode) {
|
2022-12-16 21:20:07 +03:00
|
|
|
|
2022-12-20 16:33:10 +03:00
|
|
|
if (debug) console.log('loadData called: ' + mode + " in " + title)
|
2022-12-16 21:20:07 +03:00
|
|
|
// since the worker adds Duplicates
|
|
|
|
// we pass in current ids in the model
|
|
|
|
// and skip those on insert append in the worker
|
|
|
|
for(var i = 0 ; i < model.count ; i++) {
|
|
|
|
uniqueIds.push(model.get(i).id)
|
|
|
|
//if (debug) console.log(model.get(i).id)
|
|
|
|
}
|
|
|
|
uniqueIds = removeDuplicates(uniqueIds)
|
|
|
|
|
2020-05-29 21:05:05 +03:00
|
|
|
var p = []
|
2020-07-06 11:28:42 +03:00
|
|
|
if (params.length) {
|
2017-10-27 17:44:35 +03:00
|
|
|
for(var i = 0; i<params.length; i++)
|
|
|
|
p.push(params[i])
|
2020-07-06 11:28:42 +03:00
|
|
|
}
|
2020-06-18 09:32:52 +03:00
|
|
|
if (mode === "append" && model.count) {
|
2023-01-03 20:45:22 +03:00
|
|
|
// for some types, max_id is obtained from link header
|
|
|
|
if ( linkprev === "" ) {
|
|
|
|
p.push({name: 'max_id', data: model.get(model.count-1).id})
|
|
|
|
} else {
|
|
|
|
p.push({name: 'max_id', data: linkprev})
|
|
|
|
}
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2020-06-18 09:32:52 +03:00
|
|
|
if (mode === "prepend" && model.count) {
|
2020-05-29 21:05:05 +03:00
|
|
|
p.push({name:'since_id', data: model.get(0).id})
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
2022-12-22 23:32:49 +03:00
|
|
|
//if (debug) console.log(JSON.stringify(uniqueIds))
|
|
|
|
if(title === "Local") {
|
|
|
|
type = "timelines/public"
|
|
|
|
p.push({name:'local', data: "true"})
|
|
|
|
}
|
|
|
|
// we push the ids via params which we remove in the WorkerScript
|
2022-12-16 21:20:07 +03:00
|
|
|
if (model.count) {
|
|
|
|
p.push({name:'ids', data: uniqueIds})
|
|
|
|
}
|
|
|
|
|
2017-06-07 08:56:42 +03:00
|
|
|
var msg = {
|
|
|
|
'action' : type,
|
|
|
|
'params' : p,
|
|
|
|
'model' : model,
|
|
|
|
'mode' : mode,
|
|
|
|
'conf' : Logic.conf
|
2020-07-03 11:45:30 +03:00
|
|
|
}
|
2020-06-22 21:13:05 +03:00
|
|
|
|
2022-12-16 21:20:07 +03:00
|
|
|
//if (debug) console.log(JSON.stringify(msg))
|
2017-06-22 15:49:39 +03:00
|
|
|
if (type !== "")
|
2020-05-29 21:05:05 +03:00
|
|
|
worker.sendMessage(msg)
|
2017-06-07 08:56:42 +03:00
|
|
|
}
|
|
|
|
}
|
2022-12-20 16:33:10 +03:00
|
|
|
|