DG MS; status messages can now have photos.
This commit is contained in:
parent
7f97b6f812
commit
9b7d2ed0f6
17 changed files with 116 additions and 52 deletions
|
|
@ -142,7 +142,11 @@ GEM
|
|||
childprocess (0.1.4)
|
||||
ffi (~> 0.6.3)
|
||||
closure-compiler (0.3.3)
|
||||
<<<<<<< HEAD
|
||||
cloudfiles (1.4.10)
|
||||
=======
|
||||
cloudfiles (1.4.9)
|
||||
>>>>>>> DG MS; status messages can now have photos.
|
||||
mime-types (>= 1.16)
|
||||
columnize (0.3.2)
|
||||
configuration (1.2.0)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class AspectsController < ApplicationController
|
|||
respond_to :json, :only => :show
|
||||
|
||||
def index
|
||||
@posts = current_user.visible_posts(:by_members_of => :all, :pending => false).paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
|
||||
@posts = current_user.visible_posts.paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
|
||||
@aspect = :all
|
||||
|
||||
if current_user.getting_started == true
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ class StatusMessagesController < ApplicationController
|
|||
respond_to :json, :only => :show
|
||||
|
||||
def create
|
||||
|
||||
photos = Photo.all(:id.in => [*params[:photos]])
|
||||
|
||||
public_flag = params[:status_message][:public]
|
||||
|
|
@ -17,11 +16,14 @@ class StatusMessagesController < ApplicationController
|
|||
params[:status_message][:public] = public_flag
|
||||
@status_message = current_user.build_post(:status_message, params[:status_message])
|
||||
|
||||
@status_message.photos += photos unless photos.nil?
|
||||
|
||||
puts "got it"
|
||||
if @status_message.save(:safe => true)
|
||||
raise 'MongoMapper failed to catch a failed save' unless @status_message.id
|
||||
|
||||
@status_message.photos += photos unless photos.nil?
|
||||
for photo in photos
|
||||
current_user.dispatch_post(photo, :to => params[:status_message][:to])
|
||||
end
|
||||
|
||||
current_user.dispatch_post(@status_message, :to => params[:status_message][:to])
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,19 +9,28 @@ class Photo < Post
|
|||
|
||||
xml_accessor :remote_photo
|
||||
xml_accessor :caption
|
||||
xml_reader :status_message_id
|
||||
|
||||
key :caption, String
|
||||
key :remote_photo_path
|
||||
key :remote_photo_name
|
||||
key :random_string
|
||||
|
||||
|
||||
timestamps!
|
||||
|
||||
belongs_to :status_message
|
||||
|
||||
attr_accessible :caption
|
||||
validate :ownership_of_status_message
|
||||
|
||||
before_destroy :ensure_user_picture
|
||||
|
||||
def ownership_of_status_message
|
||||
if status_message_id
|
||||
self.diaspora_handle == StatusMessage.find_by_id(self.status_message_id).diaspora_handle
|
||||
end
|
||||
end
|
||||
|
||||
def self.instantiate(params = {})
|
||||
photo = super(params)
|
||||
image_file = params.delete(:user_file)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class StatusMessage < Post
|
|||
|
||||
validates_length_of :message, :maximum => 1000, :message => "please make your status messages less than 1000 characters"
|
||||
xml_name :status_message
|
||||
xml_accessor :message
|
||||
xml_reader :message
|
||||
|
||||
key :message, String
|
||||
many :photos, :class => Photo
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ class User
|
|||
self.save
|
||||
Rails.logger.info("Pushing: #{post.inspect} out to aspects")
|
||||
push_to_aspects(post, aspect_ids)
|
||||
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid)
|
||||
post.socket_to_uid(id, :aspect_ids => aspect_ids) if post.respond_to?(:socket_to_uid) && !post.pending
|
||||
if post.public
|
||||
self.services.each do |service|
|
||||
self.send("post_to_#{service.provider}".to_sym, service, post.message)
|
||||
|
|
|
|||
|
|
@ -12,17 +12,23 @@
|
|||
debug: true,
|
||||
button: document.getElementById('file-upload'),
|
||||
sizeLimit: 5000048,
|
||||
|
||||
|
||||
onSubmit: function(id, fileName){
|
||||
$('#file-upload').text("loading");
|
||||
$('#file-upload').addClass("loading");
|
||||
$('#publisher').find("input[type='submit']").attr('disabled','disabled');
|
||||
$("#publisher .options_and_submit").fadeIn(50);
|
||||
$("#publisher_spinner").fadeIn(100);
|
||||
},
|
||||
|
||||
|
||||
onComplete: function(id, fileName, responseJSON){
|
||||
$('#file-upload').text("add photos");
|
||||
$("#publisher_spinner").fadeOut(100);
|
||||
$('#file-upload').removeClass("loading");
|
||||
var id = responseJSON.data.photo.id;
|
||||
var url = responseJSON.data.photo.url;
|
||||
$('#new_status_message').append("<input type='hidden' value='" + id + "' name='photos[]' />");
|
||||
$('#photodropzone').append("<li><img src='" + url +"' data-id='" + id + "' /></li>");
|
||||
$('#publisher').find("input[type='submit']").removeAttr('disabled');
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
= link_to (image_tag post.url(:thumb_large)), object_path(post), :class => 'stream_photo'
|
||||
|
||||
%h1
|
||||
= post.pending
|
||||
|
||||
%p.photo_description
|
||||
= post.caption
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@
|
|||
};
|
||||
});
|
||||
|
||||
//$("#publisher textarea, #publisher input").live("focus", function(evt){
|
||||
// $("#publisher .options_and_submit").fadeIn(50);
|
||||
//});
|
||||
$("#publisher textarea, #publisher input").live("focus", function(evt){
|
||||
$("#publisher .options_and_submit").fadeIn(50);
|
||||
});
|
||||
|
||||
$("#publisher form").live("submit", function(evt){
|
||||
$("#photodropzone").find('li').remove();
|
||||
//$("#publisher").find("input[name='photos[]']").remove();
|
||||
$("#publisher .options_and_submit").hide();
|
||||
});
|
||||
|
||||
#publisher
|
||||
|
|
@ -37,6 +37,9 @@
|
|||
= status.hidden_field :to, :value => (aspect == :all ? aspect : aspect.id)
|
||||
|
||||
.options_and_submit
|
||||
|
||||
.right
|
||||
= image_tag 'ajax-loader.gif', :class => 'hidden', :id => "publisher_spinner"
|
||||
- if aspect == :all
|
||||
= status.submit t('.share'), :title => t('.share_with_all'), :disable_with => t('.posting')
|
||||
- else
|
||||
|
|
@ -57,5 +60,10 @@
|
|||
.fancybox_content
|
||||
#question_mark_pane
|
||||
= render 'shared/public_explain'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#publisher_photo_upload
|
||||
= render 'photos/new_photo', :aspect_id => (aspect == :all ? aspect : aspect.id)
|
||||
|
|
|
|||
|
|
@ -5,5 +5,4 @@
|
|||
= markdownify(post.message)
|
||||
%br
|
||||
- for photo in post.photos
|
||||
/= render 'photos/photo', :post => photo
|
||||
= image_tag photo.url(:thumb_medium)
|
||||
= link_to (image_tag photo.url(:thumb_medium)), object_path(photo)
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ module Diaspora
|
|||
|
||||
def visible_posts( opts = {} )
|
||||
opts[:order] ||= 'created_at DESC'
|
||||
if opts[:by_members_of]
|
||||
return raw_visible_posts if opts[:by_members_of] == :all
|
||||
opts[:pending] ||= false
|
||||
|
||||
if opts[:by_members_of] && opts[:by_members_of] != :all
|
||||
aspect = self.aspects.find_by_id( opts[:by_members_of].id )
|
||||
aspect.posts
|
||||
aspect.posts.find_all_by_pending(opts[:pending], :order => opts[:order])
|
||||
else
|
||||
self.raw_visible_posts.all(opts)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -747,6 +747,10 @@ label
|
|||
:color #eee
|
||||
:text-shadow 0 1px 0 #333
|
||||
|
||||
&.loading
|
||||
:opacity 0.5
|
||||
|
||||
|
||||
#publisher
|
||||
:color #999
|
||||
:position relative
|
||||
|
|
@ -799,11 +803,8 @@ label
|
|||
:margin
|
||||
:bottom -2px
|
||||
input[type='submit']
|
||||
:position absolute
|
||||
:right 0
|
||||
:top 5px
|
||||
:width 75px
|
||||
:z-index 5
|
||||
|
||||
input
|
||||
:display inline
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,37 @@ describe StatusMessagesController do
|
|||
:to =>"#{aspect.id}"}}
|
||||
}
|
||||
|
||||
it "doesn't overwrite person_id" do
|
||||
new_user = make_user
|
||||
status_message_hash[:status_message][:person_id] = new_user.person.id
|
||||
post :create, status_message_hash
|
||||
StatusMessage.find_by_message(status_message_hash[:status_message][:message]).person_id.should == user.person.id
|
||||
end
|
||||
|
||||
it "doesn't overwrite id" do
|
||||
old_status_message = user.post(:status_message, :message => "hello", :to => aspect.id)
|
||||
status_message_hash[:status_message][:id] = old_status_message.id
|
||||
lambda {post :create, status_message_hash}.should raise_error /failed save/
|
||||
old_status_message.reload.message.should == 'hello'
|
||||
end
|
||||
|
||||
it "dispatches all referenced photos" do
|
||||
fixture_filename = 'button.png'
|
||||
fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', fixture_filename)
|
||||
|
||||
photo1 = user.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect.id)
|
||||
photo2 = user.build_post(:photo, :user_file=> File.open(fixture_name), :to => aspect.id)
|
||||
|
||||
photo1.save!
|
||||
photo2.save!
|
||||
|
||||
hash = status_message_hash
|
||||
hash[:photos] = [photo1.id.to_s, photo2.id.to_s]
|
||||
|
||||
user.should_receive(:dispatch_post).exactly(3).times
|
||||
post :create, hash
|
||||
end
|
||||
|
||||
context "posting out to facebook" do
|
||||
let!(:service2) { s = Factory(:service, :provider => 'facebook'); user.services << s; s }
|
||||
|
||||
|
|
@ -41,18 +72,6 @@ describe StatusMessagesController do
|
|||
user.should_not_receive(:post_to_facebook)
|
||||
post :create, status_message_hash
|
||||
end
|
||||
it "doesn't overwrite person_id" do
|
||||
new_user = make_user
|
||||
status_message_hash[:status_message][:person_id] = new_user.person.id
|
||||
post :create, status_message_hash
|
||||
StatusMessage.find_by_message(status_message_hash[:status_message][:message]).person_id.should == user.person.id
|
||||
end
|
||||
it "doesn't overwrite id" do
|
||||
old_status_message = user.post(:status_message, :message => "hello", :to => aspect.id)
|
||||
status_message_hash[:status_message][:id] = old_status_message.id
|
||||
lambda {post :create, status_message_hash}.should raise_error /failed save/
|
||||
old_status_message.reload.message.should == 'hello'
|
||||
end
|
||||
end
|
||||
|
||||
context "posting to twitter" do
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ end
|
|||
|
||||
Factory.define :photo do |p|
|
||||
p.image File.open( File.dirname(__FILE__) + '/fixtures/button.png')
|
||||
|
||||
end
|
||||
|
||||
Factory.define :service do |service|
|
||||
|
|
|
|||
|
|
@ -13,11 +13,7 @@ describe Photo do
|
|||
@fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', @fixture_filename)
|
||||
@fail_fixture_name = File.join(File.dirname(__FILE__), '..', 'fixtures', 'msg.xml')
|
||||
|
||||
# @photo = Photo.new
|
||||
#@photo.person = @user.person
|
||||
#@photo.diaspora_handle = @user.person.diaspora_handle
|
||||
@photo = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
||||
|
||||
@photo2 = @user.post(:photo, :user_file=> File.open(@fixture_name), :to => @aspect.id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,13 @@ describe User do
|
|||
user.should_receive(:post_to_facebook).exactly(0).times
|
||||
user.post :status_message, :message => "hi", :to => "all"
|
||||
end
|
||||
|
||||
|
||||
it 'should not socket a pending post' do
|
||||
sm = user.build_post(:status_message, :message => "your mom", :to => aspect.id, :pending => true)
|
||||
sm.should_not_receive(:socket_to_uid)
|
||||
user.dispatch_post(sm, :to => aspect.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#post' do
|
||||
|
|
|
|||
|
|
@ -9,17 +9,20 @@ describe User do
|
|||
let(:user) {make_user}
|
||||
let!(:aspect) { user.aspects.create(:name => "cats")}
|
||||
let!(:user2) { Factory(:user_with_aspect) }
|
||||
let!(:aspect2) { user2.aspects.first }
|
||||
|
||||
let(:person_one) { Factory.create :person }
|
||||
let(:person_two) { Factory.create :person }
|
||||
let(:person_three) { Factory.create :person }
|
||||
|
||||
|
||||
context 'with two posts' do
|
||||
let!(:status_message1) { user2.post :status_message, :message => "hi", :to => user2.aspects.first.id }
|
||||
let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => user2.aspects.first.id }
|
||||
let!(:status_message4) { user2.post :status_message, :message => "blah", :public => true , :to => user2.aspects.first.id }
|
||||
let!(:status_message3) { user.post :status_message, :message => "hey", :public => true , :to => user.aspects.first.id }
|
||||
let!(:status_message1) { user2.post :status_message, :message => "hi", :to => aspect2.id }
|
||||
let!(:status_message2) { user2.post :status_message, :message => "hey", :public => true , :to => aspect2.id }
|
||||
let!(:status_message4) { user2.post :status_message, :message => "blah", :public => true , :to => aspect2.id }
|
||||
let!(:status_message3) { user.post :status_message, :message => "hey", :public => true , :to => aspect.id }
|
||||
|
||||
let!(:pending_status_message) { user2.post :status_message, :message => "hey", :public => true , :to => aspect2.id, :pending => true }
|
||||
|
||||
describe "#visible_posts" do
|
||||
it "queries by person id" do
|
||||
|
|
@ -44,6 +47,13 @@ describe User do
|
|||
user2.visible_posts(:message => "hi").include?(status_message1).should == true
|
||||
end
|
||||
|
||||
it "does not return pending posts" do
|
||||
pending_status_message.pending.should be_true
|
||||
user2.visible_posts.should_not include pending_status_message
|
||||
|
||||
user2.visible_posts(:by_members_of => aspect2).should_not include pending_status_message
|
||||
end
|
||||
|
||||
context 'with two users' do
|
||||
let!(:first_aspect) {user.aspects.create(:name => 'bruisers')}
|
||||
let!(:second_aspect) {user.aspects.create(:name => 'losers')}
|
||||
|
|
|
|||
Loading…
Reference in a new issue