Files: 35b3aece890ce9483986f9581925792a5bcd647d / plugs / message / html / render / attending.js
1256 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: isRenderable, |
22 | render: function about (msg, opts) { |
23 | if (!isRenderable(msg)) return |
24 | |
25 | var action = msg.value.content.attendee.remove ? `can't attend` : 'is attending' |
26 | var target = msg.value.content.about |
27 | var title = api.about.obs.latestValue(target, 'title') |
28 | var element = api.message.html.layout(msg, extend({ |
29 | showActions: true, |
30 | miniContent: [action, ' ', h('a', { |
31 | href: target |
32 | }, title)], |
33 | layout: 'mini' |
34 | }, opts)) |
35 | |
36 | return api.message.html.decorate(element, { |
37 | msg |
38 | }) |
39 | } |
40 | }) |
41 | |
42 | function isRenderable (msg) { |
43 | if (msg.value.content.type !== 'about') return |
44 | if (!ref.isMsg(msg.value.content.about)) return |
45 | if (!msg.value.content.attendee) return |
46 | if (msg.value.content.attendee.link !== msg.value.author) return |
47 | return true |
48 | } |
49 | } |
50 |
Built with git-ssb-web