Merge branch 'notifications' of git.rrerr.net:justask/justask into notifications

This commit is contained in:
pixeldesu 2014-12-14 15:43:00 +01:00
commit 834659fcfd
2 changed files with 12 additions and 1 deletions

View File

@ -16,6 +16,15 @@ class Notification < ActiveRecord::Base
make_notification(recipient, target, notif_type)
end
def denotify(recipient, target)
return nil unless target.respond_to? :notification_type
notif_type = target.notification_type
return nil unless notif_type
notif_type.find_by(recipient: recipient, target: target).destroy
end
private
def make_notification(recipient, target, notification_type)

View File

@ -67,6 +67,7 @@ class User < ActiveRecord::Base
# unfollows an user
def unfollow(target_user)
active_relationships.find_by(target: target_user).destroy
Notification.denotify target_user, relationship
# decrement counts
decrement! :friend_count
@ -90,7 +91,8 @@ class User < ActiveRecord::Base
# unsmile an answer
# @param answer [Answer] the answer to unsmile
def unsmile(answer)
Smile.find_by(user: self, answer: answer).destroy
smile = Smile.find_by(user: self, answer: answer).destroy
Notification.denotify answer.user, smile unless answer.user == self
decrement! :smiled_count
answer.decrement! :smile_count
end