From 74cea58e5fd16e55af551fa7c6bbf2c26b50aeb2 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Sun, 17 Feb 2013 11:32:59 +0100 Subject: [PATCH] fixed #155 --- WebKit/scripts/controller/Profile.js | 39 +++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/WebKit/scripts/controller/Profile.js b/WebKit/scripts/controller/Profile.js index 01a1a8e..fb38124 100644 --- a/WebKit/scripts/controller/Profile.js +++ b/WebKit/scripts/controller/Profile.js @@ -115,7 +115,7 @@ function(HostApp, Core, Paths, URI) { td.appendChild(this.profile_template.url); mkLi("Homepage", td); - mkLi("Following you", this.profile_template.following_you); + mkLi("Relationships", this.profile_template.following_you); td = document.createElement("td"); td.appendChild(this.profile_template.posts); @@ -156,6 +156,12 @@ function(HostApp, Core, Paths, URI) { this.profile_template.avatar.src = "img/default-avatar.png"; + this.relationships = { + following_you: false, + followed_by_you: false, + it_is_you: false + } + this.profile_template.name.innerText = ""; this.profile_template.entity.innerText = ""; this.profile_template.bio.innerText = ""; @@ -192,6 +198,7 @@ function(HostApp, Core, Paths, URI) { var _this = this; if (HostApp.stringForKey("entity") == this.entity) { + this.relationships.it_is_you = true; this.profile_template.following_button.style.display = "none"; } @@ -298,12 +305,20 @@ function(HostApp, Core, Paths, URI) { Paths.getURL(URI(root_url + "/followers/" + encodeURIComponent(HostApp.stringForKey("entity"))).toString(), "GET", function(resp) { if (resp.status == 200) { - _this.populate(_this.profile_template.following_you, "Yes"); - } else { - _this.populate(_this.profile_template.following_you, "No"); + _this.relationships.following_you = true; } + _this.setRelationships(); + }, null, false); + Paths.getURL(URI(Paths.mkApiRootPath("/followings/" + encodeURIComponent(this.entity))), "GET", function(resp) { + if (resp.status == 200) { + _this.relationships.followed_by_you = true; + } + _this.setRelationships(); + + }); + var url = URI(root_url + "/posts/count"); var post_types = [ "https://tent.io/types/post/repost/v0.1.0", @@ -318,6 +333,22 @@ function(HostApp, Core, Paths, URI) { }, null, false); } + Profile.prototype.setRelationships = function() { + var relation = "none"; + if (this.relationships.it_is_you) { + relation = "it's you"; + } else { + if (this.relationships.following_you && !this.relationships.followed_by_you) { + relation = "is following you"; + } else if (this.relationships.following_you && this.relationships.followed_by_you) { + relation = "you both follow each other"; + } else if (!this.relationships.following_you && this.relationships.followed_by_you) { + relation = "being followed by you"; + } + } + this.populate(this.profile_template.following_you, relation); + } + Profile.prototype.getStatuses = function(root_url) { var _this = this;