git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: a69b107634854812d8fe243ff4f0ce3e4e19bd8c

Files: a69b107634854812d8fe243ff4f0ce3e4e19bd8c / plugs / message / html / render / attending.js

1313 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 undefined
44 else if (!ref.isMsg(msg.value.content.about)) return undefined
45 else if (!msg.value.content.attendee) return undefined
46 else if (msg.value.content.attendee.link !== msg.value.author) return undefined
47 else return true
48 }
49}
50

Built with git-ssb-web