Extend notifications to be marked as read and unread
This commit is contained in:
@@ -86,7 +86,7 @@ class CommentsController < ApplicationController
|
||||
notifiable = comment.reply? ? comment.parent : comment.commentable
|
||||
notifiable_author_id = notifiable.try(:author_id)
|
||||
if notifiable_author_id.present? && notifiable_author_id != comment.author_id
|
||||
Notification.add(notifiable.author_id, notifiable)
|
||||
Notification.add(notifiable.author, notifiable)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,28 +2,40 @@ class NotificationsController < ApplicationController
|
||||
include CustomUrlsHelper
|
||||
|
||||
before_action :authenticate_user!
|
||||
after_action :mark_as_read, only: :show
|
||||
skip_authorization_check
|
||||
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@notifications = current_user.notifications.unread.recent.for_render
|
||||
@notifications = current_user.notifications.unread
|
||||
end
|
||||
|
||||
def show
|
||||
@notification = current_user.notifications.find(params[:id])
|
||||
@notification.mark_as_read
|
||||
redirect_to linkable_resource_path(@notification)
|
||||
end
|
||||
|
||||
def read
|
||||
@notifications = current_user.notifications.read
|
||||
end
|
||||
|
||||
def mark_all_as_read
|
||||
current_user.notifications.each { |notification| notification.mark_as_read }
|
||||
current_user.notifications.unread.each { |notification| notification.mark_as_read }
|
||||
redirect_to notifications_path
|
||||
end
|
||||
|
||||
private
|
||||
def mark_as_read
|
||||
@notification = current_user.notifications.find(params[:id])
|
||||
@notification.mark_as_read
|
||||
end
|
||||
|
||||
def mark_as_read
|
||||
@notification.mark_as_read
|
||||
end
|
||||
def mark_as_unread
|
||||
@notification = current_user.notifications.find(params[:id])
|
||||
@notification.mark_as_unread
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def linkable_resource_path(notification)
|
||||
case notification.linkable_resource.class.name
|
||||
|
||||
@@ -12,7 +12,7 @@ class ProposalNotificationsController < ApplicationController
|
||||
@proposal = Proposal.find(proposal_notification_params[:proposal_id])
|
||||
if @notification.save
|
||||
@proposal.users_to_notify.each do |user|
|
||||
Notification.add(user.id, @notification)
|
||||
Notification.add(user, @notification)
|
||||
end
|
||||
redirect_to @notification, notice: I18n.t("flash.actions.create.proposal_notification")
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user