From f97218c005ca4e6a482d5b50f4701d0a9a19b700 Mon Sep 17 00:00:00 2001 From: maxwell Date: Thu, 15 Jul 2010 10:24:41 -0700 Subject: [PATCH] MS IZ cleanup of pubsub stuff --- app/controllers/dashboards_controller.rb | 1 - app/controllers/publics_controller.rb | 24 +++++++++++ app/helpers/dashboards_helper.rb | 17 -------- app/helpers/publics_helper.rb | 17 ++++++++ app/models/subscriber.rb | 9 ---- app/views/publics/host_meta.erb | 9 ++++ app/views/publics/webfinger.erb | 13 ++++++ .../status_messages/_status_message.haml | 14 +++++++ config/initializers/socket.rb | 2 - config/routes.rb | 2 +- .../controllers/dashboards_controller_spec.rb | 41 ------------------- spec/controllers/publics_controller_spec.rb | 26 ++++++++++++ spec/models/subscriber_spec.rb | 15 ------- 13 files changed, 104 insertions(+), 86 deletions(-) create mode 100644 app/controllers/publics_controller.rb create mode 100644 app/helpers/publics_helper.rb delete mode 100644 app/models/subscriber.rb create mode 100644 app/views/publics/host_meta.erb create mode 100644 app/views/publics/webfinger.erb create mode 100644 app/views/status_messages/_status_message.haml create mode 100644 spec/controllers/publics_controller_spec.rb delete mode 100644 spec/models/subscriber_spec.rb diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 8c814db5e..115a3d9bb 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -2,7 +2,6 @@ class DashboardsController < ApplicationController before_filter :authenticate_user!, :except => [:receive, :hub, :host_meta] include ApplicationHelper - include DashboardsHelper def index @posts = Post.paginate :page => params[:page], :order => 'created_at DESC' diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb new file mode 100644 index 000000000..76748837d --- /dev/null +++ b/app/controllers/publics_controller.rb @@ -0,0 +1,24 @@ +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 diff --git a/app/helpers/dashboards_helper.rb b/app/helpers/dashboards_helper.rb index dc181652a..28cd48d0e 100644 --- a/app/helpers/dashboards_helper.rb +++ b/app/helpers/dashboards_helper.rb @@ -1,19 +1,2 @@ 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 diff --git a/app/helpers/publics_helper.rb b/app/helpers/publics_helper.rb new file mode 100644 index 000000000..e694adef9 --- /dev/null +++ b/app/helpers/publics_helper.rb @@ -0,0 +1,17 @@ +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 diff --git a/app/models/subscriber.rb b/app/models/subscriber.rb deleted file mode 100644 index 19d234d24..000000000 --- a/app/models/subscriber.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Subscriber - include MongoMapper::Document - - key :url - key :topic - - validates_presence_of :url, :topic - -end diff --git a/app/views/publics/host_meta.erb b/app/views/publics/host_meta.erb new file mode 100644 index 000000000..3b6280e5c --- /dev/null +++ b/app/views/publics/host_meta.erb @@ -0,0 +1,9 @@ + + + <%=@user.url%> + + Resource Descriptor + + diff --git a/app/views/publics/webfinger.erb b/app/views/publics/webfinger.erb new file mode 100644 index 000000000..ebc8cbf02 --- /dev/null +++ b/app/views/publics/webfinger.erb @@ -0,0 +1,13 @@ + + + acct:<%=@user.email%> + <%=@user.url%> + + + + // + // + // + + + diff --git a/app/views/status_messages/_status_message.haml b/app/views/status_messages/_status_message.haml new file mode 100644 index 000000000..1434ca0d2 --- /dev/null +++ b/app/views/status_messages/_status_message.haml @@ -0,0 +1,14 @@ +%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 diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 2f873be23..aebf023f3 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -1,8 +1,6 @@ require 'em-websocket' require 'eventmachine' - - module WebSocket EM.next_tick { initialize_channel diff --git a/config/routes.rb b/config/routes.rb index d59627301..96f0a0231 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ Diaspora::Application.routes.draw do |map| resources :users 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 'webfinger', :to => 'publics#webfinger' root :to => 'dashboards#index' diff --git a/spec/controllers/dashboards_controller_spec.rb b/spec/controllers/dashboards_controller_spec.rb index 053dbdda0..7b9a2857b 100644 --- a/spec/controllers/dashboards_controller_spec.rb +++ b/spec/controllers/dashboards_controller_spec.rb @@ -15,45 +15,4 @@ describe DashboardsController do assigns[:friends].should == Person.friends.all 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 diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb new file mode 100644 index 000000000..e9539b464 --- /dev/null +++ b/spec/controllers/publics_controller_spec.rb @@ -0,0 +1,26 @@ +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 diff --git a/spec/models/subscriber_spec.rb b/spec/models/subscriber_spec.rb deleted file mode 100644 index 4cfad9bbe..000000000 --- a/spec/models/subscriber_spec.rb +++ /dev/null @@ -1,15 +0,0 @@ -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