ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

22 lines
475 B

  1. # frozen_string_literal: true
  2. module PostRepr
  3. BASE = { include: { tags: TagRepr::BASE, uploaded_user: UserRepr::BASE },
  4. methods: [:parent_posts] }.freeze
  5. module_function
  6. def base post, current_user = nil
  7. json = post.as_json(BASE)
  8. return json.merge(viewed: false) unless current_user
  9. viewed = current_user.viewed?(post)
  10. json.merge(viewed:)
  11. end
  12. def many posts, current_user = nil
  13. posts.map { |p| base(p, current_user) }
  14. end
  15. end