Skip to content
Extraits de code Groupes Projets
Valider 6e74ee7d rédigé par theworldbright's avatar theworldbright Validation de Jonne Haß
Parcourir les fichiers

Make PostPresenter inherit from BasePresenter

closes #6315
parent 335b1c32
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
* Refactor HomeController#toggle\_mobile [#6260](https://github.com/diaspora/diaspora/pull/6260) * 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 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) * 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 ## Bug fixes
* Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212) * Fix indentation and a link title on the default home page [#6212](https://github.com/diaspora/diaspora/pull/6212)
......
...@@ -7,7 +7,7 @@ class PostInteractionPresenter ...@@ -7,7 +7,7 @@ class PostInteractionPresenter
def as_json(_options={}) def as_json(_options={})
{ {
likes: as_api(@post.likes), 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")), comments: CommentPresenter.as_collection(@post.comments.order("created_at ASC")),
participations: as_api(participations), participations: as_api(participations),
comments_count: @post.comments_count, comments_count: @post.comments_count,
......
class PostPresenter class PostPresenter < BasePresenter
include PostsHelper include PostsHelper
attr_accessor :post, :current_user attr_accessor :post
def initialize(post, current_user=nil) def initialize(post, current_user=nil)
@post = post @post = post
@current_user = current_user @current_user = current_user
end end
def self.collection_json(collection, current_user)
collection.map {|post| PostPresenter.new(post, current_user) }
end
def as_json(_options={}) def as_json(_options={})
@post.include_root_in_json = false @post.include_root_in_json = false
@post.as_json(only: directly_retrieved_attributes).merge(non_directly_retrieved_attributes) @post.as_json(only: directly_retrieved_attributes).merge(non_directly_retrieved_attributes)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter