Merge branch 'notifications' of git.rrerr.net:justask/justask into notifications
This commit is contained in:
commit
834659fcfd
|
@ -16,6 +16,15 @@ class Notification < ActiveRecord::Base
|
||||||
make_notification(recipient, target, notif_type)
|
make_notification(recipient, target, notif_type)
|
||||||
end
|
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
|
private
|
||||||
|
|
||||||
def make_notification(recipient, target, notification_type)
|
def make_notification(recipient, target, notification_type)
|
||||||
|
|
|
@ -67,6 +67,7 @@ class User < ActiveRecord::Base
|
||||||
# unfollows an user
|
# unfollows an user
|
||||||
def unfollow(target_user)
|
def unfollow(target_user)
|
||||||
active_relationships.find_by(target: target_user).destroy
|
active_relationships.find_by(target: target_user).destroy
|
||||||
|
Notification.denotify target_user, relationship
|
||||||
|
|
||||||
# decrement counts
|
# decrement counts
|
||||||
decrement! :friend_count
|
decrement! :friend_count
|
||||||
|
@ -90,7 +91,8 @@ class User < ActiveRecord::Base
|
||||||
# unsmile an answer
|
# unsmile an answer
|
||||||
# @param answer [Answer] the answer to unsmile
|
# @param answer [Answer] the answer to unsmile
|
||||||
def unsmile(answer)
|
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
|
decrement! :smiled_count
|
||||||
answer.decrement! :smile_count
|
answer.decrement! :smile_count
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue