attempt to add muting of notifications when post has a hidden visibility; i am getting a load path error in resque now, but that seems to be independent of this commit
This commit is contained in:
parent
9a1fe2ea80
commit
91eabf0fce
2 changed files with 24 additions and 3 deletions
|
|
@ -25,9 +25,13 @@ class Notification < ActiveRecord::Base
|
|||
else
|
||||
n = note_type.make_notification(recipient, target, actor, note_type)
|
||||
end
|
||||
n.email_the_user(target, actor) if n
|
||||
n.socket_to_user(recipient, :actor => actor) if n
|
||||
n
|
||||
if n
|
||||
n.email_the_user(target, actor) if n
|
||||
n.socket_to_user(recipient, :actor => actor) if n
|
||||
n
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -43,6 +47,7 @@ class Notification < ActiveRecord::Base
|
|||
|
||||
private
|
||||
def self.concatenate_or_create(recipient, target, actor, notification_type)
|
||||
return nil if post_visiblity_is_hidden?(recipient, target)
|
||||
if n = notification_type.where(:target_id => target.id,
|
||||
:target_type => target.class.base_class,
|
||||
:recipient_id => recipient.id,
|
||||
|
|
@ -61,7 +66,9 @@ private
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
def self.make_notification(recipient, target, actor, notification_type)
|
||||
return nil if post_visiblity_is_hidden?(recipient, target)
|
||||
n = notification_type.new(:target => target,
|
||||
:recipient_id => recipient.id)
|
||||
n.actors = n.actors | [actor]
|
||||
|
|
@ -69,4 +76,11 @@ private
|
|||
n.save!
|
||||
n
|
||||
end
|
||||
|
||||
def self.post_visiblity_is_hidden?(recipient, post)
|
||||
contact = recipient.contact_for(post.author)
|
||||
return false unless contact && recipient && post
|
||||
pv = PostVisibility.where(:contact_id => contact.id, :post_id => post.id).first
|
||||
pv.present? ? pv.hidden? : false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ describe Notification do
|
|||
Notification.notify(@user, @sm, @person)
|
||||
end
|
||||
|
||||
it 'does not create a notification if the post visibility is hidden' do
|
||||
Notification.stub(:post_visiblity_is_hidden).and_return(true)
|
||||
expect{
|
||||
Notification.notify(@user, @sm, @person)
|
||||
}.to change(Notification, :count).by(0)
|
||||
end
|
||||
|
||||
context 'with a request' do
|
||||
before do
|
||||
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||
|
|
|
|||
Loading…
Reference in a new issue