Merge branch 'facebook_friend_refactor'

This commit is contained in:
Maxwell Salzberg 2011-08-19 15:57:57 -07:00
commit a5ab8a80d8
9 changed files with 95 additions and 35 deletions

View file

@ -57,29 +57,49 @@ class ServicesController < ApplicationController
@uid = params[:uid] @uid = params[:uid]
if i_id = params[:invitation_id] if i_id = params[:invitation_id]
invited_user = Invitation.find(i_id).recipient invite = Invitation.find(i_id)
invited_user = invite.recipient
else else
invite = Invitation.create(:service => params[:provider], :identifier => @uid, :sender => current_user, :aspect => current_user.aspects.find(params[:aspect_id])) invite = Invitation.create(:service => params[:provider], :identifier => @uid, :sender => current_user, :aspect => current_user.aspects.find(params[:aspect_id]))
invited_user = invite.attach_recipient! invited_user = invite.attach_recipient!
end end
@subject = t('services.inviter.join_me_on_diaspora') #to make sure a friend you just invited from facebook shows up as invited
@message = <<MSG
#{t('services.inviter.click_link_to_accept_invitation')}:
\n
\n
#{accept_invitation_url(invited_user, :invitation_token => invited_user.invitation_token)}
MSG
service = current_user.services.where(:type => "Services::Facebook").first service = current_user.services.where(:type => "Services::Facebook").first
su = ServiceUser.where(:service_id => service.id, :uid => @uid).first su = ServiceUser.where(:service_id => service.id, :uid => @uid).first
su.attach_local_models su.attach_local_models
su.save su.save
url = "https://www.facebook.com/?compose=1&id=#{@uid}&subject=#{@subject}&message=#{@message}&sk=messages"
respond_to do |format| respond_to do |format|
format.html{ redirect_to url } format.html{ invite_redirect_url(invite, invited_user, su)}
format.json{ render :json => {:url => url} } format.json{ render :json => invite_redirect_json(invite, invited_user, su) }
end
end
def facebook_message_url(user, facebook_uid)
subject = t('services.inviter.join_me_on_diaspora')
message = <<MSG
#{t('services.inviter.click_link_to_accept_invitation')}:
\n
\n
#{accept_invitation_url(user, :invitation_token => user.invitation_token)}
MSG
"https://www.facebook.com/?compose=1&id=#{facebook_uid}&subject=#{subject}&message=#{message}&sk=messages"
end
def invite_redirect_json(invite, user, service_user)
if invite.email_like_identifer
{:message => t("invitations.create.sent") + service_user.name }
else
{:url => facebook_message_url(user, service_user.uid)}
end
end
def invite_redirect_url(invite, user, service_user)
if invite.email_like_identifer
redirect_to(friend_finder_path(:provider => 'facebook'), :notice => "you re-invited #{service_user.name}")
else
redirect_to(facebook_message_url(user, service_user.uid))
end end
end end
end end

View file

@ -0,0 +1,5 @@
class DiasporaDeviseMailer < Devise::Mailer
include NotifierHelper
default :from => AppConfig[:smtp_sender_address]
end

View file

@ -61,7 +61,7 @@ class Invitation < ActiveRecord::Base
# @return [Boolean] # @return [Boolean]
# @return [void] # @return [void]
def skip_email? def skip_email?
self.service != 'email' !email_like_identifer
end end
# Attach a recipient [User] to the [Invitation] unless # Attach a recipient [User] to the [Invitation] unless
@ -115,6 +115,22 @@ class Invitation < ActiveRecord::Base
end end
end end
end end
# @return [String]
def email_like_identifer
case self.service
when 'email'
self.identifier
when 'facebook'
if username = ServiceUser.username_of_service_user_by_uid(self.identifier)
unless username.include?('profile.php?')
"#{username}@facebook.com"
else
nil
end
end
end
end
def queue_send! def queue_send!
unless self.recipient.present? unless self.recipient.present?

View file

@ -18,6 +18,14 @@ class ServiceUser < ActiveRecord::Base
self.person_id.present? self.person_id.present?
end end
def self.username_of_service_user_by_uid(uid)
if su = ServiceUser.find_by_uid(uid)
su.username
else
nil
end
end
def attach_local_models def attach_local_models
service_for_uid = Services::Facebook.where(:type => service.type.to_s, :uid => self.uid).first service_for_uid = Services::Facebook.where(:type => service.type.to_s, :uid => self.uid).first
if !service_for_uid.blank? && (service_for_uid.user.person.profile.searchable) if !service_for_uid.blank? && (service_for_uid.user.person.profile.searchable)

View file

@ -17,9 +17,6 @@
<tr> <tr>
<td style="padding: 10px 0pt 0px 20px; background: rgb(255, 255, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-size: 44px; font-weight: bold; color: rgb(0, 0, 0);"> <td style="padding: 10px 0pt 0px 20px; background: rgb(255, 255, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-size: 44px; font-weight: bold; color: rgb(0, 0, 0);">
Finally - it's here.<br> Finally - it's here.<br>
@ -31,11 +28,6 @@
</a></td></tr> </a></td></tr>
<tr><td style="padding: 0pt 30px; background: rgb(255, 255, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 20px;"> <tr><td style="padding: 0pt 30px; background: rgb(255, 255, 255) none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; line-height: 20px;">
The social network you have been waiting for has arrived. Revamped, more secure, and more fun, <strong>DIASPORA*</strong> is ready to help you share and explore the web in a whole new way. The social network you have been waiting for has arrived. Revamped, more secure, and more fun, <strong>DIASPORA*</strong> is ready to help you share and explore the web in a whole new way.
<br> <br>

View file

@ -2,7 +2,7 @@
.right .right
- if friend.already_invited? - if friend.already_invited?
= link_to t('.resend'), service_inviter_path(:uid => friend.uid, :provider => 'facebook', :invitation_id => friend.invitation_id) = link_to t('.resend'), service_inviter_path(:uid => friend.uid, :provider => 'facebook', :invitation_id => friend.invitation_id), :class => 'button resend'
- elsif friend.on_diaspora? - elsif friend.on_diaspora?
= render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left' = render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left'
- else - else

View file

@ -15,21 +15,14 @@ end
Devise.setup do |config| Devise.setup do |config|
# Configure the e-mail address which will be shown in DeviseMailer. # Configure the e-mail address which will be shown in DeviseMailer.
if AppConfig[:smtp_sender_address]
config.mailer_sender = AppConfig[:smtp_sender_address]
else
unless Rails.env == 'test'
Rails.logger.warn("No smtp sender address set, mail may fail.")
puts "WARNING: No smtp sender address set, mail may fail."
end
config.mailer_sender = "please-change-me@config-initializers-devise.com"
end
# ==> ORM configuration # ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default), :mongoid # Load and configure the ORM. Supports :active_record (default), :mongoid
# (bson_ext recommended) and :data_mapper (experimental). # (bson_ext recommended) and :data_mapper (experimental).
require 'devise/orm/active_record' require 'devise/orm/active_record'
# Configure the class responsible to send e-mails.
config.mailer = "DiasporaDeviseMailer"
# ==> Configuration for any authentication mechanism # ==> Configuration for any authentication mechanism
# Configure which keys are used when authenticating an user. By default is # Configure which keys are used when authenticating an user. By default is
# just :email. You can configure it to use [:username, :subdomain], so for # just :email. You can configure it to use [:username, :subdomain], so for

View file

@ -5,9 +5,17 @@
var ContactEdit = { var ContactEdit = {
init: function(){ init: function(){
$.extend(ContactEdit, AspectsDropdown); $.extend(ContactEdit, AspectsDropdown);
$('.dropdown.aspect_membership .dropdown_list > li').live('click', function(evt){ $('.dropdown.aspect_membership .dropdown_list > li, .dropdown.inviter .dropdown_list >li').live('click', function(evt){
ContactEdit.processClick($(this), evt); ContactEdit.processClick($(this), evt);
}); });
// $('.button.resend').live('click', function(evt){
// evt.preventDefault();
// $.post($(this).href, {},
// function(data){
// console.log(data);
// ContactEdit.processSuccess($(this), evt, data)
// });
// });
}, },
processClick: function(li, evt){ processClick: function(li, evt){
@ -15,6 +23,7 @@ var ContactEdit = {
li.addClass('loading'); li.addClass('loading');
if (dropdown.hasClass('inviter')) { if (dropdown.hasClass('inviter')) {
ContactEdit.inviteFriend(li, evt); ContactEdit.inviteFriend(li, evt);
dropdown.html('sending, please wait...');
} }
else { else {
ContactEdit.toggleAspectMembership(li, evt); ContactEdit.toggleAspectMembership(li, evt);
@ -26,11 +35,21 @@ var ContactEdit = {
"aspect_id" : li.data("aspect_id"), "aspect_id" : li.data("aspect_id"),
"uid" : li.parent().data("service_uid") "uid" : li.parent().data("service_uid")
}, function(data){ }, function(data){
li.removeClass('loading') ContactEdit.processSuccess(li, evt, data);
window.location = data.url;
}); });
}, },
processSuccess: function(element, evt, data) {
element.removeClass('loading')
element.parent().parent().html('sent!');
if (data.url != undefined) {
window.location = data.url;
} else {
element.toggleClass("selected");
Diaspora.widgets.flashes.render({'success':true, 'notice':data.message});
}
},
toggleAspectMembership: function(li, evt) { toggleAspectMembership: function(li, evt) {
var button = li.find('.button'); var button = li.find('.button');
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; } if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }

View file

@ -3397,3 +3397,10 @@ ul#getting_started
.green .green
:color green :color green
// .resend
// :color black
// &:hover
// :text-decoration none
// :color black
// &:hover
// :text-decoration none