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