calls the job on login does a sync call if the cache friends was not called before, fixed the views
This commit is contained in:
parent
dcc80d5b43
commit
aa5bef0c3f
8 changed files with 37 additions and 34 deletions
|
|
@ -8,7 +8,6 @@ class SessionsController < Devise::SessionsController
|
|||
protected
|
||||
def enqueue_update
|
||||
if current_user
|
||||
pp params
|
||||
current_user.services.each{|s|
|
||||
Resque.enqueue(Job::UpdateServiceUsers, s.id) if s.respond_to? :save_friends
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,11 @@ class Services::Facebook < Service
|
|||
|
||||
def finder(opts = {})
|
||||
Rails.logger.debug("event=friend_finder type=facebook sender_id=#{self.user_id}")
|
||||
Resque.enqueue(Job::UpdateServiceUsers, self.id)
|
||||
if self.service_users == []
|
||||
self.save_friends
|
||||
else
|
||||
Resque.enqueue(Job::UpdateServiceUsers, self.id)
|
||||
end
|
||||
person = Person.arel_table
|
||||
service_user = ServiceUser.arel_table
|
||||
if opts[:local]
|
||||
|
|
@ -38,7 +42,7 @@ class Services::Facebook < Service
|
|||
{:fields => ['name', 'id', 'picture'], :access_token => self.access_token}})
|
||||
data = JSON.parse(response.body)['data']
|
||||
data.each{ |p|
|
||||
ServiceUser.find_or_create_by_service_id_and_name_and_uid_and_photo_url(:service_id => self.id, :name => p["name"],
|
||||
ServiceUser.find_or_create_by_service_id_and_uid(:service_id => self.id, :name => p["name"],
|
||||
:uid => p["id"], :photo_url => p["picture"])
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@
|
|||
|
||||
= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('shared.contact_list.all_contacts')
|
||||
%ul.friend_finder
|
||||
- for uid in friends.keys
|
||||
= render :partial => 'services/remote_friend', :locals => {:friend => friends[uid], :uid => uid}
|
||||
- for friend in friends
|
||||
= render :partial => 'services/remote_friend', :locals => {:friend => friend, :uid => friend.uid}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
%li.remote_friend{:id => "uid_" + uid, :uid => uid}
|
||||
.right
|
||||
-if friend[:contact] && !friend[:contact].pending
|
||||
-if friend.contact && !friend.contact.pending
|
||||
= t('people.person.already_connected')
|
||||
- elsif (friend[:contact] && friend[:contact].pending) || (friend[:request] && friend[:request].sender_id != friend[:person].id)
|
||||
- elsif (friend.contact && friend.contact.pending) || (friend.request && friend.request.sender_id != friend.person.id)
|
||||
= t('people.person.pending_request')
|
||||
- elsif (friend[:request] && friend[:request].sender_id == friend[:person].id)
|
||||
= link_to t('people.show.incoming_request', :name => truncate(friend[:person].name, :length => 20, :separator => ' ', :omission => '')),
|
||||
- elsif (friend.request && friend.request.sender_id == friend.person.id)
|
||||
= link_to t('people.show.incoming_request', :name => truncate(friend.person.name, :length => 20, :separator => ' ', :omission => '')),
|
||||
'#',
|
||||
:class => 'button'
|
||||
- elsif friend[:invitation_id]
|
||||
- elsif friend.invitation_id
|
||||
= t('invitations.new.already_invited')
|
||||
%br
|
||||
= link_to t('.resend'), service_inviter_path(:uid => uid, :provider => 'facebook', :invitation_id => friend[:invitation_id])
|
||||
- elsif friend[:person]
|
||||
= link_to t('.resend'), service_inviter_path(:uid => uid, :provider => 'facebook', :invitation_id => friend.invitation_id)
|
||||
- elsif friend.person
|
||||
= link_to t('people.show.start_sharing'),
|
||||
'#',
|
||||
:class => 'button'
|
||||
|
|
@ -23,23 +23,23 @@
|
|||
= hidden_field_tag :uid, uid
|
||||
= submit_tag t('.invite')
|
||||
|
||||
- if friend[:person]
|
||||
= person_image_link(friend[:person])
|
||||
- if friend.person
|
||||
= person_image_link(friend.person)
|
||||
- else
|
||||
= image_tag('/images/user/default.png', :class => 'avatar')
|
||||
|
||||
%h4.name
|
||||
- if friend[:person]
|
||||
= link_to friend[:name], person_path(friend[:person])
|
||||
- if friend.person
|
||||
= link_to friend.name, person_path(friend.person)
|
||||
- else
|
||||
= friend[:name]
|
||||
= friend.name
|
||||
|
||||
- unless friend[:person].nil? || (friend[:contact] && friend[:contact].pending) || (friend[:request] && friend[:request].sender_id != friend[:person].id)
|
||||
- unless friend.person.nil? || (friend.contact && friend.contact.pending) || (friend.request && friend.request.sender_id != friend.person.id)
|
||||
%li{:id => "options_" + uid, :class => "share_with hidden", :style => "height:auto"}
|
||||
- contact = friend[:contact]
|
||||
- contact = friend.contact
|
||||
- contact ||= Contact.new
|
||||
= render :partial => 'contacts/share_with_list',
|
||||
:locals => {:person => friend[:person],
|
||||
:locals => {:person => friend.person,
|
||||
:contact => contact,
|
||||
:aspects_with_person => [],
|
||||
:aspects_without_person => current_user.aspects,
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@
|
|||
%h4
|
||||
= t('.invite_your_friends_from', :service => params[:provider].titleize)
|
||||
.description
|
||||
- if @friends.keys.length > 0
|
||||
= t('.friends', :count => @friends.keys.length)
|
||||
- if @friends.size > 0
|
||||
= t('.friends', :count => @friends.size)
|
||||
- else
|
||||
%i= t('.not_connected')
|
||||
|
||||
|
||||
.contact_list
|
||||
- if @friends.keys.length > 0
|
||||
- if @friends.size > 0
|
||||
= render :partial => 'services/finder', :locals => {:friends => @friends}
|
||||
- else
|
||||
%br
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ var List = {
|
|||
var list = $(this).siblings("ul").first();
|
||||
var query = new RegExp(search.val(),'i');
|
||||
|
||||
$("li", list).each( function() {
|
||||
$("> li", list).each( function() {
|
||||
var element = $(this);
|
||||
if( !element.text().match(query) ) {
|
||||
if( !element.hasClass('hidden') ) {
|
||||
|
|
|
|||
|
|
@ -17,17 +17,11 @@ describe SessionsController do
|
|||
|
||||
let(:mock_access_token) { Object.new }
|
||||
|
||||
let(:omniauth_auth) {
|
||||
{ 'provider' => 'twitter',
|
||||
'uid' => '2',
|
||||
'user_info' => { 'nickname' => 'grimmin' },
|
||||
'credentials' => { 'token' => 'tokin', 'secret' =>"not_so_much" }
|
||||
}
|
||||
}
|
||||
|
||||
before do
|
||||
request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
@request.env["devise.mapping"] = Devise.mappings[:user]
|
||||
@user = alice
|
||||
@user.password = "evankorth"
|
||||
@user.password_confirmation = "evankorth"
|
||||
@service = Services::Facebook.new(:access_token => "yeah")
|
||||
@user.services << @service
|
||||
@user.save
|
||||
|
|
@ -36,7 +30,7 @@ describe SessionsController do
|
|||
describe "#create" do
|
||||
it 'queues up an update job' do
|
||||
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, @service.id)
|
||||
post :create, {"user"=>{"remember_me"=>"0", "username"=>"alice",
|
||||
post :create, {"user"=>{"remember_me"=>"0", "username"=> @user.username,
|
||||
"password"=>"evankorth"}}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -71,8 +71,14 @@ JSON
|
|||
end
|
||||
|
||||
describe '#finder' do
|
||||
it 'does a syncronous call if it has not been called before' do
|
||||
@service.should_receive(:save_friends)
|
||||
@service.finder
|
||||
end
|
||||
it 'dispatches a resque job' do
|
||||
Resque.should_receive(:enqueue).with(Job::UpdateServiceUsers, @service.id)
|
||||
su2 = ServiceUser.create(:service => @user2_service, :uid => @user2_fb_id, :name => @user2_fb_name, :photo_url => @user2_fb_photo_url)
|
||||
@service.service_users = [su2]
|
||||
@service.finder
|
||||
end
|
||||
context 'opts' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue