Files: ed9add9c301f7f06b62492824e07772071cc5719 / plugs / message / html / render / attending.js
1337 bytesRaw
1 | var h = require('mutant/h') |
2 | var nest = require('depnest') |
3 | var extend = require('xtend') |
4 | var ref = require('ssb-ref') |
5 | |
6 | exports.needs = nest({ |
7 | 'message.html': { |
8 | decorate: 'reduce', |
9 | layout: 'first' |
10 | }, |
11 | 'about.obs.latestValue': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('message.html', { |
15 | canRender: true, |
16 | render: true |
17 | }) |
18 | |
19 | exports.create = function(api) { |
20 | return nest('message.html', { |
21 | canRender: function(msg) { |
22 | return isRenderable(msg) |
23 | }, |
24 | render: function about(msg, opts) { |
25 | if (!isRenderable(msg)) return |
26 | |
27 | var action = msg.value.content.attendee.remove ? `can't attend` : 'is attending' |
28 | var target = msg.value.content.about |
29 | var title = api.about.obs.latestValue(target, 'title') |
30 | var element = api.message.html.layout(msg, extend({ |
31 | showActions: true, |
32 | miniContent: [action, ' ', h('a', { |
33 | href: target |
34 | }, title)], |
35 | layout: 'mini' |
36 | }, opts)) |
37 | |
38 | return api.message.html.decorate(element, { |
39 | msg |
40 | }) |
41 | } |
42 | }) |
43 | |
44 | function isRenderable(msg) { |
45 | if (msg.value.content.type !== 'about') return false |
46 | else if (!ref.isMsg(msg.value.content.about)) return false |
47 | else if (!msg.value.content.attendee) return false |
48 | else if (msg.value.content.attendee.link !== msg.value.author) return false |
49 | else return true |
50 | } |
51 | } |
52 |
Built with git-ssb-web