From 6e74ee7d21ef53a44d98e853a2e1ffcb628a5012 Mon Sep 17 00:00:00 2001 From: theworldbright Date: Fri, 21 Aug 2015 10:24:42 -0700 Subject: [PATCH] Make PostPresenter inherit from BasePresenter closes #6315 --- Changelog.md | 1 + app/presenters/post_interaction_presenter.rb | 2 +- app/presenters/post_presenter.rb | 8 ++------ 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4fe0620b9..a4e0c325a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,7 @@ * Refactor HomeController#toggle\_mobile [#6260](https://github.com/diaspora/diaspora/pull/6260) * Extract CommentService from CommentsController [#6307](https://github.com/diaspora/diaspora/pull/6307) * Extract user/profile discovery into the diaspora\_federation-rails gem [#6310](https://github.com/diaspora/diaspora/pull/6310) +* Refactor PostPresenter [#6315](https://github.com/diaspora/diaspora/pull/6315) ## Bug fixes * Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212) diff --git a/app/presenters/post_interaction_presenter.rb b/app/presenters/post_interaction_presenter.rb index 2616b0f76..12c999feb 100644 --- a/app/presenters/post_interaction_presenter.rb +++ b/app/presenters/post_interaction_presenter.rb @@ -7,7 +7,7 @@ class PostInteractionPresenter def as_json(_options={}) { likes: as_api(@post.likes), - reshares: PostPresenter.collection_json(@post.reshares, @current_user), + reshares: PostPresenter.as_collection(@post.reshares, :as_json, @current_user), comments: CommentPresenter.as_collection(@post.comments.order("created_at ASC")), participations: as_api(participations), comments_count: @post.comments_count, diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 56a22decb..b1df1a917 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -1,17 +1,13 @@ -class PostPresenter +class PostPresenter < BasePresenter include PostsHelper - attr_accessor :post, :current_user + attr_accessor :post def initialize(post, current_user=nil) @post = post @current_user = current_user end - def self.collection_json(collection, current_user) - collection.map {|post| PostPresenter.new(post, current_user) } - end - def as_json(_options={}) @post.include_root_in_json = false @post.as_json(only: directly_retrieved_attributes).merge(non_directly_retrieved_attributes)