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