Skip to content
Extraits de code Groupes Projets
Valider 836b5685 rédigé par Raphael's avatar Raphael
Parcourir les fichiers

Change prune_aspect_ids to aspects_from_ids, seperate out non-backgroundable...

Change prune_aspect_ids to aspects_from_ids, seperate out non-backgroundable piece of posting from dispatch_post
parent e63a29be
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -46,6 +46,7 @@ class PhotosController < ApplicationController ...@@ -46,6 +46,7 @@ class PhotosController < ApplicationController
if @photo.save if @photo.save
raise 'MongoMapper failed to catch a failed save' unless @photo.id 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 current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids]) unless @photo.pending
respond_to do |format| respond_to do |format|
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )} format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
......
...@@ -26,9 +26,11 @@ class StatusMessagesController < ApplicationController ...@@ -26,9 +26,11 @@ class StatusMessagesController < ApplicationController
raise 'MongoMapper failed to catch a failed save' unless @status_message.id raise 'MongoMapper failed to catch a failed save' unless @status_message.id
@status_message.photos += photos unless photos.nil? @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]) current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids])
for photo in photos 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]) current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])
end end
......
...@@ -147,6 +147,7 @@ class User ...@@ -147,6 +147,7 @@ class User
if post.save if post.save
raise 'MongoMapper failed to catch a failed save' unless post.id raise 'MongoMapper failed to catch a failed save' unless post.id
add_to_streams(post, opts[:to])
dispatch_post(post, :to => opts[:to]) dispatch_post(post, :to => opts[:to])
end end
post post
...@@ -163,10 +164,6 @@ class User ...@@ -163,10 +164,6 @@ class User
def dispatch_post(post, opts = {}) def dispatch_post(post, opts = {})
aspect_ids = opts.delete(:to) aspect_ids = opts.delete(:to)
aspect_ids = prune_aspect_ids(aspect_ids)
self.raw_visible_posts << post
self.save
#socket post #socket post
Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}") Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}")
push_to_aspects(post, aspect_ids) push_to_aspects(post, aspect_ids)
...@@ -199,14 +196,27 @@ class User ...@@ -199,14 +196,27 @@ class User
end end
end end
def prune_aspect_ids(aspect_ids) def add_to_streams(post, aspect_ids)
return aspect_ids if aspect_ids == "all" self.raw_visible_posts << post
if aspect_ids.respond_to? :to_id self.save
aspect_ids = [aspect_ids]
target_aspects = aspects_from_ids(aspect_ids)
target_aspects.each do |aspect|
aspect.posts << post
aspect.save
end end
end
aspect_ids.map!{ |x| x.to_id } def aspects_from_ids(aspect_ids)
aspects.map{ |x| x.id } & 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 end
def push_to_aspects(post, aspect_ids) def push_to_aspects(post, aspect_ids)
...@@ -221,8 +231,6 @@ class User ...@@ -221,8 +231,6 @@ class User
target_contacts = [] target_contacts = []
aspects.each { |aspect| aspects.each { |aspect|
aspect.posts << post
aspect.save
target_contacts = target_contacts | aspect.contacts target_contacts = target_contacts | aspect.contacts
} }
......
...@@ -16,9 +16,8 @@ describe User do ...@@ -16,9 +16,8 @@ describe User do
let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s } let!(:service1) { s = Factory(:service, :provider => 'twitter'); user.services << s; s }
let!(:service2) { s = Factory(:service, :provider => 'facebook'); 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 before do
pending "not implemented"
@params = {:message => "hey", :to => [aspect.id, aspect1.id]} @params = {:message => "hey", :to => [aspect.id, aspect1.id]}
@post = user.build_post(:status_message, @params) @post = user.build_post(:status_message, @params)
@post.save @post.save
...@@ -27,27 +26,30 @@ describe User do ...@@ -27,27 +26,30 @@ describe User do
it 'saves post into visible post ids' do it 'saves post into visible post ids' do
proc { proc {
user.add_to_stream(@post, @aspect_ids) user.add_to_streams(@post, @aspect_ids)
}.should change(user.raw_visible_posts, :count).by(1) }.should change(user.raw_visible_posts, :count).by(1)
user.reload.raw_visible_posts.should include @post user.reload.raw_visible_posts.should include @post
end end
it 'saves post into each aspect in aspect_ids' do 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 aspect.reload.post_ids.should include @post.id
aspect1.reload.post_ids.should include @post.id aspect1.reload.post_ids.should include @post.id
end end
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 it 'returns a list of all valid aspects a user can post to' do
aspect_ids = Aspect.all.map(&:id) 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 end
it "lets you post to your own aspects" do it "lets you post to your own aspects" do
user.prune_aspect_ids(aspect.id).should be_true user.aspects_from_ids([aspect.id]).should == [aspect]
user.prune_aspect_ids(aspect1.id).should be_true 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
end end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter