Adding hashtags
This commit is contained in:
@ -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
|
||||
|
11
app/channels/hashtag_channel.rb
Normal file
11
app/channels/hashtag_channel.rb
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user