From b422fc1e8e938b340e5961d30a2d16edb54dd647 Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Sat, 15 Apr 2017 21:48:09 +0200 Subject: [PATCH] show channel when rendering post, show all followed channels in user-feed --- index.js | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 31bfa2c..ebdd2d7 100644 --- a/index.js +++ b/index.js @@ -143,26 +143,40 @@ exports.init = function (sbot, config) { console.log("serving user feed: " + feedId) var following = [] + var channelSubscriptions = [] pull( sbot.createUserStream({ id: feedId }), pull.filter((msg) => { - return !msg.value || msg.value.content.type == 'contact' + return !msg.value || + msg.value.content.type == 'contact' || + (msg.value.content.type == 'channel' && + typeof msg.value.content.subscribed != 'undefined') }), pull.collect(function (err, msgs) { msgs.forEach((msg) => { - if (msg.value.content.following) - following[msg.value.content.contact] = 1 - else - delete following[msg.value.content.contact] + if (msg.value.content.type == 'contact') + { + if (msg.value.content.following) + following[msg.value.content.contact] = 1 + else + delete following[msg.value.content.contact] + } + else // channel subscription + { + if (msg.value.content.subscribed) + channelSubscriptions[msg.value.content.channel] = 1 + else + delete following[msg.value.content.channel] + } }) - serveFeeds(req, res, following, feedId) + serveFeeds(req, res, following, channelSubscriptions, feedId) }) ) } - function serveFeeds(req, res, following, feedId) { + function serveFeeds(req, res, following, channelSubscriptions, feedId) { var opts = defaultOpts opts.marked = { @@ -181,7 +195,9 @@ exports.init = function (sbot, config) { pull( sbot.createLogStream({ reverse: true, limit: 1000 }), pull.filter((msg) => { - return !msg.value || msg.value.author in following + return !msg.value || + (msg.value.author in following || + msg.value.content.channel in channelSubscriptions) }), pull.filter((msg) => { // channel subscription return !msg.value.content.subscribed @@ -229,6 +245,9 @@ exports.init = function (sbot, config) { pull.filter((msg) => { return !msg.value || msg.value.content.channel == channelId }), + pull.filter((msg) => { // channel subscription + return !msg.value.content.subscribed + }), pull.collect(function (err, logs) { if (err) return respond(res, 500, err.stack || err) res.writeHead(200, { @@ -561,9 +580,10 @@ function formatDate(date) { function render(opts, c) { - if (c.type === 'post') - return renderPost(opts, c) - else if (c.type == 'vote' && c.vote.expression == 'Dig') { + if (c.type === 'post') { + var channel = c.channel ? ' in #' + c.channel : '' + return channel + renderPost(opts, c) + } else if (c.type == 'vote' && c.vote.expression == 'Dig') { var channel = c.channel ? ' in #' + c.channel : '' var linkedText = 'this' if (typeof c.vote.linkedText != 'undefined')