renamed Followings to Cache and fixed #85
This commit is contained in:
parent
4edf2e6c13
commit
34e3990af6
1 changed files with 49 additions and 0 deletions
49
WebKit/scripts/helper/Cache.js
Normal file
49
WebKit/scripts/helper/Cache.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
define([
|
||||||
|
"helper/Paths",
|
||||||
|
"lib/URI"
|
||||||
|
],
|
||||||
|
|
||||||
|
function(Paths, URI) {
|
||||||
|
|
||||||
|
function Cache() {
|
||||||
|
|
||||||
|
this.timeout = 2 * 60 * 1000;
|
||||||
|
this.before_id = null;
|
||||||
|
|
||||||
|
this.followings = {};
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
this.intervall = setInterval(function() { _this.getAllFollowings(); }, this.timeout);
|
||||||
|
|
||||||
|
this.getAllFollowings();
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache.prototype.getAllFollowings = function() {
|
||||||
|
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
var callback = function(resp) {
|
||||||
|
|
||||||
|
var fs = JSON.parse(resp.responseText)
|
||||||
|
|
||||||
|
if (fs.length < 1) return;
|
||||||
|
|
||||||
|
for (var i = 0; i < fs.length; i++) {
|
||||||
|
|
||||||
|
var following = fs[i];
|
||||||
|
_this.before_id = following.id;
|
||||||
|
_this.followings[following.entity] = following;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var url = URI(Paths.mkApiRootPath("/followings"));
|
||||||
|
if (this.before_id) {
|
||||||
|
url.addSearch("before_id", this.before_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
Paths.getURL(url, "GET", callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Cache;
|
||||||
|
|
||||||
|
});
|
Reference in a new issue