git ssb

10+

Matt McKegg / patchwork



Tree: 55888687e226393bac2741854678bf266fa5a92a

Files: 55888687e226393bac2741854678bf266fa5a92a / plugs / message / html / render / attending.js

1256 bytesRaw
1var h = require('mutant/h')
2var nest = require('depnest')
3var extend = require('xtend')
4var ref = require('ssb-ref')
5
6exports.needs = nest({
7 'message.html': {
8 decorate: 'reduce',
9 layout: 'first'
10 },
11 'about.obs.latestValue': 'first'
12})
13
14exports.gives = nest('message.html', {
15 canRender: true,
16 render: true
17})
18
19exports.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