Merge: add thread links to posts that have a root

And don't render them when rendering the thread
This commit is contained in:
Ev Bogue
2017-06-25 22:18:50 +02:00
committed by Anders Rune Jensen
parent 336a39d74f
commit b2c03954f0
2 changed files with 17 additions and 12 deletions
+1 -1
View File
@@ -210,7 +210,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(defaultOpts, pull(renderThread(defaultOpts, '',
renderShowAll(showAll, req.url)), renderShowAll(showAll, req.url)),
wrapPage('#' + channelId)), wrapPage('#' + channelId)),
toPull(res, function (err) { toPull(res, function (err) {
+16 -11
View File
@@ -75,7 +75,7 @@ function escape(str) {
function formatMsgs(id, ext, opts) { function formatMsgs(id, ext, opts) {
switch (ext || "html") { switch (ext || "html") {
case "html": case "html":
return pull(renderThread(opts), wrapPage(id)); return pull(renderThread(opts, id, ''), wrapPage(id));
case "js": case "js":
return pull(renderThread(opts), wrapJSEmbed(opts)); return pull(renderThread(opts), wrapJSEmbed(opts));
case "json": case "json":
@@ -110,7 +110,7 @@ function renderAbout(opts, about, showAllHTML = "") {
(about.description != undefined ? (about.description != undefined ?
marked(about.description, opts.marked) : ''); marked(about.description, opts.marked) : '');
return pull( return pull(
pull.map(renderMsg.bind(this, opts)), pull.map(renderMsg.bind(this, opts, '')),
wrap(toolTipTop() + '<main>' + wrap(toolTipTop() + '<main>' +
h('article', h('article',
h('header', h('header',
@@ -126,9 +126,9 @@ function renderAbout(opts, about, showAllHTML = "") {
); );
} }
function renderThread(opts, showAllHTML = "") { function renderThread(opts, id, showAllHTML = "") {
return pull( return pull(
pull.map(renderMsg.bind(this, opts)), pull.map(renderMsg.bind(this, opts, id)),
wrap(toolTipTop() + '<main>', wrap(toolTipTop() + '<main>',
showAllHTML + '</main>' + callToAction()) showAllHTML + '</main>' + callToAction())
); );
@@ -311,7 +311,7 @@ function docWrite(str) {
return "document.write(" + JSON.stringify(str) + ")\n"; return "document.write(" + JSON.stringify(str) + ")\n";
} }
function renderMsg(opts, msg) { function renderMsg(opts, id, msg) {
var c = msg.value.content || {}; var c = msg.value.content || {};
var name = encodeURIComponent(msg.key); var name = encodeURIComponent(msg.key);
return h('article#' + name, return h('article#' + name,
@@ -325,7 +325,7 @@ function renderMsg(opts, msg) {
{ href: opts.base + escape(msg.value.author) }, { href: opts.base + escape(msg.value.author) },
msg.author.name), msg.author.name),
msgTimestamp(msg, opts.base + name)))), msgTimestamp(msg, opts.base + name)))),
render(opts, c)).outerHTML; render(opts, id, c)).outerHTML;
} }
function msgTimestamp(msg, link) { function msgTimestamp(msg, link) {
@@ -343,7 +343,7 @@ function formatDate(date) {
return htime(date); return htime(date);
} }
function render(opts, c) { function render(opts, id, c) {
var base = opts.base; var base = opts.base;
if (c.type === "post") { if (c.type === "post") {
var channel = c.channel var channel = c.channel
@@ -352,7 +352,7 @@ function render(opts, c) {
{ href: base + 'channel/' + c.channel }, { href: base + 'channel/' + c.channel },
'#' + c.channel)) '#' + c.channel))
: ""; : "";
return [channel, renderPost(opts, c)]; return [channel, renderPost(opts, id, c)];
} else if (c.type == "vote" && c.vote.expression == "Dig") { } else if (c.type == "vote" && c.vote.expression == "Dig") {
var channel = c.channel var channel = c.channel
? [' in ', ? [' in ',
@@ -399,7 +399,7 @@ function render(opts, c) {
return [h('span.status', return [h('span.status',
"Created a git issue" + "Created a git issue" +
(c.repoName != undefined ? " in repo " + c.repoName : ""), (c.repoName != undefined ? " in repo " + c.repoName : ""),
renderPost(opts, c))]; renderPost(opts, id, c))];
} }
else if (c.type == "git-repo") { else if (c.type == "git-repo") {
return h('span.status', return h('span.status',
@@ -435,7 +435,7 @@ function render(opts, c) {
else return renderDefault(c); else return renderDefault(c);
} }
function renderPost(opts, c) { function renderPost(opts, id, c) {
opts.mentions = {}; opts.mentions = {};
if (Array.isArray(c.mentions)) { if (Array.isArray(c.mentions)) {
c.mentions.forEach(function (link) { c.mentions.forEach(function (link) {
@@ -444,7 +444,12 @@ function renderPost(opts, c) {
}); });
} }
var s = h('section'); var s = h('section');
s.innerHTML = marked(String(c.text), opts.marked); var content = '';
if (c.root && c.root != id)
content += 'Re: ' + h('a',
{ href: '/' + encodeURIComponent(c.root) },
c.root.substring(0, 10)).outerHTML + '<br>';
s.innerHTML = content + marked(String(c.text), opts.marked);
return s; return s;
} }