From 0eeffcf7f61e1273d60a74f74ee86dc990c17f55 Mon Sep 17 00:00:00 2001 From: jeena Date: Mon, 22 Jul 2013 03:33:54 +0200 Subject: [PATCH] fixed avatar in sidebar --- WebKit/scripts/controller/NewPost.js | 1 - WebKit/scripts/controller/Profile.js | 5 ++-- WebKit/scripts/controller/Sidebar.js | 33 +++++++++++++++++++++++---- WebKit/scripts/controller/Timeline.js | 2 +- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/WebKit/scripts/controller/NewPost.js b/WebKit/scripts/controller/NewPost.js index 63ec2bd..63144ff 100644 --- a/WebKit/scripts/controller/NewPost.js +++ b/WebKit/scripts/controller/NewPost.js @@ -60,7 +60,6 @@ function(APICalls, HostApp) { NewPost.prototype.setStatus = function(status_string) { if (status_string && status_string.length > 0) { - debug(status_string) this.status = JSON.parse(status_string); this.setIsPrivate(this.status.permissions && !this.status.permissions.public); this.setMentions(this.status); diff --git a/WebKit/scripts/controller/Profile.js b/WebKit/scripts/controller/Profile.js index fb8125b..f36e915 100644 --- a/WebKit/scripts/controller/Profile.js +++ b/WebKit/scripts/controller/Profile.js @@ -231,8 +231,7 @@ function(HostApp, Core, APICalls, URI) { this.profile_template.following_button.style.display = "none"; } - var url = HostApp.serverUrl("posts_feed") + "?types=" + encodeURIComponent("https://tent.io/types/meta/v0") + "&entities=" + encodeURIComponent(this.entity) - //var url = HostApp.serverUrl("discover").replace(/{entity}/, encodeURIComponent(this.entity)); + var url = HostApp.serverUrl("posts_feed") + "?types=" + encodeURIComponent("https://tent.io/types/meta/v0") + "&entities=" + encodeURIComponent(this.entity); APICalls.get(url, { callback: function(resp) { var profile = JSON.parse(resp.responseText); @@ -274,7 +273,7 @@ function(HostApp, Core, APICalls, URI) { if(profiles.posts.length < 1) return; var profile = profiles.posts[0]; - bungloo.cache.profiles[profile.entity] = profile; + bungloo.cache.profiles[profile.entity] = profile.content.profile; var basic = profile.content.profile; diff --git a/WebKit/scripts/controller/Sidebar.js b/WebKit/scripts/controller/Sidebar.js index 61d05d4..d32c1e4 100644 --- a/WebKit/scripts/controller/Sidebar.js +++ b/WebKit/scripts/controller/Sidebar.js @@ -81,15 +81,38 @@ function(HostApp, APICalls) { var entity = HostApp.stringForKey("entity"); this.menu.user.title = entity; - var img = this.menu.user.getElementsByTagName("img")[0]; - + var avatar = this.menu.user.getElementsByTagName("img")[0]; var _this = this; - var url = HostApp.serverUrl("discover"); - debug(url) - + var url = HostApp.serverUrl("posts_feed") + "?types=" + encodeURIComponent("https://tent.io/types/meta/v0") + "&entities=" + encodeURIComponent(entity); APICalls.get(url, { callback: function(resp) { + var profiles = JSON.parse(resp.responseText); + if(profiles.posts.length < 1) return; + var profile = profiles.posts[0]; + bungloo.cache.profiles[entity] = profile; + + // Find and apply avatar + if(profile.attachments) { + + var digest = null; + for (var i = 0; i < profile.attachments.length; i++) { + var attachment = profile.attachments[i]; + if(attachment.category == "avatar") { + digest = attachment.digest; + break; + } + } + + if(digest) { + var _this = this; + avatar.onerror = function() { avatar.src = 'img/default-avatar.png' }; + var avatar_url = profile.content.servers[0].urls.attachment.replace(/\{entity\}/, encodeURIComponent(profile.entity)); + avatar.src = avatar_url.replace(/\{digest\}/, digest); + avatar.src_inactive = avatar.src; + avatar.src_active = avatar.src; + } + } }}); } diff --git a/WebKit/scripts/controller/Timeline.js b/WebKit/scripts/controller/Timeline.js index c4716d7..576246b 100644 --- a/WebKit/scripts/controller/Timeline.js +++ b/WebKit/scripts/controller/Timeline.js @@ -30,7 +30,7 @@ function(Core, APICalls, HostApp, URI) { document.getElementById("content").appendChild(this.container); var _this = this; - //this.reloadIntervall = setInterval(function() { _this.getNewData() }, this.timeout); //FIXME back + this.reloadIntervall = setInterval(function() { _this.getNewData() }, this.timeout); this.getNewData(); }