Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
maxwell 2010-11-08 15:56:18 -08:00
commit 3fd5852d44
6 changed files with 43 additions and 21 deletions

View file

@ -32,6 +32,9 @@ class Profile
before_save :strip_names
attr_accessible :first_name, :last_name, :image_url, :birthday, :gender, :bio, :searchable
def person
self._parent_document
end

View file

@ -28,7 +28,8 @@ class Request
def self.instantiate(options = {})
person = options[:from]
self.new(:destination_url => options[:to],
self.new(:person_id => person.id,
:destination_url => options[:to],
:callback_url => person.receive_url,
:diaspora_handle => person.diaspora_handle,
:aspect_id => options[:into])
@ -38,7 +39,8 @@ class Request
Request.new(
:diaspora_handle => accepting_user.diaspora_handle,
:destination_url => self.callback_url,
:callback_url => self.destination_url
:callback_url => self.destination_url,
:person_id => accepting_user.person.id
)
end

View file

@ -23,7 +23,6 @@ class User
key :invitation_token, String
key :invitation_sent_at, DateTime
key :inviter_ids, Array, :typecast => 'ObjectId'
key :friend_ids, Array, :typecast => 'ObjectId'
key :pending_request_ids, Array, :typecast => 'ObjectId'
key :visible_post_ids, Array, :typecast => 'ObjectId'
key :visible_person_ids, Array, :typecast => 'ObjectId'
@ -49,7 +48,7 @@ class User
one :person, :class_name => 'Person', :foreign_key => :owner_id
many :inviters, :in => :inviter_ids, :class_name => 'User'
many :friends, :in => :friend_ids, :class_name => 'Contact'
many :friends, :class_name => 'Contact', :foreign_key => :user_id
many :visible_people, :in => :visible_person_ids, :class_name => 'Person' # One of these needs to go
many :pending_requests, :in => :pending_request_ids, :class_name => 'Request'
many :raw_visible_posts, :in => :visible_post_ids, :class_name => 'Post'
@ -371,6 +370,7 @@ class User
raise "You already invited this person"
else
invitable.pending_requests << Request.create(
:person => request.person,
:diaspora_handle => request.diaspora_handle,
:callback_url => request.callback_url,
:destination_url => request.destination_url)

View file

@ -59,12 +59,16 @@ module Diaspora
def receive_friend_request(friend_request)
Rails.logger.info("receiving friend request #{friend_request.to_json}")
#puts ("receiving friend request #{friend_request.to_json}")
#response from a friend request you sent
if original_request = original_request(friend_request)
destination_aspect = self.aspect_by_id(original_request.aspect_id)
#pp original_request
#pp friend_request
#pp friend_request.person
activate_friend(friend_request.person, destination_aspect)
Rails.logger.info("#{self.real_name}'s friend request has been accepted")
#puts ("#{self.real_name}'s friend request has been accepted")
friend_request.destroy
original_request.destroy
@ -74,7 +78,7 @@ module Diaspora
elsif !request_from_me?(friend_request)
self.pending_requests << friend_request
self.save
Rails.logger.info("#{self.real_name} has received a friend request")
#puts ("#{self.real_name} has received a friend request")
friend_request.save
Request.send_new_request(self, friend_request.person)
else
@ -92,11 +96,10 @@ module Diaspora
def remove_friend(bad_friend)
contact = contact_for(bad_friend)
raise "Friend not deleted" unless self.friend_ids.delete(contact.id)
contact.aspects.each{|aspect|
contact.aspects.delete(aspect)
aspect.posts.delete_if { |post|
post.person_id == bad_friend.id
aspect.posts.each { |post|
aspect.post_ids.delete(post.id) if post.person == bad_friend
}
aspect.save
}
@ -107,7 +110,7 @@ module Diaspora
(post.user_refs > 0 || post.person.owner.nil? == false) ? post.save : post.destroy
}
self.save
contact.destroy
raise "Friend not deleted" unless contact.destroy
bad_friend.save
end
@ -117,9 +120,8 @@ module Diaspora
end
def activate_friend(person, aspect)
new_contact = Contact.create(:user => self, :person => person, :aspects => [aspect])
new_contact = Contact.create!(:user => self, :person => person, :aspects => [aspect])
new_contact.aspects << aspect
friends << new_contact
save!
aspect.save!
end

View file

@ -69,5 +69,11 @@ describe PeopleController do
:owner_id => new_user.id}
user.person.reload.owner_id.should_not == new_user.id
end
it 'does not overwrite the profile diaspora handle' do
handle_params = {'profile' => {'diaspora_handle' => 'abc@a.com'}}
put :update, :id => user.person.id, :person => handle_params
user.person.reload.profile[:diaspora_handle].should_not == 'abc@a.com'
end
end
end

View file

@ -39,9 +39,11 @@ describe Diaspora::UserModules::Friending do
it 'should autoaccept a request the user sent' do
request = user.send_friend_request_to(user2.person, aspect)
proc{
user.receive_friend_request(request.reverse_for(user2))
}.should change(user.reload.friends, :count).by(1)
user.contact_for(user2.person).should be_nil
#proc{
user.receive_request(request.reverse_for(user2), user2.person)
#}.should change(user.reload.friends, :count).by(1)
user.contact_for(user2.person).should_not be_nil
end
end
@ -52,8 +54,8 @@ describe Diaspora::UserModules::Friending do
let(:request_from_myself) {Request.instantiate(:to => user.receive_url, :from => user.person)}
before do
request_for_user.save
user.receive_friend_request(request_for_user)
user.receive_friend_request(request2_for_user)
user.receive_request(request_for_user, friend)
user.receive_request(request2_for_user, person_one)
user.reload
end
@ -90,7 +92,7 @@ describe Diaspora::UserModules::Friending do
it 'should send an email on acceptance if a friend request' do
Request.should_receive(:send_request_accepted)
request = user.send_friend_request_to(user2.person, aspect)
user.receive_friend_request(request.reverse_for(user2))
user.receive_request(request.reverse_for(user2), user2.person)
end
@ -238,13 +240,20 @@ describe Diaspora::UserModules::Friending do
context 'with a post' do
before do
@message = user.post(:status_message, :message => "hi", :to => aspect.id)
user2.unfriend user.person
end
it "deletes the unfriended user's posts from visible_posts" do
user.reload.raw_visible_posts.include?(@message.id).should be_false
user2.reload.raw_visible_posts.include?(@message).should be_true
user2.unfriend user.person
user2.reload.raw_visible_posts.include?(@message).should be_false
end
it "deletes the unfriended user's posts from the aspect's posts" do
aspect2.posts.include?(@message).should be_false
Post.count.should == 1
aspect2.reload.posts.include?(@message).should be_true
user2.unfriend user.person
aspect2.reload.posts.include?(@message).should be_false
Post.count.should == 1
end
end
end