2017-10-15 08:17:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-21 06:13:37 +00:00
|
|
|
class Settings::KeywordMutesController < Settings::BaseController
|
2017-10-20 20:12:45 +00:00
|
|
|
before_action :load_keyword_mute, only: [:edit, :update, :destroy]
|
2017-10-15 09:51:42 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@keyword_mutes = paginated_keyword_mutes_for_account
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@keyword_mute = keyword_mutes_for_account.build
|
|
|
|
end
|
|
|
|
|
2017-10-20 20:12:45 +00:00
|
|
|
def create
|
|
|
|
@keyword_mute = keyword_mutes_for_account.create(keyword_mute_params)
|
|
|
|
|
|
|
|
if @keyword_mute.persisted?
|
|
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @keyword_mute.update(keyword_mute_params)
|
|
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
|
|
else
|
2017-10-24 23:56:44 +00:00
|
|
|
render :edit
|
2017-10-20 20:12:45 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2017-10-24 23:56:57 +00:00
|
|
|
@keyword_mute.destroy!
|
|
|
|
|
|
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
2017-10-20 20:12:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_all
|
|
|
|
keyword_mutes_for_account.delete_all
|
|
|
|
|
|
|
|
redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg')
|
|
|
|
end
|
|
|
|
|
2017-10-15 09:51:42 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def keyword_mutes_for_account
|
2017-10-22 06:02:52 +00:00
|
|
|
Glitch::KeywordMute.where(account: current_account)
|
2017-10-15 09:51:42 +00:00
|
|
|
end
|
|
|
|
|
2017-10-20 20:12:45 +00:00
|
|
|
def load_keyword_mute
|
|
|
|
@keyword_mute = keyword_mutes_for_account.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def keyword_mute_params
|
2018-06-04 04:10:59 +00:00
|
|
|
params.require(:keyword_mute).permit(:keyword, :whole_word, :apply_to_mentions)
|
2017-10-20 20:12:45 +00:00
|
|
|
end
|
|
|
|
|
2017-10-15 09:51:42 +00:00
|
|
|
def paginated_keyword_mutes_for_account
|
|
|
|
keyword_mutes_for_account.order(:keyword).page params[:page]
|
|
|
|
end
|
2017-10-15 08:17:33 +00:00
|
|
|
end
|