diff --git a/qml/lib/Mastodon.js b/qml/lib/Mastodon.js index f09b1c5..f7c812e 100644 --- a/qml/lib/Mastodon.js +++ b/qml/lib/Mastodon.js @@ -17,7 +17,8 @@ var mastodonAPI = function(config) { }, /* - * function to retrieve the Link header + * function to retrieve the Link header + * using HEAD, so bookmarks has head followed by GET */ getLink: function (endpoint) { diff --git a/qml/lib/Worker.js b/qml/lib/Worker.js index b81ee0d..c906c69 100644 --- a/qml/lib/Worker.js +++ b/qml/lib/Worker.js @@ -1,6 +1,6 @@ Qt.include("Mastodon.js") - +var debug = true; var loadImages = true; // used to dedupe on append/insert var knownIds = []; @@ -59,14 +59,16 @@ WorkerScript.onMessage = function(msg) { var API = mastodonAPI({ instance: msg.conf.instance, api_user_token: msg.conf.api_user_token}); - /* for some actions + /* + * HEAD call for some actions * we have to retrieve the Link header + * this falls through and continues for GET */ if (msg.action === "bookmarks"){ API.getLink(msg.action, msg.params, function(data) { - console.log(JSON.stringify(data)) - WorkerScript.sendMessage({ 'Header': data }) + if (debug) console.log(JSON.stringify(data)) + WorkerScript.sendMessage({ 'LinkHeader': data }) }); } @@ -182,26 +184,27 @@ WorkerScript.onMessage = function(msg) { function addDataToModel (model, mode, items) { var length = items.length; - - console.log("Fetched > " +length + " in " + mode) - console.log("ids > " + knownIds.length ) - var i + if (debug) console.log("Fetched > " +length + " in " + mode) + if (debug) console.log("ids > " + knownIds.length ) + if (mode === "append") { for(i = 0; i <= length-1; i++) { if ( knownIds.indexOf( items[i]["id"]) === -1) { model.append(items[i]) } else { - console.log("nope: " + items[i]["id"] ) - } - } - - //model.append(items) + console.log("nope: " + items[i]["id"] ) + } + } + // search does not use ids + if ( knownIds.length < 1 ) model.append(items) } else if (mode === "prepend") { for(i = length-1; i >= 0 ; i--) { + model.insert(0,items[i]) + /*if ( knownIds.indexOf( items[i]["id"]) === -1) { model.insert(0,items[i]) }*/ diff --git a/qml/pages/components/MyList.qml b/qml/pages/components/MyList.qml index 67c0fd3..12df57b 100644 --- a/qml/pages/components/MyList.qml +++ b/qml/pages/components/MyList.qml @@ -18,7 +18,10 @@ SilicaListView { property bool loadStarted: false property int scrollOffset property string action: "" + // should consider better names or + // using min_ & max_id property string linkprev: "" + property string linknext: "" property variant vars property variant conf property bool notifier: false @@ -172,7 +175,7 @@ SilicaListView { if (debug) console.log(JSON.stringify(messageObject)) } else { if (debug) console.log(JSON.stringify(messageObject)) - loadStarted = false + // loadStarted = false } if (messageObject.fireNotification && notifier){ @@ -185,13 +188,21 @@ SilicaListView { if (model.count > 20) deDouble() loadStarted = false } - 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 - } + + // the api is stupid + if (messageObject.LinkHeader) { + // ; rel=\"next\", + // ; rel=\"prev\"" + + var matches = /max_id=([0-9]+)/.exec(messageObject.LinkHeader); + var maxlink = matches[0].split("=")[1]; + var matches = /min_id=([0-9]+)/.exec(messageObject.LinkHeader); + var minlink = matches[0].split("=")[1]; + if (debug) console.log("maxlink: " + maxlink) + if (debug) console.log("minlink: " + minlink) + linkprev = maxlink + linknext = minlink + } } } @@ -204,7 +215,10 @@ SilicaListView { triggeredOnStart: false; interval: { - /* this is hamfisted */ + /* + * Varied calls so that server isn't hit + * simultaenously ... this is hamfisted + */ var listInterval = Math.floor(Math.random() * 60)*10*1000 if( title === "Home" ) listInterval = 20*60*1000 if( title === "Local" ) listInterval = 10*60*1000 @@ -250,8 +264,8 @@ SilicaListView { } //if (debug) console.log(ids) if (debug) console.log(uniqueItems.length) - if (debug) console.log( "maxminusone?:" + model.get(model.count - 2).id ) - if (debug) console.log( "max?:" + model.get(model.count - 1).id ) + if (debug) console.log( "max-one?:" + model.get(model.count - 2).id ) + if (debug) console.log( "max:" + model.get(model.count - 1).id ) if ( uniqueItems.length < model.count) { @@ -315,17 +329,27 @@ SilicaListView { for(var i = 0; i