@@ -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 @@
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 @@
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])
}*/
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-tooterb-1.1.3.tar.bz2/qml/pages/components/MyList.qml
^
|
@@ -18,7 +18,10 @@
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 @@
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 @@
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) {
+ // <https://mastodon.gamedev.place/api/v1/bookmarks?max_id=11041>; rel=\"next\",
+ // <https://mastodon.gamedev.place/api/v1/bookmarks?min_id=14158>; 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 @@
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 @@
}
//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 @@
for(var i = 0; i<params.length; i++)
p.push(params[i])
}
+
+ /*
+ * for some types, min_id, max_id
+ * is obtained from link header
+ */
+
if (mode === "append" && model.count) {
- // for some types, max_id is obtained from link header
- if ( linkprev === "" ) {
+ if ( linkprev === "" ) {
p.push({name: 'max_id', data: model.get(model.count-1).id})
- } else {
- p.push({name: 'max_id', data: linkprev})
- }
+ } else {
+ p.push({name: 'max_id', data: linkprev})
+ }
}
if (mode === "prepend" && model.count) {
- p.push({name:'since_id', data: model.get(0).id})
+ if ( linknext === "" ) {
+ p.push({name:'since_id', data: model.get(0).id})
+ } else {
+ p.push({name: 'min_id', data: linknext})
+ }
}
+
//if (debug) console.log(JSON.stringify(uniqueIds))
if(title === "Local") {
type = "timelines/public"
|