Merge branch 'master' of github.com:diaspora/diaspora

This commit is contained in:
Raphael 2010-10-18 15:46:44 -07:00
commit 676e802fd2
7 changed files with 33 additions and 6 deletions

View file

@ -10,6 +10,8 @@ class InvitationsController < Devise::InvitationsController
def create def create
begin begin
params[:user][:aspect_id] = params[:user].delete(:aspects) params[:user][:aspect_id] = params[:user].delete(:aspects)
message = params[:user].delete(:invite_messages)
params[:user][:invite_message] = message unless message == ""
self.resource = current_user.invite_user(params[resource_name]) self.resource = current_user.invite_user(params[resource_name])
flash[:notice] = I18n.t 'invitations.create.sent' flash[:notice] = I18n.t 'invitations.create.sent'
rescue RuntimeError => e rescue RuntimeError => e

View file

@ -12,10 +12,7 @@ class StatusMessagesController < ApplicationController
data = clean_hash params[:status_message] data = clean_hash params[:status_message]
if logged_into_fb? && params[:status_message][:public] == '1' if logged_into_fb? && params[:status_message][:public] == '1'
id = 'me' current_user.post_to_message_fb(params[:status_message][:message], @access_token)
type = 'feed'
Rails.logger.info("Sending a message: #{params[:status_message][:message]} to Facebook")
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{params[:status_message][:message]}&access_token=#{@access_token}").post
end end
@status_message = current_user.post(:status_message, data) @status_message = current_user.post(:status_message, data)

View file

@ -38,6 +38,8 @@ class User
key :visible_post_ids, Array key :visible_post_ids, Array
key :visible_person_ids, Array key :visible_person_ids, Array
key :invite_messages, Hash
before_validation :strip_username, :on => :create before_validation :strip_username, :on => :create
validates_presence_of :username validates_presence_of :username
validates_uniqueness_of :username, :case_sensitive => false validates_uniqueness_of :username, :case_sensitive => false
@ -131,6 +133,13 @@ class User
intitial_post(class_name, aspect_ids, options) intitial_post(class_name, aspect_ids, options)
end end
def post_to_message_fb(message, access_token)
id = 'me'
type = 'feed'
Rails.logger.info("Sending a message: #{message} to Facebook")
EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{access_token}").post
end
def intitial_post(class_name, aspect_ids, options = {}) def intitial_post(class_name, aspect_ids, options = {})
post = build_post(class_name, options) post = build_post(class_name, options)
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
@ -290,7 +299,7 @@ class User
:into => aspect_id :into => aspect_id
) )
invited_user = User.invite!(:email => opts[:email], :request => request, :inviter => self) invited_user = User.invite!(:email => opts[:email], :request => request, :inviter => self, :invite_message => opts[:invite_message])
self.invites = self.invites - 1 self.invites = self.invites - 1
self.pending_requests << request self.pending_requests << request
@ -313,6 +322,10 @@ class User
else else
invitable.pending_requests << request invitable.pending_requests << request
invitable.inviters << inviter invitable.inviters << inviter
message = attributes.delete(:invite_message)
if message
invitable.invite_messages[inviter.id.to_s] = message
end
end end
if invitable.new_record? if invitable.new_record?

View file

@ -2,6 +2,13 @@
Hello #{@resource.email}! Hello #{@resource.email}!
%p %p
#{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below. #{(@resource.inviters.count == 1)? ( @resource.inviters.first.real_name + " has") : (@resource.inviters.map{|inv| inv.real_name}.join(",") + " have")} invited you to #{root_url}, you can accept it through the link below.
- @resource.inviters.each do |inv|
- if @resource.invite_messages[inv.id.to_s]
= "#{inv.real_name}:"
= @resource.invite_messages[inv.id.to_s]
%p
%p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token) %p= link_to 'Accept invitation', accept_invitation_url(@resource, :invitation_token => @resource.invitation_token)
%p %p
If you don't want to accept the invitation, please ignore this email. If you don't want to accept the invitation, please ignore this email.

View file

@ -8,6 +8,8 @@
= invite.select(:aspects, @aspects_dropdown_array) = invite.select(:aspects, @aspects_dropdown_array)
- else - else
= invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id) = invite.select(:aspects, @aspects_dropdown_array, :selected => @aspect.id)
Message:
= invite.text_area :invite_messages
%p= invite.submit "Send an invitation" %p= invite.submit "Send an invitation"

View file

@ -28,7 +28,7 @@ $(document).ready(function(){
//buttons////// //buttons//////
$("#add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false }); $("#add_aspect_button").fancybox({ 'titleShow' : false , 'hideOnOverlayClick' : false });
$("#add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $("#add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$("#invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".invite_user_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".add_request_button").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });
$(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false }); $(".question_mark").fancybox({ 'titleShow': false , 'hideOnOverlayClick' : false });

View file

@ -46,6 +46,12 @@ describe User do
invited_user.inviters.include?(inviter).should be_true invited_user.inviters.include?(inviter).should be_true
end end
it 'adds an optional message' do
invited_user = inviter.invite_user(:email => "marcy@example.com", :invite_message => "How've you been?",:aspect_id => aspect.id)
invited_user.reload
invited_user.invite_messages[inviter.id.to_s].should == "How've you been?"
end
it 'adds a pending request to the invited user' do it 'adds a pending request to the invited user' do
invited_user = inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id) invited_user = inviter.invite_user(:email => "marcy@example.com", :aspect_id => aspect.id)