diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b0fbad915..e533c4f47 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -145,6 +145,12 @@ class ApplicationController < ActionController::Base end end + # @param stream_klass [Constant] + # @return [String] JSON representation of posts given a [Stream] constant. + def stream_json(stream_klass) + render_for_api :backbone, :json => stream(stream_klass).stream_posts, :root => :posts + end + def stream(stream_klass) authenticate_user! save_sort_order diff --git a/app/controllers/comment_stream_controller.rb b/app/controllers/comment_stream_controller.rb index a7c759f7a..d09524433 100644 --- a/app/controllers/comment_stream_controller.rb +++ b/app/controllers/comment_stream_controller.rb @@ -10,10 +10,11 @@ class CommentStreamController < ApplicationController def index @backbone = true + stream_klass = Stream::Comments respond_with do |format| - format.html{ default_stream_action(Stream::Comments) } - format.json{ render :json => stream(Stream::Comments).stream_posts.to_json(:include => {:author => {:include => :profile}}) } + format.html{ default_stream_action(stream_klass) } + format.json{ stream_json(stream_klass) } end end end diff --git a/app/controllers/mentions_controller.rb b/app/controllers/mentions_controller.rb index ff8eec734..879637b2a 100644 --- a/app/controllers/mentions_controller.rb +++ b/app/controllers/mentions_controller.rb @@ -10,10 +10,11 @@ class MentionsController < ApplicationController def index @backbone = true + stream_klass = Stream::Mention respond_with do |format| - format.html{ default_stream_action(Stream::Mention) } - format.json{ render :json => stream(Stream::Mention).stream_posts.to_json(:include => {:author => {:include => :profile}}) } + format.html{ default_stream_action(stream_klass) } + format.json{ stream_json(stream_klass) } end end end diff --git a/app/controllers/multis_controller.rb b/app/controllers/multis_controller.rb index fe921dbd6..5ece83fad 100644 --- a/app/controllers/multis_controller.rb +++ b/app/controllers/multis_controller.rb @@ -10,11 +10,11 @@ class MultisController < ApplicationController def index @backbone = true + stream_klass = Stream::Multi respond_with do |format| - format.html{ default_stream_action(Stream::Multi) } - format.json{ render :json => stream(Stream::Multi).stream_posts.to_json(:include => {:author => {:include => :profile}}) } - #format.json{ render_for_api :backbone, :json => stream(Stream::Multi).stream_posts } + format.html{ default_stream_action(stream_klass) } + format.json{ stream_json(stream_klass) } end end end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index fc99d89d5..c18b9b4ce 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -132,7 +132,7 @@ class PeopleController < ApplicationController else respond_to do |format| format.all { respond_with @person, :locals => {:post_type => :all} } - format.json{ render :json => @stream.stream_posts.to_json(:include => {:author => {:include => :profile}}) } + format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } end end end diff --git a/app/controllers/tag_followings_controller.rb b/app/controllers/tag_followings_controller.rb index f2f7c17d0..b17ffd3d4 100644 --- a/app/controllers/tag_followings_controller.rb +++ b/app/controllers/tag_followings_controller.rb @@ -11,10 +11,11 @@ class TagFollowingsController < ApplicationController def index @backbone = true + stream_klass = Stream::FollowedTag respond_with do |format| - format.html{ default_stream_action(Stream::FollowedTag) } - format.json{ render :json => stream(Stream::FollowedTag).stream_posts.to_json(:include => {:author => {:include => :profile}}) } + format.html{ default_stream_action(stream_klass) } + format.json{ stream_json(stream_klass) } end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 090503547..2964f625c 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -46,7 +46,7 @@ class TagsController < ApplicationController return end end - format.json{ render :json => @stream.stream_posts.to_json(:include => {:author => {:include => :profile}}) } + format.json{ render_for_api :backbone, :json => @stream.stream_posts, :root => :posts } end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 21d42f091..e3b6cfcae 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -16,6 +16,16 @@ class Comment < ActiveRecord::Base extract_tags_from :text before_create :build_tags + # NOTE API V1 to be extracted + acts_as_api + api_accessible :backbone do |t| + t.add :id + t.add :guid + t.add :text + t.add :author, :template => :post + end + + xml_attr :text xml_attr :diaspora_handle @@ -55,7 +65,7 @@ class Comment < ActiveRecord::Base def notification_type(user, person) if self.post.author == user.person - return Notifications::CommentOnPost + elsif self.post.comments.where(:author_id => user.person.id) != [] && self.author_id != user.person.id return Notifications::AlsoCommented else diff --git a/app/models/post.rb b/app/models/post.rb index 8c3f3e638..8a1af1210 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -16,6 +16,9 @@ class Post < ActiveRecord::Base t.add :guid t.add :text t.add :created_at + t.add :comments_count + t.add :last_three_comments + t.add :provider_display_name t.add :author, :template => :post end @@ -33,6 +36,12 @@ class Post < ActiveRecord::Base #scopes scope :includes_for_a_stream, includes(:o_embed_cache, {:author => :profile}, :mentions => {:person => :profile}) #note should include root and photos, but i think those are both on status_message + # gives the last three comments on the post + def last_three_comments + return if self.comments_count == 0 + self.comments.last(3) + end + def self.excluding_blocks(user) people = user.blocks.includes(:person).map{|b| b.person} diff --git a/app/views/shared/_stream_element.html.underscore b/app/views/shared/_stream_element.html.underscore index 8a7be0157..a9c7d9f61 100644 --- a/app/views/shared/_stream_element.html.underscore +++ b/app/views/shared/_stream_element.html.underscore @@ -1,6 +1,4 @@ -<% var post = typeof(status_message) === "undefined" ? (typeof(reshare) === "undefined" ? photo : reshare) : status_message; %> - -
+
@@ -15,37 +13,82 @@
- - + +
- - <%= post.author.profile.full_name %> + + <%= author.name %> - - - +

- <%= post.text %> + <%= text %>

- via <%= post.provider_display_name %> + via <%= provider_display_name %>
- comments +
+ + +
+
+ + +

+ +