publisher lib, prefill, open, still need to do public first message for new users
This commit is contained in:
parent
ee74948863
commit
1ccf965194
9 changed files with 125 additions and 15 deletions
|
|
@ -14,7 +14,7 @@ module InterimStreamHackinessHelper
|
||||||
if params[:prefill].present?
|
if params[:prefill].present?
|
||||||
params[:prefill]
|
params[:prefill]
|
||||||
elsif defined?(@stream)
|
elsif defined?(@stream)
|
||||||
@stream.publisher_prefill_text
|
@stream.publisher.prefill
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
@ -24,7 +24,7 @@ module InterimStreamHackinessHelper
|
||||||
if defined?(@stream) && params[:controller] == 'multis'
|
if defined?(@stream) && params[:controller] == 'multis'
|
||||||
@stream.post_from_group(post)
|
@stream.post_from_group(post)
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -35,4 +35,12 @@ module InterimStreamHackinessHelper
|
||||||
def stream_settings_link(post)
|
def stream_settings_link(post)
|
||||||
link_to "", "#{edit_user_path}#stream-preferences"
|
link_to "", "#{edit_user_path}#stream-preferences"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publisher_open
|
||||||
|
if defined?(@stream)
|
||||||
|
@stream.publisher.open?
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,13 @@
|
||||||
$(".public_icon").tipsy({trigger: 'hover', gravity: 'n'});
|
$(".public_icon").tipsy({trigger: 'hover', gravity: 'n'});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
- if publisher_open
|
||||||
|
:javascript
|
||||||
|
$(document).ready(function()
|
||||||
|
{
|
||||||
|
Publisher.open();
|
||||||
|
});
|
||||||
|
|
||||||
#publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )}
|
#publisher.closed{:class => ((aspect == :profile)? 'mention_popup' : nil )}
|
||||||
.content_creation
|
.content_creation
|
||||||
= form_for(StatusMessage.new, :remote => remote?, :html => {"data-type" => "json"}) do |status|
|
= form_for(StatusMessage.new, :remote => remote?, :html => {"data-type" => "json"}) do |status|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
class Publisher
|
class Publisher
|
||||||
attr_accessor :user, :open, :prefill_text, :public
|
attr_accessor :user, :open, :prefill, :public
|
||||||
|
|
||||||
def initialize(user, opts={})
|
def initialize(user, opts={})
|
||||||
self.user = user
|
self.user = user
|
||||||
self.open = (opts[:open] == true)? true : false
|
self.open = (opts[:open] == true)? true : false
|
||||||
self.prefill_text = opts[:prefill_text]
|
self.prefill = opts[:prefill]
|
||||||
self.public = (opts[:public] == true)? true : false
|
self.public = (opts[:public] == true)? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -126,4 +126,32 @@ class Stream::Aspect < Stream::Base
|
||||||
def can_comment?(post)
|
def can_comment?(post)
|
||||||
true
|
true
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -44,11 +44,6 @@ class Stream::Base
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [String]
|
|
||||||
def publisher_prefill_text
|
|
||||||
''
|
|
||||||
end
|
|
||||||
|
|
||||||
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
|
# @return [ActiveRecord::Association<Person>] AR association of people within stream's given aspects
|
||||||
def people
|
def people
|
||||||
people_ids = posts.map{|x| x.author_id}
|
people_ids = posts.map{|x| x.author_id}
|
||||||
|
|
@ -107,6 +102,7 @@ class Stream::Base
|
||||||
@order ||= 'created_at'
|
@order ||= 'created_at'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @return [Publisher]
|
||||||
def publisher
|
def publisher
|
||||||
@publisher ||= Publisher.new(self.user)
|
@publisher ||= Publisher.new(self.user)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -35,14 +35,14 @@ class Stream::Tag < Stream::Base
|
||||||
@posts ||= construct_post_query
|
@posts ||= construct_post_query
|
||||||
end
|
end
|
||||||
|
|
||||||
def publisher_prefill_text
|
|
||||||
display_tag_name + ' '
|
|
||||||
end
|
|
||||||
|
|
||||||
def tag_name=(tag_name)
|
def tag_name=(tag_name)
|
||||||
@tag_name = tag_name.downcase.gsub('#', '')
|
@tag_name = tag_name.downcase.gsub('#', '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publisher
|
||||||
|
@publisher ||= Publisher.new(self.user, :prefill => "#{display_tag_name} ")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def construct_post_query
|
def construct_post_query
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@ describe Publisher do
|
||||||
|
|
||||||
describe "#prefill" do
|
describe "#prefill" do
|
||||||
it 'defaults to nothing' do
|
it 'defaults to nothing' do
|
||||||
@publisher.prefill_text.should be_blank
|
@publisher.prefill.should be_blank
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is settable' do
|
it 'is settable' do
|
||||||
Publisher.new(alice, :prefill_text => "party!").prefill_text.should == "party!"
|
Publisher.new(alice, :prefill => "party!").prefill.should == "party!"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -172,4 +172,67 @@ describe Stream::Aspect do
|
||||||
end
|
end
|
||||||
it_should_behave_like 'it is a stream'
|
it_should_behave_like 'it is a stream'
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -91,4 +91,12 @@ describe Stream::Tag do
|
||||||
stream.tag_name.should == 'what'
|
stream.tag_name.should == 'what'
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue