Additional debug stuff. This is not mergeable.
This commit is contained in:
parent
cef797efb8
commit
2f88f1da59
2 changed files with 32 additions and 30 deletions
|
@ -4,6 +4,7 @@ Qt.include("Mastodon.js")
|
||||||
var loadImages = true;
|
var loadImages = true;
|
||||||
// used to dedupe on append/insert
|
// used to dedupe on append/insert
|
||||||
var knownIds = [];
|
var knownIds = [];
|
||||||
|
var max_id ;
|
||||||
|
|
||||||
WorkerScript.onMessage = function(msg) {
|
WorkerScript.onMessage = function(msg) {
|
||||||
/*
|
/*
|
||||||
|
@ -13,10 +14,10 @@ WorkerScript.onMessage = function(msg) {
|
||||||
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))
|
||||||
*/
|
*/
|
||||||
|
// this is not elegant. it's max_id and ids from MyList
|
||||||
if (msg.params[1]) {
|
if (msg.params[1]) {
|
||||||
// console.log(JSON.stringify(msg.params[1]["data"]))
|
max_id = msg.params[0]["data"]
|
||||||
knownIds = msg.params[1]["data"]
|
knownIds = msg.params[1]["data"]
|
||||||
//console.log(knownIds[0])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** order notifications in ASC order */
|
/** order notifications in ASC order */
|
||||||
|
@ -29,7 +30,7 @@ WorkerScript.onMessage = function(msg) {
|
||||||
|
|
||||||
/** Logged-in status */
|
/** Logged-in status */
|
||||||
if (!msg.conf || !msg.conf.login) {
|
if (!msg.conf || !msg.conf.login) {
|
||||||
console.log("Not loggedin")
|
//console.log("Not loggedin")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ WorkerScript.onMessage = function(msg) {
|
||||||
if (msg.method === "POST"){
|
if (msg.method === "POST"){
|
||||||
API.post(msg.action, msg.params, function(data) {
|
API.post(msg.action, msg.params, function(data) {
|
||||||
if (msg.bgAction){
|
if (msg.bgAction){
|
||||||
console.log(JSON.stringify(data))
|
//console.log(JSON.stringify(data))
|
||||||
} else if (msg.action === "statuses") {
|
} else if (msg.action === "statuses") {
|
||||||
// status posted
|
// status posted
|
||||||
if(msg.model){
|
if(msg.model){
|
||||||
|
@ -80,7 +81,7 @@ WorkerScript.onMessage = function(msg) {
|
||||||
|
|
||||||
} 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);
|
||||||
|
@ -117,7 +118,7 @@ WorkerScript.onMessage = function(msg) {
|
||||||
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);
|
||||||
|
@ -143,29 +144,27 @@ WorkerScript.onMessage = function(msg) {
|
||||||
function addDataToModel (model, mode, items) {
|
function addDataToModel (model, mode, items) {
|
||||||
|
|
||||||
var length = items.length;
|
var length = items.length;
|
||||||
|
console.log("Fetched > " +length + " in " + mode)
|
||||||
var i
|
var i
|
||||||
var inti = 0
|
|
||||||
console.log("Fetched > " +length)
|
|
||||||
|
|
||||||
if (mode === "append") {
|
if (mode === "append") {
|
||||||
for(i = length-1; i >= 0 ; i--) {
|
for(i = 0; i <= length-1; i++) {
|
||||||
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
||||||
|
console.log("max: " + max_id + " i: " + items[i]["id"] + " known: " + knownIds[0])
|
||||||
|
if ( items[i]["id"] < max_id && items[i]["id"] < knownIds[0]) {
|
||||||
model.append(items[i])
|
model.append(items[i])
|
||||||
inti++
|
} else {
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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])
|
model.insert(0,items[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inti > 0 ) model.sync()
|
|
||||||
}
|
}
|
||||||
|
} else if (mode === "prepend") {
|
||||||
|
for(i = length-1; i >= 0 ; i--) {
|
||||||
|
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
||||||
|
model.insert(0,items[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.sync()
|
||||||
}
|
}
|
||||||
function findDuplicate(arr,val) {
|
function findDuplicate(arr,val) {
|
||||||
for(var i=0; i < arr.length; i++){
|
for(var i=0; i < arr.length; i++){
|
||||||
|
|
|
@ -12,7 +12,6 @@ SilicaListView {
|
||||||
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
|
||||||
|
@ -119,9 +118,9 @@ SilicaListView {
|
||||||
}
|
}
|
||||||
|
|
||||||
onCountChanged: {
|
onCountChanged: {
|
||||||
|
if (debug) console.log("count changed on: " + title)
|
||||||
//deDouble()
|
//deDouble()
|
||||||
loadStarted = false
|
//loadStarted = false
|
||||||
|
|
||||||
/*contentY = scrollOffset
|
/*contentY = scrollOffset
|
||||||
console.log("CountChanged!")*/
|
console.log("CountChanged!")*/
|
||||||
|
@ -158,12 +157,10 @@ 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 {}
|
||||||
|
|
||||||
|
@ -175,21 +172,25 @@ SilicaListView {
|
||||||
//if (debug) console.log(JSON.stringify(messageObject))
|
//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))
|
||||||
|
} else {
|
||||||
|
loadStarted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messageObject.fireNotification && notifier){
|
if (messageObject.fireNotification && notifier){
|
||||||
Logic.notifier(messageObject.data)
|
Logic.notifier(messageObject.data)
|
||||||
}
|
}
|
||||||
// temporary debugging measure
|
// temporary debugging measure
|
||||||
// should be resolved within loadData()
|
// should be resolved within loadData()
|
||||||
if (messageObject.updatedAll){
|
if (messageObject.updatedAll){
|
||||||
//if (model.count > 30) deDouble()
|
if (model.count > 30) deDouble()
|
||||||
|
loadStarted = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
loadData("prepend")
|
loadData("prepend")
|
||||||
if (debug) console.log("MyList completed")
|
if (debug) console.log("MyList completed: " + title)
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
@ -221,9 +222,9 @@ SilicaListView {
|
||||||
for(i = 0 ; i < model.count ; i++) {
|
for(i = 0 ; i < model.count ; i++) {
|
||||||
ids.push(model.get(i).id)
|
ids.push(model.get(i).id)
|
||||||
uniqueItems = removeDuplicates(ids)
|
uniqueItems = removeDuplicates(ids)
|
||||||
//if (debug) console.log(model.get(i).id)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
//if (debug) console.log(ids)
|
||||||
if (debug) console.log(uniqueItems.length)
|
if (debug) console.log(uniqueItems.length)
|
||||||
|
|
||||||
if ( uniqueItems.length < model.count) {
|
if ( uniqueItems.length < model.count) {
|
||||||
|
@ -246,6 +247,7 @@ SilicaListView {
|
||||||
|
|
||||||
deduping = false
|
deduping = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/* utility function because this version of qt doesn't support modern javascript
|
/* utility function because this version of qt doesn't support modern javascript
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -265,7 +267,7 @@ SilicaListView {
|
||||||
|
|
||||||
function loadData(mode) {
|
function loadData(mode) {
|
||||||
|
|
||||||
if (debug) console.log('loadData called')
|
if (debug) console.log('loadData called: ' + mode + " in " + title)
|
||||||
// since the worker adds Duplicates
|
// since the worker adds Duplicates
|
||||||
// we pass in current ids in the model
|
// we pass in current ids in the model
|
||||||
// and skip those on insert append in the worker
|
// and skip those on insert append in the worker
|
||||||
|
@ -290,7 +292,7 @@ SilicaListView {
|
||||||
if (model.count) {
|
if (model.count) {
|
||||||
p.push({name:'ids', data: uniqueIds})
|
p.push({name:'ids', data: uniqueIds})
|
||||||
}
|
}
|
||||||
if (debug) console.log(JSON.stringify(uniqueIds))
|
//if (debug) console.log(JSON.stringify(uniqueIds))
|
||||||
|
|
||||||
var msg = {
|
var msg = {
|
||||||
'action' : type,
|
'action' : type,
|
||||||
|
@ -305,3 +307,4 @@ SilicaListView {
|
||||||
worker.sendMessage(msg)
|
worker.sendMessage(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue