From cecdc93fd30b7c181e4e9720a98ef8f788355906 Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Mon, 2 Jul 2018 19:52:17 +0200 Subject: [PATCH 1/6] Render gathering descriptions --- index.js | 21 ++++++++++++++++++++- render.js | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9dfd719..79140be 100644 --- a/index.js +++ b/index.js @@ -137,6 +137,7 @@ exports.init = function (sbot, config) { paramap(addFollowAbout, 8), paramap(addVoteMessage, 8), paramap(addGitLinks, 8), + paramap(addGatheringAbout, 8), render(), toPull(res, function (err) { if (err) console.error('[viewer]', err) @@ -242,6 +243,7 @@ exports.init = function (sbot, config) { paramap(addFollowAbout, 8), paramap(addVoteMessage, 8), paramap(addGitLinks, 8), + paramap(addGatheringAbout, 8), pull(renderThread(feedOpts), wrapPage(name)), toPull(res, function (err) { if (err) console.error('[viewer]', err) @@ -268,7 +270,8 @@ exports.init = function (sbot, config) { pull.values(logs), paramap(addAuthorAbout, 8), paramap(addBlog, 8), - paramap(addVoteMessage, 8), + paramap(addVoteMessage, 8), + paramap(addGatheringAbout, 8), pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)), wrapPage('#' + channelId)), toPull(res, function (err) { @@ -324,6 +327,7 @@ exports.init = function (sbot, config) { pull.values(sort(links)), paramap(addAuthorAbout, 8), paramap(addBlog, 8), + paramap(addGatheringAbout, 8), format, toPull(res, function (err) { if (err) console.error('[viewer]', err) @@ -392,6 +396,21 @@ exports.init = function (sbot, config) { }) } + function addGatheringAbout(msg, cb) { + if (msg.value && msg.value.content.type === 'gathering') { + console.log('adding gathering abouts. msg:', msg) + getAbout(msg.key, (err, about) => { + if (err) { return cb(err) } + + msg.value.content.about = about + console.log('about gathering', about) + cb(null, msg) + }) + } else { + cb(null, msg) + } + } + function addGitLinks(msg, cb) { if (msg.value.content.type == 'git-update') getMsg(msg.value.content.repo, function (err, gitRepo) { diff --git a/render.js b/render.js index 56951e3..d9b75da 100644 --- a/render.js +++ b/render.js @@ -523,9 +523,25 @@ function render(opts, id, c) { return [channel, h('h2', c.title), s]; } + else if (c.type === 'gathering') { + console.log('opts', opts) + console.log('c', c) + + return ['id: ' + id, + h('div', + ['this is a gathering boopadoop', + renderGathering(opts, id, c)] + ) + ] + } else return renderDefault(c); } +function renderGathering(opts, id, c) { + console.log('gathering content:', c) + return h('div', c.about.description) +} + function renderPost(opts, id, c) { opts.mentions = {}; if (Array.isArray(c.mentions)) { From d15a09749d2da84b14e512778ae026fad957d7fc Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Mon, 2 Jul 2018 20:26:16 +0200 Subject: [PATCH 2/6] Render gathering images and markdown the descs --- render.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/render.js b/render.js index d9b75da..3caccc3 100644 --- a/render.js +++ b/render.js @@ -524,13 +524,9 @@ function render(opts, id, c) { return [channel, h('h2', c.title), s]; } else if (c.type === 'gathering') { - console.log('opts', opts) - console.log('c', c) - return ['id: ' + id, h('div', - ['this is a gathering boopadoop', - renderGathering(opts, id, c)] + renderGathering(opts, id, c) ) ] } @@ -538,8 +534,15 @@ function render(opts, id, c) { } function renderGathering(opts, id, c) { + console.log('opts', opts) console.log('gathering content:', c) - return h('div', c.about.description) + const desc = h('div') + desc.innerHTML = marked(c.about.description, opts.marked) + const image = h('p', h('img', { src: opts.img_base + c.about.image })) + return h('section', + [image, + desc] + ) } function renderPost(opts, id, c) { From d09eab73ae3a9d7f447dfafca886750acd04e58d Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Fri, 6 Jul 2018 23:50:18 +0200 Subject: [PATCH 3/6] Count attendees --- index.js | 26 ++++++++++++++++++++++---- render.js | 13 ++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 79140be..2a0e012 100644 --- a/index.js +++ b/index.js @@ -398,13 +398,31 @@ exports.init = function (sbot, config) { function addGatheringAbout(msg, cb) { if (msg.value && msg.value.content.type === 'gathering') { - console.log('adding gathering abouts. msg:', msg) getAbout(msg.key, (err, about) => { - if (err) { return cb(err) } + if (err) { cb(err) } msg.value.content.about = about - console.log('about gathering', about) - cb(null, msg) + + pull( + sbot.backlinks.read({ + query: [{ $filter: { + dest: msg.key, + value: { content: { type: 'about' }}, + }}], + index: 'DTA' + }), + //pull.map(o => { console.log('bl:', o.value.content); return o }), + // Only grab messages about attendance + pull.filter(o => o.value.content.attendee !== undefined), + // Filter "can't attend"-messages + pull.filter(o => !o.value.content.attendee.remove), + pull.unique(o => o.value.content.attendee.link), + pull.collect((err, arr) => { + if (err) { cb(err) } + msg.value.content.numberAttending = arr.length + cb(null, msg) + }) + ) }) } else { cb(null, msg) diff --git a/render.js b/render.js index 3caccc3..1d3436b 100644 --- a/render.js +++ b/render.js @@ -296,6 +296,9 @@ var styles = ` background-color: #748ffc; border-bottom: 3px solid #4c6ef5; } + .attending { + text-align: center; + } `; @@ -524,23 +527,19 @@ function render(opts, id, c) { return [channel, h('h2', c.title), s]; } else if (c.type === 'gathering') { - return ['id: ' + id, - h('div', - renderGathering(opts, id, c) - ) - ] + return h('div', renderGathering(opts, id, c)) } else return renderDefault(c); } function renderGathering(opts, id, c) { - console.log('opts', opts) - console.log('gathering content:', c) const desc = h('div') desc.innerHTML = marked(c.about.description, opts.marked) const image = h('p', h('img', { src: opts.img_base + c.about.image })) + const attending = h('h3.attending', c.numberAttending + ' attending') return h('section', [image, + attending, desc] ) } From 3c608e0159f165149400aef6b07160373797b31b Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Sat, 7 Jul 2018 12:41:38 +0200 Subject: [PATCH 4/6] Add gathering title --- .gitignore | 2 ++ index.js | 3 ++- lib/about.js | 2 ++ render.js | 5 ++++- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ccb2c80 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +package-lock.json \ No newline at end of file diff --git a/index.js b/index.js index 2a0e012..04a99dd 100644 --- a/index.js +++ b/index.js @@ -411,7 +411,6 @@ exports.init = function (sbot, config) { }}], index: 'DTA' }), - //pull.map(o => { console.log('bl:', o.value.content); return o }), // Only grab messages about attendance pull.filter(o => o.value.content.attendee !== undefined), // Filter "can't attend"-messages @@ -419,7 +418,9 @@ exports.init = function (sbot, config) { pull.unique(o => o.value.content.attendee.link), pull.collect((err, arr) => { if (err) { cb(err) } + msg.value.content.numberAttending = arr.length + cb(null, msg) }) ) diff --git a/lib/about.js b/lib/about.js index 70761c8..a33a919 100644 --- a/lib/about.js +++ b/lib/about.js @@ -29,6 +29,8 @@ module.exports = function (sbot, id, cb) { if (typeof c.name == 'string') feedAbout.name = c.name.replace(/^@?/, '@') if (c.image) feedAbout.image = linkDest(c.image) if (c.description) feedAbout.description = c.description + if (c.title) feedAbout.title = c.title + if (c.startDateTime) feedAbout.startDateTime = c.startDateTime if (c.publicWebHosting != null && author === c.about) feedAbout.publicWebHosting = defalsify(c.publicWebHosting) }, function (err) { if (err) return cb(err) diff --git a/render.js b/render.js index 1d3436b..8e86d27 100644 --- a/render.js +++ b/render.js @@ -537,8 +537,11 @@ function renderGathering(opts, id, c) { desc.innerHTML = marked(c.about.description, opts.marked) const image = h('p', h('img', { src: opts.img_base + c.about.image })) const attending = h('h3.attending', c.numberAttending + ' attending') + const title = h('h2', c.about.title) + console.log('c', c) return h('section', - [image, + [title, + image, attending, desc] ) From d210926c8b6638ed7f9b6506fce01d51e9810aec Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Sat, 7 Jul 2018 12:51:00 +0200 Subject: [PATCH 5/6] Render gathering time --- render.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/render.js b/render.js index 8e86d27..0af4c2f 100644 --- a/render.js +++ b/render.js @@ -538,9 +538,11 @@ function renderGathering(opts, id, c) { const image = h('p', h('img', { src: opts.img_base + c.about.image })) const attending = h('h3.attending', c.numberAttending + ' attending') const title = h('h2', c.about.title) + const time = h('h3', new Date(c.about.startDateTime.epoch).toUTCString()) console.log('c', c) return h('section', [title, + time, image, attending, desc] From b74745f55636877c4c999730d632fe9896f7d37f Mon Sep 17 00:00:00 2001 From: Jacob Karlsson Date: Sat, 7 Jul 2018 13:04:43 +0200 Subject: [PATCH 6/6] Clean code --- render.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/render.js b/render.js index 0af4c2f..d6790f8 100644 --- a/render.js +++ b/render.js @@ -533,13 +533,12 @@ function render(opts, id, c) { } function renderGathering(opts, id, c) { - const desc = h('div') - desc.innerHTML = marked(c.about.description, opts.marked) - const image = h('p', h('img', { src: opts.img_base + c.about.image })) - const attending = h('h3.attending', c.numberAttending + ' attending') const title = h('h2', c.about.title) const time = h('h3', new Date(c.about.startDateTime.epoch).toUTCString()) - console.log('c', c) + const image = h('p', h('img', { src: opts.img_base + c.about.image })) + const attending = h('h3.attending', c.numberAttending + ' attending') + const desc = h('div') + desc.innerHTML = marked(c.about.description, opts.marked) return h('section', [title, time,