about summary refs log tree commit diff
path: root/app/services/process_hashtags_service.rb
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-15 13:34:05 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-15 14:12:24 -0500
commitcf3ec71aa564c7fe47ec79f8dd5f14e3bce0b85c (patch)
tree49a3356c4177157b377aeca223a7d1c1e2e3dc17 /app/services/process_hashtags_service.rb
parent0a5eba734e6aa6a6e7e8f64b022af8ea129c9f5d (diff)
local visibility scope, chat scope+tags, unlisted tags
Diffstat (limited to 'app/services/process_hashtags_service.rb')
-rw-r--r--app/services/process_hashtags_service.rb23
1 files changed, 17 insertions, 6 deletions
diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb
index 07806b4a7..fff4f5db1 100644
--- a/app/services/process_hashtags_service.rb
+++ b/app/services/process_hashtags_service.rb
@@ -1,24 +1,35 @@
 # frozen_string_literal: true
 
 class ProcessHashtagsService < BaseService
-  def call(status, tags = [])
+  def call(status, tags = [], preloaded_tags = [])
+    status.tags |= preloaded_tags unless preloaded_tags.blank?
+
     if status.local?
       tags = Extractor.extract_hashtags(status.text) | (tags.nil? ? [] : tags)
     end
     records = []
 
     tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name|
-      name = name.gsub(/[:.]+/, '.')
-      next if name.blank?
-      component_indices = name.size.times.select {|i| name[i] == '.'}
-      component_indices << name.size - 1
+      name.gsub!(/[:.]+/, '.')
+      next if name.blank? || name == '.'
+
+      chat = name.starts_with?('chat.', '.chat.')
+      if chat
+        component_indices = [name.size - 1]
+      else
+        component_indices = 1.upto(name.size).select { |i| name[i] == '.' }
+        component_indices << name.size - 1
+      end
+
       component_indices.take(6).each_with_index do |i, nest|
         frag = (nest != 5) ? name[0..i] : name
         tag = Tag.where(name: frag).first_or_create(name: frag)
 
+        tag.chatters.find_or_create_by(id: status.account_id) if chat
+
         next if status.tags.include?(tag)
         status.tags << tag
-        next if tag.local || tag.private
+        next if tag.unlisted || component_indices.size > 1
 
         records << tag
         TrendingTags.record_use!(tag, status.account, status.created_at) if status.distributable?