ぼざクリタグ広場 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.
 
 
 
 
 
 

55 lines
1.5 KiB

  1. class TheatresController < ApplicationController
  2. def show
  3. theatre = Theatre.find_by(id: params[:id])
  4. return head :not_found unless theatre
  5. render json: TheatreRepr.base(theatre)
  6. end
  7. def watching
  8. return head :unauthorized unless current_user
  9. theatre = Theatre.find_by(id: params[:id])
  10. return head :not_found unless theatre
  11. host_flg = false
  12. post_id = nil
  13. post_started_at = nil
  14. theatre.with_lock do
  15. TheatreWatchingUser.find_or_initialize_by(theatre:, user: current_user).tap {
  16. _1.expires_at = 30.seconds.from_now
  17. }.save!
  18. if (!(theatre.host_user_id?) ||
  19. !(theatre.watching_users.exists?(id: theatre.host_user_id)))
  20. theatre.update!(host_user_id: current_user.id)
  21. end
  22. host_flg = theatre.host_user_id == current_user.id
  23. post_id = theatre.current_post_id
  24. post_started_at = theatre.current_post_started_at
  25. end
  26. render json: {
  27. host_flg:, post_id:, post_started_at:,
  28. watching_users: theatre.watching_users.as_json(only: [:id, :name]) }
  29. end
  30. def next_post
  31. return head :unauthorized unless current_user
  32. theatre = Theatre.find_by(id: params[:id])
  33. return head :not_found unless theatre
  34. return head :forbidden if theatre.host_user != current_user
  35. post = Post.where("url LIKE '%nicovideo.jp%'")
  36. .or(Post.where("url LIKE '%youtube.com%'"))
  37. .order('RAND()')
  38. .first
  39. theatre.update!(current_post: post, current_post_started_at: Time.current)
  40. head :no_content
  41. end
  42. end