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:
Mark Washeim 2022-12-16 19:20:07 +01:00
parent 341b225eb8
commit cef797efb8
5 changed files with 167 additions and 36 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!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> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -112,7 +112,7 @@
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</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"/> <valuelist type="QVariantList" key="QtProjectManager.QMakeBuildStep.SelectedAbis"/>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.2">

View file

@ -2,13 +2,22 @@ Qt.include("Mastodon.js")
var loadImages = true; var loadImages = true;
// used to dedupe on append/insert
var knownIds = [];
WorkerScript.onMessage = function(msg) { WorkerScript.onMessage = function(msg) {
/*
console.log("Action > " + msg.action) console.log("Action > " + msg.action)
console.log("Model > " + msg.model) console.log("Model > " + msg.model)
console.log("Mode > " + msg.mode) console.log("Mode > " + msg.mode)
console.log("Conf > " + JSON.stringify(msg.conf)) console.log("Conf > " + JSON.stringify(msg.conf))
console.log("Params > " + JSON.stringify(msg.params)) 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 */ /** order notifications in ASC order */
function orderNotifications(items){ function orderNotifications(items){
@ -45,7 +54,7 @@ WorkerScript.onMessage = function(msg) {
} else { } else {
for (var i in data) { for (var i in data) {
if (data.hasOwnProperty(i)) { 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]}) WorkerScript.sendMessage({ 'action': msg.action, 'success': true, key: i, "data": data[i]})
} }
} }
@ -56,20 +65,26 @@ WorkerScript.onMessage = function(msg) {
API.get(msg.action, msg.params, function(data) { API.get(msg.action, msg.params, function(data) {
var items = []; var items = [];
//console.log(msg.ids)
for (var i in data) { for (var i in data) {
var item; var item;
if (data.hasOwnProperty(i)) { if (data.hasOwnProperty(i)) {
if(msg.action === "accounts/search") { if(msg.action === "accounts/search") {
item = parseAccounts([], "", data[i]); item = parseAccounts([], "", data[i]);
console.log(JSON.stringify(data[i])) //console.log(JSON.stringify(data[i]))
console.log("has own data")
items.push(item) items.push(item)
} else if(msg.action === "notifications") { } else if(msg.action === "notifications") {
// notification // notification
console.log("Get notification list") console.log("Get notification list")
console.log(JSON.stringify(data[i])) //console.log(JSON.stringify(data[i]))
item = parseNotification(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") { } else if(msg.action.indexOf("statuses") >-1 && msg.action.indexOf("context") >-1 && i === "ancestors") {
// status ancestors toots - conversation // status ancestors toots - conversation
@ -79,8 +94,9 @@ WorkerScript.onMessage = function(msg) {
item['id'] = item['status_id']; item['id'] = item['status_id'];
if (typeof item['attachments'] === "undefined") if (typeof item['attachments'] === "undefined")
item['attachments'] = []; item['attachments'] = [];
items.push(item) // don't permit doubles
console.log(JSON.stringify(data[i][j])) items.push(item);
//console.log(JSON.stringify(data[i][j]))
} }
addDataToModel (msg.model, "prepend", items); addDataToModel (msg.model, "prepend", items);
items = []; items = [];
@ -94,17 +110,18 @@ WorkerScript.onMessage = function(msg) {
item['id'] = item['status_id']; item['id'] = item['status_id'];
if (typeof item['attachments'] === "undefined") if (typeof item['attachments'] === "undefined")
item['attachments'] = []; item['attachments'] = [];
items.push(item) items.push(item);
console.log(JSON.stringify(data[i][j])) //console.log(JSON.stringify(data[i][j]))
} }
addDataToModel (msg.model, "append", items); addDataToModel (msg.model, "append", items);
items = []; items = [];
} else if (data[i].hasOwnProperty("content")){ } else if (data[i].hasOwnProperty("content")){
//console.log("Get Toot") console.log("Get Toot")
item = parseToot(data[i]); item = parseToot(data[i]);
item['id'] = item['status_id'] item['id'] = item['status_id']
items.push(item) items.push(item);
} else { } else {
WorkerScript.sendMessage({ 'action': msg.action, 'success': true, key: i, "data": data[i] }) 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) addDataToModel(msg.model, msg.mode, items)
WorkerScript.sendMessage({ 'updatedAll': true})
}
/*if(msg.action === "notifications") /*if(msg.action === "notifications")
orderNotifications(items)*/ orderNotifications(items)*/
}); });
@ -121,19 +141,40 @@ WorkerScript.onMessage = function(msg) {
//WorkerScript.sendMessage({ 'notifyNewItems': length - i }) //WorkerScript.sendMessage({ 'notifyNewItems': length - i })
function addDataToModel (model, mode, items) { function addDataToModel (model, mode, items) {
var length = items.length; var length = items.length;
var i
var inti = 0
console.log("Fetched > " +length) console.log("Fetched > " +length)
if (mode === "append") { if (mode === "append") {
model.append(items) for(i = length-1; i >= 0 ; i--) {
if ( knownIds.indexOf( items[i]["id"]) === -1) {
model.append(items[i])
inti++
}
}
// don't sync unless we have updates
if (inti > 0 ) model.sync()
} else if (mode === "prepend") { } else if (mode === "prepend") {
for(var i = length-1; i >= 0 ; i--) { for(i = length-1; i >= 0 ; i--) {
if ( knownIds.indexOf( items[i]["id"]) === -1) {
inti++
model.insert(0,items[i]) model.insert(0,items[i])
} }
} }
model.sync() 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: Get Account Data */
function parseAccounts(collection, prefix, data) { function parseAccounts(collection, prefix, data) {

View file

@ -135,23 +135,18 @@ Page {
case "embed:contentOrientationChanged": case "embed:contentOrientationChanged":
break break
case "webview:action": 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 break
} }
} }
visible: false visible: false
//opacity: 0 //opacity: 0
anchors { anchors.fill: parent
/*{
top: parent.top top: parent.top
left: parent.left left: parent.left
right: parent.right right: parent.right
bottom: parent.bottom bottom: parent.bottom
} }*/
onLoadingChanged: { onLoadingChanged: {
if(debug) console.log('loading changed: ' + url) if(debug) console.log('loading changed: ' + url)

View file

@ -7,11 +7,12 @@ import "."
SilicaListView { SilicaListView {
id: myList id: myList
property bool debug: false property bool debug: true
property string type property string type
property string title property string title
property string description property string description
property ListModel mdl: [] property ListModel mdl: []
property ListModel tempMdl: []
property variant params: [] property variant params: []
property var locale: Qt.locale() property var locale: Qt.locale()
property bool autoLoadMore: true property bool autoLoadMore: true
@ -21,6 +22,8 @@ SilicaListView {
property variant vars property variant vars
property variant conf property variant conf
property bool notifier: false property bool notifier: false
property bool deduping: false
property variant uniqueIds: []
model: mdl model: mdl
@ -116,7 +119,10 @@ SilicaListView {
} }
onCountChanged: { onCountChanged: {
//deDouble()
loadStarted = false loadStarted = false
/*contentY = scrollOffset /*contentY = scrollOffset
console.log("CountChanged!")*/ console.log("CountChanged!")*/
} }
@ -131,7 +137,7 @@ SilicaListView {
anchors.bottomMargin: Theme.paddingLarge anchors.bottomMargin: Theme.paddingLarge
visible: false visible: false
onClicked: { onClicked: {
loadData("append") if (!loadStarted && !deduping) loadData("append")
} }
} }
@ -152,10 +158,12 @@ SilicaListView {
scrollOffset = contentY scrollOffset = contentY
} }
if(contentY+height > footerItem.y && !loadStarted && autoLoadMore) { if(contentY+height > footerItem.y && !loadStarted && autoLoadMore) {
if (! deduping) {
loadData("append") loadData("append")
loadStarted = true loadStarted = true
} }
} }
}
VerticalScrollDecorator {} VerticalScrollDecorator {}
@ -163,28 +171,110 @@ SilicaListView {
id: worker id: worker
source: "../../lib/Worker.js" source: "../../lib/Worker.js"
onMessage: { onMessage: {
//if (debug) console.log("worker says")
//if (debug) console.log(JSON.stringify(messageObject))
if (messageObject.error){ if (messageObject.error){
if (debug) console.log(JSON.stringify(messageObject)) if (debug) console.log(JSON.stringify(messageObject))
} }
if (messageObject.fireNotification && notifier){ if (messageObject.fireNotification && notifier){
Logic.notifier(messageObject.data) Logic.notifier(messageObject.data)
} }
// temporary debugging measure
// should be resolved within loadData()
if (messageObject.updatedAll){
//if (model.count > 30) deDouble()
}
} }
} }
Component.onCompleted: { Component.onCompleted: {
loadData("prepend") loadData("prepend")
if (debug) console.log("MyList completed")
} }
Timer { Timer {
triggeredOnStart: false; interval: 5*60*1000; running: true; repeat: true triggeredOnStart: false; interval: 5*60*1000; running: true; repeat: true
onTriggered: { onTriggered: {
if(debug) console.log(title + ' ' +Date().toString()) 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) { 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 = [] var p = []
if (params.length) { if (params.length) {
for(var i = 0; i<params.length; i++) for(var i = 0; i<params.length; i++)
@ -197,6 +287,11 @@ SilicaListView {
p.push({name:'since_id', data: model.get(0).id}) 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 = { var msg = {
'action' : type, 'action' : type,
'params' : p, 'params' : p,
@ -205,7 +300,7 @@ SilicaListView {
'conf' : Logic.conf 'conf' : Logic.conf
} }
if (debug) console.log(JSON.stringify(msg)) //if (debug) console.log(JSON.stringify(msg))
if (type !== "") if (type !== "")
worker.sendMessage(msg) worker.sendMessage(msg)
} }

View file

@ -13,7 +13,7 @@ Name: harbour-tooterb
%{!?qtc_make:%define qtc_make make} %{!?qtc_make:%define qtc_make make}
%{?qtc_builddir:%define _builddir %qtc_builddir} %{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Tooter β Summary: Tooter β
Version: 1.1.0 Version: 1.1.1
Release: 1 Release: 1
Group: Qt/Qt Group: Qt/Qt
License: GPLv3 License: GPLv3