From c8252759df98f41860b0580b029d9efa374c7125 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 6 Feb 2017 23:46:14 +0100 Subject: [PATCH] Add streaming API channels for local-only statuses --- .../components/components/lightbox.jsx | 2 +- app/services/fan_out_on_write_service.rb | 12 ++++++++++-- streaming/index.js | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/components/components/lightbox.jsx b/app/assets/javascripts/components/components/lightbox.jsx index 65ff708b4..f04ca47ba 100644 --- a/app/assets/javascripts/components/components/lightbox.jsx +++ b/app/assets/javascripts/components/components/lightbox.jsx @@ -66,7 +66,7 @@ const Lightbox = React.createClass({ return ( {({ backgroundOpacity, opacity, y }) => -
+
{children} diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 13aad4632..71f6cbca1 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -34,13 +34,21 @@ class FanOutOnWriteService < BaseService def deliver_to_hashtags(status) Rails.logger.debug "Delivering status #{status.id} to hashtags" + + payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status) + status.tags.find_each do |tag| - FeedManager.instance.broadcast("hashtag:#{tag.name}", event: 'update', payload: FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status)) + FeedManager.instance.broadcast("hashtag:#{tag.name}", event: 'update', payload: payload) + FeedManager.instance.broadcast("hashtag:#{tag.name}:local", event: 'update', payload: payload) if status.account.local? end end def deliver_to_public(status) Rails.logger.debug "Delivering status #{status.id} to public timeline" - FeedManager.instance.broadcast(:public, event: 'update', payload: FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status)) + + payload = FeedManager.instance.inline_render(nil, 'api/v1/statuses/show', status) + + FeedManager.instance.broadcast(:public, event: 'update', payload: payload) + FeedManager.instance.broadcast('public:local', event: 'update', payload: payload) if status.account.local? end end diff --git a/streaming/index.js b/streaming/index.js index 49686b859..e2e8f943e 100644 --- a/streaming/index.js +++ b/streaming/index.js @@ -212,11 +212,21 @@ app.get('/api/v1/streaming/public', (req, res) => { streamFrom(redisClient, 'timeline:public', req, streamToHttp(req, res, redisClient), true) }) +app.get('/api/v1/streaming/public/local', (req, res) => { + const redisClient = getRedisClient() + streamFrom(redisClient, 'timeline:public:local', req, streamToHttp(req, res, redisClient), true) +}) + app.get('/api/v1/streaming/hashtag', (req, res) => { const redisClient = getRedisClient() streamFrom(redisClient, `timeline:hashtag:${req.params.tag}`, req, streamToHttp(req, res, redisClient), true) }) +app.get('/api/v1/streaming/hashtag/local', (req, res) => { + const redisClient = getRedisClient() + streamFrom(redisClient, `timeline:hashtag:${req.params.tag}:local`, req, streamToHttp(req, res, redisClient), true) +}) + wss.on('connection', ws => { const location = url.parse(ws.upgradeReq.url, true) const token = location.query.access_token @@ -238,9 +248,15 @@ wss.on('connection', ws => { case 'public': streamFrom(redisClient, 'timeline:public', req, streamToWs(req, ws, redisClient), true) break; + case 'public:local': + streamFrom(redisClient, 'timeline:public:local', req, streamToWs(req, ws, redisClient), true) + break; case 'hashtag': streamFrom(redisClient, `timeline:hashtag:${location.query.tag}`, req, streamToWs(req, ws, redisClient), true) break; + case 'hashtag:local': + streamFrom(redisClient, `timeline:hashtag:${location.query.tag}:local`, req, streamToWs(req, ws, redisClient), true) + break; default: ws.close() }