From 83c2c466fb407607948306b59aebfc1767a4ad7e Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Tue, 21 May 2019 01:55:03 -0500 Subject: [PATCH] use dots instead of colons for tag scopes --- app/lib/bangtags.rb | 8 ++++---- app/models/tag.rb | 2 +- app/services/process_hashtags_service.rb | 4 ++-- db/migrate/20190521003909_rewrite_scoped_tag_delims.rb | 9 +++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20190521003909_rewrite_scoped_tag_delims.rb diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb index 33721e0c2..3441b7464 100644 --- a/app/lib/bangtags.rb +++ b/app/lib/bangtags.rb @@ -36,7 +36,7 @@ class Bangtags end def process - return unless status.text&.present? && status.text.include?('#!') + return unless !@vars['_bangtags:disable'] && status.text&.present? && status.text.include?('#!') status.text.gsub!('#!!', "#\u200c!") @@ -218,7 +218,7 @@ class Bangtags chunk = mentions.join(' ') when 'tag' chunk = nil - tags = cmd[1..-1].map {|t| t.gsub('.', ':')} + tags = cmd[1..-1].map {|t| t.gsub(':', '.')} add_tags(status, *tags) when 'thread' chunk = nil @@ -291,7 +291,7 @@ class Bangtags when 'tag' chunk = nil next unless @parent_status.account.id == @account.id - tags = cmd[2..-1].map {|t| t.gsub('.', ':')} + tags = cmd[2..-1].map {|t| t.gsub(':', '.')} add_tags(@parent_status, *tags) when 'emoji' @parent_status.emojis.each do |theirs| @@ -404,7 +404,7 @@ class Bangtags status.visibility = :direct @vore_stack.push('_draft') @component_stack.push(:var) - add_tags(status, 'self:draft') + add_tags(status, 'self.draft') when 'format', 'type' chunk = nil next if cmd[1].nil? diff --git a/app/models/tag.rb b/app/models/tag.rb index 04b902885..47bbfea1d 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -19,7 +19,7 @@ class Tag < ApplicationRecord has_many :featured_tags, dependent: :destroy, inverse_of: :tag has_one :account_tag_stat, dependent: :destroy - HASHTAG_NAME_RE = '[[:word:]:_\-]*[[:alpha:]:_·\-][[:word:]:_\-]*' + HASHTAG_NAME_RE = '[[:word:]._\-]*[[:alpha:]._·\-][[:word:]._\-]*' HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i validates :name, presence: true, uniqueness: true, format: { with: /\A#{HASHTAG_NAME_RE}\z/i } diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb index 68a87b11a..e8c2c95bb 100644 --- a/app/services/process_hashtags_service.rb +++ b/app/services/process_hashtags_service.rb @@ -8,9 +8,9 @@ class ProcessHashtagsService < BaseService records = [] tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name| - name = name.gsub(/::+/, ':') + name = name.gsub(/\.\.+/, '.') next if name.blank? - component_indices = name.size.times.select {|i| name[i] == ':'} + component_indices = name.size.times.select {|i| name[i] == '.'} component_indices << name.size - 1 component_indices.take(6).each_with_index do |i, nest| frag = (nest != 5) ? name[0..i] : name diff --git a/db/migrate/20190521003909_rewrite_scoped_tag_delims.rb b/db/migrate/20190521003909_rewrite_scoped_tag_delims.rb new file mode 100644 index 000000000..a7b2c0224 --- /dev/null +++ b/db/migrate/20190521003909_rewrite_scoped_tag_delims.rb @@ -0,0 +1,9 @@ +class RewriteScopedTagDelims < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + def up + Tag.where("tags.name LIKE '%:%'").find_each do |tag| + tag.name.gsub!(':', '.') + tag.save + end + end +end