2024-01-27 04:31:36 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
class Ajax::InboxController < AjaxController
|
2014-11-30 09:05:51 -08:00
|
|
|
def remove
|
|
|
|
params.require :id
|
|
|
|
|
2024-01-27 04:02:58 -08:00
|
|
|
inbox = InboxEntry.find(params[:id])
|
2014-11-30 09:05:51 -08:00
|
|
|
|
|
|
|
unless current_user == inbox.user
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :fail
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t(".error")
|
2014-11-30 09:05:51 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
begin
|
|
|
|
inbox.remove
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t("errors.base")
|
2014-11-30 09:05:51 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:success] = true
|
2014-11-30 09:05:51 -08:00
|
|
|
end
|
2014-12-21 04:41:57 -08:00
|
|
|
|
|
|
|
def remove_all
|
2020-04-30 10:57:39 -07:00
|
|
|
raise unless user_signed_in?
|
|
|
|
|
2014-12-21 04:41:57 -08:00
|
|
|
begin
|
2024-01-27 04:31:36 -08:00
|
|
|
InboxEntry.where(user: current_user).find_each(&:remove)
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t("errors.base")
|
2014-12-21 04:41:57 -08:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:success] = true
|
2014-12-21 04:41:57 -08:00
|
|
|
end
|
2015-07-17 11:29:19 -07:00
|
|
|
|
|
|
|
def remove_all_author
|
|
|
|
begin
|
2024-01-27 04:31:36 -08:00
|
|
|
@target_user = User.where("LOWER(screen_name) = ?", params[:author].downcase).first!
|
2024-01-27 04:04:29 -08:00
|
|
|
@inbox = current_user.inbox_entries.joins(:question)
|
2024-01-27 04:31:36 -08:00
|
|
|
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
|
|
|
@inbox.each(&:remove)
|
2020-04-28 11:32:36 -07:00
|
|
|
rescue => e
|
2021-12-28 09:32:03 -08:00
|
|
|
Sentry.capture_exception(e)
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :err
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t("errors.base")
|
2015-07-17 11:29:19 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:status] = :okay
|
2022-07-06 01:29:05 -07:00
|
|
|
@response[:message] = t(".success")
|
2020-04-28 11:27:59 -07:00
|
|
|
@response[:success] = true
|
2015-07-17 11:29:19 -07:00
|
|
|
end
|
2014-11-11 07:19:20 -08:00
|
|
|
end
|