about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/status.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/status.rb b/app/models/status.rb
index f8c11d109..6a02aa13b 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -293,6 +293,7 @@ class Status < ApplicationRecord
   before_validation :set_local
 
   after_create :set_poll_id
+  after_create :process_bangtags, if: :local?
 
   after_find :limit_domain_visibility
 
@@ -565,6 +566,26 @@ class Status < ApplicationRecord
     end
   end
 
+  def process_bangtags
+    return if text&.nil?
+    return unless '#!'.in?(text)
+    chunks = []
+    text.split(/(#!\w+)/).each do |chunk|
+      if chunk.start_with?("#!")
+        case chunk[2..-1]
+        when 'permalink'
+          chunks << TagManager.instance.url_for(self)
+        else
+          chunks << chunk
+        end
+      else
+        chunks << chunk
+      end
+    end
+    self.text = chunks.join('')
+    update_column(:text, text)
+  end
+
   def set_conversation
     self.thread = thread.reblog if thread&.reblog?