2014-11-10 22:10:41 -08:00
|
|
|
class InboxController < ApplicationController
|
2020-04-18 16:45:50 -07:00
|
|
|
before_action :authenticate_user!
|
2014-11-11 10:53:25 -08:00
|
|
|
|
2014-11-10 22:10:41 -08:00
|
|
|
def show
|
2020-04-20 14:03:57 -07:00
|
|
|
@inbox = current_user.cursored_inbox(last_id: params[:last_id])
|
|
|
|
@inbox_last_id = @inbox.map(&:id).min
|
|
|
|
@more_data_available = !current_user.cursored_inbox(last_id: @inbox_last_id, size: 1).count.zero?
|
|
|
|
@inbox_count = current_user.inboxes.count
|
|
|
|
|
2015-07-17 11:29:19 -07:00
|
|
|
if params[:author].present?
|
|
|
|
begin
|
|
|
|
@author = true
|
2015-07-17 13:46:05 -07:00
|
|
|
@target_user = User.where('LOWER(screen_name) = ?', params[:author].downcase).first!
|
2020-04-20 14:03:57 -07:00
|
|
|
@inbox_author = @inbox.joins(:question)
|
|
|
|
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
|
|
|
@inbox_author_count = current_user.inboxes
|
|
|
|
.joins(:question)
|
|
|
|
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
|
|
|
.count
|
|
|
|
|
2015-07-17 11:29:19 -07:00
|
|
|
if @inbox_author.empty?
|
2015-07-17 13:31:10 -07:00
|
|
|
@empty = true
|
2015-07-17 12:34:53 -07:00
|
|
|
flash.now[:info] = "No questions from @#{params[:author]} found, showing default entries instead!"
|
2015-07-17 11:29:19 -07:00
|
|
|
else
|
|
|
|
@inbox = @inbox_author
|
2015-07-17 11:54:11 -07:00
|
|
|
@inbox_count = @inbox_author_count
|
2020-04-20 14:03:57 -07:00
|
|
|
@inbox_last_id = @inbox.map(&:id).min
|
|
|
|
@more_data_available = !current_user.cursored_inbox(last_id: @inbox_last_id, size: 1)
|
|
|
|
.joins(:question)
|
|
|
|
.where(questions: { user_id: @target_user.id, author_is_anonymous: false })
|
|
|
|
.count
|
|
|
|
.zero?
|
2015-07-17 11:29:19 -07:00
|
|
|
end
|
2020-04-20 14:03:57 -07:00
|
|
|
rescue => e
|
|
|
|
NewRelic::Agent.notice_error(e)
|
2015-07-17 12:34:53 -07:00
|
|
|
flash.now[:error] = "No user with the name @#{params[:author]} found, showing default entries instead!"
|
2015-07-17 12:45:45 -07:00
|
|
|
@not_found = true
|
2015-07-17 11:29:19 -07:00
|
|
|
end
|
|
|
|
end
|
2015-07-17 12:45:45 -07:00
|
|
|
|
2015-07-17 13:31:10 -07:00
|
|
|
if @empty or @not_found
|
|
|
|
@delete_id = "ib-delete-all"
|
|
|
|
elsif @author
|
|
|
|
@delete_id = "ib-delete-all-author"
|
|
|
|
else
|
|
|
|
@delete_id = "ib-delete-all"
|
|
|
|
end
|
|
|
|
|
|
|
|
@disabled = true if @inbox.empty?
|
2015-02-12 13:09:11 -08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2020-05-08 19:39:09 -07:00
|
|
|
format.js { render layout: false }
|
2015-02-12 13:09:11 -08:00
|
|
|
end
|
2014-11-10 22:10:41 -08:00
|
|
|
end
|
|
|
|
end
|