git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: ed9add9c301f7f06b62492824e07772071cc5719

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

1337 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: 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