From 08321fdd28495d2cb08d4f7256ed2f6aab925315 Mon Sep 17 00:00:00 2001 From: Dominic Tarr Date: Sun, 15 Apr 2018 13:15:08 -0700 Subject: [PATCH 1/2] respect privacy better. hides who is in a private thread, does not show private messages in user feed, also does not show like/vote as thread replies --- index.js | 236 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 126 insertions(+), 110 deletions(-) diff --git a/index.js b/index.js index f401363..4621aae 100644 --- a/index.js +++ b/index.js @@ -120,6 +120,9 @@ exports.init = function (sbot, config) { pull( sbot.createUserStream({ id: feedId, reverse: true, limit: showAll ? -1 : (ext == 'rss' ? 25 : 10) }), + pull.filter(function (data) { + return 'object' === typeof data.value.content + }), pull.collect(function (err, logs) { if (err) return respond(res, 500, err.stack || err) res.writeHead(200, { @@ -150,34 +153,34 @@ exports.init = function (sbot, config) { getAbout(feedId, function (err, about) { pull( - sbot.createUserStream({ id: feedId }), - pull.filter((msg) => { - 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.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 channelSubscriptions[msg.value.content.channel] - } - }) - - serveFeeds(req, res, following, channelSubscriptions, feedId, + sbot.createUserStream({ id: feedId }), + pull.filter((msg) => { + 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.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 channelSubscriptions[msg.value.content.channel] + } + }) + + serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : "")) - }) + }) ) }) } @@ -192,27 +195,27 @@ exports.init = function (sbot, config) { pull( sbot.createLogStream({ reverse: true, limit: 5000 }), pull.filter((msg) => { - return !msg.value || - (msg.value.author in following || - msg.value.content.channel in channelSubscriptions) + return !msg.value || + (msg.value.author in following || + msg.value.content.channel in channelSubscriptions) }), pull.take(150), pull.collect(function (err, logs) { - if (err) return respond(res, 500, err.stack || err) - res.writeHead(200, { - 'Content-Type': ctype("html") - }) - pull( - pull.values(logs), - paramap(addAuthorAbout, 8), - paramap(addFollowAbout, 8), - paramap(addVoteMessage, 8), - paramap(addGitLinks, 8), - pull(renderThread(feedOpts), wrapPage(name)), - toPull(res, function (err) { - if (err) console.error('[viewer]', err) - }) - ) + if (err) return respond(res, 500, err.stack || err) + res.writeHead(200, { + 'Content-Type': ctype("html") + }) + pull( + pull.values(logs), + paramap(addAuthorAbout, 8), + paramap(addFollowAbout, 8), + paramap(addVoteMessage, 8), + paramap(addGitLinks, 8), + pull(renderThread(feedOpts), wrapPage(name)), + toPull(res, function (err) { + if (err) console.error('[viewer]', err) + }) + ) }) ) } @@ -226,21 +229,21 @@ exports.init = function (sbot, config) { pull( sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}), pull.collect(function (err, logs) { - if (err) return respond(res, 500, err.stack || err) - res.writeHead(200, { - 'Content-Type': ctype("html") - }) - pull( - pull.values(logs), - paramap(addAuthorAbout, 8), - paramap(addVoteMessage, 8), - pull(renderThread(defaultOpts, '', - renderShowAll(showAll, req.url)), - wrapPage('#' + channelId)), - toPull(res, function (err) { - if (err) console.error('[viewer]', err) - }) - ) + if (err) return respond(res, 500, err.stack || err) + res.writeHead(200, { + 'Content-Type': ctype("html") + }) + pull( + pull.values(logs), + paramap(addAuthorAbout, 8), + paramap(addVoteMessage, 8), + pull(renderThread(defaultOpts, '', + renderShowAll(showAll, req.url)), + wrapPage('#' + channelId)), + toPull(res, function (err) { + if (err) console.error('[viewer]', err) + }) + ) }) ) } @@ -279,36 +282,45 @@ exports.init = function (sbot, config) { var format = formatMsgs(id, ext, opts) if (format === null) return respond(res, 415, 'Invalid format') - pull( - sbot.links({dest: id, values: true }), - includeRoot && prepend(getMsg, id), - pull.unique('key'), - pull.collect(function (err, links) { - if (err) return respond(res, 500, err.stack || err) - var etag = hash(sort.heads(links).concat(appHash, ext, qs)) - if (req.headers['if-none-match'] === etag) return respond(res, 304) - res.writeHead(200, { - 'Content-Type': ctype(ext), - 'etag': etag - }) - pull( - pull.values(sort(links)), - paramap(addAuthorAbout, 8), - format, - toPull(res, function (err) { - if (err) console.error('[viewer]', err) - }) - ) + function render (links) { + var etag = hash(sort.heads(links).concat(appHash, ext, qs)) + if (req.headers['if-none-match'] === etag) return respond(res, 304) + res.writeHead(200, { + 'Content-Type': ctype(ext), + 'etag': etag }) - ) + pull( + pull.values(sort(links)), + paramap(addAuthorAbout, 8), + format, + toPull(res, function (err) { + if (err) console.error('[viewer]', err) + }) + ) + } + + getMsgWithValue(sbot, id, function (err, root) { + if (err) return respond(res, 500, err.stack || err) + if('string' === typeof root.value.content) + return render([root]) + + pull( + sbot.links({dest: id, values: true, rel: 'root' }), + pull.unique('key'), + pull.collect(function (err, links) { + if (err) return respond(res, 500, err.stack || err) + render(links) + }) + ) + }) } function addFollowAbout(msg, cb) { if (msg.value.content.contact) getAbout(msg.value.content.contact, function (err, about) { - if (err) return cb(err) - msg.value.content.contactAbout = about - cb(null, msg) + if (err) return cb(err) + msg.value.content.contactAbout = about + cb(null, msg) }) else cb(null, msg) @@ -317,9 +329,9 @@ exports.init = function (sbot, config) { function addVoteMessage(msg, cb) { if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%') getMsg(msg.value.content.vote.link, function (err, linkedMsg) { - if (linkedMsg) - msg.value.content.vote.linkedText = linkedMsg.value.content.text - cb(null, msg) + if (linkedMsg) + msg.value.content.vote.linkedText = linkedMsg.value.content.text + cb(null, msg) }) else cb(null, msg) @@ -336,15 +348,15 @@ exports.init = function (sbot, config) { function addGitLinks(msg, cb) { if (msg.value.content.type == 'git-update') getMsg(msg.value.content.repo, function (err, gitRepo) { - if (gitRepo) - msg.value.content.repoName = gitRepo.value.content.name - cb(null, msg) + if (gitRepo) + msg.value.content.repoName = gitRepo.value.content.name + cb(null, msg) }) else if (msg.value.content.type == 'issue') getMsg(msg.value.content.project, function (err, gitRepo) { - if (gitRepo) - msg.value.content.repoName = gitRepo.value.content.name - cb(null, msg) + if (gitRepo) + msg.value.content.repoName = gitRepo.value.content.name + cb(null, msg) }) else cb(null, msg) @@ -432,20 +444,24 @@ function serveFile(req, res, file) { }) } -function prepend(fn, arg) { - return function (read) { - return function (abort, cb) { - if (fn && !abort) { - var _fn = fn - fn = null - return _fn(arg, function (err, value) { - if (err) return read(err, function (err) { - cb(err || true) - }) - cb(null, value) - }) - } - read(abort, cb) - } - } -} +//function prepend(fn, arg) { +// return function (read) { +// return function (abort, cb) { +// if (fn && !abort) { +// var _fn = fn +// fn = null +// return _fn(arg, function (err, value) { +// if (err) return read(err, function (err) { +// cb(err || true) +// }) +// cb(null, value) +// }) +// } +// read(abort, cb) +// } +// } +//} + + + + From 728dd36ef62070f884bb5a7854652d466aaf5fe2 Mon Sep 17 00:00:00 2001 From: cel Date: Sun, 15 Apr 2018 20:30:04 -1000 Subject: [PATCH 2/2] whitespace --- index.js | 182 +++++++++++++++++++++++++++---------------------------- 1 file changed, 89 insertions(+), 93 deletions(-) diff --git a/index.js b/index.js index 4621aae..9df23d5 100644 --- a/index.js +++ b/index.js @@ -153,34 +153,34 @@ exports.init = function (sbot, config) { getAbout(feedId, function (err, about) { pull( - sbot.createUserStream({ id: feedId }), - pull.filter((msg) => { - 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.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 channelSubscriptions[msg.value.content.channel] - } - }) - - serveFeeds(req, res, following, channelSubscriptions, feedId, + sbot.createUserStream({ id: feedId }), + pull.filter((msg) => { + 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.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 channelSubscriptions[msg.value.content.channel] + } + }) + + serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : "")) - }) + }) ) }) } @@ -195,27 +195,27 @@ exports.init = function (sbot, config) { pull( sbot.createLogStream({ reverse: true, limit: 5000 }), pull.filter((msg) => { - return !msg.value || - (msg.value.author in following || - msg.value.content.channel in channelSubscriptions) + return !msg.value || + (msg.value.author in following || + msg.value.content.channel in channelSubscriptions) }), pull.take(150), pull.collect(function (err, logs) { - if (err) return respond(res, 500, err.stack || err) - res.writeHead(200, { - 'Content-Type': ctype("html") - }) - pull( - pull.values(logs), - paramap(addAuthorAbout, 8), - paramap(addFollowAbout, 8), - paramap(addVoteMessage, 8), - paramap(addGitLinks, 8), - pull(renderThread(feedOpts), wrapPage(name)), - toPull(res, function (err) { - if (err) console.error('[viewer]', err) - }) - ) + if (err) return respond(res, 500, err.stack || err) + res.writeHead(200, { + 'Content-Type': ctype("html") + }) + pull( + pull.values(logs), + paramap(addAuthorAbout, 8), + paramap(addFollowAbout, 8), + paramap(addVoteMessage, 8), + paramap(addGitLinks, 8), + pull(renderThread(feedOpts), wrapPage(name)), + toPull(res, function (err) { + if (err) console.error('[viewer]', err) + }) + ) }) ) } @@ -229,21 +229,21 @@ exports.init = function (sbot, config) { pull( sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}), pull.collect(function (err, logs) { - if (err) return respond(res, 500, err.stack || err) - res.writeHead(200, { - 'Content-Type': ctype("html") - }) - pull( - pull.values(logs), - paramap(addAuthorAbout, 8), - paramap(addVoteMessage, 8), - pull(renderThread(defaultOpts, '', - renderShowAll(showAll, req.url)), - wrapPage('#' + channelId)), - toPull(res, function (err) { - if (err) console.error('[viewer]', err) - }) - ) + if (err) return respond(res, 500, err.stack || err) + res.writeHead(200, { + 'Content-Type': ctype("html") + }) + pull( + pull.values(logs), + paramap(addAuthorAbout, 8), + paramap(addVoteMessage, 8), + pull(renderThread(defaultOpts, '', + renderShowAll(showAll, req.url)), + wrapPage('#' + channelId)), + toPull(res, function (err) { + if (err) console.error('[viewer]', err) + }) + ) }) ) } @@ -318,9 +318,9 @@ exports.init = function (sbot, config) { function addFollowAbout(msg, cb) { if (msg.value.content.contact) getAbout(msg.value.content.contact, function (err, about) { - if (err) return cb(err) - msg.value.content.contactAbout = about - cb(null, msg) + if (err) return cb(err) + msg.value.content.contactAbout = about + cb(null, msg) }) else cb(null, msg) @@ -329,9 +329,9 @@ exports.init = function (sbot, config) { function addVoteMessage(msg, cb) { if (msg.value.content.type == 'vote' && msg.value.content.vote.link[0] == '%') getMsg(msg.value.content.vote.link, function (err, linkedMsg) { - if (linkedMsg) - msg.value.content.vote.linkedText = linkedMsg.value.content.text - cb(null, msg) + if (linkedMsg) + msg.value.content.vote.linkedText = linkedMsg.value.content.text + cb(null, msg) }) else cb(null, msg) @@ -348,15 +348,15 @@ exports.init = function (sbot, config) { function addGitLinks(msg, cb) { if (msg.value.content.type == 'git-update') getMsg(msg.value.content.repo, function (err, gitRepo) { - if (gitRepo) - msg.value.content.repoName = gitRepo.value.content.name - cb(null, msg) + if (gitRepo) + msg.value.content.repoName = gitRepo.value.content.name + cb(null, msg) }) else if (msg.value.content.type == 'issue') getMsg(msg.value.content.project, function (err, gitRepo) { - if (gitRepo) - msg.value.content.repoName = gitRepo.value.content.name - cb(null, msg) + if (gitRepo) + msg.value.content.repoName = gitRepo.value.content.name + cb(null, msg) }) else cb(null, msg) @@ -444,24 +444,20 @@ function serveFile(req, res, file) { }) } -//function prepend(fn, arg) { -// return function (read) { -// return function (abort, cb) { -// if (fn && !abort) { -// var _fn = fn -// fn = null -// return _fn(arg, function (err, value) { -// if (err) return read(err, function (err) { -// cb(err || true) -// }) -// cb(null, value) -// }) -// } -// read(abort, cb) -// } -// } -//} - - - - +function prepend(fn, arg) { + return function (read) { + return function (abort, cb) { + if (fn && !abort) { + var _fn = fn + fn = null + return _fn(arg, function (err, value) { + if (err) return read(err, function (err) { + cb(err || true) + }) + cb(null, value) + }) + } + read(abort, cb) + } + } +}