diff --git a/app/helpers/interim_stream_hackiness_helper.rb b/app/helpers/interim_stream_hackiness_helper.rb index 20e2a5b7a..db9eb9711 100644 --- a/app/helpers/interim_stream_hackiness_helper.rb +++ b/app/helpers/interim_stream_hackiness_helper.rb @@ -14,7 +14,7 @@ module InterimStreamHackinessHelper if params[:prefill].present? params[:prefill] elsif defined?(@stream) - @stream.publisher_prefill_text + @stream.publisher.prefill else nil end @@ -24,7 +24,7 @@ module InterimStreamHackinessHelper if defined?(@stream) && params[:controller] == 'multis' @stream.post_from_group(post) else - [] + [] end end @@ -35,4 +35,12 @@ module InterimStreamHackinessHelper def stream_settings_link(post) link_to "", "#{edit_user_path}#stream-preferences" end + + def publisher_open + if defined?(@stream) + @stream.publisher.open? + else + false + end + end end diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index 45d429fa5..1aae76dae 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -9,6 +9,13 @@ $(".public_icon").tipsy({trigger: 'hover', gravity: 'n'}); }); +- if publisher_open + :javascript + $(document).ready(function() + { + Publisher.open(); + }); + #publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )} .content_creation = form_for(StatusMessage.new, :remote => remote?, :html => {"data-type" => "json"}) do |status| diff --git a/lib/publisher.rb b/lib/publisher.rb index f5f5f5022..c098a9332 100644 --- a/lib/publisher.rb +++ b/lib/publisher.rb @@ -1,10 +1,10 @@ class Publisher - attr_accessor :user, :open, :prefill_text, :public + attr_accessor :user, :open, :prefill, :public def initialize(user, opts={}) self.user = user self.open = (opts[:open] == true)? true : false - self.prefill_text = opts[:prefill_text] + self.prefill = opts[:prefill] self.public = (opts[:public] == true)? true : false end diff --git a/lib/stream/aspect.rb b/lib/stream/aspect.rb index 0cf4ce668..41a1af47b 100644 --- a/lib/stream/aspect.rb +++ b/lib/stream/aspect.rb @@ -126,4 +126,32 @@ class Stream::Aspect < Stream::Base def can_comment?(post) true end + + def publisher + if welcome? + @publisher ||= Publisher.new(self.user, :open => true, :prefill => publisher_prefill, + :public => true) + else + super + end + end + + private + # Generates the prefill for the publisher + # + # @return [String] + def publisher_prefill + prefill = "Hi, I'm #newhere." + + if self.user.followed_tags.size > 0 + tag_string = self.user.followed_tags.map{|t| "##{t.name}"}.join(", ") + prefill << "I like #{tag_string}." + end + + prefill + end + + def welcome? + self.user.getting_started + end end diff --git a/lib/stream/base.rb b/lib/stream/base.rb index b1fb00441..c8044da57 100644 --- a/lib/stream/base.rb +++ b/lib/stream/base.rb @@ -44,11 +44,6 @@ class Stream::Base [] end - # @return [String] - def publisher_prefill_text - '' - end - # @return [ActiveRecord::Association] AR association of people within stream's given aspects def people people_ids = posts.map{|x| x.author_id} @@ -107,6 +102,7 @@ class Stream::Base @order ||= 'created_at' end + # @return [Publisher] def publisher @publisher ||= Publisher.new(self.user) end diff --git a/lib/stream/tag.rb b/lib/stream/tag.rb index c02868af8..f12e48a33 100644 --- a/lib/stream/tag.rb +++ b/lib/stream/tag.rb @@ -35,14 +35,14 @@ class Stream::Tag < Stream::Base @posts ||= construct_post_query end - def publisher_prefill_text - display_tag_name + ' ' - end - def tag_name=(tag_name) @tag_name = tag_name.downcase.gsub('#', '') end + def publisher + @publisher ||= Publisher.new(self.user, :prefill => "#{display_tag_name} ") + end + private def construct_post_query diff --git a/spec/lib/publisher_spec.rb b/spec/lib/publisher_spec.rb index 0c2a6fb1f..4be5485ce 100644 --- a/spec/lib/publisher_spec.rb +++ b/spec/lib/publisher_spec.rb @@ -21,11 +21,11 @@ describe Publisher do describe "#prefill" do it 'defaults to nothing' do - @publisher.prefill_text.should be_blank + @publisher.prefill.should be_blank end it 'is settable' do - Publisher.new(alice, :prefill_text => "party!").prefill_text.should == "party!" + Publisher.new(alice, :prefill => "party!").prefill.should == "party!" end end diff --git a/spec/lib/stream/aspect_spec.rb b/spec/lib/stream/aspect_spec.rb index b7e96e52c..ef2dedfc8 100644 --- a/spec/lib/stream/aspect_spec.rb +++ b/spec/lib/stream/aspect_spec.rb @@ -172,4 +172,67 @@ describe Stream::Aspect do end it_should_behave_like 'it is a stream' end + + describe "#publisher" do + before do + @stream = Stream::Aspect.new(alice, alice.aspects.map(&:id)) + @stream.stub(:welcome?).and_return(false) + end + + it 'does not use prefill text by default' do + @stream.should_not_receive(:publisher_prefill) + + @stream.publisher + end + + it 'checks welcome?' do + @stream.should_receive(:welcome?).and_return(true) + + @stream.publisher + end + + it 'creates a welcome publisher for new user' do + @stream.stub(:welcome?).and_return(true) + @stream.should_receive(:publisher_prefill).and_return("abc") + + Publisher.should_receive(:new).with(alice, hash_including(:open => true, :prefill => "abc", :public => true)) + @stream.publisher + end + + it 'creates a default publisher for returning users' do + Publisher.should_receive(:new).with(alice) + @stream.publisher + end + end + + describe "#publisher_prefill" do + before do + @tag = ActsAsTaggableOn::Tag.find_or_create_by_name("cats") + @tag_following = alice.tag_followings.create(:tag_id => @tag.id) + + @stream = Stream::Aspect.new(alice, alice.aspects.map(&:id)) + end + + it 'returns includes new user hashtag' do + @stream.send(:publisher_prefill).include?("#newhere").should be_true + end + + it 'includes followed hashtags' do + @stream.send(:publisher_prefill).include?("#cats").should be_true + end + end + + describe "#welcome?" do + it 'returns true if user is getting started' do + alice.getting_started = true + + Stream::Aspect.new(alice, alice.aspects.map(&:id)).send(:welcome?).should be_true + end + + it 'returns false if user is getting started' do + alice.getting_started = false + + Stream::Aspect.new(alice, alice.aspects.map(&:id)).send(:welcome?).should be_false + end + end end diff --git a/spec/lib/stream/tag_spec.rb b/spec/lib/stream/tag_spec.rb index 5a585dd90..4d9cbd08f 100644 --- a/spec/lib/stream/tag_spec.rb +++ b/spec/lib/stream/tag_spec.rb @@ -91,4 +91,12 @@ describe Stream::Tag do stream.tag_name.should == 'what' end end + + describe "#publisher" do + it 'creates a publisher with the tag prefill' do + Publisher.should_receive(:new).with(anything(), hash_including(:prefill => "#what ")) + @stream = Stream::Tag.new(alice, "what") + @stream.publisher + end + end end