From dd70b4e463a537011641d6de1b73b04c87018c7d Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Tue, 2 Apr 2019 13:42:24 -0500 Subject: initial bangtags implementation, permalinks --- app/models/status.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'app') 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? -- cgit