8 failures left. wip.

This commit is contained in:
danielgrippi 2011-03-28 18:44:10 -07:00
parent 9a0d6219b5
commit 8816bd7f91
7 changed files with 21 additions and 16 deletions

View file

@ -30,10 +30,7 @@ class ApisController < ApplicationController #We should start with this versione
def home_timeline def home_timeline
set_defaults set_defaults
timeline = current_user.raw_visible_posts.includes(:comments, :photos, :likes, :dislikes).paginate(
aspect_ids = current_user.aspects.map{|a| a.id}
timeline = StatusMessage.joins(:aspects).where(:pending => false,
:aspects => {:id => aspect_ids}).includes(:comments, :photos, :likes, :dislikes).select('DISTINCT `posts`.*').paginate(
:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC") :page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
respond_with timeline do |format| respond_with timeline do |format|

View file

@ -21,13 +21,13 @@ module ApplicationHelper
def aspects_with_post aspects, post def aspects_with_post aspects, post
aspects.select do |aspect| aspects.select do |aspect|
PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) AspectVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id)
end end
end end
def aspects_without_post aspects, post def aspects_without_post aspects, post
aspects.reject do |aspect| aspects.reject do |aspect|
PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) AspectVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id)
end end
end end

View file

@ -32,6 +32,11 @@ class Contact < ActiveRecord::Base
:aspect => aspects.first) :aspect => aspects.first)
end end
def receive_post(post)
PostVisibility.create!(:post_id => post.id, :contact_id => self.id)
post.socket_to_user(self.user, :aspect_ids => self.aspect_ids) if post.respond_to? :socket_to_user
end
def contacts def contacts
people = Person.arel_table people = Person.arel_table
incoming_aspects = Aspect.joins(:contacts).where( incoming_aspects = Aspect.joins(:contacts).where(

View file

@ -84,16 +84,14 @@ class Post < ActiveRecord::Base
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason=immutable existing_post=#{known_post.id}") Rails.logger.info("event=receive payload_type=#{self.class} update=true status=abort sender=#{self.diaspora_handle} reason=immutable existing_post=#{known_post.id}")
end end
else else
contact = user.contact_for(person) user.contact_for(person).receive_post(local_post)
PostVisibility.create(:post_id => self.id, :contact_id => contact.id)
user.notify_if_mentioned(local_post) user.notify_if_mentioned(local_post)
Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle} existing_post=#{local_post.id}") Rails.logger.info("event=receive payload_type=#{self.class} update=true status=complete sender=#{self.diaspora_handle} existing_post=#{local_post.id}")
return local_post return local_post
end end
elsif !local_post elsif !local_post
self.save self.save
contact = user.contact_for(person) user.contact_for(person).receive_post(self)
PostVisibility.create(:post_id => self.id, :contact_id => contact.id)
user.notify_if_mentioned(self) user.notify_if_mentioned(self)
Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}") Rails.logger.info("event=receive payload_type=#{self.class} update=false status=complete sender=#{self.diaspora_handle}")
return self return self

View file

@ -5,7 +5,7 @@ module PhotoMover
FileUtils::mkdir_p temp_dir FileUtils::mkdir_p temp_dir
Dir.chdir 'tmp/exports' Dir.chdir 'tmp/exports'
photos = user.raw_visible_posts(:author_id => user.person.id, :type => 'Photo') photos = user.raw_visible_posts.where(:author_id => user.person.id, :type => 'Photo')
photos_dir = "#{user.id}/photos" photos_dir = "#{user.id}/photos"
FileUtils::mkdir_p photos_dir FileUtils::mkdir_p photos_dir

View file

@ -20,9 +20,7 @@ module Diaspora
end end
def visible_photos def visible_photos
p = Photo.arel_table raw_visible_posts.where(:type => 'Photo')
Photo.joins(:aspects).where(p[:status_message_id].not_eq(nil).or(p[:pending].eq(false))
).where(:aspects => {:user_id => self.id}).select('DISTINCT `posts`.*').order("posts.updated_at DESC")
end end
def contact_for(person) def contact_for(person)
@ -70,6 +68,7 @@ module Diaspora
end end
def posts_from(person) def posts_from(person)
return self.person.posts.where(:pending => false) if person == self.person
con = Contact.arel_table con = Contact.arel_table
p = Post.arel_table p = Post.arel_table
post_ids = [] post_ids = []

View file

@ -154,11 +154,12 @@ describe 'a user receives a post' do
@status_message = @user2.post :status_message, :text => "hi", :to => @aspect2.id @status_message = @user2.post :status_message, :text => "hi", :to => @aspect2.id
@user1.reload @user1.reload
@aspect.reload @aspect.reload
@contact = @user1.contact_for(@user2.person)
end end
it "adds a received post to the aspect and visible_posts array" do it "adds a received post to the the contact" do
@user1.raw_visible_posts.include?(@status_message).should be_true @user1.raw_visible_posts.include?(@status_message).should be_true
@aspect.posts.include?(@status_message).should be_true @contact.posts.include?(@status_message).should be_true
end end
it 'removes posts upon disconnecting' do it 'removes posts upon disconnecting' do
@ -174,6 +175,11 @@ describe 'a user receives a post' do
@post = Factory.create(:status_message, :author => @person) @post = Factory.create(:status_message, :author => @person)
@post.post_visibilities.should be_empty @post.post_visibilities.should be_empty
receive_with_zord(@user1, @person, @post.to_diaspora_xml) receive_with_zord(@user1, @person, @post.to_diaspora_xml)
@contact = @user1.contact_for(@person)
@contact.post_visibilities.reset
@contact.posts(true).should include(@post)
@post.post_visibilities.reset
end end
it 'deletes a post if the noone links to it' do it 'deletes a post if the noone links to it' do