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