Show what people vote on inline

This commit is contained in:
Anders Rune Jensen
2017-04-15 21:29:04 +02:00
parent dd5c82b06c
commit 2ee923fecc
+29 -12
View File
@@ -128,6 +128,7 @@ exports.init = function (sbot, config) {
pull.values(logs), pull.values(logs),
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8), paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(feedId)), pull(renderThread(opts), wrapPage(feedId)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
@@ -182,7 +183,7 @@ exports.init = function (sbot, config) {
pull.filter((msg) => { pull.filter((msg) => {
return !msg.value || msg.value.author in following return !msg.value || msg.value.author in following
}), }),
pull.filter((msg) => { pull.filter((msg) => { // channel subscription
return !msg.value.content.subscribed return !msg.value.content.subscribed
}), }),
pull.collect(function (err, logs) { pull.collect(function (err, logs) {
@@ -194,6 +195,7 @@ exports.init = function (sbot, config) {
pull.values(logs), pull.values(logs),
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addFollowAbout, 8), paramap(addFollowAbout, 8),
paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(feedId)), pull(renderThread(opts), wrapPage(feedId)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
@@ -223,13 +225,10 @@ exports.init = function (sbot, config) {
} }
pull( pull(
sbot.createLogStream({ reverse: true, limit: 10000 }), sbot.createLogStream({ reverse: true, limit: 2000 }),
pull.filter((msg) => { pull.filter((msg) => {
return !msg.value || msg.value.content.channel == channelId return !msg.value || msg.value.content.channel == channelId
}), }),
pull.filter((msg) => {
return !msg.value.content.subscribed
}),
pull.collect(function (err, logs) { pull.collect(function (err, logs) {
if (err) return respond(res, 500, err.stack || err) if (err) return respond(res, 500, err.stack || err)
res.writeHead(200, { res.writeHead(200, {
@@ -238,6 +237,7 @@ exports.init = function (sbot, config) {
pull( pull(
pull.values(logs), pull.values(logs),
paramap(addAuthorAbout, 8), paramap(addAuthorAbout, 8),
paramap(addVoteMessage, 8),
pull(renderThread(opts), wrapPage(channelId)), pull(renderThread(opts), wrapPage(channelId)),
toPull(res, function (err) { toPull(res, function (err) {
if (err) console.error('[viewer]', err) if (err) console.error('[viewer]', err)
@@ -257,7 +257,18 @@ exports.init = function (sbot, config) {
else else
cb(null, msg) cb(null, msg)
} }
function addVoteMessage(msg, cb) {
if (msg.value.content.type == 'vote')
getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
if (err) return cb(err)
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)
@@ -552,13 +563,19 @@ function render(opts, c)
{ {
if (c.type === 'post') if (c.type === 'post')
return renderPost(opts, c) return renderPost(opts, c)
else if (c.type == 'vote' && c.vote.expression == 'Dig') else if (c.type == 'vote' && c.vote.expression == 'Dig') {
{ var channel = c.channel ? ' in #' + c.channel : ''
var channel = c.channel ? ' in #' + c.channel : '' var linkedText = 'this'
return ' dug ' + '<a href="/' + c.vote.link + '">this</a>' + channel if (typeof c.vote.linkedText != 'undefined')
linkedText = c.vote.linkedText.substring(0, 100)
return ' dug ' + '<a href="/' + c.vote.link + '">' + linkedText + '</a>' + channel
}
else if (c.type == 'vote') {
var linkedText = 'this'
if (typeof c.vote.linkedText != 'undefined')
linkedText = c.vote.linkedText.substring(0, 100)
return ' voted <a href="/' + c.vote.link + '">' + linkedText + '</a>'
} }
else if (c.type == 'vote')
return ' voted <a href="/' + c.vote.link + '">this</a>'
else if (c.type == 'contact' && c.following) else if (c.type == 'contact' && c.following)
return ' followed <a href="/user/' + c.contact + '">' + c.contactAbout.name + "</a>" return ' followed <a href="/user/' + c.contact + '">' + c.contactAbout.name + "</a>"
else if (typeof c == 'string') else if (typeof c == 'string')