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-05-05 23:04:23 -0500
committermultiple creatures <dev@multiple-creature.party>2019-05-21 03:16:22 -0500
commita47b1daaebea09ca07ca93079e530f26cfeef914 (patch)
tree04f08b28710732d1a9747c64537cd75162a651ca /app/services/process_hashtags_service.rb
parent992218f05f76106857f2cb5a72c0bb4510aa4563 (diff)
Implement scoped tags; use `local:` and `self:` scopes for community and personal tags, respectively.
Diffstat (limited to 'app/services/process_hashtags_service.rb')
-rw-r--r--app/services/process_hashtags_service.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb
index fb89f6c5b..4257d9231 100644
--- a/app/services/process_hashtags_service.rb
+++ b/app/services/process_hashtags_service.rb
@@ -2,19 +2,26 @@
 
 class ProcessHashtagsService < BaseService
   def call(status, tags = [])
-    tags    = Extractor.extract_hashtags(status.text) if status.network?
+    tags    = Extractor.extract_hashtags(status.text) if tags.blank? && status.local?
     records = []
 
     tags.map { |str| str.mb_chars.downcase }.uniq(&:to_s).each do |name|
-      tag = Tag.where(name: name).first_or_create(name: name)
+      component_indices = name.size.times.select {|i| name[i] == ':'}
+      component_indices << name.size - 1
+      component_indices.each do |i|
+        frag = name[0..i]
+        tag = Tag.where(name: frag).first_or_create(name: frag)
 
-      status.tags << tag
-      records << tag
+        status.tags << tag
 
-      TrendingTags.record_use!(tag, status.account, status.created_at) if status.distributable?
+        next if tag.local || tag.private
+
+        records << tag
+        TrendingTags.record_use!(tag, status.account, status.created_at) if status.distributable?
+      end
     end
 
-    return unless status.public_visibility? || status.unlisted_visibility?
+    return unless status.distributable?
 
     status.account.featured_tags.where(tag_id: records.map(&:id)).each do |featured_tag|
       featured_tag.increment(status.created_at)