about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-04-02 13:42:24 -0500
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:21 -0500
commitdd70b4e463a537011641d6de1b73b04c87018c7d (patch)
treed0d7c489445f10913d87ea5509aa350a8bf11415 /app
parent8bf596861b24e1f813bdbb88aab853c3c94870c6 (diff)
initial bangtags implementation, permalinks
Diffstat (limited to 'app')
-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?