git ssb

10+

Matt McKegg / patchwork



Tree: 56cb52d74a5a9b11c319182d03631bd5c99b3cb8

Files: 56cb52d74a5a9b11c319182d03631bd5c99b3cb8 / modules / page / html / render / gatherings.js

2114 bytesRaw
1var { h } = require('mutant')
2var nest = require('depnest')
3
4exports.needs = nest({
5 'feed.pull.type': 'first',
6 'feed.html.rollup': 'first',
7 'feed.pull.public': 'first',
8 'gathering.sheet.edit': 'first',
9 'keys.sync.id': 'first',
10 'contact.obs.following': 'first',
11 'sbot.pull.stream': 'first',
12 'intl.sync.i18n': 'first'
13})
14
15exports.gives = nest('page.html.render')
16
17exports.create = function (api) {
18 const i18n = api.intl.sync.i18n
19 return nest('page.html.render', function channel (path) {
20 if (path !== '/gatherings') return
21
22 var id = api.keys.sync.id()
23 var following = api.contact.obs.following(id)
24
25 var prepend = [
26 h('PageHeading', [
27 h('h1', [h('strong', i18n('Gatherings'))]),
28 h('div.meta', [
29 h('button -add', {
30 'ev-click': createGathering
31 }, i18n('+ Add Gathering'))
32 ])
33 ])
34 ]
35
36 return api.feed.html.rollup(api.feed.pull.type('gathering'), {
37 prepend,
38 rootFilter: (msg) => isGathering(msg),
39 bumpFilter: (msg) => {
40 if (isGathering(msg)) {
41 return true
42 } else if (followsAuthor(following, id, msg) && isAttendee(msg)) {
43 return 'attending'
44 }
45 },
46 resultFilter: (msg) => followsAuthor(following, id, msg) || followingIsAttending(following, msg),
47 updateStream: api.sbot.pull.stream(sbot => sbot.patchwork.latest({ids: [id]}))
48 })
49 })
50
51 function createGathering () {
52 api.gathering.sheet.edit()
53 }
54}
55
56function followsAuthor (following, yourId, msg) {
57 var author = msg.value.author
58 return yourId === author || following().includes(author)
59}
60
61function followingIsAttending (following, msg) {
62 if (Array.isArray(msg.replies)) {
63 return msg.replies.some((reply) => isAttendee(reply) && following().includes(reply.value.author))
64 }
65}
66
67function isAttendee (msg) {
68 var content = msg.value && msg.value.content
69 return (content && content.type === 'about' && content.attendee && !content.attendee.remove)
70}
71
72function isGathering (msg) {
73 return (msg.value && msg.value.content && msg.value.content.type === 'gathering')
74}

Built with git-ssb-web