docbrown/app/controllers/notifications_controller.rb
Ben Halpern 86c60307d2
Small notification update (#1169)
* Small notification update

* Rescue errors in notifications
2018-11-20 20:03:55 -05:00

30 lines
1.3 KiB
Ruby

class NotificationsController < ApplicationController
# No authorization required because we provide authentication on notifications page
def index
if user_signed_in?
@notifications_index = true
@user = if params[:username] && current_user.admin?
User.find_by_username(params[:username])
else
current_user
end
if params[:filter].to_s.downcase == "posts"
@notifications = NotificationDecorator.
decorate_collection(Notification.where(user_id: current_user.id, notifiable_type: "Article", action: "Published").
order("notified_at DESC").limit(55).to_a)
elsif params[:filter].to_s.downcase == "comments"
@notifications = NotificationDecorator.
decorate_collection(Notification.where(user_id: current_user.id, notifiable_type: "Comment", action: nil). # Nil action means not reaction in this context
order("notified_at DESC").limit(55).to_a)
else
@notifications = NotificationDecorator.
decorate_collection(Notification.where(user_id: current_user.id).
order("notified_at DESC").limit(55).to_a)
end
@last_user_reaction = @user.reactions.last&.id
@last_user_comment = @user.comments.last&.id
end
end
private
end