posts now have public permalinks
This commit is contained in:
parent
756824d072
commit
38d9d75162
17 changed files with 185 additions and 34 deletions
2
Gemfile
2
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'
|
||||
|
|
|
|||
18
Gemfile.lock
18
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)
|
||||
|
|
|
|||
20
app/controllers/posts_controller.rb
Normal file
20
app/controllers/posts_controller.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -13,6 +13,7 @@ class ServicesController < ApplicationController
|
|||
def create
|
||||
auth = request.env['omniauth.auth']
|
||||
|
||||
pp auth
|
||||
provider = auth['provider']
|
||||
user = auth['user_info']
|
||||
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
-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')
|
||||
- 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"
|
||||
.fancybox_content
|
||||
#add_aspect_pane
|
||||
= render "aspects/new_aspect"
|
||||
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
|
|
|
|||
36
app/views/posts/photo.html.haml
Normal file
36
app/views/posts/photo.html.haml
Normal file
|
|
@ -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)
|
||||
21
app/views/posts/status_message.haml
Normal file
21
app/views/posts/status_message.haml
Normal file
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ form
|
|||
header
|
||||
:z-index 4
|
||||
:position relative
|
||||
:min-height 40px
|
||||
:margin -2em
|
||||
:bottom 2em
|
||||
:color #000
|
||||
|
|
|
|||
28
spec/controllers/posts_controller_spec.rb
Normal file
28
spec/controllers/posts_controller_spec.rb
Normal file
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -37,4 +37,3 @@ describe Post do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in a new issue