2019-08-30 08:02:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class Settings::AccountSubscribesController < Settings::BaseController
|
|
|
|
layout 'admin'
|
|
|
|
|
|
|
|
before_action :authenticate_user!
|
2020-01-05 06:36:28 +00:00
|
|
|
before_action :set_lists, only: [:index, :new, :edit, :update]
|
2019-08-30 08:02:41 +00:00
|
|
|
before_action :set_account_subscribings, only: :index
|
2020-01-05 06:36:28 +00:00
|
|
|
before_action :set_account_subscribing, only: [:edit, :update, :destroy]
|
2019-08-30 08:02:41 +00:00
|
|
|
|
2020-01-05 06:36:28 +00:00
|
|
|
def index
|
2019-08-30 08:02:41 +00:00
|
|
|
end
|
|
|
|
|
2020-01-05 06:36:28 +00:00
|
|
|
def new
|
|
|
|
@form_account_subscribing = Form::AccountSubscribe.new
|
2019-08-30 08:02:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-01-05 06:36:28 +00:00
|
|
|
@form_account_subscribing = Form::AccountSubscribe.new(account_subscribe_params)
|
2020-07-15 02:27:18 +00:00
|
|
|
target_account = AccountSubscribeService.new.call(current_account, @form_account_subscribing.acct, { show_reblogs: @form_account_subscribing.show_reblogs, list_id: @form_account_subscribing.list_id })
|
2019-08-30 08:02:41 +00:00
|
|
|
|
|
|
|
if target_account
|
|
|
|
redirect_to settings_account_subscribes_path
|
|
|
|
else
|
|
|
|
set_account_subscribings
|
|
|
|
|
|
|
|
render :index
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-05 06:36:28 +00:00
|
|
|
def edit; end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @account_subscribing.update(account_subscribe_params.merge(account: current_account))
|
|
|
|
redirect_to settings_account_subscribes_path
|
|
|
|
else
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-30 08:02:41 +00:00
|
|
|
def destroy
|
2020-03-21 04:25:30 +00:00
|
|
|
UnsubscribeAccountService.new.call(current_account, @account_subscribing.target_account, @account_subscribing.list_id)
|
2019-08-30 08:02:41 +00:00
|
|
|
redirect_to settings_account_subscribes_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-01-05 06:36:28 +00:00
|
|
|
def set_account_subscribing
|
|
|
|
@account_subscribing = current_account.active_subscribes.find(params[:id])
|
|
|
|
@form_account_subscribing = Form::AccountSubscribe.new(id: @account_subscribing.id, acct: @account_subscribing.target_account.acct, show_reblogs: @account_subscribing.show_reblogs, list_id: @account_subscribing.list_id)
|
|
|
|
end
|
|
|
|
|
2019-08-30 08:02:41 +00:00
|
|
|
def set_account_subscribings
|
2020-01-05 06:36:28 +00:00
|
|
|
@account_subscribings = current_account.active_subscribes.order('list_id NULLS FIRST', :updated_at).reject(&:new_record?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_lists
|
|
|
|
@lists = List.where(account: current_account).all
|
2019-08-30 08:02:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def account_subscribe_params
|
2020-01-05 06:36:28 +00:00
|
|
|
new_params = resource_params.permit!.to_h
|
|
|
|
|
|
|
|
if resource_params[:list_id] == '-1'
|
|
|
|
list = List.find_or_create_by!({ account: current_account, title: new_params[:acct] })
|
|
|
|
new_params.merge!({list_id: list.id})
|
|
|
|
end
|
|
|
|
|
|
|
|
new_params
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_params
|
|
|
|
params.require(:form_account_subscribe).permit(:acct, :show_reblogs, :list_id)
|
2019-08-30 08:02:41 +00:00
|
|
|
end
|
|
|
|
end
|