about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-28 09:14:21 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:16 -0500
commit8ce1fd6edb8e5dc1335cdac6c46711441220dbf7 (patch)
treefb57253f05e1e5318839e0b99faff546a9a01315
parent625121ab53ea4a54d381fb2fe8c3c31244ad6ab7 (diff)
[Feature] Use unprocessed text for edits
-rw-r--r--app/models/status.rb1
-rw-r--r--app/serializers/rest/status_serializer.rb4
-rw-r--r--app/services/post_status_service.rb1
-rw-r--r--app/services/update_status_service.rb2
-rw-r--r--db/migrate/20200728135753_add_original_text_to_statuses.rb5
-rw-r--r--db/schema.rb3
6 files changed, 15 insertions, 1 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index c92d00935..edddffcc6 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -30,6 +30,7 @@
 #  published              :boolean          default(TRUE), not null
 #  title                  :text
 #  semiprivate            :boolean          default(FALSE), not null
+#  original_text          :text
 #
 
 # rubocop:disable Metrics/ClassLength
diff --git a/app/serializers/rest/status_serializer.rb b/app/serializers/rest/status_serializer.rb
index 4b06ec268..96ae59c62 100644
--- a/app/serializers/rest/status_serializer.rb
+++ b/app/serializers/rest/status_serializer.rb
@@ -85,6 +85,10 @@ class REST::StatusSerializer < ActiveModel::Serializer
     Formatter.instance.format(object)
   end
 
+  def text
+    object.original_text.presence || object.text
+  end
+
   def url
     ActivityPub::TagManager.instance.url_for(object)
   end
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 33440a5a4..82588d254 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -196,6 +196,7 @@ class PostStatusService < BaseService
   def status_attributes
     {
       text: @text,
+      original_text: @text,
       media_attachments: @media || [],
       thread: @in_reply_to,
       poll_attributes: poll_attributes,
diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb
index 18fee3e17..887384991 100644
--- a/app/services/update_status_service.rb
+++ b/app/services/update_status_service.rb
@@ -8,6 +8,7 @@ class UpdateStatusService < BaseService
     spoiler_text
     title
     text
+    original_text
     content_type
     language
     sensitive
@@ -33,6 +34,7 @@ class UpdateStatusService < BaseService
     @tags                   = (tags.nil? ? @status.tags : (tags || [])).to_set
 
     @params[:text]        ||= ''
+    @params[:original_text] = @params[:text]
     @params[:published]     = true if @status.published?
     (@params[:edited]     ||= 1 + @status.edited) if @params[:published].presence || @status.published?
 
diff --git a/db/migrate/20200728135753_add_original_text_to_statuses.rb b/db/migrate/20200728135753_add_original_text_to_statuses.rb
new file mode 100644
index 000000000..6bf210191
--- /dev/null
+++ b/db/migrate/20200728135753_add_original_text_to_statuses.rb
@@ -0,0 +1,5 @@
+class AddOriginalTextToStatuses < ActiveRecord::Migration[5.2]
+  def change
+    add_column :statuses, :original_text, :text
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a9f0b0653..3bf2d2e9e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 2020_07_26_095058) do
+ActiveRecord::Schema.define(version: 2020_07_28_135753) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -835,6 +835,7 @@ ActiveRecord::Schema.define(version: 2020_07_26_095058) do
     t.boolean "published", default: true, null: false
     t.text "title"
     t.boolean "semiprivate", default: false, null: false
+    t.text "original_text"
     t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20190820", order: { id: :desc }, where: "(deleted_at IS NULL)"
     t.index ["account_id", "id"], name: "index_unpublished_statuses", order: { id: :desc }, where: "((deleted_at IS NULL) AND (published = false))"
     t.index ["conversation_id"], name: "index_statuses_on_conversation_id", where: "(deleted_at IS NULL)"