invitation text

setting the invites

added requests to the fb hash

finder has options

remove the requester from the list

typo

making a block

another typo

remove the if statement for the notifications

checking on the right field

translations and correct indenting

fixed stuff added

added a temp puts

added a temp puts

now actually referencing the service

not double nesting

remove stream element

updated remote friends to old style

removed it from the h1 block

putting the stream element back
This commit is contained in:
zhitomirskiyi 2011-02-04 16:45:56 -08:00
parent df4ebb286d
commit d147da1b4a
9 changed files with 79 additions and 30 deletions

View file

@ -25,7 +25,7 @@ class ServicesController < ApplicationController
flash[:notice] = I18n.t 'services.create.success' flash[:notice] = I18n.t 'services.create.success'
if current_user.getting_started if current_user.getting_started
redirect_to getting_started_path(:step => 3) redirect_to getting_started_path(:step => 1)
else else
redirect_to services_url redirect_to services_url
end end

View file

@ -78,15 +78,18 @@ class UsersController < ApplicationController
@person = @user.person @person = @user.person
@profile = @user.profile @profile = @user.profile
@services = @user.services @services = @user.services
@requests = Request.where(:recipient_id => @person.id).all service = current_user.services.where(:type => "Services::Facebook").first
@step = ((params[:step].to_i>0)&&(params[:step].to_i<5)) ? params[:step].to_i : 1 @step = ((params[:step].to_i>0)&&(params[:step].to_i<5)) ? params[:step].to_i : 1
@step ||= 1 @step ||= 1
if @step == 3 if @step == 3
service = current_user.services.where(:type => "Services::Facebook").first @requests = Request.where(:recipient_id => @person.id).includes(:sender).all
@friends = service ? service.finder : {} @friends = service ? service.finder(:local => true) : {}
@friends.delete_if{|key, value| @requests.any?{ |r| r.sender_id == value[:person].id} }
elsif @step == 4 elsif @step == 4
@invites = @user.invites
@friends = service ? service.finder(:remote => true) : {}
@user.getting_started = false @user.getting_started = false
@user.save @user.save
end end

View file

@ -19,7 +19,7 @@ class Services::Facebook < Service
super(post, MAX_CHARACTERS, url) super(post, MAX_CHARACTERS, url)
end end
def finder def finder(opts = {})
Rails.logger.debug("event=friend_finder type=facebook sender_id=#{self.user_id}") Rails.logger.debug("event=friend_finder type=facebook sender_id=#{self.user_id}")
response = RestClient.get("https://graph.facebook.com/me/friends", {:params => {:access_token => self.access_token}}) response = RestClient.get("https://graph.facebook.com/me/friends", {:params => {:access_token => self.access_token}})
data = JSON.parse(response.body)['data'] data = JSON.parse(response.body)['data']
@ -45,9 +45,21 @@ class Services::Facebook < Service
person_ids_and_uids[s.user.person.id] = s.uid person_ids_and_uids[s.user.person.id] = s.uid
end end
requests = Request.where(:recipient_id => self.user.person.id, :sender_id => person_ids_and_uids.keys).all
requests.each{|r| data_h[person_ids_and_uids[r.sender_id]][:request] = r}
contact_objects = self.user.contacts.where(:person_id => person_ids_and_uids.keys) contact_objects = self.user.contacts.where(:person_id => person_ids_and_uids.keys)
contact_objects.each{|c| data_h[person_ids_and_uids[c.person_id]][:contact] = c} contact_objects.each{|c| data_h[person_ids_and_uids[c.person_id]][:contact] = c}
if opts[:local]
data_h.delete_if {|key, value| value[:person].nil? }
end
if opts[:remote]
data_h.delete_if {|key, value| !value[:person].nil? }
end
data_h data_h
end end
end end

View file

@ -2,7 +2,7 @@
-if friend[:person] -if friend[:person]
= render :partial => 'people/person', :locals => {:person => friend[:person], :contact => friend[:contact], :request => friend[:request]} = render :partial => 'people/person', :locals => {:person => friend[:person], :contact => friend[:contact], :request => friend[:request]}
-else -else
.stream_element .steam_element
.right .right
-if friend[:invitation_id] -if friend[:invitation_id]
= t('invitations.new.already_invited') = t('invitations.new.already_invited')

View file

@ -38,10 +38,10 @@
= t('.edit_profile') = t('.edit_profile')
%br %br
- if @step != 3 - if @step != 3
= link_to t('.define_aspects'), getting_started_path(:step => 3) = link_to t('.connect_on_diaspora'), getting_started_path(:step => 3)
- else - else
%span.current_gs_step %span.current_gs_step
= t('.define_aspects') = t('.connect_on_diaspora')
%br %br
- if @step != 4 - if @step != 4
= link_to t('.finished'), getting_started_path(:step => 4) = link_to t('.finished'), getting_started_path(:step => 4)

View file

@ -8,7 +8,6 @@
= t('.your_aspects') = t('.your_aspects')
.description .description
= t('.description') = t('.description')
-if @requests.length > 0
%br %br
= t('.your_inviter') = t('.your_inviter')
%br %br
@ -18,10 +17,10 @@
- person = pending_req.sender - person = pending_req.sender
= render :partial => 'people/person', :locals => {:request => pending_req, :person => person, :contact => nil} = render :partial => 'people/person', :locals => {:request => pending_req, :person => person, :contact => nil}
-unless @friends.blank? - for fb_id in @friends.keys
%br - friend = @friends[fb_id]
.contact_list = render :partial => 'people/person', :locals => {:request => friend[:request], :person => friend[:person], :contact => friend[:contact]}
= render :partial => 'services/finder', :locals => {:friends => @friends, :getting_started => true}
.submit_block .submit_block

View file

@ -10,7 +10,13 @@
%ul.inline_aspect_listing %ul.inline_aspect_listing
- for aspect in @all_aspects - for aspect in @all_aspects
%li= aspect %li= aspect
-unless @friends.blank?
%br
= t('services.finder.invite_your_friends_from', :service => "facebook".titleize)
= t('shared.invitations.invitations_left', :count => @invites)
%br
.contact_list
= render :partial => 'services/finder', :locals => {:friends => @friends, :getting_started => true}
%br %br
%br %br

View file

@ -230,7 +230,7 @@ en:
welcome: "Welcome to Diaspora!" welcome: "Welcome to Diaspora!"
signup_steps: "Finish your sign up by completing these three steps:" signup_steps: "Finish your sign up by completing these three steps:"
edit_profile: "Edit your profile" edit_profile: "Edit your profile"
define_aspects: "Define your aspects" connect_on_diaspora: "Connect on Diaspora"
connect_services: "Connect your other services" connect_services: "Connect your other services"
finished: "Finished!" finished: "Finished!"
skip: "skip getting started" skip: "skip getting started"

View file

@ -40,6 +40,10 @@ describe Services::Facebook do
{ {
"name": "#{@user2_fb_name}", "name": "#{@user2_fb_name}",
"id": "#{@user2_fb_id}" "id": "#{@user2_fb_id}"
},
{
"name": "Person to Invite",
"id": "abc123"
} }
] ]
} }
@ -54,12 +58,14 @@ JSON
@service.finder @service.finder
end end
context 'returns a hash' do context 'returns a hash' do
it 'returns a hash' do it 'returns a hash' do
@service.finder.class.should == Hash @service.finder.class.should == Hash
end end
it 'contains a name' do it 'contains a name' do
@service.finder.values.first[:name].should == @user2_fb_name @service.finder["#{@user2_fb_id}"][:name].should == @user2_fb_name
end end
it 'contains a photo url' do it 'contains a photo url' do
pending pending
@ -68,21 +74,44 @@ JSON
@service.finder.include?(@user2_fb_id).should be_true @service.finder.include?(@user2_fb_id).should be_true
end end
it 'contains a diaspora person object' do it 'contains a diaspora person object' do
@service.finder.values.first[:person].should == @user2.person @service.finder["#{@user2_fb_id}"][:person].should == @user2.person
end end
it 'caches the profile' do it 'caches the profile' do
@service.finder.values.first[:person].profile.loaded?.should be_true @service.finder["#{@user2_fb_id}"][:person].profile.loaded?.should be_true
end end
it 'does not include the person if the search is disabled' do it 'does not include the person if the search is disabled' do
p = @user2.person.profile p = @user2.person.profile
p.searchable = false p.searchable = false
p.save p.save
@service.finder.values.first[:person].should be_nil @service.finder["#{@user2_fb_id}"][:person].should be_nil
end end
it 'contains a request object if one has been sent' do
request = Request.diaspora_initialize(:from => @user2.person, :to => @user.person, :into => @user2.aspects.first)
Postzord::Receiver.new(@user, :object => request, :person => @user2.person).receive_object
Request.count.should == 1
@service.finder["#{@user2_fb_id}"][:request].should == request
end
it 'contains a contact object if connected' do it 'contains a contact object if connected' do
connect_users(@user, @user.aspects.first, @user2, @user2.aspects.first) connect_users(@user, @user.aspects.first, @user2, @user2.aspects.first)
@service.finder.values.first[:contact].should == @user.reload.contact_for(@user2.person) @service.finder["#{@user2_fb_id}"][:contact].should == @user.reload.contact_for(@user2.person)
end end
context 'only local' do
it 'does not return people who are remote' do
@service.finder(:local => true)['abc123'].should be nil
@service.finder(:local => true)["#{@user2_fb_id}"].should_not be_nil
end
end
context 'only remote' do
it 'does not return people who are remote' do
@service.finder(:remote => true)['abc123'].should_not be nil
@service.finder(:remote => true)["#{@user2_fb_id}"].should be_nil
end
end
context 'already invited' do context 'already invited' do
before do before do
@user2.invitation_service = 'facebook' @user2.invitation_service = 'facebook'
@ -91,14 +120,14 @@ JSON
end end
it 'contains an invitation if invited' do it 'contains an invitation if invited' do
@inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first) @inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first)
@service.finder.values.first[:invitation_id].should == @inv.id @service.finder["#{@user2_fb_id}"][:invitation_id].should == @inv.id
end end
it 'does not find the user with a wrong identifier' do it 'does not find the user with a wrong identifier' do
@user2.invitation_identifier = 'dsaofhnadsoifnsdanf' @user2.invitation_identifier = 'dsaofhnadsoifnsdanf'
@user2.save @user2.save
@inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first) @inv = Invitation.create(:sender => @user, :recipient => @user2, :aspect => @user.aspects.first)
@service.finder.values.first[:invitation_id].should be_nil @service.finder["#{@user2_fb_id}"][:invitation_id].should be_nil
end end
end end
end end