git ssb

9+

cel / ssb-viewer



Commit b2c03954f07ab2baee3e4a7390bb6bcffe2c6df3

Merge: add thread links to posts that have a root

And don't render them when rendering the thread
Ev Bogue authored on 6/24/2017, 8:44:46 PM
Anders Rune Jensen committed on 6/25/2017, 8:18:50 PM
Parent: 336a39d74fbef28c1b1f707863fb872bcc447a6c

Files changed

index.jschanged
render.jschanged
index.jsView
@@ -209,9 +209,9 @@
209209 pull(
210210 pull.values(logs),
211211 paramap(addAuthorAbout, 8),
212212 paramap(addVoteMessage, 8),
213- pull(renderThread(defaultOpts,
213 + pull(renderThread(defaultOpts, '',
214214 renderShowAll(showAll, req.url)),
215215 wrapPage('#' + channelId)),
216216 toPull(res, function (err) {
217217 if (err) console.error('[viewer]', err)
render.jsView
@@ -74,9 +74,9 @@
7474
7575 function formatMsgs(id, ext, opts) {
7676 switch (ext || "html") {
7777 case "html":
78- return pull(renderThread(opts), wrapPage(id));
78 + return pull(renderThread(opts, id, ''), wrapPage(id));
7979 case "js":
8080 return pull(renderThread(opts), wrapJSEmbed(opts));
8181 case "json":
8282 return wrapJSON();
@@ -109,9 +109,9 @@
109109 figCaption.innerHTML = 'Feed of ' + about.name + '<br>' +
110110 (about.description != undefined ?
111111 marked(about.description, opts.marked) : '');
112112 return pull(
113- pull.map(renderMsg.bind(this, opts)),
113 + pull.map(renderMsg.bind(this, opts, '')),
114114 wrap(toolTipTop() + '<main>' +
115115 h('article',
116116 h('header',
117117 h('figure',
@@ -125,11 +125,11 @@
125125 showAllHTML + '</main>' + callToAction())
126126 );
127127 }
128128
129-function renderThread(opts, showAllHTML = "") {
129 +function renderThread(opts, id, showAllHTML = "") {
130130 return pull(
131- pull.map(renderMsg.bind(this, opts)),
131 + pull.map(renderMsg.bind(this, opts, id)),
132132 wrap(toolTipTop() + '<main>',
133133 showAllHTML + '</main>' + callToAction())
134134 );
135135 }
@@ -310,9 +310,9 @@
310310 function docWrite(str) {
311311 return "document.write(" + JSON.stringify(str) + ")\n";
312312 }
313313
314-function renderMsg(opts, msg) {
314 +function renderMsg(opts, id, msg) {
315315 var c = msg.value.content || {};
316316 var name = encodeURIComponent(msg.key);
317317 return h('article#' + name,
318318 h('header',
@@ -324,9 +324,9 @@
324324 h('a.ssb-avatar-name',
325325 { href: opts.base + escape(msg.value.author) },
326326 msg.author.name),
327327 msgTimestamp(msg, opts.base + name)))),
328- render(opts, c)).outerHTML;
328 + render(opts, id, c)).outerHTML;
329329 }
330330
331331 function msgTimestamp(msg, link) {
332332 var date = new Date(msg.value.timestamp);
@@ -342,18 +342,18 @@
342342 function formatDate(date) {
343343 return htime(date);
344344 }
345345
346-function render(opts, c) {
346 +function render(opts, id, c) {
347347 var base = opts.base;
348348 if (c.type === "post") {
349349 var channel = c.channel
350350 ? h('div.top-right',
351351 h('a',
352352 { href: base + 'channel/' + c.channel },
353353 '#' + c.channel))
354354 : "";
355- return [channel, renderPost(opts, c)];
355 + return [channel, renderPost(opts, id, c)];
356356 } else if (c.type == "vote" && c.vote.expression == "Dig") {
357357 var channel = c.channel
358358 ? [' in ',
359359 h('a',
@@ -398,9 +398,9 @@
398398 else if (c.type == "issue") {
399399 return [h('span.status',
400400 "Created a git issue" +
401401 (c.repoName != undefined ? " in repo " + c.repoName : ""),
402- renderPost(opts, c))];
402 + renderPost(opts, id, c))];
403403 }
404404 else if (c.type == "git-repo") {
405405 return h('span.status',
406406 "Created a git repo " + c.name);
@@ -434,18 +434,23 @@
434434 '#' + c.channel))
435435 else return renderDefault(c);
436436 }
437437
438-function renderPost(opts, c) {
438 +function renderPost(opts, id, c) {
439439 opts.mentions = {};
440440 if (Array.isArray(c.mentions)) {
441441 c.mentions.forEach(function (link) {
442442 if (link && link.name && link.link)
443443 opts.mentions[link.name] = link.link;
444444 });
445445 }
446446 var s = h('section');
447- s.innerHTML = marked(String(c.text), opts.marked);
447 + var content = '';
448 + if (c.root && c.root != id)
449 + content += 'Re: ' + h('a',
450 + { href: '/' + encodeURIComponent(c.root) },
451 + c.root.substring(0, 10)).outerHTML + '<br>';
452 + s.innerHTML = content + marked(String(c.text), opts.marked);
448453 return s;
449454 }
450455
451456 function renderDefault(c) {

Built with git-ssb-web