public posts are now accessible by your friends, and facebook and twitter include a permalink. we prob want to link shorten these bad boys(and it has a max length of 140 chars, with a permalink), also, facebook and twitter posting are sync, but that will make it more reliable

This commit is contained in:
maxwell 2010-12-02 18:47:02 -08:00
parent 11f04a060e
commit 579a288351
12 changed files with 39 additions and 39 deletions

View file

@ -12,8 +12,9 @@ class PostsController < ApplicationController
@post = Post.first(:id => params[:id], :public => true) @post = Post.first(:id => params[:id], :public => true)
@landing_page = true @landing_page = true
if @post if @post
render "posts/#{@post.class.to_s.snake_case}", :layout => true render "posts/#{@post.class.to_s.underscore}", :layout => true
else else
flash[:error] = "that post does not exsist!"
redirect_to root_url redirect_to root_url
end end
end end

View file

@ -13,29 +13,17 @@ class ServicesController < ApplicationController
def create def create
auth = request.env['omniauth.auth'] auth = request.env['omniauth.auth']
pp auth['credentials']
toke = auth['credentials']['token'] toke = auth['credentials']['token']
secret = auth['credentials']['secret'] secret = auth['credentials']['secret']
provider = auth['provider'] provider = auth['provider']
user = auth['user_info'] user = auth['user_info']
if provider == 'twitter' current_user.services.create(:nickname => user['nickname'],
access_token = auth['extra']['access_token'] :access_token => toke,
current_user.services.create(:nickname => user['nickname'], :access_secret => secret,
:access_token => toke, :provider => provider,
:access_secret => secret, :uid => auth['uid'])
:provider => provider,
:uid => auth['uid'])
elsif provider == 'facebook'
current_user.services.create(:nickname => user['nickname'],
:access_token => auth['credentials']['token'],
:provider => provider,
:uid => auth['uid'])
end
flash[:notice] = I18n.t 'services.create.success' flash[:notice] = I18n.t 'services.create.success'
if current_user.getting_started if current_user.getting_started

View file

@ -27,10 +27,12 @@ class StatusMessagesController < ApplicationController
@status_message.photos += photos unless photos.nil? @status_message.photos += photos unless photos.nil?
current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids]) current_user.add_to_streams(@status_message, params[:status_message][:aspect_ids])
current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_path(@status_message)) current_user.dispatch_post(@status_message, :to => params[:status_message][:aspect_ids], :url => post_url(@status_message))
for photo in photos for photo in photos
photo.public = public_flag
photo.save
current_user.add_to_streams(photo, params[:status_message][:aspect_ids]) current_user.add_to_streams(photo, params[:status_message][:aspect_ids])
current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids]) current_user.dispatch_post(photo, :to => params[:status_message][:aspect_ids])
end end

View file

@ -9,7 +9,8 @@ class User
include MongoMapper::Document include MongoMapper::Document
include Diaspora::UserModules include Diaspora::UserModules
include Encryptor::Private include Encryptor::Private
include ActionView::Helpers::TextHelper
plugin MongoMapper::Devise plugin MongoMapper::Devise
QUEUE = MessageHandler.new QUEUE = MessageHandler.new
@ -169,7 +170,14 @@ class User
push_to_aspects(post, aspects_from_ids(aspect_ids)) push_to_aspects(post, aspects_from_ids(aspect_ids))
if post.public && post.respond_to?(:message) if post.public && post.respond_to?(:message)
message = opts[:url] ? "#{post.message}%20#{opts[:url]}" : post.message
if opts[:url]
message = truncate(post.message, :length => (140 - (opts[:url].length + 1)))
message = "#{message} #{opts[:url]}"
else
message = post.message
end
self.services.each do |service| self.services.each do |service|
self.send("post_to_#{service.provider}".to_sym, service, message) self.send("post_to_#{service.provider}".to_sym, service, message)
end end
@ -193,10 +201,8 @@ class User
config.oauth_token = service.access_token config.oauth_token = service.access_token
config.oauth_token_secret = service.access_secret config.oauth_token_secret = service.access_secret
end end
client = Twitter::Client.new Twitter.update(message)
client.update(message)
end end
def update_post(post, post_hash = {}) def update_post(post, post_hash = {})

View file

@ -9,7 +9,7 @@
- else - else
= link_to image_tag('diaspora_logo_large.png', :height => "32px", :width => "321px", :class => "diaspora_header_logo"), root_path = link_to image_tag('diaspora_logo_large.png', :height => "32px", :width => "321px", :class => "diaspora_header_logo"), root_path
- unless current_user - if !current_user
.right .right
%ul#landing_nav %ul#landing_nav
%li= link_to '@joindiaspora', "http://twitter.com/joindiaspora" %li= link_to '@joindiaspora', "http://twitter.com/joindiaspora"
@ -17,7 +17,7 @@
%li= link_to t('.blog'), 'http://blog.joindiaspora.com/' %li= link_to t('.blog'), 'http://blog.joindiaspora.com/'
%li= link_to t('.login'), new_user_session_path, :class => 'login' %li= link_to t('.login'), new_user_session_path, :class => 'login'
- else - elsif (current_user || !@landing_page)
#global_search #global_search
= form_tag(people_path, :method => 'get', :id => "global_search_form") do = form_tag(people_path, :method => 'get', :id => "global_search_form") do
= text_field_tag 'q', nil, :placeholder => t('search'), :type => 'search', :results => 5 = text_field_tag 'q', nil, :placeholder => t('search'), :type => 'search', :results => 5

View file

@ -11,7 +11,7 @@
%h2 %h2
= @post.person.name = @post.person.name
.span-14.append-1.last .span-14.append-1.last
#show_photo{:data=>{:guid=>@ost.id}} #show_photo{:data=>{:guid=>@post.id}}
= image_tag @post.url(:scaled_full) = image_tag @post.url(:scaled_full)
#caption #caption
@ -23,14 +23,14 @@
- if @post.status_message_id - if @post.status_message_id
#original_post_info #original_post_info
%h4{:style=>"position:relative;"} %h4{:style=>"position:relative;"}
= t('.original_post') = t('photos.show.original_post')
= link_to t('.view'), @post.status_message = link_to t('photos.show.view'), post_path(@post.status_message)
%p %p
= @post.status_message.message = @post.status_message.message
%p %p
- for photo in @post.status_message.photos - for photo in @post.status_message.photos
= link_to (image_tag photo.url(:thumb_small)), photo_path(photo) = link_to (image_tag photo.url(:thumb_small)), post_path(photo)
%p %p
= link_to 'permalink', post_path(@post) = link_to t('photos.show.permalink'), post_path(@post)

View file

@ -14,8 +14,8 @@
= markdownify(@post.message, :youtube_maps => @post[:youtube_titles]) = markdownify(@post.message, :youtube_maps => @post[:youtube_titles])
- for photo in @post.photos - for photo in @post.photos
= link_to (image_tag photo.url(:thumb_small)), photo_path(photo) = link_to (image_tag photo.url(:thumb_small)), post_path(photo)
.time .time
= how_long_ago(@post) = how_long_ago(@post)
= link_to 'permalink', post_path(@post) = link_to t('status_messages.show.permalink'), post_path(@post)

View file

@ -232,6 +232,7 @@ en:
edit: "edit" edit: "edit"
edit_delete_photo: "Edit photo description / delete photo" edit_delete_photo: "Edit photo description / delete photo"
original_post: "Original Post" original_post: "Original Post"
permalink: "permalink"
edit: edit:
editing: "Editing" editing: "Editing"
photo: photo:
@ -292,6 +293,7 @@ en:
oh_yeah: "oh yeah!" oh_yeah: "oh yeah!"
show: show:
destroy: "Destroy" destroy: "Destroy"
permalink: "permalink"
helper: helper:
no_message_to_display: "No message to display." no_message_to_display: "No message to display."
people: people:

View file

@ -1,5 +1,5 @@
twitter: twitter:
consumer_key: "" consumer_token: ""
consumer_secret: "" consumer_secret: ""
facebook: facebook:
app_id: "" app_id: ""

View file

@ -7,7 +7,7 @@ Diaspora::Application.routes.draw do
resources :comments, :only => [:create] resources :comments, :only => [:create]
resources :requests, :only => [:destroy, :create] resources :requests, :only => [:destroy, :create]
resources :services resources :services
resources :posts, :only => [:show] resources :posts, :only => [:show], :path => '/p/'
resources :people do resources :people do
resources :status_messages resources :status_messages
resources :photos resources :photos

View file

@ -18,7 +18,8 @@ describe ServicesController do
let(:omniauth_auth) {{ 'provider' => 'twitter', 'uid' => '2', let(:omniauth_auth) {{ 'provider' => 'twitter', 'uid' => '2',
'user_info' => { 'nickname' => 'grimmin' }, 'user_info' => { 'nickname' => 'grimmin' },
'extra' => { 'access_token' => mock_access_token }}} 'credentials' => { 'token' => 'tokin', 'secret' =>"not_so_much" }
}}
before do before do
sign_in :user, user sign_in :user, user

View file

@ -96,8 +96,8 @@ describe User do
it 'includes a permalink to my post' do it 'includes a permalink to my post' do
@status_opts[:public] = true @status_opts[:public] = true
status.save status.save
user.should_receive(:post_to_twitter).with(service1, @message+ "%20#{post_path(status)}").once user.should_receive(:post_to_twitter).with(service1, @message+ " #{post_path(status)}").once
user.should_receive(:post_to_facebook).with(service2, @message + "%20#{post_path(status)}").once user.should_receive(:post_to_facebook).with(service2, @message + " #{post_path(status)}").once
user.dispatch_post(status, :to => "all", :url => post_path(status)) user.dispatch_post(status, :to => "all", :url => post_path(status))
end end