Skip to content
Snippets Groups Projects
Commit 843c0d9c authored by Maxwell Salzberg's avatar Maxwell Salzberg
Browse files

Merge pull request #3068 from diaspora/posting

Merging the trumpeter
parents 9d266432 9550082a
No related branches found
No related tags found
No related merge requests found
Showing
with 150 additions and 64 deletions
......@@ -17,6 +17,7 @@ gem 'rack-cors', '~> 0.2.4', :require => 'rack/cors'
gem 'devise', '1.5.3'
gem 'jwt'
gem 'oauth2-provider', '0.0.19'
gem 'remotipart', '~> 1.0'
gem 'omniauth', '1.0.1'
gem 'omniauth-facebook'
......
......@@ -162,7 +162,7 @@ GEM
fixture_builder (0.3.1)
activerecord (>= 2)
activesupport (>= 2)
fog (1.2.0)
fog (1.3.0)
builder
excon (~> 0.12.0)
formatador (~> 0.2.0)
......@@ -341,6 +341,7 @@ GEM
redis (2.2.2)
redis-namespace (1.0.3)
redis (< 3.0.0)
remotipart (1.0.2)
resque (1.20.0)
multi_json (~> 1.0)
redis-namespace (~> 1.0.2)
......@@ -513,6 +514,7 @@ DEPENDENCIES
rails-i18n
rails_autolink
redcarpet (= 2.0.1)
remotipart (~> 1.0)
resque (= 1.20.0)
resque-timeout (= 1.0.0)
rest-client (= 1.6.7)
......
......@@ -41,55 +41,19 @@ class PhotosController < ApplicationController
end
def create
begin
raise unless params[:photo][:aspect_ids]
if params[:photo][:aspect_ids] == "all"
params[:photo][:aspect_ids] = current_user.aspects.collect{|x| x.id}
elsif params[:photo][:aspect_ids].is_a?(Hash)
params[:photo][:aspect_ids] = params[:photo][:aspect_ids].values
end
params[:photo][:user_file] = file_handler(params)
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids])
unless @photo.pending
current_user.add_to_streams(@photo, aspects)
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids])
end
if params[:photo][:set_profile_photo]
profile_params = {:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small)}
current_user.update_profile(profile_params)
end
respond_to do |format|
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
format.html{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
rescuing_photo_errors do
if remotipart_submitted?
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
respond_to do |format|
format.json { render :json => {"success" => true, "data" => @photo.as_api_response(:backbone)} }
end
else
respond_with @photo, :location => photos_path, :error => message
end
else
respond_with @photo, :location => photos_path, :error => message
legacy_create
end
rescue TypeError
message = I18n.t 'photos.create.type_error'
respond_with @photo, :location => photos_path, :error => message
rescue CarrierWave::IntegrityError
message = I18n.t 'photos.create.integrity_error'
respond_with @photo, :location => photos_path, :error => message
rescue RuntimeError => e
message = I18n.t 'photos.create.runtime_error'
respond_with @photo, :location => photos_path, :error => message
raise e
end
end
......@@ -200,4 +164,57 @@ class PhotosController < ApplicationController
file
end
end
def legacy_create
if params[:photo][:aspect_ids] == "all"
params[:photo][:aspect_ids] = current_user.aspects.collect { |x| x.id }
elsif params[:photo][:aspect_ids].is_a?(Hash)
params[:photo][:aspect_ids] = params[:photo][:aspect_ids].values
end
params[:photo][:user_file] = file_handler(params)
@photo = current_user.build_post(:photo, params[:photo])
if @photo.save
aspects = current_user.aspects_from_ids(params[:photo][:aspect_ids])
unless @photo.pending
current_user.add_to_streams(@photo, aspects)
current_user.dispatch_post(@photo, :to => params[:photo][:aspect_ids])
end
if params[:photo][:set_profile_photo]
profile_params = {:image_url => @photo.url(:thumb_large),
:image_url_medium => @photo.url(:thumb_medium),
:image_url_small => @photo.url(:thumb_small)}
current_user.update_profile(profile_params)
end
respond_to do |format|
format.json{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
format.html{ render(:layout => false , :json => {"success" => true, "data" => @photo}.to_json )}
end
else
respond_with @photo, :location => photos_path, :error => message
end
end
def rescuing_photo_errors
begin
yield
rescue TypeError
message = I18n.t 'photos.create.type_error'
respond_with @photo, :location => photos_path, :error => message
rescue CarrierWave::IntegrityError
message = I18n.t 'photos.create.integrity_error'
respond_with @photo, :location => photos_path, :error => message
rescue RuntimeError => e
message = I18n.t 'photos.create.runtime_error'
respond_with @photo, :location => photos_path, :error => message
raise e
end
end
end
......@@ -8,11 +8,18 @@ class PostsController < ApplicationController
before_filter :authenticate_user!, :except => :show
before_filter :set_format_if_malformed_from_status_net, :only => :show
layout 'post'
respond_to :html,
:mobile,
:json,
:xml
def new
redirect_to "/stream" and return unless FeatureFlags.new_publisher
render :text => "", :layout => true
end
def show
key = params[:id].to_s.length <= 8 ? :id : :guid
......@@ -34,7 +41,7 @@ class PostsController < ApplicationController
format.xml{ render :xml => @post.to_diaspora_xml }
format.mobile{render 'posts/show.mobile.haml'}
format.json{ render :json => PostPresenter.new(@post, current_user).to_json }
format.any{render 'posts/show.html.haml', :layout => 'layouts/post'}
format.any{render 'posts/show.html.haml'}
end
else
......
......@@ -53,7 +53,8 @@ class StatusMessagesController < ApplicationController
receiving_services = Service.titles(services)
current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :service_types => receiving_services)
#this is done implicitly, somewhere else, apparently, says max. :'(
# @status_message.photos.each do |photo|
# current_user.dispatch_post(photo)
# end
......
module FeatureFlags
def self.new_publisher
!(Rails.env.production? || Rails.env.staging?)
end
end
\ No newline at end of file
......@@ -9,8 +9,6 @@ class Photo < ActiveRecord::Base
include Diaspora::Commentable
include Diaspora::Shareable
# NOTE API V1 to be extracted
acts_as_api
api_accessible :backbone do |t|
......
......@@ -14,6 +14,7 @@ class Service < ActiveRecord::Base
end
def public_message(post, length, url = "")
Rails.logger.info("Posting out to #{self.class}")
url = "" if post.respond_to?(:photos) && post.photos.count == 0
space_for_url = url.blank? ? 0 : (url.length + 1)
truncated = truncate(post.text(:plain_text => true), :length => (length - space_for_url))
......
......@@ -21,7 +21,7 @@ class StatusMessage < Post
# therefore, we put the validation in a before_destory callback instead of a validation
before_destroy :presence_of_content
attr_accessible :text, :provider_display_name
attr_accessible :text, :provider_display_name, :frame_name
attr_accessor :oembed_url
after_create :create_mentions
......
class AspectPresenter < BasePresenter
def initialize(aspect)
@aspect = aspect
end
def as_json
{ :id => @aspect.id,
:name => @aspect.name,
}
end
def to_json(options = {})
as_json.to_json(options)
end
end
\ No newline at end of file
class BasePresenter
def self.as_collection(collection)
collection.map{|object| self.new(object).as_json}
end
end
......@@ -23,7 +23,7 @@ class PostPresenter
:reshares => self.reshares,
:comments => self.comments,
:participations => self.participations,
:templateName => template_name,
:frame_name => self.post.frame_name || template_name,
:title => title
})
end
......
class ServicePresenter < BasePresenter
def initialize(service)
@service = service
end
def as_json
{
:provider => @service.provider
}
end
def to_json(options = {})
as_json.to_json(options)
end
end
\ No newline at end of file
class UserPresenter
attr_accessor :user
def initialize(user)
self.user = user
end
......@@ -9,15 +9,23 @@ class UserPresenter
self.user.person.as_api_response(:backbone).update(
{ :notifications_count => notifications_count,
:unread_messages_count => unread_messages_count,
:admin => admin
:admin => admin,
:aspects => aspects,
:services => services
}
).to_json(options)
end
protected
def services
ServicePresenter.as_collection(user.services)
end
def aspects
AspectPresenter.as_collection(user.aspects)
end
def notifications_count
@notification_count ||= user.unread_notifications.count
@notification_count ||= user.unread_notifications.count
end
def unread_messages_count
......@@ -27,4 +35,4 @@ class UserPresenter
def admin
user.admin?
end
end
\ No newline at end of file
end
......@@ -50,5 +50,6 @@
%body
= flash_messages
#container
= yield
......@@ -83,4 +83,4 @@
});
}
createUploader();
createUploader();
\ No newline at end of file
......@@ -4,5 +4,3 @@
- content_for :page_title do
= post_page_title @post
#container
......@@ -25,12 +25,15 @@ javascripts:
- public/javascripts/vendor/timeago.js
- public/javascripts/vendor/facebox.js
- public/javascripts/vendor/underscore.js
- public/javascripts/vendor/jquery.iframe-transport.js
- public/javascripts/vendor/jquery.remotipart.js
- public/javascripts/vendor/jquery.events.input.js
- public/javascripts/vendor/jquery.elastic.js
- public/javascripts/vendor/jquery.mentionsInput.js
- public/javascripts/vendor/jquery.idle-timer.js
- public/javascripts/jquery.infinitescroll-custom.js
- public/javascripts/jquery.autocomplete-custom.js
- public/javascripts/vendor/jquery.textchange.min.js
- public/javascripts/keycodes.js
- public/javascripts/fileuploader-custom.js
......@@ -43,6 +46,7 @@ javascripts:
- public/javascripts/app/helpers/*
- public/javascripts/app/router.js
- public/javascripts/app/views.js
- public/javascripts/app/forms.js
- public/javascripts/app/models/post.js
- public/javascripts/app/models/*
- public/javascripts/app/pages/*
......@@ -51,6 +55,7 @@ javascripts:
- public/javascripts/app/views/content_view.js
- public/javascripts/app/views/*.js
- public/javascripts/app/views/**/*.js
- public/javascripts/app/forms/*.js
- public/javascripts/diaspora.js
- public/javascripts/helpers/*.js
......@@ -71,6 +76,7 @@ javascripts:
- public/javascripts/vendor/bootstrap/bootstrap-twipsy.js
- public/javascripts/vendor/bootstrap/bootstrap-popover.js
- public/javascripts/vendor/bootstrap/bootstrap-dropdown.js
login:
- public/javascripts/login.js
......@@ -90,7 +96,6 @@ javascripts:
- public/javascripts/friend-finder.js
home:
- public/javascripts/publisher.js
- public/javascripts/vendor/jquery.textchange.min.js
- public/javascripts/aspect-edit-pane.js
- public/javascripts/fileuploader-custom.js
people:
......
......@@ -8,11 +8,14 @@ Diaspora::Application.routes.draw do
resources :status_messages, :only => [:new, :create]
resources :posts, :only => [:show, :destroy] do
resources :posts, :only => [:show, :new, :destroy] do
resources :likes, :only => [:create, :destroy, :index]
resources :participations, :only => [:create, :destroy, :index]
resources :comments, :only => [:new, :create, :destroy, :index]
end
match "/framer" => redirect("/posts/new")
get 'p/:id' => 'posts#show', :as => 'short_post'
# roll up likes into a nested resource above
resources :comments, :only => [:create, :destroy] do
......@@ -32,7 +35,6 @@ Diaspora::Application.routes.draw do
get "commented" => "streams#commented", :as => "commented_stream"
get "aspects" => "streams#aspects", :as => "aspects_stream"
resources :aspects do
put :toggle_contact_visibility
end
......
class AddTemplateNameToPosts < ActiveRecord::Migration
def change # thanks josh susser
add_column :posts, :frame_name, :string
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment