Merge branch 'facebook_friend_refactor'
This commit is contained in:
commit
a5ab8a80d8
9 changed files with 95 additions and 35 deletions
|
|
@ -57,29 +57,49 @@ class ServicesController < ApplicationController
|
|||
@uid = params[:uid]
|
||||
|
||||
if i_id = params[:invitation_id]
|
||||
invited_user = Invitation.find(i_id).recipient
|
||||
invite = Invitation.find(i_id)
|
||||
invited_user = invite.recipient
|
||||
else
|
||||
invite = Invitation.create(:service => params[:provider], :identifier => @uid, :sender => current_user, :aspect => current_user.aspects.find(params[:aspect_id]))
|
||||
invited_user = invite.attach_recipient!
|
||||
end
|
||||
|
||||
@subject = t('services.inviter.join_me_on_diaspora')
|
||||
@message = <<MSG
|
||||
#{t('services.inviter.click_link_to_accept_invitation')}:
|
||||
\n
|
||||
\n
|
||||
#{accept_invitation_url(invited_user, :invitation_token => invited_user.invitation_token)}
|
||||
MSG
|
||||
|
||||
#to make sure a friend you just invited from facebook shows up as invited
|
||||
service = current_user.services.where(:type => "Services::Facebook").first
|
||||
su = ServiceUser.where(:service_id => service.id, :uid => @uid).first
|
||||
su.attach_local_models
|
||||
su.save
|
||||
|
||||
url = "https://www.facebook.com/?compose=1&id=#{@uid}&subject=#{@subject}&message=#{@message}&sk=messages"
|
||||
respond_to do |format|
|
||||
format.html{ redirect_to url }
|
||||
format.json{ render :json => {:url => url} }
|
||||
format.html{ invite_redirect_url(invite, invited_user, su)}
|
||||
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
|
||||
|
|
|
|||
5
app/mailers/diaspora_devise_mailer.rb
Normal file
5
app/mailers/diaspora_devise_mailer.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class DiasporaDeviseMailer < Devise::Mailer
|
||||
include NotifierHelper
|
||||
default :from => AppConfig[:smtp_sender_address]
|
||||
|
||||
end
|
||||
|
|
@ -61,7 +61,7 @@ class Invitation < ActiveRecord::Base
|
|||
# @return [Boolean]
|
||||
# @return [void]
|
||||
def skip_email?
|
||||
self.service != 'email'
|
||||
!email_like_identifer
|
||||
end
|
||||
|
||||
# Attach a recipient [User] to the [Invitation] unless
|
||||
|
|
@ -115,6 +115,22 @@ class Invitation < ActiveRecord::Base
|
|||
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!
|
||||
unless self.recipient.present?
|
||||
|
|
|
|||
|
|
@ -18,6 +18,14 @@ class ServiceUser < ActiveRecord::Base
|
|||
self.person_id.present?
|
||||
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
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -17,9 +17,6 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<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);">
|
||||
Finally - it's here.<br>
|
||||
|
|
@ -31,11 +28,6 @@
|
|||
</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;">
|
||||
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>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
.right
|
||||
|
||||
- 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?
|
||||
= render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left'
|
||||
- else
|
||||
|
|
|
|||
|
|
@ -15,21 +15,14 @@ end
|
|||
|
||||
Devise.setup do |config|
|
||||
# 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
|
||||
# Load and configure the ORM. Supports :active_record (default), :mongoid
|
||||
# (bson_ext recommended) and :data_mapper (experimental).
|
||||
require 'devise/orm/active_record'
|
||||
|
||||
# Configure the class responsible to send e-mails.
|
||||
config.mailer = "DiasporaDeviseMailer"
|
||||
|
||||
# ==> Configuration for any authentication mechanism
|
||||
# Configure which keys are used when authenticating an user. By default is
|
||||
# just :email. You can configure it to use [:username, :subdomain], so for
|
||||
|
|
|
|||
|
|
@ -5,9 +5,17 @@
|
|||
var ContactEdit = {
|
||||
init: function(){
|
||||
$.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);
|
||||
});
|
||||
// $('.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){
|
||||
|
|
@ -15,6 +23,7 @@ var ContactEdit = {
|
|||
li.addClass('loading');
|
||||
if (dropdown.hasClass('inviter')) {
|
||||
ContactEdit.inviteFriend(li, evt);
|
||||
dropdown.html('sending, please wait...');
|
||||
}
|
||||
else {
|
||||
ContactEdit.toggleAspectMembership(li, evt);
|
||||
|
|
@ -26,11 +35,21 @@ var ContactEdit = {
|
|||
"aspect_id" : li.data("aspect_id"),
|
||||
"uid" : li.parent().data("service_uid")
|
||||
}, function(data){
|
||||
li.removeClass('loading')
|
||||
window.location = data.url;
|
||||
ContactEdit.processSuccess(li, evt, data);
|
||||
});
|
||||
},
|
||||
|
||||
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) {
|
||||
var button = li.find('.button');
|
||||
if(button.hasClass('disabled') || li.hasClass('newItem')){ return; }
|
||||
|
|
|
|||
|
|
@ -3397,3 +3397,10 @@ ul#getting_started
|
|||
|
||||
.green
|
||||
:color green
|
||||
// .resend
|
||||
// :color black
|
||||
// &:hover
|
||||
// :text-decoration none
|
||||
// :color black
|
||||
// &:hover
|
||||
// :text-decoration none
|
||||
|
|
|
|||
Loading…
Reference in a new issue