about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
Diffstat (limited to 'app/services')
-rw-r--r--app/services/fan_out_on_write_service.rb2
-rw-r--r--app/services/hashtag_query_service.rb12
-rw-r--r--app/services/process_hashtags_service.rb19
3 files changed, 23 insertions, 10 deletions
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 2efd51445..4db3d4cf4 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -93,7 +93,7 @@ class FanOutOnWriteService < BaseService
   def deliver_to_hashtags(status)
     Rails.logger.debug "Delivering status #{status.id} to hashtags"
 
-    status.tags.pluck(:name).each do |hashtag|
+    status.tags.reject { |t| t.private }.pluck(:name).each do |hashtag|
       Redis.current.publish("timeline:hashtag:#{hashtag}", @payload)
       Redis.current.publish("timeline:hashtag:#{hashtag}:local", @payload) if status.local?
     end
diff --git a/app/services/hashtag_query_service.rb b/app/services/hashtag_query_service.rb
index 5773d78c6..5a1464805 100644
--- a/app/services/hashtag_query_service.rb
+++ b/app/services/hashtag_query_service.rb
@@ -1,13 +1,19 @@
 # frozen_string_literal: true
 
 class HashtagQueryService < BaseService
-  def call(tag, params, account = nil, local = false)
-    tags = tags_for(Array(tag.name) | Array(params[:any])).pluck(:id)
+  def call(tag, params, account = nil, local = false, priv = false)
+    tags = tags_for(Array(tag.name) | Array(params[:any]))
     all  = tags_for(params[:all])
     none = tags_for(params[:none])
 
+    all_tags = Array(tags) | Array(all) | Array(none)
+    local = all_tags.any? { |t| t.local } unless local
+    priv = all_tags.any? { |t| t.private } unless priv
+
+    tags = tags.pluck(:id)
+
     Status.distinct
-          .as_tag_timeline(tags, account, local)
+          .as_tag_timeline(tags, account, local, priv)
           .tagged_with_all(all)
           .tagged_with_none(none)
   end
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)