diff --git a/app/models/notification.rb b/app/models/notification.rb index 0c681579..d5c0a3b1 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index b3b5982d..6ef2dff6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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