added denotify method
This commit is contained in:
parent
91711b24fe
commit
622af3490c
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue