about summary refs log tree commit diff
path: root/app/channels
diff options
context:
space:
mode:
Diffstat (limited to 'app/channels')
-rw-r--r--app/channels/application_cable/channel.rb13
-rw-r--r--app/channels/hashtag_channel.rb11
-rw-r--r--app/channels/public_channel.rb14
-rw-r--r--app/channels/timeline_channel.rb4
4 files changed, 26 insertions, 16 deletions
diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb
index d67269728..d27b058fb 100644
--- a/app/channels/application_cable/channel.rb
+++ b/app/channels/application_cable/channel.rb
@@ -1,4 +1,17 @@
 module ApplicationCable
   class Channel < ActionCable::Channel::Base
+    protected
+
+    def hydrate_status(encoded_message)
+      message = ActiveSupport::JSON.decode(encoded_message)
+      status  = Status.find_by(id: message['id'])
+      message['message'] = FeedManager.instance.inline_render(current_user.account, status)
+
+      [status, message]
+    end
+
+    def filter?(status)
+      status.nil? || current_user.account.blocking?(status.account) || (status.reblog? && current_user.account.blocking?(status.reblog.account))
+    end
   end
 end
diff --git a/app/channels/hashtag_channel.rb b/app/channels/hashtag_channel.rb
new file mode 100644
index 000000000..5be8d94cd
--- /dev/null
+++ b/app/channels/hashtag_channel.rb
@@ -0,0 +1,11 @@
+class HashtagChannel < ApplicationCable::Channel
+  def subscribed
+    tag = params[:tag].downcase
+
+    stream_from "timeline:hashtag:#{tag}", lambda { |encoded_message|
+      status, message = hydrate_status(encoded_message)
+      next if filter?(status)
+      transmit message
+    }
+  end
+end
diff --git a/app/channels/public_channel.rb b/app/channels/public_channel.rb
index 708eff055..41e21611d 100644
--- a/app/channels/public_channel.rb
+++ b/app/channels/public_channel.rb
@@ -1,19 +1,9 @@
-# Be sure to restart your server when you modify this file. Action Cable runs in a loop that does not support auto reloading.
 class PublicChannel < ApplicationCable::Channel
   def subscribed
     stream_from 'timeline:public', lambda { |encoded_message|
-      message = ActiveSupport::JSON.decode(encoded_message)
-
-      status = Status.find_by(id: message['id'])
-      next if status.nil? || current_user.account.blocking?(status.account) || (status.reblog? && current_user.account.blocking?(status.reblog.account))
-
-      message['message'] = FeedManager.instance.inline_render(current_user.account, status)
-
+      status, message = hydrate_status(encoded_message)
+      next if filter?(status)
       transmit message
     }
   end
-
-  def unsubscribed
-    # Any cleanup needed when channel is unsubscribed
-  end
 end
diff --git a/app/channels/timeline_channel.rb b/app/channels/timeline_channel.rb
index 9e5a81188..f2a9636fd 100644
--- a/app/channels/timeline_channel.rb
+++ b/app/channels/timeline_channel.rb
@@ -2,8 +2,4 @@ class TimelineChannel < ApplicationCable::Channel
   def subscribed
     stream_from "timeline:#{current_user.account_id}"
   end
-
-  def unsubscribed
-    # Any cleanup needed when channel is unsubscribed
-  end
 end