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.

61 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class Settings::KeywordMutesController < Settings::BaseController
  3. before_action :load_keyword_mute, only: [:edit, :update, :destroy]
  4. def index
  5. @keyword_mutes = paginated_keyword_mutes_for_account
  6. end
  7. def new
  8. @keyword_mute = keyword_mutes_for_account.build
  9. end
  10. def create
  11. @keyword_mute = keyword_mutes_for_account.create(keyword_mute_params)
  12. if @keyword_mute.persisted?
  13. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  14. else
  15. render :new
  16. end
  17. end
  18. def update
  19. if @keyword_mute.update(keyword_mute_params)
  20. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  21. else
  22. render :edit
  23. end
  24. end
  25. def destroy
  26. @keyword_mute.destroy!
  27. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  28. end
  29. def destroy_all
  30. keyword_mutes_for_account.delete_all
  31. redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
  32. end
  33. private
  34. def keyword_mutes_for_account
  35. Glitch::KeywordMute.where(account: current_account)
  36. end
  37. def load_keyword_mute
  38. @keyword_mute = keyword_mutes_for_account.find(params[:id])
  39. end
  40. def keyword_mute_params
  41. params.require(:keyword_mute).permit(:keyword, :whole_word)
  42. end
  43. def paginated_keyword_mutes_for_account
  44. keyword_mutes_for_account.order(:keyword).page params[:page]
  45. end
  46. end