diff --git a/Changelog.md b/Changelog.md index 4fe0620b90a64eab4650d26837fb52dbf190388b..a4e0c325abe1bbbce2c6fb8182d26482d3dde228 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 2616b0f76e77ff1fc3c71c2133891a104fadd962..12c999febb57bd0da85d16e30fe51625bc66d350 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 56a22decbc9b7f3c655d60e115f79832e68f6934..b1df1a917aaec83c3effcee867f6ea6a960cfcc7 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)