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)
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)
p = [self.post.person]
p = [self.post.person]
end
p
end

View file

@ -5,8 +5,9 @@ module Jobs
def self.perform(user_id, post_id, url)
user = User.find_by_id(user_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

View file

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

View file

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

View file

@ -157,7 +157,7 @@ class User
self.raw_visible_posts << post
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.each do |aspect|
aspect.posts << post
@ -198,28 +198,6 @@ class User
def dispatch_comment(comment)
mailman = Postzord::Dispatch.new(self, comment)
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
######### Mailer #######################
@ -234,8 +212,8 @@ class User
aspect_ids = aspects_with_post(post.id)
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)
post.unsocket_from_uid(self, retraction, :aspect_ids => aspect_ids) if post.respond_to? :unsocket_from_uid
mailman = Postzord::Dispatch.new(self, retraction)
mailman.post

View file

@ -59,8 +59,6 @@ module Diaspora
receive_object(object, person)
Rails.logger.info("event=receive status=complete recipient=#{self.diaspora_handle} sender=#{salmon_author.diaspora_handle} payload_type#{object.class}")
return object
end
end
@ -92,7 +90,7 @@ module Diaspora
end
disconnected_by visible_person_by_id(retraction.post_id)
else
retraction.perform self.id
retraction.perform self
aspects = self.aspects_with_person(retraction.person)
aspects.each{ |aspect| aspect.post_ids.delete(retraction.post_id.to_id)
aspect.save
@ -138,7 +136,7 @@ module Diaspora
dispatch_comment comment
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
end
@ -146,7 +144,7 @@ module Diaspora
post.class.find_by_id(post.id)
end
def receive_post post
def receive_post(post)
#exsists locally, but 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.save
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
end
end

View file

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

View file

@ -98,10 +98,12 @@ describe Comment do
end
end
describe 'comment propagation' do
context 'comment propagation' do
before do
@person = Factory.create(:person)
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)
@person_status = Factory.build(:status_message, :person => @person)
@ -120,16 +122,19 @@ describe Comment do
user.comment "yo", :on => @person_status
end
describe '#subscribers' 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
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
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
m = mock()
m.stub!(:post)
@ -137,31 +142,7 @@ describe Comment do
user.comment "yo", :on => @person_status
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
end
it 'should not clear the aspect post array on receiving a comment' do
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")
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!(:services).and_return([])
user.should_receive(:post_to_services)
m = mock()
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)
end
end

View file

@ -36,4 +36,13 @@ describe Post do
post.mutable?.should == false
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

View file

@ -74,6 +74,20 @@ describe Profile do
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
let(:profile) { make_user.profile }

View file

@ -80,6 +80,7 @@ describe Request do
Request.from(@user).to(@user2.person).first.should == @request
end
end
describe '#notification_type' do
before do
@request = Request.instantiate(:from => @user.person, :to => @user2.person, :into => @aspect)
@ -94,6 +95,13 @@ describe Request do
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
before do
@user = make_user

View file

@ -20,14 +20,38 @@ describe Retraction do
end
end
describe 'dispatching' do
it 'should dispatch a message on delete' do
Factory.create(:person)
m = mock()
m.should_receive(:post)
Postzord::Dispatch.should_receive(:new).and_return(m)
post.destroy
describe '#subscribers' do
it 'returns the subscribers to the post for all objects other than person' do
retraction = Retraction.for(post)
obj = retraction.instance_variable_get(:@object)
wanted_subscribers = obj.subscribers(user)
obj.should_receive(:subscribers).with(user).and_return(wanted_subscribers)
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
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

View file

@ -38,7 +38,7 @@ describe User do
end
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)
end
end