From c0414b81842a02f225cd29b776834428483f0cde Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 16 Nov 2010 16:17:53 -0800 Subject: [PATCH] Make requesting ajaxy, refactor _person request partials, add route for ajaxy webfingering, people now socket to search and _manage_aspect_contacts --- app/controllers/people_controller.rb | 49 ++++++++++--------- app/helpers/people_helper.rb | 8 +++ app/helpers/sockets_helper.rb | 2 +- app/views/people/_person.html.haml | 3 +- app/views/people/show.html.haml | 2 +- .../requests/_manage_aspect_contacts.haml | 9 ++-- .../requests/_new_request_to_person.haml | 8 +-- .../_new_request_with_aspect_to_person.haml | 8 +++ config/locales/diaspora/en.yml | 2 + config/routes.rb | 4 +- public/stylesheets/sass/application.sass | 13 +++-- 11 files changed, 69 insertions(+), 39 deletions(-) create mode 100644 app/views/requests/_new_request_with_aspect_to_person.haml diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 8ffa6651c..8abb47d6f 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -18,33 +18,13 @@ class PeopleController < ApplicationController #only do it if it is an email address if params[:q].try(:match, Devise.email_regexp) - find_remote_user(params[:q]) + webfinger(params[:q]) end respond_with @people end - def find_remote_user(account) - - finger = EMWebfinger.new(account) - finger.on_person do |response| - begin - puts response.inspect - if response.class == Person - - response.socket_to_uid(current_user.id, :aspects => @aspects) - else - require File.join(Rails.root,'lib/diaspora/websocket') - puts Diaspora::WebSocket - Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'person', :query => account, :response => response}) - end - rescue - end - end - end - def show - @person = Person.find(params[:id].to_id) @post_type = :all @aspect = :none @@ -62,7 +42,6 @@ class PeopleController < ApplicationController @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' respond_with @person, :locals => {:post_type => :all} - else flash[:error] = I18n.t 'people.show.does_not_exist' redirect_to people_path @@ -111,4 +90,30 @@ class PeopleController < ApplicationController redirect_to edit_person_path end end + + def retrieve_remote + if params[:diaspora_handle] + webfinger(params[:diaspora_handle], :single_aspect_form => true) + render :nothing => true + else + render :nothing => true, :status => 422 + end + end + + private + def webfinger(account, opts = {}) + finger = EMWebfinger.new(account) + finger.on_person do |response| + begin + if response.class == Person + response.socket_to_uid(current_user.id, opts) + else + require File.join(Rails.root,'lib/diaspora/websocket') + Diaspora::WebSocket.queue_to_user(current_user.id, {:class => 'person', :query => account, :response => response}) + end + rescue RuntimeError => e + puts e.message + end + end + end end diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index 485fdc1d6..1a382a499 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -4,6 +4,14 @@ module PeopleHelper + def request_partial single_aspect_form + if single_aspect_form + 'requests/new_request_with_aspect_to_person' + else + 'requests/new_request_to_person' + end + end + def search_or_index if params[:q] I18n.t 'people.helper.results_for',:params => params[:q] diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 1ad68551b..d646f0e4e 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -15,7 +15,7 @@ module SocketsHelper if object.is_a? Post v = render_to_string(:partial => 'shared/stream_element', :locals => {:post => object, :current_user => user}) elsif object.is_a? Person - v = render_to_string(:partial => type_partial(object), :locals => {:person => object, :current_user => user}) unless object.is_a? Retraction + v = render_to_string(:partial => type_partial(object), :locals => {:single_aspect_form => opts[:single_aspect_form], :person => object, :aspects => user.aspects, :current_user => user}) else v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction end diff --git a/app/views/people/_person.html.haml b/app/views/people/_person.html.haml index a66632e88..b0c94bbe3 100644 --- a/app/views/people/_person.html.haml +++ b/app/views/people/_person.html.haml @@ -18,7 +18,8 @@ - elsif current_user.pending_requests.find_by_person_id(person.id) = link_to =t('.pending_request'), aspects_manage_path - else - = render :partial => 'requests/new_request_to_person', :locals => {:aspects => aspects, :person => person} + - single_aspect_form ||= nil + = render(:partial => request_partial(single_aspect_form), :locals => {:aspects => aspects, :destination_handle => person.diaspora_handle}) .info = person.diaspora_handle diff --git a/app/views/people/show.html.haml b/app/views/people/show.html.haml index ffdc11362..94ca94356 100644 --- a/app/views/people/show.html.haml +++ b/app/views/people/show.html.haml @@ -30,7 +30,7 @@ .description = t('.request_people') - = render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :person => @person} + = render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle} - else %h3 diff --git a/app/views/requests/_manage_aspect_contacts.haml b/app/views/requests/_manage_aspect_contacts.haml index d44ac2761..4fba6a143 100644 --- a/app/views/requests/_manage_aspect_contacts.haml +++ b/app/views/requests/_manage_aspect_contacts.haml @@ -7,21 +7,20 @@ %h4 Manage contacts within %i= aspect.name - .span-6.append-1.last %h3 Existing contacts = render 'shared/contact_list', :aspect => aspect, :contacts => @contacts, :manage => defined?(manage) .span-7.last %h3 Add a new contact - = form_tag(requests_path, :id => "new_request_to_#{aspect.id}") do + = form_tag(person_by_handle_path, :id => "new_request_to_#{aspect.id}", :remote => true) do =t('.enter_a_diaspora_username') %br %i= t '.your_diaspora_username_is', :diaspora_handle => current_user.diaspora_handle %p - = label_tag :destination_handle, t('.contact_username'), :for => "request_d_handle_to_#{aspect.id}" - = text_field_tag :destination_handle,'', :id => "request_d_handle_to_#{aspect.id}" + = label_tag :diaspora_handle, t('.contact_username'), :for => "request_d_handle_to_#{aspect.id}" + = text_field_tag :diaspora_handle,'', :id => "request_d_handle_to_#{aspect.id}" = hidden_field_tag :aspect_id, aspect.id - if defined?(getting_started) @@ -30,4 +29,6 @@ = hidden_field_tag :manage, true = submit_tag t('.create_request') + %br + %ul#request_result{:aspect_id => aspect.id} diff --git a/app/views/requests/_new_request_to_person.haml b/app/views/requests/_new_request_to_person.haml index 204ca1488..0f380e533 100644 --- a/app/views/requests/_new_request_to_person.haml +++ b/app/views/requests/_new_request_to_person.haml @@ -2,7 +2,7 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -= form_tag(requests_path) do - = select_tag(:aspect_id, options_from_collection_for_select(aspects, "id", "name")) - = hidden_field_tag :destination_handle, person.diaspora_handle - = submit_tag t('people.person.add_contact') += form_for(Request.new, :remote => true ) do |request| + = request.select(:into, options_from_collection_for_select(aspects, "id", "name")) + = request.hidden_field :to, :value => destination_handle + = request.submit t('people.person.add_contact'), :disable_with => t('requests.create.sending') diff --git a/app/views/requests/_new_request_with_aspect_to_person.haml b/app/views/requests/_new_request_with_aspect_to_person.haml new file mode 100644 index 000000000..31d771ef9 --- /dev/null +++ b/app/views/requests/_new_request_with_aspect_to_person.haml @@ -0,0 +1,8 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + += form_for Request.new, :remote => true do |request| + = request.hidden_field :into, :value => "changeme" + = request.hidden_field :to, :value => destination_handle + = request.submit '+', :class => 'add', :disable_with => "Sending..." diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 4ed3f60fe..612dbc1ff 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -303,6 +303,8 @@ en: error: "Please select an aspect!" ignore: "Ignored contact request." create: + sending: "Sending..." + sent: "You've asked to share with %{name}. They should see it next time they log in to Diaspora." tried: "we tried our best to send a message to %{account}" services: index: diff --git a/config/routes.rb b/config/routes.rb index 315364e28..6d05b8ac9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,18 +3,18 @@ # the COPYRIGHT file. Diaspora::Application.routes.draw do - resources :people resources :status_messages, :only => [:create, :destroy, :show] resources :comments, :except => [:index] resources :requests, :except => [:edit, :update] resources :photos, :except => [:index] resources :services + resources :people resources :people do resources :status_messages resources :photos end - + match '/people/by_handle' => 'people#retrieve_remote', :as => 'person_by_handle' match '/auth/:provider/callback' => 'services#create' diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index a33be907a..d436b3754 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -511,7 +511,6 @@ input.comment_submit :margin :right -10px - ul.comments :margin 0 :top 1em @@ -909,9 +908,6 @@ h1.big_text > li :padding 0 :display inline - :margin 0 - :left -1px - a :-webkit-border-radius 4px 4px 0 0 :-moz-border-radius 4px 4px 0 0 @@ -1548,6 +1544,15 @@ h3 span.current_gs_step :color #eee :text-shadow none +ul#request_result + :list-style none + :padding 0 + :margin 0 + li + :margin + :bottom 25px + input.add + :color green .contact_list :height 300px