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
|
def index
|
||||||
@aspect = :search
|
@aspect = :search
|
||||||
|
|
||||||
@people = Person.search(params[:q]).paginate :page => params[:page], :per_page => 25, :order => 'created_at DESC'
|
@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
|
respond_with @people
|
||||||
end
|
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
|
def show
|
||||||
|
|
||||||
@person = Person.find(params[:id].to_id)
|
@person = Person.find(params[:id].to_id)
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,19 @@
|
||||||
# the COPYRIGHT file.
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
module SocketsHelper
|
module SocketsHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
def obj_id(object)
|
def obj_id(object)
|
||||||
(object.is_a? Post) ? object.id : object.post_id
|
object.respond_to?(:post_id) ? object.post_id : object.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_hash(uid, object, opts={})
|
def action_hash(uid, object, opts={})
|
||||||
begin
|
begin
|
||||||
user = User.find_by_id uid
|
user = User.find_by_id uid
|
||||||
if object.is_a? Post
|
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
|
else
|
||||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
||||||
end
|
end
|
||||||
|
|
@ -32,7 +34,7 @@ module SocketsHelper
|
||||||
action_hash[:notification] = notification(object)
|
action_hash[:notification] = notification(object)
|
||||||
end
|
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
|
action_hash.to_json
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ class Person
|
||||||
include MongoMapper::Document
|
include MongoMapper::Document
|
||||||
include ROXML
|
include ROXML
|
||||||
include Encryptor::Public
|
include Encryptor::Public
|
||||||
|
require File.join(Rails.root, 'lib/diaspora/websocket')
|
||||||
|
include Diaspora::Socketable
|
||||||
|
|
||||||
xml_accessor :_id
|
xml_accessor :_id
|
||||||
xml_accessor :diaspora_handle
|
xml_accessor :diaspora_handle
|
||||||
|
|
@ -148,7 +150,6 @@ class Person
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def clean_url
|
def clean_url
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@
|
||||||
if(obj['notice']){
|
if(obj['notice']){
|
||||||
processNotification(obj['notice']);
|
processNotification(obj['notice']);
|
||||||
|
|
||||||
|
}else if (obj['class'] == 'people'){
|
||||||
|
processPerson(obj['html']);
|
||||||
}else{
|
}else{
|
||||||
debug("got a " + obj['class'] + " for aspects " + obj['aspect_ids']);
|
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){
|
function processNotification(html){
|
||||||
$('#notification').html(html).fadeIn(200).delay(4000).fadeOut(200, function(){ $(this).html("");});
|
$('#notification').html(html).fadeIn(200).delay(4000).fadeOut(200, function(){ $(this).html("");});
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +103,7 @@
|
||||||
function processPhotoInAlbum(photoHash){
|
function processPhotoInAlbum(photoHash){
|
||||||
if (location.href.indexOf(photoHash['album_id']) == -1){
|
if (location.href.indexOf(photoHash['album_id']) == -1){
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
html = "<div class=\'image_thumb\' id=\'"+photoHash['id']+"\' style=\'padding-right:3px;\'> \
|
||||||
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
<a href=\"/photos/"+ photoHash['id'] +"\"> \
|
||||||
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
<img alt=\"New thumbnail\" src=\""+ photoHash['thumb_url'] +"\" /> \
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
- elsif current_user.pending_requests.find_by_person_id(person.id)
|
- elsif current_user.pending_requests.find_by_person_id(person.id)
|
||||||
= link_to =t('.pending_request'), aspects_manage_path
|
= link_to =t('.pending_request'), aspects_manage_path
|
||||||
- else
|
- 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
|
.info
|
||||||
= person.diaspora_handle
|
= person.diaspora_handle
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
=t('.results_for')
|
=t('.results_for')
|
||||||
%u= params[:q]
|
%u= params[:q]
|
||||||
|
|
||||||
%ul#stream
|
%ul#stream.people
|
||||||
- for person in @people
|
- for person in @people
|
||||||
= render 'people/person', :person => person
|
= render 'people/person', :person => person, :aspects => @aspects
|
||||||
|
|
||||||
= will_paginate @people
|
= 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