diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 11ded0064..88b8235f2 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -2,7 +2,7 @@ class GroupsController < ApplicationController before_filter :authenticate_user! def index - @posts = current_user.posts.paginate :page => params[:page], :order => 'created_at DESC' + @posts = current_user.raw_visible_posts.paginate :page => params[:page], :order => 'created_at DESC' end def create diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 226f3233b..28b5de57d 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -12,12 +12,11 @@ class PeopleController < ApplicationController end def show - @person= current_user.visible_person_by_id(params[:id]) - - @person_profile = @person.profile - @person_posts = Post.where(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' + @person = current_user.visible_person_by_id(params[:id]) + @profile = @person.profile + @posts = Post.find_all_by_person_id(@person.id).paginate :page => params[:page], :order => 'created_at DESC' @latest_status_message = StatusMessage.newest_for(@person) - @post_count = @person_posts.count + @post_count = @posts.count end def destroy diff --git a/app/models/album.rb b/app/models/album.rb index 7b9a746aa..b6daabb47 100644 --- a/app/models/album.rb +++ b/app/models/album.rb @@ -67,6 +67,6 @@ class Album end def propagate_retraction - Retraction.for(self).notify_people + self.person.owner.retract(self) end end diff --git a/app/models/person.rb b/app/models/person.rb index d9cf93145..26236a5b8 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -20,20 +20,17 @@ class Person belongs_to :owner, :class_name => 'User' one :profile, :class_name => 'Profile' - many :posts, :class_name => 'Post', :foreign_key => :person_id many :albums, :class_name => 'Album', :foreign_key => :person_id timestamps! + before_destroy :remove_all_traces before_validation :clean_url validates_presence_of :email, :url, :profile, :serialized_key validates_format_of :url, :with => /^(https?):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*(\.[a-z]{2,5})?(:[0-9]{1,5})?(\/.*)?$/ix - - after_destroy :remove_all_traces - def self.search(query) Person.all('$where' => "function() { return this.email.match(/^#{query}/i) || @@ -92,11 +89,9 @@ class Person self.url = self.url + '/' if self.url[-1,1] != '/' end end - private - def remove_all_traces - self.posts.delete_all + Post.all(:person_id => id).each{|p| p.delete} + Album.all(:person_id => id).each{|p| p.delete} end - end diff --git a/app/models/user.rb b/app/models/user.rb index b3f9b48b3..f18069cea 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -102,6 +102,7 @@ class User ######### Posts and Such ############### def retract( post ) + post.unsocket_from_uid(self.id) if post.respond_to? :unsocket_from_uid retraction = Retraction.for(post) retraction.creator_signature = retraction.sign_with_key( encryption_key ) retraction.notify_people @@ -269,7 +270,7 @@ class User self.save groups = groups_with_person(object.person) - object.socket_to_uid(id, :group_id => groups.first.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) + object.socket_to_uid(id, :group_id => group.id) if (object.respond_to?(:socket_to_uid) && !self.owns?(object)) end end diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index b29699997..af8eb86ab 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -6,13 +6,13 @@ %h1 = @person.real_name - unless @person.id == current_user.id - .button.right - = link_to 'remove friend', @person, :confirm => 'Are you sure?', :method => :delete + .right + = link_to 'remove friend', @person, :confirm => 'Are you sure?', :method => :delete, :class => "button" %ul - -unless @person_posts.first.nil? + -unless @posts.first.nil? %li - %i= "last seen: #{how_long_ago(@person_posts.first)}" + %i= "last seen: #{how_long_ago(@posts.first)}" %li %i= "friends since: #{how_long_ago(@person)}" %li @@ -26,11 +26,11 @@ %span="posted: #{how_long_ago(@latest_status_message)}" .span-20.last - - if @person.posts + - if @posts %h3= "stream - #{@post_count} item(s)" %ul#stream - - for post in @person_posts + - for post in @posts = render type_partial(post), :post => post - = will_paginate @person_posts + = will_paginate @posts - else %h3 no posts to display! diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index a571e0582..ad4d00e2b 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -32,7 +32,7 @@ describe Person do person_message = Factory.create(:status_message, :person => @person) person_two = Factory.create(:person) - @person.owns? (person_message).should be true + @person.owns?(person_message).should be true person_two.owns?(person_message).should be false end @@ -53,7 +53,7 @@ describe Person do person.destroy - Post.count.should == 1 + Post.count.should == 1 Comment.all.count.should == 4 status_message.comments.count.should == 4 end @@ -77,7 +77,7 @@ describe Person do request = @user.send_friend_request_to @person.receive_url, @group.id request2 = @user2.send_friend_request_to @person.receive_url, @group2.id - @user.activate_friend (@person, @group) + @user.activate_friend(@person, @group) @user2.activate_friend(@person, @group2) @user.reload diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 9ec8ccb19..c6196b0f0 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -27,27 +27,6 @@ describe Post do end - describe "stream" do - before do - @owner = Factory.build(:user) - @person_one = Factory.create(:person, :email => "some@dudes.com") - @person_two = Factory.create(:person, :email => "other@dudes.com") - - Factory.create(:status_message, :message => "puppies", :created_at => Time.now+1, :person => @owner.person) - Factory.create(:status_message, :message => "http://reddit.com", :created_at => Time.now+2, :person => @person_one) - Factory.create(:status_message, :message => "kittens", :created_at => Time.now+3, :person => @person_two) - Factory.create(:status_message, :message => "Bear's body", :created_at => Time.now+4, :person => @owner.person) - Factory.create(:status_message, :message => "Google", :created_at => Time.now+5, :person => @person_two) - end - - it "should get all posts for a specified user" do - person_posts = @person_one.posts - person_posts.count.should == 1 - - person_posts = @person_two.posts - person_posts.count.should == 2 - end - end describe 'xml' do it 'should serialize to xml with its person' do message = Factory.create(:status_message, :person => @user.person) diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 7e850c490..4919e66f4 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -22,7 +22,7 @@ describe User do StatusMessage.all.size.should == 0 @user.receive( xml ) - person.posts.first.message.should == 'store this!' + Post.all(:person_id => person.id).first.message.should == 'store this!' StatusMessage.all.size.should == 1 end