diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 8c814db5e9c72ba159bc7ef96bc611e0d302b17f..115a3d9bbcdf971ffecbe820dd7c047d0cbc9e89 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 0000000000000000000000000000000000000000..76748837d7938244c04d9a337ddbd80a1f45f6fa --- /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 dc181652a18882d6ab2b583ea97d0a449d2e70ef..28cd48d0e0f347525e4281099321455dedcd0246 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 0000000000000000000000000000000000000000..e694adef9ed68bdaf8a01880d12a28e93fb559c9 --- /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 19d234d2466f77c19948fe27fac421a72c96545f..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..3b6280e5c66c74cc07a928e36e0b38ff436bd803 --- /dev/null +++ b/app/views/publics/host_meta.erb @@ -0,0 +1,9 @@ +<?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> diff --git a/app/views/publics/webfinger.erb b/app/views/publics/webfinger.erb new file mode 100644 index 0000000000000000000000000000000000000000..ebc8cbf029d3ec3fdb3cd9d43a013171e755cb76 --- /dev/null +++ b/app/views/publics/webfinger.erb @@ -0,0 +1,13 @@ +<?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> + diff --git a/app/views/status_messages/_status_message.haml b/app/views/status_messages/_status_message.haml new file mode 100644 index 0000000000000000000000000000000000000000..1434ca0d2cb232a3cd56b21f85032eb9fe874e38 --- /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 2f873be233e3b086e25bdccbc350279076b4ae73..aebf023f3a92e2cb8865f5dc3653b76d51fa8af1 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 d59627301be60651d19c07033b23245d0a7bb8bd..96f0a02312c77e2b398379471196cf5a85e71283 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 053dbdda027314661f6baa37800d1ed9e4d5ae9f..7b9a2857b14c7ae3ef5d729a02746b86f8af5cdf 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 0000000000000000000000000000000000000000..e9539b4641fc42b80f5c0c000d8841b71b9974e7 --- /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 4cfad9bbe53a2560c88efe10b9b928573766f136..0000000000000000000000000000000000000000 --- 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