make the postman work across everything. remove lots of now useless methods

This commit is contained in:
maxwell 2011-01-05 17:35:30 -08:00
parent 5e58eba240
commit a7d651236f
14 changed files with 93 additions and 78 deletions

View file

@ -52,9 +52,9 @@ class Comment
def subscribers(user) def subscribers(user)
if user.owns?(self.post) if user.owns?(self.post)
p = user.people_in_aspects(user.aspects_with_post(self.post_id)) p = self.post.subscribers(user)
elsif user.owns?(self) elsif user.owns?(self)
p = [self.post.person] p = [self.post.person]
end end
p p
end end

View file

@ -5,8 +5,9 @@ module Jobs
def self.perform(user_id, post_id, url) def self.perform(user_id, post_id, url)
user = User.find_by_id(user_id) user = User.find_by_id(user_id)
post = Post.find_by_id(post_id) post = Post.find_by_id(post_id)
user.post_to_services(post, url) user.services.each do |s|
s.post(post, url)
end
end end
end end
end end

View file

@ -5,8 +5,9 @@ module Jobs
def self.perform(user_id, account, opts={}) def self.perform(user_id, account, opts={})
finger = Webfinger.new(account) finger = Webfinger.new(account)
begin begin
user = User.find_by_id(user_id)
result = finger.fetch result = finger.fetch
result.socket_to_uid(user_id, opts) result.socket_to_uid(user, opts)
rescue rescue
Diaspora::WebSocket.queue_to_user(user_id, Diaspora::WebSocket.queue_to_user(user_id,
{:class => 'people', {:class => 'people',

View file

@ -29,8 +29,8 @@ class Notification
:kind => kind, :kind => kind,
:person_id => person.id, :person_id => person.id,
:user_id => user.id) :user_id => user.id)
n.socket_to_uid(user.id) if n
n.email_the_user(object) unless user.disable_mail || !n n.email_the_user(object) unless user.disable_mail || !n
n.socket_to_uid(user) if n
n n
end end
end end

View file

@ -157,7 +157,7 @@ class User
self.raw_visible_posts << post self.raw_visible_posts << post
self.save self.save
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid post.socket_to_uid(self, :aspect_ids => aspect_ids) if post.respond_to? :socket_to_uid
target_aspects = aspects_from_ids(aspect_ids) target_aspects = aspects_from_ids(aspect_ids)
target_aspects.each do |aspect| target_aspects.each do |aspect|
aspect.posts << post aspect.posts << post
@ -198,28 +198,6 @@ class User
def dispatch_comment(comment) def dispatch_comment(comment)
mailman = Postzord::Dispatch.new(self, comment) mailman = Postzord::Dispatch.new(self, comment)
mailman.post mailman.post
#if owns? comment.post
##push DOWNSTREAM (to original audience)
#Rails.logger.info "event=dispatch_comment direction=downstream user=#{self.diaspora_handle} comment=#{comment.id}"
#aspects = aspects_with_post(comment.post_id)
##just socket to local users, as the comment has already
##been associated and saved by post owner
## (we'll push to all of their aspects for now, the comment won't
## show up via js where corresponding posts are not present)
#people_in_aspects(aspects, :type => 'local').each do |person|
#comment.socket_to_uid(person.owner_id, :aspect_ids => 'all')
#end
##push to remote people
#push_to_people(comment, people_in_aspects(aspects, :type => 'remote'))
#elsif owns? comment
##push UPSTREAM (to poster)
#Rails.logger.info "event=dispatch_comment direction=upstream user=#{self.diaspora_handle} comment=#{comment.id}"
#push_to_people comment, [comment.post.person]
#end
end end
######### Mailer ####################### ######### Mailer #######################
@ -234,8 +212,8 @@ class User
aspect_ids = aspects_with_post(post.id) aspect_ids = aspects_with_post(post.id)
aspect_ids.map! { |aspect| aspect.id.to_s } aspect_ids.map! { |aspect| aspect.id.to_s }
post.unsocket_from_uid(self.id, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid
retraction = Retraction.for(post) retraction = Retraction.for(post)
post.unsocket_from_uid(self, retraction, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid
mailman = Postzord::Dispatch.new(self, retraction) mailman = Postzord::Dispatch.new(self, retraction)
mailman.post mailman.post

View file

@ -59,8 +59,6 @@ module Diaspora
receive_object(object, person) receive_object(object, person)
Rails.logger.info("event=receive status=complete recipient=#{self.diaspora_handle} sender=#{salmon_author.diaspora_handle} payload_type#{object.class}") Rails.logger.info("event=receive status=complete recipient=#{self.diaspora_handle} sender=#{salmon_author.diaspora_handle} payload_type#{object.class}")
return object return object
end end
end end
@ -92,7 +90,7 @@ module Diaspora
end end
disconnected_by visible_person_by_id(retraction.post_id) disconnected_by visible_person_by_id(retraction.post_id)
else else
retraction.perform self.id retraction.perform self
aspects = self.aspects_with_person(retraction.person) aspects = self.aspects_with_person(retraction.person)
aspects.each{ |aspect| aspect.post_ids.delete(retraction.post_id.to_id) aspects.each{ |aspect| aspect.post_ids.delete(retraction.post_id.to_id)
aspect.save aspect.save
@ -138,7 +136,7 @@ module Diaspora
dispatch_comment comment dispatch_comment comment
end end
comment.socket_to_uid(self.id, :aspect_ids => comment.post.aspect_ids) comment.socket_to_uid(self, :aspect_ids => comment.post.aspect_ids)
comment comment
end end
@ -146,7 +144,7 @@ module Diaspora
post.class.find_by_id(post.id) post.class.find_by_id(post.id)
end end
def receive_post post def receive_post(post)
#exsists locally, but you dont know about it #exsists locally, but you dont know about it
#does not exsist locally, and you dont know about it #does not exsist locally, and you dont know about it
@ -191,7 +189,7 @@ module Diaspora
aspect.posts << post aspect.posts << post
aspect.save aspect.save
end end
post.socket_to_uid(id, :aspect_ids => aspects.map{|x| x.id}) if (post.respond_to?(:socket_to_uid) && !self.owns?(post)) post.socket_to_uid(self, :aspect_ids => aspects.map{|x| x.id}) if (post.respond_to?(:socket_to_uid) && !self.owns?(post))
post post
end end
end end

View file

@ -49,12 +49,12 @@ module Diaspora
end end
module Socketable module Socketable
def socket_to_uid(id, opts={}) def socket_to_uid(user, opts={})
SocketsController.new.outgoing(id, self, opts) SocketsController.new.outgoing(user, self, opts)
end end
def unsocket_from_uid(id, opts={}) def unsocket_from_uid(user, retraction, opts={})
SocketsController.new.outgoing(id, Retraction.for(self), opts) SocketsController.new.outgoing(user, retraction, opts)
end end
end end
end end

View file

@ -98,10 +98,12 @@ describe Comment do
end end
end end
describe 'comment propagation' do context 'comment propagation' do
before do before do
@person = Factory.create(:person) @person = Factory.create(:person)
user.activate_contact(@person, Aspect.first(:id => aspect.id)) user.activate_contact(@person, Aspect.first(:id => aspect.id))
@person3 = Factory.create(:person)
user.activate_contact(@person3, Aspect.first(:id => aspect.id))
@person2 = Factory.create(:person) @person2 = Factory.create(:person)
@person_status = Factory.build(:status_message, :person => @person) @person_status = Factory.build(:status_message, :person => @person)
@ -119,17 +121,20 @@ describe Comment do
Postzord::Dispatch.should_receive(:new).and_return(m) Postzord::Dispatch.should_receive(:new).and_return(m)
user.comment "yo", :on => @person_status user.comment "yo", :on => @person_status
end end
describe '#subscribers' do describe '#subscribers' do
it 'returns the posts original audience, if the post is owned by the user' do it 'returns the posts original audience, if the post is owned by the user' do
comment = user.build_comment "yo", :on => @person_status
comment.subscribers(user).should =~ [@person]
end end
it 'returns the owner of the original post, if the user owns the comment' do it 'returns the owner of the original post, if the user owns the comment' do
comment = user.build_comment "yo", :on => @user_status
comment.subscribers(user).should =~ [@person, @person3, user2.person]
end end
end end
context 'testing a method only used for testing' do
it "should send a user's comment on a person's post to that person" do it "should send a user's comment on a person's post to that person" do
m = mock() m = mock()
m.stub!(:post) m.stub!(:post)
@ -137,31 +142,7 @@ describe Comment do
user.comment "yo", :on => @person_status user.comment "yo", :on => @person_status
end end
end
#context 'posts from a remote person' do
#before(:all) do
#stub_comment_signature_verification
#end
#before do
#@mailman = Postzord::Dipatch.new(user, @person_status)
#end
#it 'should not send a comment a person made on his own post to anyone' do
#@mailman.should_not_receive(:deliver_to_local)
#comment = Comment.new(:person_id => @person.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
#user.receive comment.to_diaspora_xml, @person
#end
#it 'should not send a comment a person made on a person post to anyone' do
#@mailman.should_not_receive(:deliver_to_local)
#comment = Comment.new(:person_id => @person2.id, :diaspora_handle => @person.diaspora_handle, :text => "cats", :post => @person_status)
#user.receive comment.to_diaspora_xml, @person
#end
#after(:all) do
#unstub_mocha_stubs
#end
#end
it 'should not clear the aspect post array on receiving a comment' do it 'should not clear the aspect post array on receiving a comment' do
aspect.post_ids.include?(@user_status.id).should be true aspect.post_ids.include?(@user_status.id).should be true

View file

@ -6,9 +6,10 @@ describe Jobs::PostToServices do
aspect = user.aspects.create(:name => "yeah") aspect = user.aspects.create(:name => "yeah")
post = user.post(:status_message, :message => 'foo', :to => aspect.id) post = user.post(:status_message, :message => 'foo', :to => aspect.id)
User.stub!(:find_by_id).with(user.id.to_s).and_return(user) User.stub!(:find_by_id).with(user.id.to_s).and_return(user)
user.stub!(:services).and_return([]) m = mock()
user.should_receive(:post_to_services)
url = "foobar" url = "foobar"
m.should_receive(:post).with(anything, url)
user.stub!(:services).and_return([m])
Jobs::PostToServices.perform(user.id.to_s, post.id.to_s, url) Jobs::PostToServices.perform(user.id.to_s, post.id.to_s, url)
end end
end end

View file

@ -36,4 +36,13 @@ describe Post do
post.mutable?.should == false post.mutable?.should == false
end end
end end
describe '#subscribers' do
it 'returns the people contained in the aspects the post appears in' do
post = @user.post :status_message, :message => "hello", :to => @aspect.id
post.subscribers(@user).should =~ []
end
end
end end

View file

@ -74,6 +74,20 @@ describe Profile do
end end
end end
describe '#subscribers' do
it 'returns all non-pending contacts for a user' do
user = make_user
aspect = user.aspects.create(:name => "zord")
person = Factory.create(:person)
user.activate_contact(person, Aspect.first(:id => aspect.id))
person2 = Factory.create(:person)
user.activate_contact(person2, Aspect.first(:id => aspect.id))
user.profile.subscribers(user).should =~ [person, person2]
end
end
describe 'date=' do describe 'date=' do
let(:profile) { make_user.profile } let(:profile) { make_user.profile }

View file

@ -80,6 +80,7 @@ describe Request do
Request.from(@user).to(@user2.person).first.should == @request Request.from(@user).to(@user2.person).first.should == @request
end end
end end
describe '#notification_type' do describe '#notification_type' do
before do before do
@request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect) @request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
@ -94,6 +95,13 @@ describe Request do
end end
end end
describe '#subscribers' do
it 'returns an array with to field on a request' do
request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
request.subscribers(@user).should =~ [@user2.person]
end
end
describe '.hashes_for_person' do describe '.hashes_for_person' do
before do before do
@user = make_user @user = make_user

View file

@ -20,14 +20,38 @@ describe Retraction do
end end
end end
describe 'dispatching' do describe '#subscribers' do
it 'should dispatch a message on delete' do it 'returns the subscribers to the post for all objects other than person' do
Factory.create(:person) retraction = Retraction.for(post)
m = mock() obj = retraction.instance_variable_get(:@object)
m.should_receive(:post) wanted_subscribers = obj.subscribers(user)
Postzord::Dispatch.should_receive(:new).and_return(m) obj.should_receive(:subscribers).with(user).and_return(wanted_subscribers)
post.destroy retraction.subscribers(user).should =~ wanted_subscribers
end
context 'hax' do
it 'barfs if the type is a person, and subscribers instance varabile is not set' do
retraction = Retraction.for(user)
obj = retraction.instance_variable_get(:@object)
proc{retraction.subscribers(user)}.should raise_error
end
it 'returns manually set subscribers' do
retraction = Retraction.for(user)
retraction.subscribers = "fooey"
retraction.subscribers(user).should == 'fooey'
end
end end
end end
describe 'dispatching' do
it 'should dispatch a retraction on delete' do
Factory.create(:person)
m = mock()
m.should_receive(:post)
Postzord::Dispatch.should_receive(:new).with(instance_of(User), instance_of(Retraction)).and_return(m)
post.destroy
end
end
end end

View file

@ -38,7 +38,7 @@ describe User do
end end
it 'sockets the post to the poster' do it 'sockets the post to the poster' do
@post.should_receive(:socket_to_uid).with(user.id, anything) @post.should_receive(:socket_to_uid).with(user, anything)
user.add_to_streams(@post, @aspect_ids) user.add_to_streams(@post, @aspect_ids)
end end
end end