diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 602856908..892c9a872 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -63,7 +63,7 @@ module SocketsHelper end - action_hash[:mine?] = object.person && (object.person.owner.id == uid) if object.respond_to?(:person) + action_hash[:mine?] = object.person && (object.person.owner_id == uid) if object.respond_to?(:person) I18n.locale = old_locale unless user.nil? diff --git a/app/models/person.rb b/app/models/person.rb index 9716a3581..bd5cb2860 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -35,20 +35,17 @@ class Person < ActiveRecord::Base validates_presence_of :url, :profile, :serialized_public_key validates_uniqueness_of :diaspora_handle, :case_sensitive => false - scope :searchable, includes(:profile).where(:profile => {:searchable => true}) + scope :searchable, joins(:profile).where(:profiles => {:searchable => true}) def self.search(query) return [] if query.to_s.empty? query_tokens = query.to_s.strip.split(" ") - full_query_text = Regexp.escape(query.to_s.strip) - p = [] query_tokens.each do |token| - q = Regexp.escape(token.to_s.strip) - p = Person.searchable.all('profile.first_name' => /^#{q}/i, 'limit' => 30) \ - | Person.searchable.all('profile.last_name' => /^#{q}/i, 'limit' => 30) \ - | Person.searchable.all('diaspora_handle' => /^#{q}/i, 'limit' => 30) \ + p = Person.searchable.where('profiles.first_name LIKE :token', :token => token).limit(30) \ + | Person.searchable.where('profiles.last_name LIKE :token', :token => token).limit(30) \ + | Person.searchable.where('profiles.diaspora_handle LIKE :token', :token => token).limit(30) \ | p end diff --git a/app/models/post.rb b/app/models/post.rb index 659639272..51e76b760 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -25,7 +25,9 @@ class Post < ActiveRecord::Base before_destroy :propogate_retraction after_destroy :destroy_comments - attr_accessible :user_refs + def user_refs + self.post_visibilities.count + end def self.diaspora_initialize params new_post = self.new params.to_hash @@ -52,15 +54,6 @@ class Post < ActiveRecord::Base false end - def decrement_user_refs - user_refs -= 1 - if (user_refs > 0) || person.owner.nil? == false - save - else - destroy - end - end - protected def destroy_comments comments.each { |c| c.destroy } diff --git a/app/models/profile.rb b/app/models/profile.rb index 04f266cc0..1af925587 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -24,8 +24,8 @@ class Profile < ActiveRecord::Base validates_length_of :first_name, :maximum => 32 validates_length_of :last_name, :maximum => 32 -# attr_accessible :first_name, :last_name, :image_url, :image_url_medium, -# :image_url_small, :birthday, :gender, :bio, :searchable, :date + attr_accessible :first_name, :last_name, :image_url, :image_url_medium, + :image_url_small, :birthday, :gender, :bio, :searchable, :date belongs_to :person diff --git a/app/models/user.rb b/app/models/user.rb index 201cb6813..73c273530 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -263,11 +263,11 @@ class User < ActiveRecord::Base ########### Profile ###################### def update_profile(params) - if params[:photo] - params[:photo].update_attributes(:pending => false) if params[:photo].pending - params[:image_url] = params[:photo].url(:thumb_large) - params[:image_url_medium] = params[:photo].url(:thumb_medium) - params[:image_url_small] = params[:photo].url(:thumb_small) + if photo = params.delete(:photo) + photo.update_attributes(:pending => false) if photo.pending + params[:image_url] = photo.url(:thumb_large) + params[:image_url_medium] = photo.url(:thumb_medium) + params[:image_url_small] = photo.url(:thumb_small) end if self.person.profile.update_attributes(params) push_to_people profile, contacts.includes(:person).where(:pending => false).map{|c| c.person} diff --git a/db/migrate/0000_create_schema.rb b/db/migrate/0000_create_schema.rb index 3daa23116..47207989c 100644 --- a/db/migrate/0000_create_schema.rb +++ b/db/migrate/0000_create_schema.rb @@ -76,7 +76,6 @@ class CreateSchema < ActiveRecord::Migration t.string :diaspora_handle t.string :guid t.boolean :pending, :default => false - t.integer :user_refs, :default => 0 t.string :type t.text :message diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 5ff961fc3..01744703b 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -62,7 +62,8 @@ module Diaspora end def request_from(person) - Request.where(:sender_id => person.id, :recipient_id => self.person.id).first + Request.where(:sender_id => person.id, + :recipient_id => self.person.id).first end def posts_from(person) diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index 2155c984b..b54f31a9b 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -135,9 +135,8 @@ describe Comment do end it 'should send a comment a user made on your post to all people' do - comment = user2.comment( "balls", :on => @user_status) MessageHandler.should_receive(:add_post_request).once - user.receive comment.to_diaspora_xml, user2.person + comment = user2.comment( "balls", :on => @user_status) end context 'posts from a remote person' do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 9a1f9ac98..f0151e42d 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -193,7 +193,7 @@ describe Person do end it 'should only display searchable people' do - invisible_person = Factory(:person, :profile => {:searchable => false, :first_name => "johnson"}) + invisible_person = Factory(:person, :profile => Factory(:profile,:searchable => false, :first_name => "johnson")) Person.search("johnson").should_not include invisible_person Person.search("").should_not include invisible_person end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 37d4433cf..f34d61f72 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -36,15 +36,4 @@ describe Post do post.mutable?.should == false end end - - describe '#decrement_user_refs' do - before do - @post = @user.post :status_message, :message => "hello", :to => @aspect.id - end - it 'decrements user_refs' do - lambda { - @post.decrement_user_refs - }.should change(@post, :user_refs).by(-1) - end - end end diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 7c3b955bb..b7e22850d 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -43,6 +43,10 @@ describe Diaspora::UserModules::Connecting do user.send_contact_request_to(user2.person, aspect1) }.should_not change{Request.where(:recipient_id => user.person.id).count} end + it 'persists a request for the recipient' do + user.send_contact_request_to(user2.person, aspect1) + user2.request_from(user.person).should_not be_nil + end end context 'contact requesting' do diff --git a/spec/models/user/querying_spec.rb b/spec/models/user/querying_spec.rb index 50d7f1ee2..95150482d 100644 --- a/spec/models/user/querying_spec.rb +++ b/spec/models/user/querying_spec.rb @@ -206,7 +206,7 @@ describe User do it 'should have a pending request after sending a request' do @user.send_contact_request_to(user5.person, @user.aspects.first) - request = @user.reload.request_from(user5.person) + request = user5.request_from(@user.person) request.should_not be_nil end end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index f950a331f..c0cd550f2 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -99,8 +99,6 @@ describe User do person = user2.person person.owner_id = nil person.save - @status_message.user_refs = 1 - @status_message.save lambda { user.disconnected_by(user2.person) @@ -109,23 +107,23 @@ describe User do it 'should keep track of user references for one person ' do @status_message.reload - @status_message.user_refs.should == 1 + @status_message.user_refs.should == 2 user.disconnect(user2.person) @status_message.reload - @status_message.user_refs.should == 0 + @status_message.user_refs.should == 1 end it 'should not override userrefs on receive by another person' do user3.activate_contact(user2.person, aspect3) user3.receive @status_message.to_diaspora_xml, user2.person - @status_message.reload - @status_message.user_refs.should == 2 + @status_message.post_visibilities.reset + @status_message.user_refs.should == 3 user.disconnect(user2.person) - @status_message.reload - @status_message.user_refs.should == 1 + @status_message.post_visibilities.reset + @status_message.user_refs.should == 2 end end