diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 6f2634be0..8ffa6651c 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -10,10 +10,39 @@ class PeopleController < ApplicationController def index @aspect = :search + @people = Person.search(params[:q]).paginate :page => params[:page], :per_page => 25, :order => 'created_at DESC' + + + # dont do it@people.first.diaspora_handle == params[:q] + + #only do it if it is an email address + if params[:q].try(:match, Devise.email_regexp) + find_remote_user(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) diff --git a/app/helpers/sockets_helper.rb b/app/helpers/sockets_helper.rb index 7c70b8e21..1ad68551b 100644 --- a/app/helpers/sockets_helper.rb +++ b/app/helpers/sockets_helper.rb @@ -3,17 +3,19 @@ # the COPYRIGHT file. module SocketsHelper - include ApplicationHelper + include ApplicationHelper - def obj_id(object) - (object.is_a? Post) ? object.id : object.post_id + def obj_id(object) + object.respond_to?(:post_id) ? object.post_id : object.id end def action_hash(uid, object, opts={}) begin user = User.find_by_id uid if object.is_a? Post - v = render_to_string(:partial => 'shared/stream_element', :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction + 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 else v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction end @@ -32,7 +34,7 @@ module SocketsHelper action_hash[:notification] = notification(object) end - action_hash[:mine?] = object.person && (object.person.owner.id == uid) + action_hash[:mine?] = object.person && (object.person.owner.id == uid) if object.respond_to?(:person) action_hash.to_json end diff --git a/app/models/person.rb b/app/models/person.rb index b7025a25e..62cc5759b 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -8,6 +8,8 @@ class Person include MongoMapper::Document include ROXML include Encryptor::Public + require File.join(Rails.root, 'lib/diaspora/websocket') + include Diaspora::Socketable xml_accessor :_id xml_accessor :diaspora_handle @@ -148,7 +150,6 @@ class Person } } end - protected def clean_url diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 4e4d26170..fa2636e35 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -17,6 +17,8 @@ if(obj['notice']){ processNotification(obj['notice']); + }else if (obj['class'] == 'people'){ + processPerson(obj['html']); }else{ debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']); @@ -42,6 +44,10 @@ }); + function processPerson(html){ + $('.people#stream').prepend(html).slideDown('slow', function(){}) + } + function processNotification(html){ $('#notification').html(html).fadeIn(200).delay(4000).fadeOut(200, function(){ $(this).html("");}); } @@ -97,7 +103,7 @@ function processPhotoInAlbum(photoHash){ if (location.href.indexOf(photoHash['album_id']) == -1){ return ; - } + } html = "