renamed Followings into Caching and fixed #85 (adding more files to the commit)

This commit is contained in:
Jeena Paradies 2012-12-07 09:18:02 +01:00
parent 34e3990af6
commit dacd2ee019
5 changed files with 25 additions and 67 deletions

View file

@ -72,9 +72,9 @@ function(HostApp, Core, Paths, URI) {
var url = URI(Paths.mkApiRootPath("/posts/" + id)); var url = URI(Paths.mkApiRootPath("/posts/" + id));
Paths.getURL(url.toString(), "GET", callback, null); Paths.getURL(url.toString(), "GET", callback, null);
} else if(this.followings.followings[entity]) { } else if(this.cache.followings[entity]) {
getRemoteStatus(this.followings.followings[entity].profile); getRemoteStatus(this.cache.followings[entity].profile);
} else { } else {

View file

@ -33,8 +33,8 @@ function(HostApp, Timeline) {
var status = statuses[i]; var status = statuses[i];
var name; var name;
if(this.followings.followings[status.entity]) { if(this.cache.followings[status.entity]) {
name = this.followings.followings[status.entity].profile["https://tent.io/types/info/basic/v0.1.0"].name; name = this.cache.followings[status.entity].profile["https://tent.io/types/info/basic/v0.1.0"].name;
} }
HostApp.notificateUserAboutMention(status.content.text, name || status.entity, status.id, status.entity); HostApp.notificateUserAboutMention(status.content.text, name || status.entity, status.id, status.entity);

View file

@ -26,7 +26,7 @@ function(HostApp, Core, Paths, URI) {
this.profile_template.entity.innerHTML = this.entity; this.profile_template.entity.innerHTML = this.entity;
this.profile_template.entity.href = this.entity; this.profile_template.entity.href = this.entity;
this.setFollowingButton(!!this.followings.followings[this.entity]); this.setFollowingButton(!!this.cache.followings[this.entity]);
this.getProfile(); this.getProfile();
} }
@ -313,14 +313,14 @@ function(HostApp, Core, Paths, URI) {
Profile.prototype.toggleFollow = function() { Profile.prototype.toggleFollow = function() {
var _this = this; var _this = this;
var callback = function(resp) { _this.followings.getAllFollowings(); debug(resp.responseText) }; var callback = function(resp) { _this.cache.getAllFollowings(); debug(resp.responseText) };
if (this.followings.followings[this.entity]) { if (this.cache.followings[this.entity]) {
var url = URI(Paths.mkApiRootPath("/followings/" + this.followings.followings[this.entity].id)); var url = URI(Paths.mkApiRootPath("/followings/" + this.cache.followings[this.entity].id));
Paths.getURL(url.toString(), "DELETE", callback); Paths.getURL(url.toString(), "DELETE", callback);
this.setFollowingButton(false); this.setFollowingButton(false);
delete this.followings.followings[this.entity]; delete this.cache.followings[this.entity];
} else { } else {

View file

@ -3,15 +3,15 @@ define([
"helper/Paths", "helper/Paths",
"lib/URI", "lib/URI",
"helper/HostApp", "helper/HostApp",
"helper/Followings", "helper/Cache",
"lib/Timeago" "lib/Timeago"
], ],
function(jQuery, Paths, URI, HostApp, Followings) { function(jQuery, Paths, URI, HostApp, Cache) {
function Core() { function Core() {
this.followings = new Followings(); this.cache = new Cache();
} }
@ -207,9 +207,9 @@ function(jQuery, Paths, URI, HostApp, Followings) {
} }
if (this.followings.followings[status.entity]) { if (this.cache.followings[status.entity]) {
profile(this.followings.followings[status.entity].profile); profile(this.cache.followings[status.entity].profile);
} else { } else {
@ -234,9 +234,9 @@ function(jQuery, Paths, URI, HostApp, Followings) {
return false; return false;
} }
if (this.followings.followings[status.__repost.entity]) { if (this.cache.followings[status.__repost.entity]) {
var basic = this.followings.followings[status.__repost.entity].profile["https://tent.io/types/info/basic/v0.1.0"]; var basic = this.cache.followings[status.__repost.entity].profile["https://tent.io/types/info/basic/v0.1.0"];
template.reposted_by.innerText = basic.name; template.reposted_by.innerText = basic.name;
} else { } else {
@ -420,7 +420,13 @@ function(jQuery, Paths, URI, HostApp, Followings) {
"content": { "content": {
"entity": entity, "entity": entity,
"id": id "id": id
} },
"mentions": [
{
"entity": entity,
"post": id
}
]
}; };
Paths.getURL(url.toString(), "POST", callback, JSON.stringify(data)); Paths.getURL(url.toString(), "POST", callback, JSON.stringify(data));
@ -577,9 +583,9 @@ function(jQuery, Paths, URI, HostApp, Followings) {
} }
} }
if (_this.followings.followings[mention.entity]) { if (_this.cache.followings[mention.entity]) {
profile(_this.followings.followings[mention.entity].profile) profile(_this.cache.followings[mention.entity].profile)
} else { } else {

View file

@ -1,48 +0,0 @@
define([
"helper/Paths",
"lib/URI"
],
function(Paths, URI) {
function Followings() {
this.timeout = 2 * 60 * 1000;
this.followings = {};
this.before_id = null;
var _this = this;
this.intervall = setInterval(function() { _this.getAllFollowings(); }, this.timeout);
this.getAllFollowings();
}
Followings.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 Followings;
});