fixed following/unfollowing

This commit is contained in:
jeena 2013-07-17 03:01:43 +02:00
parent 16d7016e29
commit 771243a75f
4 changed files with 44 additions and 19 deletions

View file

@ -247,14 +247,17 @@ function(HostApp, Core, APICalls, URI) {
var url = HostApp.serverUrl("posts_feed") + "?mentions=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/subscription/v0#https://tent.io/types/status/v0"); var url = HostApp.serverUrl("posts_feed") + "?mentions=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/subscription/v0#https://tent.io/types/status/v0");
var _this = this; var _this = this;
APICalls.head(url, {callback: function(resp) { APICalls.get(url, {callback: function(resp) {
var count = APICalls.getCount(resp); var json = JSON.parse(resp.responseText);
var count = json.posts.length;
if (count > 0) { if (count > 0) {
_this.setFollowingButton(true); _this.setFollowingButton(true);
_this.following_id = json.posts[0].id;
} else { } else {
_this.setFollowingButton(false); _this.setFollowingButton(false);
delete _this.following_id;
} }
}}); }});
@ -331,13 +334,14 @@ function(HostApp, Core, APICalls, URI) {
Profile.prototype.getMeta = function(profile) { Profile.prototype.getMeta = function(profile) {
// FIXME!
return;
var _this = this; var _this = this;
var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/relationship/v0#follower"); var url = HostApp.serverUrl("posts_feed") + "?entities=" + encodeURIComponent(this.entity) + "&types=" + encodeURIComponent("https://tent.io/types/relationship/v0#follower");
APICalls.head(url, { APICalls.head(url, {
callback: function(resp) { callback: function(resp) {
debug(APICalls.getCount(resp))
_this.populate(_this.profile_template.followed, APICalls.getCount(resp)+" "); _this.populate(_this.profile_template.followed, APICalls.getCount(resp)+" ");
} }
}); });
@ -518,16 +522,15 @@ function(HostApp, Core, APICalls, URI) {
this.setFollowingButton(false); this.setFollowingButton(false);
/* var url = HostApp.serverUrl("post").replace(/\{entity\}/, encodeURIComponent(HostApp.stringForKey("entity"))).replace(/\{post\}/, this.following_id);
var url = APICalls.mkApiRootPath("/followings/") + this.following_id; APICalls.delete(url, { callback: function(resp) {
APICalls.http_call(url, "DELETE", function(resp) {
if (resp.status >= 200 && resp.status < 300) { if (resp.status >= 200 && resp.status < 300) {
_this.setFollowingButton(false); _this.setFollowingButton(false);
_this.following_id = null; delete _this.following_id;
} else { } else {
_this.setFollowingButton(true); _this.setFollowingButton(true);
} }
});*/ }});
} else { } else {
@ -535,19 +538,23 @@ function(HostApp, Core, APICalls, URI) {
var url = HostApp.serverUrl("new_post"); var url = HostApp.serverUrl("new_post");
var data = JSON.stringify({ var data = {
type: "https://tent.io/types/subscription/v0#https://tent.io/types/status/v0", content: {
type: "https://tent.io/types/status/v0"
},
mentions: [{ mentions: [{
entity: this.entity entity: this.entity
}] }],
}); type: "https://tent.io/types/subscription/v0#https://tent.io/types/status/v0"
};
APICalls.post(url, data, { APICalls.post(url, JSON.stringify(data), {
content_type: "https://tent.io/types/subscription/v0", content_type: data.type,
callback: function(resp) { callback: function(resp) {
debug(resp.status)
if (resp.status >= 200 && resp.status < 300) { if (resp.status >= 200 && resp.status < 300) {
_this.setFollowingButton(true); _this.setFollowingButton(true);
var json = JSON.parse(resp.responseText);
_this.following_id = json.post.id;
} else { } else {
_this.setFollowingButton(false); _this.setFollowingButton(false);
} }

View file

@ -49,7 +49,11 @@ function(Core, APICalls, HostApp, URI) {
Timeline.prototype.newStatus = function(_statuses, append) { Timeline.prototype.newStatus = function(_statuses, append) {
for (var entity in _statuses.profiles) { for (var entity in _statuses.profiles) {
if (_statuses.profiles[entity] != null) {
bungloo.cache.profiles[entity] = _statuses.profiles[entity]; bungloo.cache.profiles[entity] = _statuses.profiles[entity];
} else {
bungloo.cache.profiles[entity] = {};
}
} }
statuses = _statuses.posts; statuses = _statuses.posts;

View file

@ -38,10 +38,9 @@ function(jQuery, HostApp, Hmac, Cache) {
} else { } else {
if(options.content_type == "application/json") { if(options.content_type == "application/json") {
content_type = "application/json"; content_type = "application/json";
} else { } else if(options.content_type) {
content_type = "application/vnd.tent.post.v0+json; type=\"" + options.content_type + "\""; content_type = "application/vnd.tent.post.v0+json; type=\"" + options.content_type + "\"";
} }
} }
var settings = { var settings = {
@ -120,6 +119,20 @@ function(jQuery, HostApp, Hmac, Cache) {
APICalls.http_call(settings); APICalls.http_call(settings);
} }
APICalls.delete = function(url, options) {
var settings = {
url: url,
http_method: "DELETE"
};
for (var key in options) {
settings[key] = options[key];
}
APICalls.http_call(settings);
}
APICalls.postMultipart = function(url, callback, data, boundary, accepts) { APICalls.postMultipart = function(url, callback, data, boundary, accepts) {
accepts = accepts || "application/vnd.tent.v0+json"; accepts = accepts || "application/vnd.tent.v0+json";

View file

@ -236,6 +236,7 @@ function(jQuery, APICalls, URI, HostApp, Cache) {
} }
if(bungloo.cache.profiles[status.entity].name) template.username.innerText = bungloo.cache.profiles[status.entity].name; if(bungloo.cache.profiles[status.entity].name) template.username.innerText = bungloo.cache.profiles[status.entity].name;
else template.username.innerText = status.entity;
template.username.href = status.entity; template.username.href = status.entity;
template.username.title = status.entity; template.username.title = status.entity;
template.username.onclick = function() { template.username.onclick = function() {