git ssb

0+

Daan Patchwork / ssb-viewer



forked from cel / ssb-viewer

Commit 78e7e8a0087325795a746c98fad5255a3ae405aa

Merge pull request #7 from Powersource/render-gatherings

Render gatherings
Anders Rune Jensen authored on 7/7/2018, 6:45:07 PM
GitHub committed on 7/7/2018, 6:45:07 PM
Parent: 857dc63ce5bae471cf7123b6ec6ace0896677b64
Parent: b74745f55636877c4c999730d632fe9896f7d37f

Files changed

index.jschanged
lib/about.jschanged
render.jschanged
.gitignoreadded
index.jsView
@@ -136,8 +136,9 @@
136136 paramap(addBlog, 8),
137137 paramap(addFollowAbout, 8),
138138 paramap(addVoteMessage, 8),
139139 paramap(addGitLinks, 8),
140+ paramap(addGatheringAbout, 8),
140141 render(),
141142 toPull(res, function (err) {
142143 if (err) console.error('[viewer]', err)
143144 })
@@ -241,8 +242,9 @@
241242 paramap(addBlog, 8),
242243 paramap(addFollowAbout, 8),
243244 paramap(addVoteMessage, 8),
244245 paramap(addGitLinks, 8),
246+ paramap(addGatheringAbout, 8),
245247 pull(renderThread(feedOpts), wrapPage(name)),
246248 toPull(res, function (err) {
247249 if (err) console.error('[viewer]', err)
248250 })
@@ -267,9 +269,10 @@
267269 pull(
268270 pull.values(logs),
269271 paramap(addAuthorAbout, 8),
270272 paramap(addBlog, 8),
271- paramap(addVoteMessage, 8),
273+ paramap(addVoteMessage, 8),
274+ paramap(addGatheringAbout, 8),
272275 pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)),
273276 wrapPage('#' + channelId)),
274277 toPull(res, function (err) {
275278 if (err) console.error('[viewer]', err)
@@ -323,8 +326,9 @@
323326 pull(
324327 pull.values(sort(links)),
325328 paramap(addAuthorAbout, 8),
326329 paramap(addBlog, 8),
330+ paramap(addGatheringAbout, 8),
327331 format,
328332 toPull(res, function (err) {
329333 if (err) console.error('[viewer]', err)
330334 })
@@ -391,8 +395,42 @@
391395 cb(null, msg)
392396 })
393397 }
394398
399+ function addGatheringAbout(msg, cb) {
400+ if (msg.value && msg.value.content.type === 'gathering') {
401+ getAbout(msg.key, (err, about) => {
402+ if (err) { cb(err) }
403+
404+ msg.value.content.about = about
405+
406+ pull(
407+ sbot.backlinks.read({
408+ query: [{ $filter: {
409+ dest: msg.key,
410+ value: { content: { type: 'about' }},
411+ }}],
412+ index: 'DTA'
413+ }),
414+ // Only grab messages about attendance
415+ pull.filter(o => o.value.content.attendee !== undefined),
416+ // Filter "can't attend"-messages
417+ pull.filter(o => !o.value.content.attendee.remove),
418+ pull.unique(o => o.value.content.attendee.link),
419+ pull.collect((err, arr) => {
420+ if (err) { cb(err) }
421+
422+ msg.value.content.numberAttending = arr.length
423+
424+ cb(null, msg)
425+ })
426+ )
427+ })
428+ } else {
429+ cb(null, msg)
430+ }
431+ }
432+
395433 function addGitLinks(msg, cb) {
396434 if (msg.value.content.type == 'git-update')
397435 getMsg(msg.value.content.repo, function (err, gitRepo) {
398436 if (gitRepo)
lib/about.jsView
@@ -28,8 +28,10 @@
2828 var feedAbout = aboutByFeed[author] || (aboutByFeed[author] = {})
2929 if (typeof c.name == 'string') feedAbout.name = c.name.replace(/^@?/, '@')
3030 if (c.image) feedAbout.image = linkDest(c.image)
3131 if (c.description) feedAbout.description = c.description
32+ if (c.title) feedAbout.title = c.title
33+ if (c.startDateTime) feedAbout.startDateTime = c.startDateTime
3234 if (c.publicWebHosting != null && author === c.about) feedAbout.publicWebHosting = defalsify(c.publicWebHosting)
3335 }, function (err) {
3436 if (err) return cb(err)
3537 // Use whatever properties have the most counts.
render.jsView
@@ -295,8 +295,11 @@
295295 .call-to-action:hover {
296296 background-color: #748ffc;
297297 border-bottom: 3px solid #4c6ef5;
298298 }
299+ .attending {
300+ text-align: center;
301+ }
299302 </style>
300303 `;
301304
302305 function wrapJSON() {
@@ -522,11 +525,30 @@
522525 s.innerHTML = marked(String(c.blogContent), opts.marked)
523526
524527 return [channel, h('h2', c.title), s];
525528 }
529+ else if (c.type === 'gathering') {
530+ return h('div', renderGathering(opts, id, c))
531+ }
526532 else return renderDefault(c);
527533 }
528534
535+function renderGathering(opts, id, c) {
536+ const title = h('h2', c.about.title)
537+ const time = h('h3', new Date(c.about.startDateTime.epoch).toUTCString())
538+ const image = h('p', h('img', { src: opts.img_base + c.about.image }))
539+ const attending = h('h3.attending', c.numberAttending + ' attending')
540+ const desc = h('div')
541+ desc.innerHTML = marked(c.about.description, opts.marked)
542+ return h('section',
543+ [title,
544+ time,
545+ image,
546+ attending,
547+ desc]
548+ )
549+}
550+
529551 function renderPost(opts, id, c) {
530552 opts.mentions = {};
531553 if (Array.isArray(c.mentions)) {
532554 c.mentions.forEach(function (link) {
.gitignoreView
@@ -1,0 +1,2 @@
1+node_modules/
2+package-lock.json

Built with git-ssb-web