Commit cf45f317 authored by zhitomirskiyi's avatar zhitomirskiyi

facebook friend finder is now contact-aware

parent d976bf09
......@@ -21,12 +21,17 @@ class Services::Facebook < Service
data = JSON.parse(response.body)['data']
data_h = {}
data.map do |d|
data.each do |d|
data_h[d['id']] = {:name => d['name']}
end
service_objects = Services::Facebook.where(:uid => data_h.keys).includes(:user => :person)
service_objects.each{|s| data_h[s.uid][:person] = s.user.person}
service_objects.each do |s|
data_h[s.uid][:person] = s.user.person
data_h[s.uid][:contact] = self.user.contacts.where(:person_id => s.user.person.id).first
end
data_h
end
......
......@@ -11,17 +11,20 @@
.contact_list
= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('shared.contact_list.all_contacts')
%ul
- for friend in @friends
- for friend in @friends.values
%li
%h4.name
= link_to friend[:name], '#'
- if person = friend[:person]
.right
.right
-if friend[:contact] && !friend[:contact].pending
= t('.already_connected')
- elsif (friend[:contact] && friend[:contact].pending)
= t('.pending_request')
- elsif friend[:person]
= link_to t('people.show.start_sharing'),
{:controller => "people",
:action => "share_with",
:id => person.id},
:id => friend[:person].id},
:class => 'button',
:rel => 'facebox'
......@@ -29,7 +29,7 @@ describe Services::Facebook do
describe '#finder' do
before do
@user2 = Factory(:user)
@user2 = Factory.create(:user_with_aspect)
@user2_fb_id = '820651'
@user2_fb_name = 'Maxwell Salzberg'
@user2_service = Services::Facebook.create(:uid => @user2_fb_id, :access_token => "yo")
......@@ -50,25 +50,29 @@ JSON
end
it 'requests a friend list' do
RestClient.should_receive(:get).with("https://graph.facebook.com/me/friends", {:params => {:access_token => @user2_service.access_token}}).and_return(@web_mock)
@user2_service.finder
RestClient.should_receive(:get).with("https://graph.facebook.com/me/friends", {:params => {:access_token => @service.access_token}}).and_return(@web_mock)
@service.finder
end
context 'returns a hash' do
it 'returns a hash' do
@user2_service.finder.class.should == Hash
@service.finder.class.should == Hash
end
it 'contains a name' do
@user2_service.finder.values.first[:name].should == @user2_fb_name
@service.finder.values.first[:name].should == @user2_fb_name
end
it 'contains a photo url' do
pending
end
it 'contains a FB id' do
@user2_service.finder.include?(@user2_fb_id).should be_true
@service.finder.include?(@user2_fb_id).should be_true
end
it 'contains a diaspora person object' do
@user2_service.finder.values.first[:person].should == @user2.person
@service.finder.values.first[:person].should == @user2.person
end
it 'contains a contact object if connected' do
connect_users(@user, @user.aspects.first, @user2, @user2.aspects.first)
@service.finder.values.first[:contact].should == @user.reload.contact_for(@user2.person)
end
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment