git ssb

0+

Dominic / yap-gatherings



Commit 98fd28641650bead5543428cdffb2bc932dbb165

get working well enough to attend events

Dominic Tarr committed on 5/23/2019, 5:22:36 PM
Parent: 94f0e4dd667e6f3e2c417ed1c141aaa49f8cdf08

Files changed

README.mdchanged
get.jschanged
index.jschanged
render.jschanged
README.mdView
@@ -1,6 +1,8 @@
11 # yap-gatherings
22
33
4 +
5 +
46 ## License
57
68 MIT
get.jsView
@@ -35,13 +35,13 @@
3535 pull.collect(function (err, ary) {
3636 if(err) return cb(err)
3737 ary.unshift(root)
3838 var r = Reduce(ary)
39- console.log(r)
4039 cb(null, r)
4140 })
4241 )
4342 })
4443 }
4544
4645
4746
47 +
index.jsView
@@ -1,36 +1,54 @@
11 var Get = require('./get')
22 var paramap = require('pull-paramap')
33 var pull = require('pull-stream')
44 var u = require('yap-util')
5 +var Render = require('./render')
56
67 module.exports = function (sbot) {
78 return function (use) {
89 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"
1012 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))
1316 })
1417 }
1518 })
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 +
1634 use('all', function (opts, apply, req) {
1735 console.log(opts)
1836 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))),
2238 // sbot.messagesByType({
2339 // type: 'gathering',
2440 // limit: 10,
2541 // reverse: true
2642 // }),
2743 pull.map(function (e) {
28- return apply('/gatherings/event', {id: e.key, private: true})
44 + return apply('gatherings/event', {id: e.key, private: true})
2945 })
3046 )
3147 })
48 +
3249 use.map('messages', 'gathering', 'event')
50 + use.map('messages', 'about', 'about')
3351
3452 // use.list('
3553 }
3654 }
render.jsView
@@ -1,22 +1,25 @@
11 var u = require('yap-util')
22
3-module.exports = function (apply, gathering) {
3 +module.exports = function (apply, gathering, context) {
44 var attending = {}
55 gathering.value.attendee.forEach(function (attendee) {
66 if(attendee.link) attending[attendee.link] = true
77 if(attendee.remove) delete attending[attendee.link]
88 })
99 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)
1214 return ['div.Gathering',
1315 apply('avatar', {id: gathering.creator, name: true, image: true}),' ',
1416 ['h1',
1517 ['a',
1618 {href: apply.toUrl('gatherings/event', {id:gathering.root, replies: true})},
1719 gth.title
18- ]
20 + ],
21 + tz && '(tz: '+tz+')'
1922 ],
2023 ['h2', {title: tz}, new Date(epoch).toString()],
2124 u.markdown({text:gth.description, mentions: gth.mentions}),
2225 gathering.value.image
@@ -27,12 +30,46 @@
2730 Object.keys(attending).map(function (id) {
2831 return apply('avatar', id)
2932 })
3033 ],
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 &&
3150 ['div.Replies',
3251 gathering.replies.map(function (reply) {
3352 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 + }
3462 })
63 +
3564 ]
3665 ]
3766 }
3867
68 +
69 +
70 +
71 +
72 +
73 +
74 +
75 +

Built with git-ssb-web