diff --git a/Gemfile b/Gemfile index 9820f47e95e0a258e04c58a117145eb5c0ad3496..7245982de3b97a4722d80f6ea62a79434bc46ee8 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem 'devise_invitable','0.3.5' #Authentication gem 'omniauth' -gem 'twitter', '0.9.12' +gem 'twitter', '1.0.0.rc.8' #Mongo gem 'mongo_mapper', :branch => 'rails3', :git => 'git://github.com/jnunemaker/mongomapper.git' diff --git a/Gemfile.lock b/Gemfile.lock index 3d47088e10f5fd207451eba86ab7cf2363dff027..52f234240c126694b48288cebb79223596e7b88f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -176,6 +176,8 @@ GEM addressable (~> 2.2.2) multipart-post (~> 1.0.1) rack (>= 1.1.0, < 2) + faraday_middleware (0.3.1) + faraday (~> 0.5.3) fastercsv (1.5.3) fastthread (1.0.7) ffi (0.6.3) @@ -188,8 +190,6 @@ GEM hashie (0.4.0) highline (1.6.1) http_connection (1.4.0) - httparty (0.6.1) - crack (= 0.1.8) i18n (0.4.2) jammit (0.5.4) closure-compiler (>= 0.1.0) @@ -224,6 +224,7 @@ GEM fastthread (>= 1.0.1) gem_plugin (>= 0.2.3) multi_json (0.0.5) + multi_xml (0.2.0) multipart-post (1.0.1) net-ldap (0.1.1) nokogiri (1.4.3.1) @@ -330,6 +331,7 @@ GEM ffi (~> 0.6.3) json_pure rubyzip + simple_oauth (0.1.3) subexec (0.0.4) systemu (1.2.0) term-ansicolor (1.0.5) @@ -340,11 +342,13 @@ GEM thor (0.14.6) treetop (1.4.9) polyglot (>= 0.3.1) - twitter (0.9.12) + twitter (1.0.0.rc.8) + faraday (~> 0.5.3) + faraday_middleware (~> 0.3.0) hashie (~> 0.4.0) - httparty (~> 0.6.1) - multi_json (~> 0.0.4) - oauth (~> 0.4.3) + multi_json (~> 0.0.5) + multi_xml (~> 0.2.0) + simple_oauth (~> 0.1.2) tzinfo (0.3.23) uuidtools (2.1.1) warden (0.10.7) @@ -399,6 +403,6 @@ DEPENDENCIES rspec-rails (>= 2.0.0) ruby-debug thin - twitter (= 0.9.12) + twitter (= 1.0.0.rc.8) webmock will_paginate (= 3.0.pre2) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..4beaa6ecd78f2ca4af80cc0a2dd4e98cadc4d337 --- /dev/null +++ b/app/controllers/posts_controller.rb @@ -0,0 +1,20 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class PostsController < ApplicationController + skip_before_filter :set_contacts_and_status + skip_before_filter :count_requests + skip_before_filter :set_invites + skip_before_filter :set_locale + + def show + @post = Post.first(:id => params[:id], :public => true) + @landing_page = true + if @post + render "posts/#{@post.class.to_s.snake_case}", :layout => true + else + redirect_to root_url + end + end +end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 6f4e0fe1713f49f045a2ed65e89cc7627455906a..7d2322e9441f4cd8ff1d8dd230eb2ba1abfbc7ae 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -13,6 +13,7 @@ class ServicesController < ApplicationController def create auth = request.env['omniauth.auth'] + pp auth provider = auth['provider'] user = auth['user_info'] diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index e62c46064f09ab8a41170673f695b7726f19a2e9..8694d05f701c6fb1e86502fb21e5e956991c9d43 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -27,7 +27,8 @@ class StatusMessagesController < ApplicationController @status_message.photos += photos unless photos.nil? current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids]) - current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids]) + current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_path(@status_message)) + for photo in photos current_user.add_to_streams(photo, params[:status_message][:aspect_ids]) diff --git a/app/models/user.rb b/app/models/user.rb index 5af5b67229843c158f375d5e47dd9d7193cb49f4..fc3af996bcc4a94ab4d63509a8e70ef826b07662 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -168,22 +168,34 @@ class User Rails.logger.info("event=dispatch user=#{diaspora_handle} post=#{post.id.to_s}") push_to_aspects(post, aspects_from_ids(aspect_ids)) - if post.public + if post.public && post.respond_to?(:message) + message = opts[:url] ? "#{post.message}%20#{opts[:url]}" : post.message self.services.each do |service| - self.send("post_to_#{service.provider}".to_sym, service, post.message) + self.send("post_to_#{service.provider}".to_sym, service, message) end end end def post_to_facebook(service, message) Rails.logger.info("Sending a message: #{message} to Facebook") - EventMachine::HttpRequest.new("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}").post + begin + RestClient.post("https://graph.facebook.com/me/feed?message=#{message}&access_token=#{service.access_token}") + rescue Exception => e + Rails.logger.info("#{e.message} failed to post to facebook") + end end def post_to_twitter(service, message) - oauth = Twitter::OAuth.new(SERVICES['twitter']['consumer_token'], SERVICES['twitter']['consumer_secret']) - oauth.authorize_from_access(service.access_token, service.access_secret) - client = Twitter::Base.new(oauth) + + Twitter.configure do |config| + config.consumer_key = SERVICES['twitter']['consumer_token'] + config.consumer_secret = SERVICES['twitter']['consumer_secret'] + config.oauth_token = service.access_token + config.oauth_token_secret = service.access_secret + end + + client = Twitter::Client.new + client.update(message) end diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index ea7aa2a0148f5b670f1df20dc446d36bf6d23388..adfa88a446980d500168e1150bed17b2962ae999 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -2,14 +2,14 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -.container{:style => "position:relative;"} +.container#head{:style => "position:relative;"} - if current_user = link_to image_tag('diaspora_logo_small.png', :height => "16px", :width => "161px", :class => "diaspora_header_logo"), root_path - else = link_to image_tag('diaspora_logo_large.png', :height => "32px", :width => "321px", :class => "diaspora_header_logo"), root_path - - unless current_user + - unless current_user .right %ul#landing_nav %li= link_to '@joindiaspora', "http://twitter.com/joindiaspora" @@ -33,18 +33,19 @@ %li= link_to t('.account_settings'), edit_user_path(current_user) %li= link_to t('.logout'), destroy_user_session_path - #aspect_nav - %ul - %li{:class => ("selected" if @aspect == :all)} - = link_to ((@request_count == 0)? t('_home') : "#{t('_home')} (#{@request_count})"), root_path, :class => new_request?(@request_count) - - - for aspect in @aspects - %li{:class => ("selected" if current_aspect?(aspect))} - = link_for_aspect aspect - %li - = link_to '+', '#add_aspect_pane', :class => "add_aspect_button", :title => t('aspects.manage.add_a_new_aspect') - - .fancybox_content - #add_aspect_pane - = render "aspects/new_aspect" + -unless @landing_page + #aspect_nav + %ul + %li{:class => ("selected" if @aspect == :all)} + = link_to ((@request_count == 0)? t('_home') : "#{t('_home')} (#{@request_count})"), root_path, :class => new_request?(@request_count) + + - for aspect in @aspects + %li{:class => ("selected" if current_aspect?(aspect))} + = link_for_aspect aspect + %li + = link_to '+', '#add_aspect_pane', :class => "add_aspect_button", :title => t('aspects.manage.add_a_new_aspect') + + .fancybox_content + #add_aspect_pane + = render "aspects/new_aspect" diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 6dd2d9cfda2e6c3017878c491f06b0b5c39e9d03..9d2e7b80ee7d7813125ffc913ae27f03fa8966ac 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -72,7 +72,7 @@ %link{:rel => "alternate", :href => "#{current_user.public_url}", :type => "application/atom+xml", :title => "Public Diaspora Feed for #{current_user.name}"} %body - -unless @landing_page + - unless @landing_page #notification - flash.each do |name, msg| diff --git a/app/views/posts/photo.html.haml b/app/views/posts/photo.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..67e2603011dbe5bc50bc37feed6bfde507f11738 --- /dev/null +++ b/app/views/posts/photo.html.haml @@ -0,0 +1,36 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +- content_for :head do + = include_javascripts :photos + +#author_info + = person_image_link(@post.person) + .from + %h2 + = @post.person.name +.span-14.append-1.last + #show_photo{:data=>{:guid=>@ost.id}} + = image_tag @post.url(:scaled_full) + + #caption + = @post.caption + + %br + +.span-9.last + - if @post.status_message_id + #original_post_info + %h4{:style=>"position:relative;"} + = t('.original_post') + = link_to t('.view'), @post.status_message + + %p + = @post.status_message.message + + %p + - for photo in @post.status_message.photos + = link_to (image_tag photo.url(:thumb_small)), photo_path(photo) + %p + = link_to 'permalink', post_path(@post) diff --git a/app/views/posts/status_message.haml b/app/views/posts/status_message.haml new file mode 100644 index 0000000000000000000000000000000000000000..7feeb93404b188e0b49cf838e905a1542fe6f44d --- /dev/null +++ b/app/views/posts/status_message.haml @@ -0,0 +1,21 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +#author_info + = person_image_link(@post.person) + .from + %h2 + = @post.person.name + +.span-14.append-1.last + #show_text + %p + = markdownify(@post.message, :youtube_maps => @post[:youtube_titles]) + + - for photo in @post.photos + = link_to (image_tag photo.url(:thumb_small)), photo_path(photo) + + .time + = how_long_ago(@post) + = link_to 'permalink', post_path(@post) diff --git a/app/views/status_messages/show.html.haml b/app/views/status_messages/show.html.haml index 58a08214d1a98dcc7141878705c7cb8c2ca74368..b315b35e259fabb34e0efda52510b58896498d48 100644 --- a/app/views/status_messages/show.html.haml +++ b/app/views/status_messages/show.html.haml @@ -11,10 +11,12 @@ = markdownify(@status_message.message, :youtube_maps => @status_message[:youtube_titles]) - for photo in @status_message.photos - = link_to (image_tag photo.url(:thumb_small)), object_path(photo) + = link_to (image_tag photo.url(:thumb_small)), photo_path(photo) .time = how_long_ago(@status_message) + %p + =link_to "public permalink", post_path(@status_message) - if current_user.owns? @status_message = link_to t('.destroy'), @status_message, :confirm => t('are_you_sure'), :method => :delete diff --git a/config/routes.rb b/config/routes.rb index f2444bbb02e8aeccca7a9139866bf7bc14b369cb..99c8eb65fbf75cdaa38eed7f64f85622bf8c688d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,7 +7,7 @@ Diaspora::Application.routes.draw do resources :comments, :only => [:create] resources :requests, :only => [:destroy, :create] resources :services - + resources :posts, :only => [:show] resources :people do resources :status_messages resources :photos diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 32f77c142c24af6118303f648ed5f2d76f25712e..489ae94085af287a92613514bceb0fa4f8cd671b 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -112,6 +112,7 @@ form header :z-index 4 :position relative + :min-height 40px :margin -2em :bottom 2em :color #000 diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..f59215d88930af6d42b94996535c505724403bd7 --- /dev/null +++ b/spec/controllers/posts_controller_spec.rb @@ -0,0 +1,28 @@ +# 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 PostsController do + render_views + + before do + @user = make_user + @controller.stub!(:current_user).and_return(nil) + end + describe '#show' do + it 'shows a public post' do + status = @user.post(:status_message, :message => "hello", :public => true, :to => 'all') + + get :show, :id => status.id + response.status= 200 + end + + it 'does not show a private post' do + status = @user.post(:status_message, :message => "hello", :public => false, :to => 'all') + get :show, :id => status.id + response.status = 302 + end + end +end diff --git a/spec/controllers/status_message_controller_spec.rb b/spec/controllers/status_message_controller_spec.rb index 5e7d686cf6b6b2cb4455a5d4934be33a1dd72c9f..3915bd5ec64da2e5671f863444a8ccbbdf4bc45d 100644 --- a/spec/controllers/status_message_controller_spec.rb +++ b/spec/controllers/status_message_controller_spec.rb @@ -99,6 +99,10 @@ describe StatusMessagesController do user.should_not_receive(:post_to_facebook) post :create, status_message_hash end + + it 'should include the permalink to the post' do + pending + end end context "posting to twitter" do @@ -114,6 +118,9 @@ describe StatusMessagesController do user.should_not_receive(:post_to_twitter) post :create, status_message_hash end + + it 'should include a permalink to the post' do + end end end diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index e4ca64938ca90093ecbd2a3537fe4a0edda10f45..9369798358247f4b7c216dc16c99130d3b5ebf38 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -37,4 +37,3 @@ describe Post do end end end - diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 66473f901cebb1d83d88f93289254fac8a3301ad..5be8ce1ecd30f028ab26411ac74c13393809f94e 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -71,6 +71,7 @@ describe User do end describe '#dispatch_post' do + include Rails.application.routes.url_helpers let(:status) {user.build_post(:status_message, @status_opts)} before do @message = "hello, world!" @@ -91,8 +92,25 @@ describe User do user.should_not_receive(:post_to_facebook) user.dispatch_post(status, :to => "all") end - end + it 'includes a permalink to my post' do + @status_opts[:public] = true + status.save + user.should_receive(:post_to_twitter).with(service1, @message+ "%20#{post_path(status)}").once + user.should_receive(:post_to_facebook).with(service2, @message + "%20#{post_path(status)}").once + user.dispatch_post(status, :to => "all", :url => post_path(status)) + end + + it 'only pushes to services if it is a status message' do + photo = Photo.new() + photo.public = true + user.stub!(:push_to_aspects) + user.should_not_receive(:post_to_twitter) + user.should_not_receive(:post_to_facebook) + user.dispatch_post(photo, :to =>"all") + end + end + describe '#post' do it 'should not create a post with invalid aspect' do pending "this would just cause db polution"