Commit 78e7e8a0087325795a746c98fad5255a3ae405aa
Merge pull request #7 from Powersource/render-gatherings
Render gatheringsAnders 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.js | changed |
lib/about.js | changed |
render.js | changed |
.gitignore | added |
index.js | ||
---|---|---|
@@ -136,8 +136,9 @@ | ||
136 | 136 | paramap(addBlog, 8), |
137 | 137 | paramap(addFollowAbout, 8), |
138 | 138 | paramap(addVoteMessage, 8), |
139 | 139 | paramap(addGitLinks, 8), |
140 | + paramap(addGatheringAbout, 8), | |
140 | 141 | render(), |
141 | 142 | toPull(res, function (err) { |
142 | 143 | if (err) console.error('[viewer]', err) |
143 | 144 | }) |
@@ -241,8 +242,9 @@ | ||
241 | 242 | paramap(addBlog, 8), |
242 | 243 | paramap(addFollowAbout, 8), |
243 | 244 | paramap(addVoteMessage, 8), |
244 | 245 | paramap(addGitLinks, 8), |
246 | + paramap(addGatheringAbout, 8), | |
245 | 247 | pull(renderThread(feedOpts), wrapPage(name)), |
246 | 248 | toPull(res, function (err) { |
247 | 249 | if (err) console.error('[viewer]', err) |
248 | 250 | }) |
@@ -267,9 +269,10 @@ | ||
267 | 269 | pull( |
268 | 270 | pull.values(logs), |
269 | 271 | paramap(addAuthorAbout, 8), |
270 | 272 | paramap(addBlog, 8), |
271 | - paramap(addVoteMessage, 8), | |
273 | + paramap(addVoteMessage, 8), | |
274 | + paramap(addGatheringAbout, 8), | |
272 | 275 | pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)), |
273 | 276 | wrapPage('#' + channelId)), |
274 | 277 | toPull(res, function (err) { |
275 | 278 | if (err) console.error('[viewer]', err) |
@@ -323,8 +326,9 @@ | ||
323 | 326 | pull( |
324 | 327 | pull.values(sort(links)), |
325 | 328 | paramap(addAuthorAbout, 8), |
326 | 329 | paramap(addBlog, 8), |
330 | + paramap(addGatheringAbout, 8), | |
327 | 331 | format, |
328 | 332 | toPull(res, function (err) { |
329 | 333 | if (err) console.error('[viewer]', err) |
330 | 334 | }) |
@@ -391,8 +395,42 @@ | ||
391 | 395 | cb(null, msg) |
392 | 396 | }) |
393 | 397 | } |
394 | 398 | |
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 | + | |
395 | 433 | function addGitLinks(msg, cb) { |
396 | 434 | if (msg.value.content.type == 'git-update') |
397 | 435 | getMsg(msg.value.content.repo, function (err, gitRepo) { |
398 | 436 | if (gitRepo) |
lib/about.js | ||
---|---|---|
@@ -28,8 +28,10 @@ | ||
28 | 28 | var feedAbout = aboutByFeed[author] || (aboutByFeed[author] = {}) |
29 | 29 | if (typeof c.name == 'string') feedAbout.name = c.name.replace(/^@?/, '@') |
30 | 30 | if (c.image) feedAbout.image = linkDest(c.image) |
31 | 31 | if (c.description) feedAbout.description = c.description |
32 | + if (c.title) feedAbout.title = c.title | |
33 | + if (c.startDateTime) feedAbout.startDateTime = c.startDateTime | |
32 | 34 | if (c.publicWebHosting != null && author === c.about) feedAbout.publicWebHosting = defalsify(c.publicWebHosting) |
33 | 35 | }, function (err) { |
34 | 36 | if (err) return cb(err) |
35 | 37 | // Use whatever properties have the most counts. |
render.js | ||
---|---|---|
@@ -295,8 +295,11 @@ | ||
295 | 295 | .call-to-action:hover { |
296 | 296 | background-color: #748ffc; |
297 | 297 | border-bottom: 3px solid #4c6ef5; |
298 | 298 | } |
299 | + .attending { | |
300 | + text-align: center; | |
301 | + } | |
299 | 302 | </style> |
300 | 303 | `; |
301 | 304 | |
302 | 305 | function wrapJSON() { |
@@ -522,11 +525,30 @@ | ||
522 | 525 | s.innerHTML = marked(String(c.blogContent), opts.marked) |
523 | 526 | |
524 | 527 | return [channel, h('h2', c.title), s]; |
525 | 528 | } |
529 | + else if (c.type === 'gathering') { | |
530 | + return h('div', renderGathering(opts, id, c)) | |
531 | + } | |
526 | 532 | else return renderDefault(c); |
527 | 533 | } |
528 | 534 | |
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 | + | |
529 | 551 | function renderPost(opts, id, c) { |
530 | 552 | opts.mentions = {}; |
531 | 553 | if (Array.isArray(c.mentions)) { |
532 | 554 | c.mentions.forEach(function (link) { |
Built with git-ssb-web