Commit df9874b7 authored by Benjamin Neff's avatar Benjamin Neff

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.
parent 8cffc5cf
......@@ -59,7 +59,6 @@ class Post < ActiveRecord::Base
end
def root; end
def raw_message; ""; end
def mentioned_people; []; end
def photos; []; end
......
......@@ -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
......
......@@ -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
......
......@@ -42,7 +42,7 @@ class PostPresenter < BasePresenter
if @post.message
@post.message.plain_text_for_json
else
@post.raw_message
@post.text
end
end
......
......@@ -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,
......
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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("&gt;", "&lt;", "&#39;") # ">", "<", "'"
......@@ -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
......
......@@ -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
......
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