this version, brings a check on current List memeber to stop duplication
It also fixes a spacing bug in the login and some small issues.
This commit is contained in:
parent
341b225eb8
commit
cef797efb8
5 changed files with 167 additions and 36 deletions
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.15.2, 2022-11-29T17:24:15. -->
|
||||
<!-- Written by QtCreator 4.15.2, 2022-12-02T16:03:12. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
@ -112,7 +112,7 @@
|
|||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">true</value>
|
||||
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
|
||||
<valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">
|
||||
|
|
|
@ -2,13 +2,22 @@ Qt.include("Mastodon.js")
|
|||
|
||||
|
||||
var loadImages = true;
|
||||
// used to dedupe on append/insert
|
||||
var knownIds = [];
|
||||
|
||||
WorkerScript.onMessage = function(msg) {
|
||||
/*
|
||||
console.log("Action > " + msg.action)
|
||||
console.log("Model > " + msg.model)
|
||||
console.log("Mode > " + msg.mode)
|
||||
console.log("Conf > " + JSON.stringify(msg.conf))
|
||||
console.log("Params > " + JSON.stringify(msg.params))
|
||||
*/
|
||||
if (msg.params[1]) {
|
||||
// console.log(JSON.stringify(msg.params[1]["data"]))
|
||||
knownIds = msg.params[1]["data"]
|
||||
//console.log(knownIds[0])
|
||||
}
|
||||
|
||||
/** order notifications in ASC order */
|
||||
function orderNotifications(items){
|
||||
|
@ -45,7 +54,7 @@ WorkerScript.onMessage = function(msg) {
|
|||
} else {
|
||||
for (var i in data) {
|
||||
if (data.hasOwnProperty(i)) {
|
||||
console.log(JSON.stringify(data[i]))
|
||||
//console.log(JSON.stringify(data[i]))
|
||||
WorkerScript.sendMessage({ 'action': msg.action, 'success': true, key: i, "data": data[i]})
|
||||
}
|
||||
}
|
||||
|
@ -54,22 +63,28 @@ WorkerScript.onMessage = function(msg) {
|
|||
return;
|
||||
}
|
||||
|
||||
API.get(msg.action, msg.params, function(data) {
|
||||
API.get(msg.action, msg.params, function(data) {
|
||||
var items = [];
|
||||
|
||||
//console.log(msg.ids)
|
||||
|
||||
for (var i in data) {
|
||||
var item;
|
||||
if (data.hasOwnProperty(i)) {
|
||||
if(msg.action === "accounts/search") {
|
||||
item = parseAccounts([], "", data[i]);
|
||||
console.log(JSON.stringify(data[i]))
|
||||
//console.log(JSON.stringify(data[i]))
|
||||
console.log("has own data")
|
||||
|
||||
items.push(item)
|
||||
|
||||
} else if(msg.action === "notifications") {
|
||||
// notification
|
||||
console.log("Get notification list")
|
||||
console.log(JSON.stringify(data[i]))
|
||||
//console.log(JSON.stringify(data[i]))
|
||||
item = parseNotification(data[i]);
|
||||
items.push(item)
|
||||
items.push(item);
|
||||
|
||||
|
||||
} else if(msg.action.indexOf("statuses") >-1 && msg.action.indexOf("context") >-1 && i === "ancestors") {
|
||||
// status ancestors toots - conversation
|
||||
|
@ -79,8 +94,9 @@ WorkerScript.onMessage = function(msg) {
|
|||
item['id'] = item['status_id'];
|
||||
if (typeof item['attachments'] === "undefined")
|
||||
item['attachments'] = [];
|
||||
items.push(item)
|
||||
console.log(JSON.stringify(data[i][j]))
|
||||
// don't permit doubles
|
||||
items.push(item);
|
||||
//console.log(JSON.stringify(data[i][j]))
|
||||
}
|
||||
addDataToModel (msg.model, "prepend", items);
|
||||
items = [];
|
||||
|
@ -94,17 +110,18 @@ WorkerScript.onMessage = function(msg) {
|
|||
item['id'] = item['status_id'];
|
||||
if (typeof item['attachments'] === "undefined")
|
||||
item['attachments'] = [];
|
||||
items.push(item)
|
||||
console.log(JSON.stringify(data[i][j]))
|
||||
items.push(item);
|
||||
//console.log(JSON.stringify(data[i][j]))
|
||||
}
|
||||
addDataToModel (msg.model, "append", items);
|
||||
items = [];
|
||||
|
||||
} else if (data[i].hasOwnProperty("content")){
|
||||
//console.log("Get Toot")
|
||||
console.log("Get Toot")
|
||||
item = parseToot(data[i]);
|
||||
item['id'] = item['status_id']
|
||||
items.push(item)
|
||||
items.push(item);
|
||||
|
||||
|
||||
} else {
|
||||
WorkerScript.sendMessage({ 'action': msg.action, 'success': true, key: i, "data": data[i] })
|
||||
|
@ -112,8 +129,11 @@ WorkerScript.onMessage = function(msg) {
|
|||
}
|
||||
}
|
||||
|
||||
if(msg.model && items.length)
|
||||
console.log("Get em all?")
|
||||
if(msg.model && items.length) {
|
||||
addDataToModel(msg.model, msg.mode, items)
|
||||
WorkerScript.sendMessage({ 'updatedAll': true})
|
||||
}
|
||||
/*if(msg.action === "notifications")
|
||||
orderNotifications(items)*/
|
||||
});
|
||||
|
@ -121,19 +141,40 @@ WorkerScript.onMessage = function(msg) {
|
|||
|
||||
//WorkerScript.sendMessage({ 'notifyNewItems': length - i })
|
||||
function addDataToModel (model, mode, items) {
|
||||
|
||||
var length = items.length;
|
||||
var i
|
||||
var inti = 0
|
||||
console.log("Fetched > " +length)
|
||||
|
||||
if (mode === "append") {
|
||||
model.append(items)
|
||||
} else if (mode === "prepend") {
|
||||
for(var i = length-1; i >= 0 ; i--) {
|
||||
model.insert(0,items[i])
|
||||
for(i = length-1; i >= 0 ; i--) {
|
||||
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
||||
model.append(items[i])
|
||||
inti++
|
||||
}
|
||||
}
|
||||
}
|
||||
model.sync()
|
||||
}
|
||||
// don't sync unless we have updates
|
||||
if (inti > 0 ) model.sync()
|
||||
|
||||
} else if (mode === "prepend") {
|
||||
for(i = length-1; i >= 0 ; i--) {
|
||||
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
||||
inti++
|
||||
model.insert(0,items[i])
|
||||
}
|
||||
}
|
||||
if (inti > 0 ) model.sync()
|
||||
}
|
||||
}
|
||||
function findDuplicate(arr,val) {
|
||||
for(var i=0; i < arr.length; i++){
|
||||
if( arr.indexOf(val) === -1 ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** Function: Get Account Data */
|
||||
function parseAccounts(collection, prefix, data) {
|
||||
|
||||
|
|
|
@ -135,23 +135,18 @@ Page {
|
|||
case "embed:contentOrientationChanged":
|
||||
break
|
||||
case "webview:action":
|
||||
if ( data.topic != lon ) {
|
||||
//webview.runJavaScript("return latlon('" + lat + "','" + lon + "')");
|
||||
//if (debug) console.debug(data.topic)
|
||||
//if (debug) console.debug(data.also)
|
||||
//if (debug) console.debug(data.src)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
visible: false
|
||||
//opacity: 0
|
||||
anchors {
|
||||
anchors.fill: parent
|
||||
/*{
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
}*/
|
||||
|
||||
onLoadingChanged: {
|
||||
if(debug) console.log('loading changed: ' + url)
|
||||
|
|
|
@ -7,11 +7,12 @@ import "."
|
|||
SilicaListView {
|
||||
id: myList
|
||||
|
||||
property bool debug: false
|
||||
property bool debug: true
|
||||
property string type
|
||||
property string title
|
||||
property string description
|
||||
property ListModel mdl: []
|
||||
property ListModel tempMdl: []
|
||||
property variant params: []
|
||||
property var locale: Qt.locale()
|
||||
property bool autoLoadMore: true
|
||||
|
@ -21,6 +22,8 @@ SilicaListView {
|
|||
property variant vars
|
||||
property variant conf
|
||||
property bool notifier: false
|
||||
property bool deduping: false
|
||||
property variant uniqueIds: []
|
||||
|
||||
model: mdl
|
||||
|
||||
|
@ -116,7 +119,10 @@ SilicaListView {
|
|||
}
|
||||
|
||||
onCountChanged: {
|
||||
|
||||
//deDouble()
|
||||
loadStarted = false
|
||||
|
||||
/*contentY = scrollOffset
|
||||
console.log("CountChanged!")*/
|
||||
}
|
||||
|
@ -131,7 +137,7 @@ SilicaListView {
|
|||
anchors.bottomMargin: Theme.paddingLarge
|
||||
visible: false
|
||||
onClicked: {
|
||||
loadData("append")
|
||||
if (!loadStarted && !deduping) loadData("append")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -152,8 +158,10 @@ SilicaListView {
|
|||
scrollOffset = contentY
|
||||
}
|
||||
if(contentY+height > footerItem.y && !loadStarted && autoLoadMore) {
|
||||
loadData("append")
|
||||
loadStarted = true
|
||||
if (! deduping) {
|
||||
loadData("append")
|
||||
loadStarted = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,28 +171,110 @@ SilicaListView {
|
|||
id: worker
|
||||
source: "../../lib/Worker.js"
|
||||
onMessage: {
|
||||
//if (debug) console.log("worker says")
|
||||
//if (debug) console.log(JSON.stringify(messageObject))
|
||||
if (messageObject.error){
|
||||
if (debug) console.log(JSON.stringify(messageObject))
|
||||
}
|
||||
if (messageObject.fireNotification && notifier){
|
||||
Logic.notifier(messageObject.data)
|
||||
}
|
||||
// temporary debugging measure
|
||||
// should be resolved within loadData()
|
||||
if (messageObject.updatedAll){
|
||||
//if (model.count > 30) deDouble()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
loadData("prepend")
|
||||
if (debug) console.log("MyList completed")
|
||||
}
|
||||
|
||||
Timer {
|
||||
triggeredOnStart: false; interval: 5*60*1000; running: true; repeat: true
|
||||
onTriggered: {
|
||||
if(debug) console.log(title + ' ' +Date().toString())
|
||||
loadData("prepend")
|
||||
// let's avoid pre and appending at the same time!
|
||||
if ( ! loadStarted && ! deduping ) loadData("prepend")
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
//if (debug) console.log(model.get(i).id)
|
||||
}
|
||||
|
||||
if (debug) console.log(uniqueItems.length)
|
||||
|
||||
if ( uniqueItems.length < model.count) {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deduping = false
|
||||
}
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* Principle load function, uses websocket's worker.js
|
||||
*
|
||||
*/
|
||||
|
||||
function loadData(mode) {
|
||||
|
||||
if (debug) console.log('loadData called')
|
||||
// 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)
|
||||
|
||||
var p = []
|
||||
if (params.length) {
|
||||
for(var i = 0; i<params.length; i++)
|
||||
|
@ -197,6 +287,11 @@ SilicaListView {
|
|||
p.push({name:'since_id', data: model.get(0).id})
|
||||
}
|
||||
|
||||
if (model.count) {
|
||||
p.push({name:'ids', data: uniqueIds})
|
||||
}
|
||||
if (debug) console.log(JSON.stringify(uniqueIds))
|
||||
|
||||
var msg = {
|
||||
'action' : type,
|
||||
'params' : p,
|
||||
|
@ -205,7 +300,7 @@ SilicaListView {
|
|||
'conf' : Logic.conf
|
||||
}
|
||||
|
||||
if (debug) console.log(JSON.stringify(msg))
|
||||
//if (debug) console.log(JSON.stringify(msg))
|
||||
if (type !== "")
|
||||
worker.sendMessage(msg)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ Name: harbour-tooterb
|
|||
%{!?qtc_make:%define qtc_make make}
|
||||
%{?qtc_builddir:%define _builddir %qtc_builddir}
|
||||
Summary: Tooter β
|
||||
Version: 1.1.0
|
||||
Version: 1.1.1
|
||||
Release: 1
|
||||
Group: Qt/Qt
|
||||
License: GPLv3
|
||||
|
|
Loading…
Reference in a new issue