Commit 98fd28641650bead5543428cdffb2bc932dbb165
get working well enough to attend events
Dominic Tarr committed on 5/23/2019, 5:22:36 PMParent: 94f0e4dd667e6f3e2c417ed1c141aaa49f8cdf08
Files changed
README.md | changed |
get.js | changed |
index.js | changed |
render.js | changed |
get.js | ||
---|---|---|
@@ -35,13 +35,13 @@ | ||
35 | 35 … | pull.collect(function (err, ary) { |
36 | 36 … | if(err) return cb(err) |
37 | 37 … | ary.unshift(root) |
38 | 38 … | var r = Reduce(ary) |
39 | - console.log(r) | |
40 | 39 … | cb(null, r) |
41 | 40 … | }) |
42 | 41 … | ) |
43 | 42 … | }) |
44 | 43 … | } |
45 | 44 … | |
46 | 45 … | |
47 | 46 … | |
47 … | + |
index.js | ||
---|---|---|
@@ -1,36 +1,54 @@ | ||
1 | 1 … | var Get = require('./get') |
2 | 2 … | var paramap = require('pull-paramap') |
3 | 3 … | var pull = require('pull-stream') |
4 | 4 … | var u = require('yap-util') |
5 … | +var Render = require('./render') | |
5 | 6 … | |
6 | 7 … | module.exports = function (sbot) { |
7 | 8 … | return function (use) { |
8 | 9 … | use('event', function (opts, apply, req) { |
9 | - opts.id = opts.id || "%eFzw9Qca1MUppBgyGG0e2AwzlwonvwDk2GDyxM9B37c=.sha256" | |
10 … | + var context = Object.assign({}, req.cookies, {id: sbot.id, forms: opts.embed !== true}) | |
11 … | +// opts.id = opts.id || "%eFzw9Qca1MUppBgyGG0e2AwzlwonvwDk2GDyxM9B37c=.sha256" | |
10 | 12 … | return function (cb) { |
11 | - Get(sbot, opts, function (err, thread) { | |
12 | - cb(null, require('./render')(apply, thread)) | |
13 … | + Get(sbot, opts, function (err, gathering) { | |
14 … | + if(err) cb(err) | |
15 … | + else cb(null, Render(apply, gathering, context)) | |
13 | 16 … | }) |
14 | 17 … | } |
15 | 18 … | }) |
19 … | + | |
20 … | + use('about', u.createRenderer(function (data, apply) { | |
21 … | + console.log('RENDER ABOUT', data) | |
22 … | + return ['div.Message', | |
23 … | + //currently, a vote message has no need for a cache tag. | |
24 … | + //unless we decide to show other peers that have liked this. | |
25 … | + //u.cacheTag(toUrl('message', {id: data.key}), data.key, ), | |
26 … | + ['h3', apply('avatar', {id: data.value.content.attendee.link}), data.value.content.attendee.remove ? 'is not attending' : 'is attending'], | |
27 … | + ['div.EmbeddedMessage', | |
28 … | + apply('gatherings/event', {id: data.value.content.about, embed: true}), | |
29 … | + ] | |
30 … | + ] | |
31 … | + })(sbot)) | |
32 … | + | |
33 … | + | |
16 | 34 … | use('all', function (opts, apply, req) { |
17 | 35 … | console.log(opts) |
18 | 36 … | return pull( |
19 | - sbot.query.read( | |
20 | - u.createQuery(Object.assign({ type: 'gathering'}, opts)) | |
21 | - ), | |
37 … | + sbot.query.read(u.createQuery(Object.assign({ type: 'gathering'}, opts))), | |
22 | 38 … | // sbot.messagesByType({ |
23 | 39 … | // type: 'gathering', |
24 | 40 … | // limit: 10, |
25 | 41 … | // reverse: true |
26 | 42 … | // }), |
27 | 43 … | pull.map(function (e) { |
28 | - return apply('/gatherings/event', {id: e.key, private: true}) | |
44 … | + return apply('gatherings/event', {id: e.key, private: true}) | |
29 | 45 … | }) |
30 | 46 … | ) |
31 | 47 … | }) |
48 … | + | |
32 | 49 … | use.map('messages', 'gathering', 'event') |
50 … | + use.map('messages', 'about', 'about') | |
33 | 51 … | |
34 | 52 … | // use.list(' |
35 | 53 … | } |
36 | 54 … | } |
render.js | ||
---|---|---|
@@ -1,22 +1,25 @@ | ||
1 | 1 … | var u = require('yap-util') |
2 | 2 … | |
3 | -module.exports = function (apply, gathering) { | |
3 … | +module.exports = function (apply, gathering, context) { | |
4 | 4 … | var attending = {} |
5 | 5 … | gathering.value.attendee.forEach(function (attendee) { |
6 | 6 … | if(attendee.link) attending[attendee.link] = true |
7 | 7 … | if(attendee.remove) delete attending[attendee.link] |
8 | 8 … | }) |
9 | 9 … | var gth = gathering.value |
10 | - var epoch = gth.startDateTime && gth.startDateTime.epoch | |
11 | - var tz = epoch && epoch.tz | |
10 … | + var start = gth.startDateTime && gth.startDateTime//.epoch | |
11 … | + var epoch = start && start.epoch | |
12 … | + var tz = start && start.tz | |
13 … | +// console.log("START", gth.startDateTime) | |
12 | 14 … | return ['div.Gathering', |
13 | 15 … | apply('avatar', {id: gathering.creator, name: true, image: true}),' ', |
14 | 16 … | ['h1', |
15 | 17 … | ['a', |
16 | 18 … | {href: apply.toUrl('gatherings/event', {id:gathering.root, replies: true})}, |
17 | 19 … | gth.title |
18 | - ] | |
20 … | + ], | |
21 … | + tz && '(tz: '+tz+')' | |
19 | 22 … | ], |
20 | 23 … | ['h2', {title: tz}, new Date(epoch).toString()], |
21 | 24 … | u.markdown({text:gth.description, mentions: gth.mentions}), |
22 | 25 … | gathering.value.image |
@@ -27,12 +30,46 @@ | ||
27 | 30 … | Object.keys(attending).map(function (id) { |
28 | 31 … | return apply('avatar', id) |
29 | 32 … | }) |
30 | 33 … | ], |
34 … | + context.forms !== false && | |
35 … | + apply('publish', { | |
36 … | + id: context.id, | |
37 … | + name: attending[context.id] ? "can't attend" : "attend", | |
38 … | + content: { | |
39 … | + type: 'about', | |
40 … | + about: gathering.root, | |
41 … | + root: gathering.root, | |
42 … | + branch: gathering.branch, | |
43 … | + attendee: { | |
44 … | + link: context.id, | |
45 … | + remove: attending[context.id] ? true : undefined | |
46 … | + }, | |
47 … | + } | |
48 … | + }), | |
49 … | + gathering.replies.length && | |
31 | 50 … | ['div.Replies', |
32 | 51 … | gathering.replies.map(function (reply) { |
33 | 52 … | return apply('messages/post', reply) |
53 … | + }), | |
54 … | + context.forms !== false && apply('compose', { | |
55 … | + content: { | |
56 … | + type: 'post', | |
57 … | + root: gathering.root, | |
58 … | +// recps: recps, | |
59 … | + branch: gathering.branch, | |
60 … | + //channel: ary[0].value.content.channel | |
61 … | + } | |
34 | 62 … | }) |
63 … | + | |
35 | 64 … | ] |
36 | 65 … | ] |
37 | 66 … | } |
38 | 67 … | |
68 … | + | |
69 … | + | |
70 … | + | |
71 … | + | |
72 … | + | |
73 … | + | |
74 … | + | |
75 … | + |
Built with git-ssb-web