Browse Source

split `i:am` signatures into their very own `footer` column

undefined
multiple creatures 1 month ago
parent
commit
214f704878

+ 10
- 0
app/services/post_status_service.rb View File

@@ -28,6 +28,7 @@ class PostStatusService < BaseService
28 28
     @account     = account
29 29
     @options     = options
30 30
     @text        = @options[:text] || ''
31
+    @footer      = @options[:footer]
31 32
     @in_reply_to = @options[:thread]
32 33
     @tags        = @options[:tags]
33 34
     @local_only  = @options[:local_only]
@@ -53,12 +54,20 @@ class PostStatusService < BaseService
53 54
 
54 55
   private
55 56
 
57
+  def set_footer_from_i_am
58
+    name = @account.vars['_they:are']
59
+    return if name.blank?
60
+    @account.vars["_they:are:#{name}"]
61
+  end
62
+
56 63
   def preprocess_attributes!
57 64
     if @text.blank? && @options[:spoiler_text].present?
58 65
      @text = '.'
59 66
      @text = @media.find(&:video?) ? '📹' : '🖼' if @media.size > 0
60 67
     end
61 68
 
69
+    @footer = set_footer_from_i_am if @footer.nil?
70
+
62 71
     @visibility   = @options[:visibility] || @account.user_default_visibility
63 72
     @visibility   = :unlisted if @visibility.in?([nil, 'public']) && @account.silenced? || @account.force_unlisted
64 73
 
@@ -178,6 +187,7 @@ class PostStatusService < BaseService
178 187
     {
179 188
       created_at: @options[:created_at] ? @options[:created_at].to_datetime : Time.now.utc,
180 189
       text: @text,
190
+      footer: @footer,
181 191
       media_attachments: @media || [],
182 192
       thread: @in_reply_to,
183 193
       poll_attributes: poll_attributes,

+ 5
- 0
db/migrate/20190518044851_add_footer_to_statuses.rb View File

@@ -0,0 +1,5 @@
1
+class AddFooterToStatuses < ActiveRecord::Migration[5.2]
2
+  def change
3
+    add_column :statuses, :footer, :text
4
+  end
5
+end

+ 19
- 0
db/migrate/20190518150215_reformat_local_statuses.rb View File

@@ -0,0 +1,19 @@
1
+class ReformatLocalStatuses < ActiveRecord::Migration[5.2]
2
+  disable_ddl_transaction!
3
+  def up
4
+    Status.local.without_reblogs.find_each do |status|
5
+      status.content_type = 'text/x-bbcode+markdown'
6
+      text = status.text
7
+      matches = text.match(/\[(right|rfloat)\][\u200c\u200b—–-]+ *(.*?)\[\/\1\]\u200c?\Z/)
8
+      if matches
9
+        status.footer = matches[2].strip
10
+        text = text.sub(/\[(right|rfloat)\][\u200c\u200b—–-]+.*?\[\/\1\]\u200c?\Z/, '').rstrip
11
+      end
12
+      text = text.gsub(/\[(color|colorhex|hexcolor)=\w+\](.*?)\[\/\1\]/, '[b]\2[/b]')
13
+      text = text.gsub(/\[(spin|pulse)\](.*?)\[\/\1\]/, '[b]\2[/b]')
14
+      status.text = text unless text.blank?
15
+      Rails.logger.info("Rewrote status ID #{status.id}")
16
+      status.save
17
+    end
18
+  end
19
+end

+ 3
- 2
db/schema.rb View File

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 2019_05_12_200918) do
13
+ActiveRecord::Schema.define(version: 2019_05_18_150215) do
14 14
 
15 15
   # These are extensions that must be enabled in order to support this database
16 16
   enable_extension "plpgsql"
@@ -644,11 +644,12 @@ ActiveRecord::Schema.define(version: 2019_05_12_200918) do
644 644
     t.bigint "in_reply_to_account_id"
645 645
     t.boolean "local_only"
646 646
     t.bigint "poll_id"
647
-    t.string "content_type"
648 647
     t.tsvector "tsv"
649 648
     t.boolean "curated", default: false, null: false
650 649
     t.string "sharekey"
651 650
     t.boolean "network", default: false, null: false
651
+    t.string "content_type"
652
+    t.text "footer"
652 653
     t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc }
653 654
     t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id"
654 655
     t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id"

Loading…
Cancel
Save