about summary refs log tree commit diff
path: root/app/services
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2016-11-05 15:20:05 +0100
committerEugen Rochko <eugen@zeonfederated.com>2016-11-05 17:13:14 +0100
commit48b9619439818ecb344ae33c9c31a55ecb1aa27a (patch)
treeef350e3ebf2563adbe4d57778a08f561d912415f /app/services
parent62292797eccc5bcf47abae9f4daaa2c186660644 (diff)
Adding hashtags
Diffstat (limited to 'app/services')
-rw-r--r--app/services/fan_out_on_write_service.rb15
-rw-r--r--app/services/post_status_service.rb5
-rw-r--r--app/services/process_feed_service.rb6
-rw-r--r--app/services/process_hashtags_service.rb11
4 files changed, 34 insertions, 3 deletions
diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb
index 707f74c35..a36f80150 100644
--- a/app/services/fan_out_on_write_service.rb
+++ b/app/services/fan_out_on_write_service.rb
@@ -5,6 +5,10 @@ class FanOutOnWriteService < BaseService
     deliver_to_self(status) if status.account.local?
     deliver_to_followers(status)
     deliver_to_mentioned(status)
+
+    return if status.account.silenced?
+
+    deliver_to_hashtags(status)
     deliver_to_public(status)
   end
 
@@ -15,22 +19,27 @@ class FanOutOnWriteService < BaseService
   end
 
   def deliver_to_followers(status)
-    status.account.followers.each do |follower|
+    status.account.followers.find_each do |follower|
       next if !follower.local? || FeedManager.instance.filter?(:home, status, follower)
       FeedManager.instance.push(:home, follower, status)
     end
   end
 
   def deliver_to_mentioned(status)
-    status.mentions.each do |mention|
+    status.mentions.find_each do |mention|
       mentioned_account = mention.account
       next if !mentioned_account.local? || mentioned_account.id == status.account_id || FeedManager.instance.filter?(:mentions, status, mentioned_account)
       FeedManager.instance.push(:mentions, mentioned_account, status)
     end
   end
 
+  def deliver_to_hashtags(status)
+    status.tags.find_each do |tag|
+      FeedManager.instance.broadcast("hashtag:#{tag.name}", id: status.id)
+    end
+  end
+
   def deliver_to_public(status)
-    return if status.account.silenced?
     FeedManager.instance.broadcast(:public, id: status.id)
   end
 end
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index 5cac6b70a..b23808a7c 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -9,6 +9,7 @@ class PostStatusService < BaseService
     status = account.statuses.create!(text: text, thread: in_reply_to)
     attach_media(status, media_ids)
     process_mentions_service.call(status)
+    process_hashtags_service.call(status)
     DistributionWorker.perform_async(status.id)
     HubPingWorker.perform_async(account.id)
     status
@@ -26,4 +27,8 @@ class PostStatusService < BaseService
   def process_mentions_service
     @process_mentions_service ||= ProcessMentionsService.new
   end
+
+  def process_hashtags_service
+    @process_hashtags_service ||= ProcessHashtagsService.new
+  end
 end
diff --git a/app/services/process_feed_service.rb b/app/services/process_feed_service.rb
index 2f53b9c77..e60284d8e 100644
--- a/app/services/process_feed_service.rb
+++ b/app/services/process_feed_service.rb
@@ -47,6 +47,12 @@ class ProcessFeedService < BaseService
       record_remote_mentions(status, entry.xpath('./xmlns:link[@rel="mentioned"]'))
       record_remote_mentions(status.reblog, entry.at_xpath('./activity:object', activity: ACTIVITY_NS).xpath('./xmlns:link[@rel="mentioned"]')) if status.reblog?
 
+      if status.reblog?
+        ProcessHashtagsService.new.call(status.reblog, entry.at_xpath('./activity:object', activity: ACTIVITY_NS).xpath('./xmlns:category').map { |category| category['term'] })
+      else
+        ProcessHashtagsService.new.call(status, entry.xpath('./xmlns:category').map { |category| category['term'] })
+      end
+
       process_attachments(entry, status)
       process_attachments(entry.xpath('./activity:object', activity: ACTIVITY_NS), status.reblog) if status.reblog?
 
diff --git a/app/services/process_hashtags_service.rb b/app/services/process_hashtags_service.rb
new file mode 100644
index 000000000..8c68ce989
--- /dev/null
+++ b/app/services/process_hashtags_service.rb
@@ -0,0 +1,11 @@
+class ProcessHashtagsService < BaseService
+  def call(status, tags = [])
+    if status.local?
+      tags = status.text.scan(Tag::HASHTAG_RE).map(&:first)
+    end
+
+    tags.map(&:downcase).each do |tag|
+      status.tags << Tag.where(name: tag).first_or_initialize(name: tag)
+    end
+  end
+end