More refactor

This commit is contained in:
Anders Rune Jensen
2017-05-11 21:49:44 +02:00
parent 4f7d162bf1
commit 1b057d84aa
+25 -31
View File
@@ -92,8 +92,6 @@ exports.init = function (sbot, config) {
function serveFeed(req, res, feedId) { function serveFeed(req, res, feedId) {
console.log("serving feed: " + feedId) console.log("serving feed: " + feedId)
var opts = defaultOpts
getAbout(feedId, function (err, about) { getAbout(feedId, function (err, about) {
if (err) return cb(err) if (err) return cb(err)
@@ -109,7 +107,7 @@ exports.init = function (sbot, config) {
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8), paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8), paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(about.name)), pull(renderThread(defaultOpts), wrapPage(about.name)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
}) })
@@ -160,8 +158,6 @@ exports.init = function (sbot, config) {
} }
function serveFeeds(req, res, following, channelSubscriptions, feedId, name) { function serveFeeds(req, res, following, channelSubscriptions, feedId, name) {
var opts = defaultOpts
pull( pull(
sbot.createLogStream({ reverse: true, limit: 2500 }), sbot.createLogStream({ reverse: true, limit: 2500 }),
pull.filter((msg) => { pull.filter((msg) => {
@@ -180,7 +176,7 @@ exports.init = function (sbot, config) {
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8), paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8), paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(name)), pull(renderThread(defaultOpts), wrapPage(name)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
}) })
@@ -192,8 +188,6 @@ exports.init = function (sbot, config) {
function serveChannel(req, res, url) { function serveChannel(req, res, url) {
var channelId = url.substring(url.lastIndexOf('channel/')+8, 100) var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
console.log("serving channel: " + channelId) console.log("serving channel: " + channelId)
var opts = defaultOpts
pull( pull(
sbot.query.read({ limit: 500, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}), sbot.query.read({ limit: 500, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
@@ -206,7 +200,7 @@ exports.init = function (sbot, config) {
pull.values(logs), pull.values(logs),
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addVoteMessage, 8), paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage('#' + channelId)), pull(renderThread(defaultOpts), wrapPage('#' + channelId)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
}) })
@@ -215,28 +209,6 @@ 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)
})
else
cb(null, msg)
}
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)
})
else
cb(null, msg)
}
function serveId(req, res, id, ext, query) { function serveId(req, res, id, ext, query) {
var q = query ? qs.parse(query) : {} var q = query ? qs.parse(query) : {}
var includeRoot = !('noroot' in q) var includeRoot = !('noroot' in q)
@@ -295,6 +267,28 @@ 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)
})
else
cb(null, msg)
}
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)
})
else
cb(null, msg)
}
function addAuthorAbout(msg, cb) { function addAuthorAbout(msg, cb) {
getAbout(msg.value.author, function (err, about) { getAbout(msg.value.author, function (err, about) {
if (err) return cb(err) if (err) return cb(err)