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