Add conditional append all for search when no knownIds
Add linkprev for bookmarks (and follows, etc)
This commit is contained in:
parent
ed48eb0a94
commit
abd5912f98
3 changed files with 59 additions and 31 deletions
|
@ -18,6 +18,7 @@ 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) {
|
getLink: function (endpoint) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Qt.include("Mastodon.js")
|
Qt.include("Mastodon.js")
|
||||||
|
|
||||||
|
var debug = true;
|
||||||
var loadImages = true;
|
var loadImages = true;
|
||||||
// used to dedupe on append/insert
|
// used to dedupe on append/insert
|
||||||
var knownIds = [];
|
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});
|
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
|
* we have to retrieve the Link header
|
||||||
|
* this falls through and continues for GET
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (msg.action === "bookmarks"){
|
if (msg.action === "bookmarks"){
|
||||||
API.getLink(msg.action, msg.params, function(data) {
|
API.getLink(msg.action, msg.params, function(data) {
|
||||||
console.log(JSON.stringify(data))
|
if (debug) console.log(JSON.stringify(data))
|
||||||
WorkerScript.sendMessage({ 'Header': data })
|
WorkerScript.sendMessage({ 'LinkHeader': data })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,12 +184,11 @@ 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)
|
|
||||||
console.log("ids > " + knownIds.length )
|
|
||||||
|
|
||||||
var i
|
var i
|
||||||
|
|
||||||
|
if (debug) console.log("Fetched > " +length + " in " + mode)
|
||||||
|
if (debug) console.log("ids > " + knownIds.length )
|
||||||
|
|
||||||
if (mode === "append") {
|
if (mode === "append") {
|
||||||
for(i = 0; i <= length-1; i++) {
|
for(i = 0; i <= length-1; i++) {
|
||||||
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
||||||
|
@ -196,12 +197,14 @@ function addDataToModel (model, mode, items) {
|
||||||
console.log("nope: " + items[i]["id"] )
|
console.log("nope: " + items[i]["id"] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// search does not use ids
|
||||||
//model.append(items)
|
if ( knownIds.length < 1 ) model.append(items)
|
||||||
|
|
||||||
} else if (mode === "prepend") {
|
} else if (mode === "prepend") {
|
||||||
for(i = length-1; i >= 0 ; i--) {
|
for(i = length-1; i >= 0 ; i--) {
|
||||||
|
|
||||||
model.insert(0,items[i])
|
model.insert(0,items[i])
|
||||||
|
|
||||||
/*if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
/*if ( knownIds.indexOf( items[i]["id"]) === -1) {
|
||||||
model.insert(0,items[i])
|
model.insert(0,items[i])
|
||||||
}*/
|
}*/
|
||||||
|
|
|
@ -18,7 +18,10 @@ SilicaListView {
|
||||||
property bool loadStarted: false
|
property bool loadStarted: false
|
||||||
property int scrollOffset
|
property int scrollOffset
|
||||||
property string action: ""
|
property string action: ""
|
||||||
|
// should consider better names or
|
||||||
|
// using min_ & max_id
|
||||||
property string linkprev: ""
|
property string linkprev: ""
|
||||||
|
property string linknext: ""
|
||||||
property variant vars
|
property variant vars
|
||||||
property variant conf
|
property variant conf
|
||||||
property bool notifier: false
|
property bool notifier: false
|
||||||
|
@ -172,7 +175,7 @@ SilicaListView {
|
||||||
if (debug) console.log(JSON.stringify(messageObject))
|
if (debug) console.log(JSON.stringify(messageObject))
|
||||||
} else {
|
} else {
|
||||||
if (debug) console.log(JSON.stringify(messageObject))
|
if (debug) console.log(JSON.stringify(messageObject))
|
||||||
loadStarted = false
|
// loadStarted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (messageObject.fireNotification && notifier){
|
if (messageObject.fireNotification && notifier){
|
||||||
|
@ -185,12 +188,20 @@ SilicaListView {
|
||||||
if (model.count > 20) deDouble()
|
if (model.count > 20) deDouble()
|
||||||
loadStarted = false
|
loadStarted = false
|
||||||
}
|
}
|
||||||
if (messageObject.Header) {
|
|
||||||
//if (debug) console.log(JSON.stringify(messageObject))
|
// the api is stupid
|
||||||
var matches = /max_id=([0-9]+)/.exec(messageObject.Header);
|
if (messageObject.LinkHeader) {
|
||||||
var link = matches[0].split("=")[1];
|
// <https://mastodon.gamedev.place/api/v1/bookmarks?max_id=11041>; rel=\"next\",
|
||||||
if (debug) console.log("link: " + link)
|
// <https://mastodon.gamedev.place/api/v1/bookmarks?min_id=14158>; rel=\"prev\""
|
||||||
linkprev = link
|
|
||||||
|
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;
|
triggeredOnStart: false;
|
||||||
interval: {
|
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
|
var listInterval = Math.floor(Math.random() * 60)*10*1000
|
||||||
if( title === "Home" ) listInterval = 20*60*1000
|
if( title === "Home" ) listInterval = 20*60*1000
|
||||||
if( title === "Local" ) listInterval = 10*60*1000
|
if( title === "Local" ) listInterval = 10*60*1000
|
||||||
|
@ -250,8 +264,8 @@ SilicaListView {
|
||||||
}
|
}
|
||||||
//if (debug) console.log(ids)
|
//if (debug) console.log(ids)
|
||||||
if (debug) console.log(uniqueItems.length)
|
if (debug) console.log(uniqueItems.length)
|
||||||
if (debug) console.log( "maxminusone?:" + model.get(model.count - 2).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 (debug) console.log( "max:" + model.get(model.count - 1).id )
|
||||||
|
|
||||||
if ( uniqueItems.length < model.count) {
|
if ( uniqueItems.length < model.count) {
|
||||||
|
|
||||||
|
@ -315,8 +329,13 @@ SilicaListView {
|
||||||
for(var i = 0; i<params.length; i++)
|
for(var i = 0; i<params.length; i++)
|
||||||
p.push(params[i])
|
p.push(params[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* for some types, min_id, max_id
|
||||||
|
* is obtained from link header
|
||||||
|
*/
|
||||||
|
|
||||||
if (mode === "append" && model.count) {
|
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})
|
p.push({name: 'max_id', data: model.get(model.count-1).id})
|
||||||
} else {
|
} else {
|
||||||
|
@ -324,8 +343,13 @@ SilicaListView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mode === "prepend" && model.count) {
|
if (mode === "prepend" && model.count) {
|
||||||
|
if ( linknext === "" ) {
|
||||||
p.push({name:'since_id', data: model.get(0).id})
|
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 (debug) console.log(JSON.stringify(uniqueIds))
|
||||||
if(title === "Local") {
|
if(title === "Local") {
|
||||||
type = "timelines/public"
|
type = "timelines/public"
|
||||||
|
|
Loading…
Reference in a new issue