1
0

announcements_controller.rb 755 B

1234567891011121314151617181920212223242526272829
  1. # frozen_string_literal: true
  2. class Api::V1::AnnouncementsController < Api::BaseController
  3. before_action -> { doorkeeper_authorize! :write, :'write:accounts' }, only: :dismiss
  4. before_action :require_user!
  5. before_action :set_announcements, only: :index
  6. before_action :set_announcement, except: :index
  7. def index
  8. render json: @announcements, each_serializer: REST::AnnouncementSerializer
  9. end
  10. def dismiss
  11. AnnouncementMute.find_or_create_by!(account: current_account, announcement: @announcement)
  12. render_empty
  13. end
  14. private
  15. def set_announcements
  16. @announcements = begin
  17. Announcement.published.chronological
  18. end
  19. end
  20. def set_announcement
  21. @announcement = Announcement.published.find(params[:id])
  22. end
  23. end