search now sockets a person
This commit is contained in:
parent
8a47b3d538
commit
248e768846
7 changed files with 61 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
||||
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
||||
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
- 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}
|
||||
= render :partial => 'requests/new_request_to_person', :locals => {:aspects => aspects, :person => person}
|
||||
|
||||
.info
|
||||
= person.diaspora_handle
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
=t('.results_for')
|
||||
%u= params[:q]
|
||||
|
||||
%ul#stream
|
||||
%ul#stream.people
|
||||
- for person in @people
|
||||
= render 'people/person', :person => person
|
||||
= render 'people/person', :person => person, :aspects => @aspects
|
||||
|
||||
= will_paginate @people
|
||||
|
|
|
|||
13
spec/helpers/sockets_helper_spec.rb
Normal file
13
spec/helpers/sockets_helper_spec.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
#
|
||||
require 'spec_helper'
|
||||
|
||||
describe SocketsHelper do
|
||||
|
||||
describe '#obj_id' do
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Reference in a new issue