automatically mark notifications as read

This commit is contained in:
nilsding 2015-02-10 06:53:50 +01:00
parent 87cfff8809
commit 31d8e68725
2 changed files with 27 additions and 0 deletions

View File

@ -2,5 +2,23 @@ class AnswerController < ApplicationController
def show
@answer = Answer.find(params[:id])
@display_all = true
if user_signed_in?
notif = Notification.where(target_type: "Answer", target_id: @answer.id, recipient_id: current_user.id, new: true).first
unless notif.nil?
notif.new = false
notif.save
end
notif = Notification.where(target_type: "Comment", target_id: @answer.comments.pluck(:id), recipient_id: current_user.id, new: true).first
unless notif.nil?
notif.new = false
notif.save
end
notif = Notification.where(target_type: "Smile", target_id: @answer.smiles.pluck(:id), recipient_id: current_user.id, new: true).first
unless notif.nil?
notif.new = false
notif.save
end
end
end
end

View File

@ -4,6 +4,15 @@ class UserController < ApplicationController
def show
@user = User.where('LOWER(screen_name) = ?', params[:username].downcase).first!
@answers = @user.answers.reverse_order.paginate(page: params[:page])
if user_signed_in?
notif = Notification.where(target_type: "Relationship", target_id: @user.active_relationships.where(target_id: current_user.id).pluck(:id), recipient_id: current_user.id, new: true).first
unless notif.nil?
notif.new = false
notif.save
end
end
respond_to do |format|
format.html
format.js