From df9874b73aaafa5349f97948d162525585edf8fb Mon Sep 17 00:00:00 2001 From: Benjamin Neff <benjamin@coding4coffee.ch> Date: Sat, 16 Jul 2016 23:08:41 +0200 Subject: [PATCH] remove raw_message This was only an alias for "text", and "raw_message" is also not used for federation anymore, so we can drop it. --- app/models/post.rb | 1 - app/models/reshare.rb | 4 ++-- app/models/status_message.rb | 20 ++++++------------- app/presenters/post_presenter.rb | 2 +- lib/diaspora/federation/entities.rb | 2 +- lib/diaspora/federation/receive.rb | 2 +- lib/diaspora/message_renderer.rb | 24 +++++++++++------------ spec/controllers/users_controller_spec.rb | 4 ++-- spec/lib/diaspora/fetcher/public_spec.rb | 6 +++--- spec/lib/diaspora/mentionable_spec.rb | 10 +++++----- spec/models/status_message_spec.rb | 6 +++--- 11 files changed, 36 insertions(+), 45 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 071d27b641..cb94c408ad 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -59,7 +59,6 @@ class Post < ActiveRecord::Base end def root; end - def raw_message; ""; end def mentioned_people; []; end def photos; []; end diff --git a/app/models/reshare.rb b/app/models/reshare.rb index e6d925c57e..d69c9d2781 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -29,8 +29,8 @@ class Reshare < Post :message, :nsfw, to: :absolute_root, allow_nil: true - def raw_message - absolute_root.try(:raw_message) || super + def text + absolute_root.try(:text) || "" end def mentioned_people diff --git a/app/models/status_message.rb b/app/models/status_message.rb index b2be566e18..5b78fa3242 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -8,7 +8,7 @@ class StatusMessage < Post include PeopleHelper acts_as_taggable_on :tags - extract_tags_from :raw_message + extract_tags_from :text validates_length_of :text, :maximum => 65535, :message => proc {|p, v| I18n.t('status_messages.too_long', :count => 65535, :current_length => v[:value].length)} @@ -51,20 +51,12 @@ class StatusMessage < Post tag_stream(tag_ids) end - def raw_message - read_attribute(:text) || "" - end - - def raw_message=(text) - write_attribute(:text, text) - end - def nsfw - self.raw_message.match(/#nsfw/i) || super + text.try(:match, /#nsfw/i) || super end def message - @message ||= Diaspora::MessageRenderer.new raw_message, mentioned_people: mentioned_people + @message ||= Diaspora::MessageRenderer.new(text, mentioned_people: mentioned_people) end def mentioned_people @@ -72,7 +64,7 @@ class StatusMessage < Post create_mentions if self.mentions.empty? self.mentions.includes(:person => :profile).map{ |mention| mention.person } else - Diaspora::Mentionable.people_from_string(self.raw_message) + Diaspora::Mentionable.people_from_string(text) end end @@ -84,7 +76,7 @@ class StatusMessage < Post ## ---- ---- def create_mentions - ppl = Diaspora::Mentionable.people_from_string(self.raw_message) + ppl = Diaspora::Mentionable.people_from_string(text) ppl.each do |person| self.mentions.find_or_create_by(person_id: person.id) end @@ -103,7 +95,7 @@ class StatusMessage < Post end def text_and_photos_blank? - self.raw_message.blank? && self.photos.blank? + text.blank? && photos.blank? end def queue_gather_oembed_data diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 3aef5fd5d6..6cee90e2fb 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -42,7 +42,7 @@ class PostPresenter < BasePresenter if @post.message @post.message.plain_text_for_json else - @post.raw_message + @post.text end end diff --git a/lib/diaspora/federation/entities.rb b/lib/diaspora/federation/entities.rb index f0c373dee3..f18f74c2b4 100644 --- a/lib/diaspora/federation/entities.rb +++ b/lib/diaspora/federation/entities.rb @@ -222,7 +222,7 @@ module Diaspora DiasporaFederation::Entities::StatusMessage.new( author: status_message.diaspora_handle, guid: status_message.guid, - text: status_message.raw_message, + text: status_message.text, photos: status_message.photos.map {|photo| photo(photo) }, location: status_message.location ? location(status_message.location) : nil, poll: status_message.poll ? poll(status_message.poll) : nil, diff --git a/lib/diaspora/federation/receive.rb b/lib/diaspora/federation/receive.rb index d8b75c2e6b..6ceb4ddb92 100644 --- a/lib/diaspora/federation/receive.rb +++ b/lib/diaspora/federation/receive.rb @@ -248,7 +248,7 @@ module Diaspora StatusMessage.new( author: author_of(entity), guid: entity.guid, - raw_message: entity.text, + text: entity.text, public: entity.public, created_at: entity.created_at, provider_display_name: entity.provider_display_name diff --git a/lib/diaspora/message_renderer.rb b/lib/diaspora/message_renderer.rb index 7edfc711d9..7c39470fb0 100644 --- a/lib/diaspora/message_renderer.rb +++ b/lib/diaspora/message_renderer.rb @@ -120,7 +120,7 @@ module Diaspora delegate :empty?, :blank?, :present?, to: :raw - # @param [String] raw_message Raw input text + # @param [String] text Raw input text # @param [Hash] opts Global options affecting output # @option opts [Array<Person>] :mentioned_people ([]) List of people # allowed to mention @@ -147,8 +147,8 @@ module Diaspora # to Redcarpet # @option opts [Hash] :markdown_render_options Override default options # passed to the Redcarpet renderer - def initialize raw_message, opts={} - @raw_message = raw_message + def initialize(text, opts={}) + @text = text @options = DEFAULTS.deep_merge opts end @@ -211,12 +211,12 @@ module Diaspora # this length. If not given defaults to 70. def title opts={} # Setext-style header - heading = if /\A(?<setext_content>.{1,200})\n(?:={1,200}|-{1,200})(?:\r?\n|$)/ =~ @raw_message.lstrip - setext_content - # Atx-style header - elsif /\A\#{1,6}\s+(?<atx_content>.{1,200}?)(?:\s+#+)?(?:\r?\n|$)/ =~ @raw_message.lstrip - atx_content - end + heading = if /\A(?<setext_content>.{1,200})\n(?:={1,200}|-{1,200})(?:\r?\n|$)/ =~ @text.lstrip + setext_content + # Atx-style header + elsif /\A\#{1,6}\s+(?<atx_content>.{1,200}?)(?:\s+#+)?(?:\r?\n|$)/ =~ @text.lstrip + atx_content + end heading &&= self.class.new(heading).plain_text_without_markdown @@ -236,7 +236,7 @@ module Diaspora end def raw - @raw_message + @text end def to_s @@ -245,8 +245,8 @@ module Diaspora private - def process opts, &block - Processor.process(@raw_message, @options.deep_merge(opts), &block) + def process(opts, &block) + Processor.process(@text, @options.deep_merge(opts), &block) end end end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index bde9b7d1d8..00bcc6ea88 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -61,7 +61,7 @@ describe UsersController, :type => :controller do it 'renders xml if atom is requested' do sm = FactoryGirl.create(:status_message, :public => true, :author => @user.person) get :public, :username => @user.username, :format => :atom - expect(response.body).to include(sm.raw_message) + expect(response.body).to include(sm.text) end it 'renders xml if atom is requested with clickalbe urls' do @@ -77,7 +77,7 @@ describe UsersController, :type => :controller do it 'includes reshares in the atom feed' do reshare = FactoryGirl.create(:reshare, :author => @user.person) get :public, :username => @user.username, :format => :atom - expect(response.body).to include reshare.root.raw_message + expect(response.body).to include reshare.root.text end it 'do not show reshares in atom feed if origin post is deleted' do diff --git a/spec/lib/diaspora/fetcher/public_spec.rb b/spec/lib/diaspora/fetcher/public_spec.rb index 82eb8f2e7e..6ad2fbebe7 100644 --- a/spec/lib/diaspora/fetcher/public_spec.rb +++ b/spec/lib/diaspora/fetcher/public_spec.rb @@ -122,10 +122,10 @@ describe Diaspora::Fetcher::Public do end end - it 'copied the text correctly' do + it "copied the text correctly" do @data.each do |post| - entry = StatusMessage.find_by_guid(post['guid']) - expect(entry.raw_message).to eql(post['text']) + entry = StatusMessage.find_by_guid(post["guid"]) + expect(entry.text).to eql(post["text"]) end end diff --git a/spec/lib/diaspora/mentionable_spec.rb b/spec/lib/diaspora/mentionable_spec.rb index a328fe7cc7..efc0860b02 100644 --- a/spec/lib/diaspora/mentionable_spec.rb +++ b/spec/lib/diaspora/mentionable_spec.rb @@ -24,7 +24,7 @@ STR describe "#format" do context "html output" do it "adds the links to the formatted message" do - fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, @people) + fmt_msg = Diaspora::Mentionable.format(@status_msg.text, @people) @people.each do |person| expect(fmt_msg).to include person_link(person, class: "mention hovercardable") @@ -32,7 +32,7 @@ STR end it "should work correct when message is escaped html" do - raw_msg = @status_msg.raw_message + raw_msg = @status_msg.text fmt_msg = Diaspora::Mentionable.format(CGI.escapeHTML(raw_msg), @people) @people.each do |person| @@ -45,7 +45,7 @@ STR p.first_name = "</a><script>alert('h')</script>" p.save! - fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, @people) + fmt_msg = Diaspora::Mentionable.format(@status_msg.text, @people) expect(fmt_msg).not_to include(p.first_name) expect(fmt_msg).to include(">", "<", "'") # ">", "<", "'" @@ -54,7 +54,7 @@ STR context "plain text output" do it "removes mention markup and displays unformatted name" do - fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, @people, plain_text: true) + fmt_msg = Diaspora::Mentionable.format(@status_msg.text, @people, plain_text: true) @people.each do |person| expect(fmt_msg).to include person.first_name @@ -64,7 +64,7 @@ STR end it "leaves the name of people that cannot be found" do - fmt_msg = Diaspora::Mentionable.format(@status_msg.raw_message, []) + fmt_msg = Diaspora::Mentionable.format(@status_msg.text, []) expect(fmt_msg).to eql @test_txt_plain end end diff --git a/spec/models/status_message_spec.rb b/spec/models/status_message_spec.rb index 88d15b923c..fb7ef503ce 100644 --- a/spec/models/status_message_spec.rb +++ b/spec/models/status_message_spec.rb @@ -91,7 +91,7 @@ describe StatusMessage, type: :model do end end - context "emptyness" do + context "emptiness" do it "needs either a message or at least one photo" do post = user.build_post(:status_message, text: nil) expect(post).not_to be_valid @@ -109,8 +109,8 @@ describe StatusMessage, type: :model do post.photos << photo expect(post).to be_valid expect(post.message.to_s).to be_empty - expect(post.raw_message).to eq "" - expect(post.nsfw).to be_falsy + expect(post.text).to be_nil + expect(post.nsfw).to be_falsey expect(post.errors.full_messages).to eq([]) end -- GitLab