Commit 1ccf9651 authored by Ilya Zhitomirskiy's avatar Ilya Zhitomirskiy Committed by danielgrippi

publisher lib, prefill, open, still need to do public first message for new users

parent ee749488
......@@ -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
......@@ -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
......@@ -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|
......
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
......
......@@ -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
......@@ -44,11 +44,6 @@ class Stream::Base
[]
end
# @return [String]
def publisher_prefill_text
''
end
# @return [ActiveRecord::Association<Person>] 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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment