Retrospring/app/controllers/ajax/inbox_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.5 KiB
Ruby
Raw Normal View History

2024-01-27 04:31:36 -08:00
# frozen_string_literal: true
class Ajax::InboxController < AjaxController
def remove
params.require :id
inbox = InboxEntry.find(params[:id])
unless current_user == inbox.user
@response[:status] = :fail
@response[:message] = t(".error")
return
end
begin
inbox.remove
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :err
@response[:message] = t("errors.base")
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
def remove_all
2020-04-30 10:57:39 -07:00
raise unless user_signed_in?
begin
2024-01-27 04:31:36 -08:00
InboxEntry.where(user: current_user).find_each(&:remove)
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :err
@response[:message] = t("errors.base")
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
def remove_all_author
begin
2024-01-27 04:31:36 -08:00
@target_user = User.where("LOWER(screen_name) = ?", params[:author].downcase).first!
@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)
rescue => e
2021-12-28 09:32:03 -08:00
Sentry.capture_exception(e)
@response[:status] = :err
@response[:message] = t("errors.base")
return
end
@response[:status] = :okay
@response[:message] = t(".success")
@response[:success] = true
end
2014-11-11 07:19:20 -08:00
end