diff --git a/app/helpers/interim_stream_hackiness_helper.rb b/app/helpers/interim_stream_hackiness_helper.rb index 9ed9ad7a9..4219d29fe 100644 --- a/app/helpers/interim_stream_hackiness_helper.rb +++ b/app/helpers/interim_stream_hackiness_helper.rb @@ -39,27 +39,19 @@ module InterimStreamHackinessHelper end end + def publisher_method(method) + @stream.try(:publisher).try(method) == true + end + def publisher_open - if defined?(@stream) - @stream.publisher.open? - else - false - end + publisher_method(:open) end def publisher_public - if defined?(@stream) - @stream.publisher.public? - else - false - end + publisher_method(:public) end def publisher_explain - if defined?(@stream) - @stream.publisher.public? - else - false - end + publisher_method(:explain) end end diff --git a/lib/publisher.rb b/lib/publisher.rb index 3de0d0aed..71894b652 100644 --- a/lib/publisher.rb +++ b/lib/publisher.rb @@ -10,26 +10,10 @@ class Publisher end def text - formatted_message - end - - def open? - self.open - end - - def public? - self.public - end - - def explain? - self.explain - end - - private - def formatted_message - if self.prefill.present? - sm = StatusMessage.new(:text => self.prefill) - Diaspora::Mentionable.format(sm.raw_message, sm.mentioned_people, plain_text: true) - end + return unless prefill.present? + Diaspora::MessageRenderer.new( + prefill, + mentioned_people: Diaspora::Mentionable.people_from_string(prefill) + ).plain_text end end diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index e92ee93d0..995804372 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -25,7 +25,7 @@ class Stream::Multi < Stream::Base private def publisher_opts if welcome? - {:open => true, :prefill => publisher_prefill, :public => true} + {open: true, prefill: publisher_prefill, public: true, explain: true} else super end diff --git a/spec/lib/publisher_spec.rb b/spec/lib/publisher_spec.rb index 7bb7a7c5d..26bfe34a4 100644 --- a/spec/lib/publisher_spec.rb +++ b/spec/lib/publisher_spec.rb @@ -24,13 +24,13 @@ describe Publisher do end ["open", "public", "explain"].each do |property| - describe "##{property}?" do + describe "##{property}" do it 'defaults to closed' do - expect(@publisher.send("#{property}?".to_sym)).to be_falsey + expect(@publisher.send("#{property}".to_sym)).to be_falsey end it 'listens to the opts' do - expect(Publisher.new(alice, {property.to_sym => true}).send("#{property}?".to_sym)).to be true + expect(Publisher.new(alice, property.to_sym => true).send("#{property}".to_sym)).to be true end end end diff --git a/spec/lib/stream/multi_spec.rb b/spec/lib/stream/multi_spec.rb index 2f77fc180..5c1df2468 100644 --- a/spec/lib/stream/multi_spec.rb +++ b/spec/lib/stream/multi_spec.rb @@ -26,9 +26,7 @@ describe Stream::Multi do prefill_text = "sup?" allow(@stream).to receive(:welcome?).and_return(true) allow(@stream).to receive(:publisher_prefill).and_return(prefill_text) - expect(@stream.send(:publisher_opts)).to eq({:open => true, - :prefill => prefill_text, - :public => true}) + expect(@stream.send(:publisher_opts)).to eq(open: true, prefill: prefill_text, public: true, explain: true) end it 'provides no opts if welcome? is not set' do