From d504bf4591aa5d53123b1dc8e243da0173670233 Mon Sep 17 00:00:00 2001 From: Daniel Grippi Date: Thu, 1 Dec 2011 13:56:57 -0800 Subject: [PATCH] add current user to body tag data field (hackity hack). add comment links to posts --- app/models/comment.rb | 1 + app/models/post.rb | 1 + app/models/services/facebook.rb | 1 + app/views/layouts/application.html.haml | 3 +- .../shared/_stream_element.html.underscore | 40 +++++++++++++++---- config/assets.yml | 1 + public/javascripts/app.js | 9 +++++ public/javascripts/models/post.js | 5 --- public/javascripts/views/stream-view.js | 6 ++- 9 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 public/javascripts/app.js diff --git a/app/models/comment.rb b/app/models/comment.rb index 63e46cb19..24b95941f 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -23,6 +23,7 @@ class Comment < ActiveRecord::Base t.add :guid t.add :text t.add :author + t.add :created_at end diff --git a/app/models/post.rb b/app/models/post.rb index 9780e88b6..87572b783 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -15,6 +15,7 @@ class Post < ActiveRecord::Base t.add :id t.add :guid t.add :text + t.add :public t.add :created_at t.add :comments_count t.add :last_three_comments diff --git a/app/models/services/facebook.rb b/app/models/services/facebook.rb index 7564637c3..45ee847e0 100644 --- a/app/models/services/facebook.rb +++ b/app/models/services/facebook.rb @@ -42,6 +42,7 @@ class Services::Facebook < Service end def save_friends + return url = "https://graph.facebook.com/me/friends?fields[]=name&fields[]=picture&access_token=#{URI.escape(self.access_token)}" response = Faraday.get(url) data = JSON.parse(response.body)['data'] diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 7deaa9ecc..77629ef9f 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -60,7 +60,8 @@ - if @person %link{:rel => "alternate", :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => "#{t('.public_feed', :name => @person.name)}"} - %body{:class => "#{yield(:body_class)}", 'data-current-user-metadata' => CGI::escape(current_user.person.as_api_response(:backbone).to_json) } + - metadata = user_signed_in? ? CGI::escape({:current_user => current_user.person.as_api_response(:backbone)}.to_json) : "" + %body{:class => "#{yield(:body_class)}", 'data-current-user-metadata' => metadata } - unless @page == :logged_out - flash.each do |name, msg| diff --git a/app/views/shared/_stream_element.html.underscore b/app/views/shared/_stream_element.html.underscore index a9c7d9f61..040856cb5 100644 --- a/app/views/shared/_stream_element.html.underscore +++ b/app/views/shared/_stream_element.html.underscore @@ -1,8 +1,11 @@
- - - + + <% if(author.id != current_user.id) { %> + + + + <% } %> @@ -37,14 +40,33 @@

-
    + + + +
      <% _.each(last_three_comments, function(comment) { %>
    • @@ -74,9 +96,11 @@
    -
    +
    - + + +

    diff --git a/config/assets.yml b/config/assets.yml index f6ddd38f3..57f9ec65e 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -15,6 +15,7 @@ javascripts: - public/javascripts/vendor/underscore.js - public/javascripts/vendor/backbone.js + - public/javascripts/app.js - public/javascripts/models/* - public/javascripts/collections/* - public/javascripts/views/* diff --git a/public/javascripts/app.js b/public/javascripts/app.js new file mode 100644 index 000000000..d5f3b767b --- /dev/null +++ b/public/javascripts/app.js @@ -0,0 +1,9 @@ +var App = { + Collections: {}, + Models: {}, + Views: {}, + + currentUser: function() { + return $.parseJSON(unescape($("body").data("current-user-metadata"))); + } +}; diff --git a/public/javascripts/models/post.js b/public/javascripts/models/post.js index 316b08d0b..5ed8a9ada 100644 --- a/public/javascripts/models/post.js +++ b/public/javascripts/models/post.js @@ -2,10 +2,5 @@ var Post = Backbone.Model.extend({ url: "/posts/:id", intTime: function(){ return +new Date(this.get("created_at")) / 1000; - }, - - // should be moved into the view or something? - currentUserJSON: function(){ - return $.parseJSON(unescape($("body").data("current-user-metadata"))); } }); diff --git a/public/javascripts/views/stream-view.js b/public/javascripts/views/stream-view.js index 1458d016a..54f36dc37 100644 --- a/public/javascripts/views/stream-view.js +++ b/public/javascripts/views/stream-view.js @@ -18,13 +18,17 @@ $(function() { }, appendPost: function(model) { - var post = $(this.template(model.toJSON())); + var post = $(this.template($.extend( + model.toJSON(), + App.currentUser() + ))); $(this.el).append(post); Diaspora.BaseWidget.instantiate("StreamElement", post); }, collectionFetched: function() { this.$(".details time").timeago(); + this.$("label").inFieldLabels(); this.$("#paginate").remove(); $(this.el).append($("", {