Merge remote-tracking branch 'origin/master'

This commit is contained in:
Andreas N 2015-02-12 15:57:21 +01:00
commit 1c0a70165a
3 changed files with 28 additions and 1 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

View file

@ -4,7 +4,7 @@ class Notification < ActiveRecord::Base
class << self
def for(recipient, options={})
self.where(options.merge!(recipient: recipient)).order(:updated_at).reverse_order
self.where(options.merge!(recipient: recipient)).order(:created_at).reverse_order
end
def notify(recipient, target)