Change prune_aspect_ids to aspects_from_ids, seperate out non-backgroundable piece of posting from dispatch_post
This commit is contained in:
parent
e63a29be64
commit
836b5685f7
4 changed files with 34 additions and 21 deletions
|
|
@ -46,6 +46,7 @@ class PhotosController < ApplicationController
|
|||
if @photo.save
|
||||
raise 'MongoMapper failed to catch a failed save' unless @photo.id
|
||||
|
||||
current_user.add_to_streams(@photo, params[:photo][:aspect_ids])
|
||||
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids]) unless @photo.pending
|
||||
respond_to do |format|
|
||||
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@ class StatusMessagesController < ApplicationController
|
|||
raise 'MongoMapper failed to catch a failed save' unless @status_message.id
|
||||
|
||||
@status_message.photos += photos unless photos.nil?
|
||||
current_user.add_to_streams(post, params[:status_message][:aspect_ids])
|
||||
current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids])
|
||||
|
||||
for photo in photos
|
||||
current_user.add_to_streams(photo, params[:status_message][:aspect_ids])
|
||||
current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -147,6 +147,7 @@ class User
|
|||
|
||||
if post.save
|
||||
raise 'MongoMapper failed to catch a failed save' unless post.id
|
||||
add_to_streams(post, opts[:to])
|
||||
dispatch_post(post, :to => opts[:to])
|
||||
end
|
||||
post
|
||||
|
|
@ -163,10 +164,6 @@ class User
|
|||
def dispatch_post(post, opts = {})
|
||||
aspect_ids = opts.delete(:to)
|
||||
|
||||
aspect_ids = prune_aspect_ids(aspect_ids)
|
||||
self.raw_visible_posts << post
|
||||
self.save
|
||||
|
||||
#socket post
|
||||
Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}")
|
||||
push_to_aspects(post, aspect_ids)
|
||||
|
|
@ -199,14 +196,27 @@ class User
|
|||
end
|
||||
end
|
||||
|
||||
def prune_aspect_ids(aspect_ids)
|
||||
return aspect_ids if aspect_ids == "all"
|
||||
if aspect_ids.respond_to? :to_id
|
||||
aspect_ids = [aspect_ids]
|
||||
end
|
||||
def add_to_streams(post, aspect_ids)
|
||||
self.raw_visible_posts << post
|
||||
self.save
|
||||
|
||||
aspect_ids.map!{ |x| x.to_id }
|
||||
aspects.map{ |x| x.id } & aspect_ids
|
||||
target_aspects = aspects_from_ids(aspect_ids)
|
||||
target_aspects.each do |aspect|
|
||||
aspect.posts << post
|
||||
aspect.save
|
||||
end
|
||||
end
|
||||
|
||||
def aspects_from_ids(aspect_ids)
|
||||
if aspect_ids == "all" || aspect_ids == :all
|
||||
self.aspects
|
||||
else
|
||||
if aspect_ids.respond_to? :to_id
|
||||
aspect_ids = [aspect_ids]
|
||||
end
|
||||
aspect_ids.map!{ |x| x.to_id }
|
||||
aspects.all(:id.in => aspect_ids)
|
||||
end
|
||||
end
|
||||
|
||||
def push_to_aspects(post, aspect_ids)
|
||||
|
|
@ -221,8 +231,6 @@ class User
|
|||
target_contacts = []
|
||||
|
||||
aspects.each { |aspect|
|
||||
aspect.posts << post
|
||||
aspect.save
|
||||
target_contacts = target_contacts | aspect.contacts
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,8 @@ describe User do
|
|||
let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
|
||||
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }
|
||||
|
||||
describe '#add_to_stream' do
|
||||
describe '#add_to_streams' do
|
||||
before do
|
||||
pending "not implemented"
|
||||
@params = {:message => "hey", :to => [aspect.id, aspect1.id]}
|
||||
@post = user.build_post(:status_message, @params)
|
||||
@post.save
|
||||
|
|
@ -27,27 +26,30 @@ describe User do
|
|||
|
||||
it 'saves post into visible post ids' do
|
||||
proc {
|
||||
user.add_to_stream(@post, @aspect_ids)
|
||||
user.add_to_streams(@post, @aspect_ids)
|
||||
}.should change(user.raw_visible_posts, :count).by(1)
|
||||
user.reload.raw_visible_posts.should include @post
|
||||
end
|
||||
|
||||
it 'saves post into each aspect in aspect_ids' do
|
||||
user.add_to_stream(@post, @aspect_ids)
|
||||
user.add_to_streams(@post, @aspect_ids)
|
||||
aspect.reload.post_ids.should include @post.id
|
||||
aspect1.reload.post_ids.should include @post.id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '#prune_aspect_ids' do
|
||||
describe '#aspects_from_ids' do
|
||||
it 'returns a list of all valid aspects a user can post to' do
|
||||
aspect_ids = Aspect.all.map(&:id)
|
||||
user.prune_aspect_ids(aspect_ids).should =~ [aspect.id, aspect1.id]
|
||||
user.aspects_from_ids(aspect_ids).should =~ [aspect, aspect1]
|
||||
end
|
||||
it "lets you post to your own aspects" do
|
||||
user.prune_aspect_ids(aspect.id).should be_true
|
||||
user.prune_aspect_ids(aspect1.id).should be_true
|
||||
user.aspects_from_ids([aspect.id]).should == [aspect]
|
||||
user.aspects_from_ids([aspect1.id]).should == [aspect1]
|
||||
end
|
||||
it 'removes aspects that are not yours' do
|
||||
user.aspects_from_ids(aspect2.id).should == []
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue