fixed paging

This commit is contained in:
jeena 2013-07-22 14:00:43 +02:00
parent ec43a38b86
commit 0bf0324702
2 changed files with 51 additions and 43 deletions

View file

@ -55,7 +55,7 @@ function(HostApp, Timeline, URI, APICalls, Core) {
this.is_not_init = true; this.is_not_init = true;
} }
Mentions.prototype.getNewData = function(add_to_search, append) { Mentions.prototype.getNewData = function(add_to_search, append, query) {
add_to_search = add_to_search || {}; add_to_search = add_to_search || {};
@ -63,7 +63,7 @@ function(HostApp, Timeline, URI, APICalls, Core) {
add_to_search["mentions"] = HostApp.stringForKey("entity"); add_to_search["mentions"] = HostApp.stringForKey("entity");
} }
Timeline.prototype.getNewData.call(this, add_to_search, append); Timeline.prototype.getNewData.call(this, add_to_search, append, query);
//this.getLatestMentionRead(); //this.getLatestMentionRead();
} }

View file

@ -14,13 +14,15 @@ function(Core, APICalls, HostApp, URI) {
this.action = "timeline"; this.action = "timeline";
this.reload_blocked = false; this.reload_blocked = false;
this.posts_limit = 25; this.posts_limit = 4;
this.max_length = 200; this.max_length = 200;
this.timeout = 10 * 1000; // every 10 seconds this.timeout = 10 * 1000; // every 10 seconds
this.since_id = null; this.since_id = null;
this.since_id_entity = null; this.since_id_entity = null;
this.since_time = 0; this.since_time = 0;
this.pages = {};
this.before = {id: null, entity: null, loading: false}; this.before = {id: null, entity: null, loading: false};
this.container = document.createElement("div"); this.container = document.createElement("div");
@ -56,6 +58,8 @@ function(Core, APICalls, HostApp, URI) {
} }
} }
this.pages = _statuses.pages;
statuses = _statuses.posts; statuses = _statuses.posts;
if(statuses != null && statuses.length > 0) { if(statuses != null && statuses.length > 0) {
@ -104,48 +108,43 @@ function(Core, APICalls, HostApp, URI) {
} }
} }
Timeline.prototype.getNewData = function(add_to_search, append) { Timeline.prototype.getNewData = function(add_to_search, append, query) {
add_to_search = add_to_search || {}; add_to_search = add_to_search || {};
var those = this; var those = this;
var url = URI(HostApp.serverUrl("posts_feed")); var url = HostApp.serverUrl("posts_feed");
var post_types = [ if(!query) {
"https://tent.io/types/status/v0#",
"https://tent.io/types/status/v0#reply",
"https://tent.io/types/repost/v0#",
"https://tent.io/types/delete/v0#",
//"https://tent.io/types/post/photo/v0.1.0"
];
url.addSearch("types", post_types.join(","));
//url.addSearch("sort_by", "published_at");
url.addSearch("limit", this.posts_limit);
url.addSearch("max_refs", 20);
url.addSearch("profiles", "entity");
if(this.since_id && !append) { var uri = URI(url);
url.addSearch("since_id", this.since_id);
url.addSearch("since_id_entity", this.since_id_entity);
}
for (key in add_to_search) { var post_types = [
url.addSearch(key, add_to_search[key]); "https://tent.io/types/status/v0#",
} "https://tent.io/types/status/v0#reply",
"https://tent.io/types/repost/v0#",
"https://tent.io/types/delete/v0#",
//"https://tent.io/types/post/photo/v0.1.0"
];
uri.addSearch("types", post_types.join(","));
//uri.addSearch("sort_by", "published_at");
uri.addSearch("limit", this.posts_limit);
uri.addSearch("max_refs", 20);
uri.addSearch("profiles", "entity");
var http_method = "GET"; if(this.since_id && !append) {
var callback = function(resp) { uri.addSearch("since_id", this.since_id);
uri.addSearch("since_id_entity", this.since_id_entity);
those.reload_blocked = false;
try {
var json = JSON.parse(resp.responseText);
those.newStatus(json, append);
} catch (e) {
console.error(url + " JSON parse error");
throw e;
} }
for (key in add_to_search) {
uri.addSearch(key, add_to_search[key]);
}
url = uri.toString();
} else {
url += query;
} }
var data = null; var data = null;
@ -155,20 +154,29 @@ function(Core, APICalls, HostApp, URI) {
if (!this.reload_blocked) { if (!this.reload_blocked) {
this.reload_blocked = true; this.reload_blocked = true;
APICalls.get(url.toString(), { callback: callback }); APICalls.get(url, { callback: function(resp) {
those.reload_blocked = false;
try {
var json = JSON.parse(resp.responseText);
those.newStatus(json, append);
} catch (e) {
console.error(url + " JSON parse error");
throw e;
}
} });
} }
} }
} }
Timeline.prototype.getMoreStatusPosts = function() { Timeline.prototype.getMoreStatusPosts = function() {
if (!this.before.loading) { if (!this.before.loading) {
this.before.loading = true; if (this.pages.next) {
var add_search = { this.before.loading = true;
"before_id": this.body.lastChild.status.id, this.getNewData({}, true, this.pages.next);
"before_id_entity": this.body.lastChild.status.entity
} }
this.getNewData(add_search, true);
} }
} }