Files: c41a27a2d832340a4e31d5f78b95d182759bb0e2 / index.js
2011 bytesRaw
1 | var Get = require('./get') |
2 | var paramap = require('pull-paramap') |
3 | var pull = require('pull-stream') |
4 | var u = require('yap-util') |
5 | var Render = require('./render') |
6 | |
7 | module.exports = function (sbot) { |
8 | return function (use) { |
9 | use('event', function (opts, apply, req) { |
10 | if(!opts.id) opts.id = opts.key |
11 | var context = Object.assign({}, req.cookies, {id: sbot.id, forms: opts.embed !== true}) |
12 | return function (cb) { |
13 | Get(sbot, opts, function (err, gathering) { |
14 | if(err) cb(err) |
15 | else cb(null, apply('messageLayout', { |
16 | id: gathering.root, |
17 | author: gathering.creator, |
18 | ts: gathering.created, |
19 | content: Render(apply, gathering, context), |
20 | meta: !opts.embed ? |
21 | ['a', {href: u.toUrl('gatherings/event', {id: gathering.root})}, 'Event'] |
22 | : [] |
23 | })) |
24 | }) |
25 | } |
26 | }) |
27 | |
28 | use('about', u.createRenderer(function (data, apply) { |
29 | return ['div.Message', |
30 | //currently, a vote message has no need for a cache tag. |
31 | //unless we decide to show other peers that have liked this. |
32 | //u.cacheTag(toUrl('message', {id: data.key}), data.key, ), |
33 | ['h3', apply('avatar', {id: data.value.content.attendee.link}), data.value.content.attendee.remove ? 'is not attending' : 'is attending'], |
34 | ['div.EmbeddedMessage', |
35 | apply('gatherings/event', {id: data.value.content.about, embed: true}), |
36 | ] |
37 | ] |
38 | })(sbot)) |
39 | |
40 | |
41 | use('all', function (opts, apply, req) { |
42 | return pull( |
43 | sbot.query.read(u.createQuery(Object.assign({ type: 'gathering'}, opts))), |
44 | pull.map(function (e) { |
45 | return apply('gatherings/event', {id: e.key, private: true}) |
46 | }) |
47 | ) |
48 | }) |
49 | |
50 | use.map('messages', 'gathering', 'event') |
51 | use.map('messages', 'about', 'about') |
52 | use('menu', function (opts, apply, req) { |
53 | return ['a', {href: '/gatherings/all'}, 'Gatherings'] |
54 | }) |
55 | use.list('menu', 'menu') |
56 | } |
57 | } |
58 |
Built with git-ssb-web