wip
This commit is contained in:
parent
32368a16dd
commit
70fe2cf10f
5 changed files with 71 additions and 16 deletions
|
|
@ -57,29 +57,40 @@ 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.json{ render :json => invite_redirect_url(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_url(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
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@
|
|||
.right
|
||||
|
||||
- if friend.already_invited?
|
||||
= link_to t('.resend'), service_inviter_path(:uid => friend.uid, :provider => 'facebook', :invitation_id => friend.invitation_id)
|
||||
.button.resend
|
||||
= link_to t('.resend'), service_inviter_path(:uid => friend.uid, :provider => 'facebook', :invitation_id => friend.invitation_id, :format => :json)
|
||||
- elsif friend.on_diaspora?
|
||||
= render 'shared/aspect_dropdown', :selected_aspects => contact_proxy(friend).aspects, :person => friend.person, :hang => 'left'
|
||||
- else
|
||||
|
|
|
|||
|
|
@ -8,6 +8,14 @@ var ContactEdit = {
|
|||
$('.dropdown.aspect_membership .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){
|
||||
|
|
@ -26,11 +34,22 @@ var ContactEdit = {
|
|||
"aspect_id" : li.data("aspect_id"),
|
||||
"uid" : li.parent().data("service_uid")
|
||||
}, function(data){
|
||||
li.removeClass('loading')
|
||||
window.location = data.url;
|
||||
processSuccess(li, evt, data);
|
||||
});
|
||||
},
|
||||
|
||||
processSuccess: function(element, evt, data) {
|
||||
element.removeClass('loading')
|
||||
|
||||
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; }
|
||||
|
|
|
|||
Loading…
Reference in a new issue