Files: bfff9ddc0fc0159cb662f4168b1960ff7822dfa0 / modules / page / html / render / gatherings.js
2114 bytesRaw
1 | var { h } = require('mutant') |
2 | var nest = require('depnest') |
3 | |
4 | exports.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 | |
15 | exports.gives = nest('page.html.render') |
16 | |
17 | exports.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 | |
56 | function followsAuthor (following, yourId, msg) { |
57 | var author = msg.value.author |
58 | return yourId === author || following().includes(author) |
59 | } |
60 | |
61 | function 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 | |
67 | function isAttendee (msg) { |
68 | var content = msg.value && msg.value.content |
69 | return (content && content.type === 'about' && content.attendee && !content.attendee.remove) |
70 | } |
71 | |
72 | function isGathering (msg) { |
73 | return (msg.value && msg.value.content && msg.value.content.type === 'gathering') |
74 | } |
Built with git-ssb-web