Skip to content
Extraits de code Groupes Projets
Valider f97218c0 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

MS IZ cleanup of pubsub stuff

parent 892eec19
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -2,7 +2,6 @@ class DashboardsController < ApplicationController ...@@ -2,7 +2,6 @@ class DashboardsController < ApplicationController
before_filter :authenticate_user!, :except => [:receive, :hub, :host_meta] before_filter :authenticate_user!, :except => [:receive, :hub, :host_meta]
include ApplicationHelper include ApplicationHelper
include DashboardsHelper
def index def index
@posts = Post.paginate :page => params[:page], :order => 'created_at DESC' @posts = Post.paginate :page => params[:page], :order => 'created_at DESC'
......
class PublicsController < ApplicationController
include ApplicationHelper
include PublicsHelper
def hcard
end
def host_meta
@user = User.owner
render 'host_meta', :layout => false, :content_type => 'application/xrd+xml'
end
def webfinger
@user = Person.first(:email => params[:q])
render 'webfinger', :layout => false, :content_type => 'application/xrd+xml'
end
def hubbub
if params['hub.mode'] == "subscribe"
render :text => params['hub.challenge'], :status => 202
end
end
end
module DashboardsHelper module DashboardsHelper
def subscribe(opts = {})
subscriber = Subscriber.first(:url => opts[:callback], :topic => opts[:topic])
subscriber ||= Subscriber.new(:url => opts[:callback], :topic => opts[:topic])
if subscriber.save
if opts[:verify] == 'sync'
204
elsif opts[:verify] == 'async'
202
end
else
400
end
end
end end
module PublicsHelper
def subscribe(opts = {})
subscriber = Subscriber.first(:url => opts[:callback], :topic => opts[:topic])
subscriber ||= Subscriber.new(:url => opts[:callback], :topic => opts[:topic])
if subscriber.save
if opts[:verify] == 'sync'
204
elsif opts[:verify] == 'async'
202
end
else
400
end
end
end
\ No newline at end of file
class Subscriber
include MongoMapper::Document
key :url
key :topic
validates_presence_of :url, :topic
end
<?xml version='1.0' encoding='UTF-8'?>
<XRD xmlns='http://docs.oasis-open.org/ns/xri/xrd-1.0'
xmlns:hm='http://host-meta.net/xrd/1.0'>
<hm:Host xmlns='http://host-meta.net/xrd/1.0'><%=@user.url%></hm:Host>
<Link rel='lrdd'
template='<%=@user.url%>webfinger/?q={uri}'>
<Title>Resource Descriptor</Title>
</Link>
</XRD>
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Subject>acct:<%=@user.email%></Subject>
<Alias><%=@user.url%></Alias>
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="<%=@user.url%>public/profile"/>
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@user.url%>status_messages.atom"/>
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%@user.url%>public/hcard"/>
//<Link rel="http://salmon-protocol.org/ns/salmon-replies" href="http://identi.ca/main/salmon/user/169966"/>
//<Link rel="http://salmon-protocol.org/ns/salmon-mention" href="http://identi.ca/main/salmon/user/169966"/>
//<Link rel="magic-public-key" href="data:application/magic-public-key,RSA.mGJbO8SYr9CSzfpI0TDLTvn7mnYWmTYcg4uP80rVh_lHJI-IGs7k9nb5XzGzyr4Ah8wHaxLVvmgdChw1eOd6VPDm58Bkpx9iwd9oMXwrrSBvlmE8grlzlb15GuvywPQJ7tCerNYGFNhtqBk1iUB5mue6UZAE0Y3ZaAgYfYNwITE=.AQAB"/>
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="http://identi.ca/main/ostatussub?profile={uri}"/>
</XRD>
%li.message{:id => post.id, :class => ("mine" if mine?(post))}
%span.from
= link_to post.person.real_name, post.person
= auto_link post.message
%div.time
= link_to(how_long_ago(post), status_message_path(post))
\--
= link_to "show comments (#{post.comments.count})", '#', :class => "show_post_comments"
= render "comments/comments", :post => post
- if mine?(post)
.destroy_link
= link_to 'Delete', status_message_path(post), :confirm => 'Are you sure?', :method => :delete, :remote => true
require 'em-websocket' require 'em-websocket'
require 'eventmachine' require 'eventmachine'
module WebSocket module WebSocket
EM.next_tick { EM.next_tick {
initialize_channel initialize_channel
......
...@@ -18,7 +18,7 @@ Diaspora::Application.routes.draw do |map| ...@@ -18,7 +18,7 @@ Diaspora::Application.routes.draw do |map|
resources :users resources :users
match 'receive', :to => 'dashboards#receive' match 'receive', :to => 'dashboards#receive'
match 'hub', :to => 'publics#hub' match 'hub', :to => 'publics#hubbub'
match '.well-known/host-meta', :to => 'publics#host_meta' match '.well-known/host-meta', :to => 'publics#host_meta'
match 'webfinger', :to => 'publics#webfinger' match 'webfinger', :to => 'publics#webfinger'
root :to => 'dashboards#index' root :to => 'dashboards#index'
......
...@@ -15,45 +15,4 @@ describe DashboardsController do ...@@ -15,45 +15,4 @@ describe DashboardsController do
assigns[:friends].should == Person.friends.all assigns[:friends].should == Person.friends.all
end end
describe 'PubSubHubBuB intergration' do
describe 'incoming subscriptions' do
it 'should register a friend' do
Subscriber.all.count.should == 0
post :hub, {:callback => "http://example.com/",
:mode => 'subscribe',
:topic => '/status_messages',
:verify => 'async'}
response.status.should == 202
Subscriber.all.count.should == 1
end
it 'should keep track of what topic a subscriber wants' do
post :hub, {:callback => "http://example.com/",
:mode => 'subscribe',
:topic => '/status_messages',
:verify => 'async'}
Subscriber.first.topic.should == '/status_messages'
end
end
it 'should return a 204 for a sync request' do
post :hub, {:callback => "http://example.com/",
:mode => 'subscribe',
:topic => '/status_messages',
:verify => 'sync'}
response.status.should == 204
end
it 'should confirm subscription of a sync request' do
post :hub, {:callback => "http://example.com/",
:mode => 'subscribe',
:topic => '/status_messages',
:verify => 'sync'}
end
end
end end
require File.dirname(__FILE__) + '/../spec_helper'
describe PublicsController do
render_views
before do
@user = Factory.create(:user, :profile => Profile.create( :first_name => "bob", :last_name => "smith"))
request.env['warden'] = mock_model(Warden, :authenticate? => @user, :authenticate! => @user, :authenticate => @user)
end
describe 'PubSubHubBuB intergration' do
describe 'incoming subscriptions' do
it 'should respond to a incoming subscription request' do
get :hubbub, {'hub.callback' => "http://example.com/",
'hub.mode' => 'subscribe',
'hub.topic' => '/status_messages',
'hub.verify' => 'sync',
'hub.challenge' => 'foobar'}
response.status.should == 202
response.body.should == 'foobar'
end
end
end
end
require File.dirname(__FILE__) + '/../spec_helper'
describe Subscriber do
it 'should require a url' do
n = Subscriber.new
n.valid?.should be false
n.topic = '/status_messages'
n.valid?.should be false
n.url = "http://clown.com/"
n.valid?.should be true
end
end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter