Files: e0439586cabe63fc84e88ff400edb18470cdec52 / message / html / render / channel.js
1067 bytesRaw
1 | var h = require('mutant/h') |
2 | var nest = require('depnest') |
3 | var extend = require('xtend') |
4 | |
5 | exports.needs = nest({ |
6 | 'message.html': { |
7 | decorate: 'reduce', |
8 | layout: 'first', |
9 | link: 'first', |
10 | markdown: 'first' |
11 | } |
12 | }) |
13 | |
14 | exports.gives = nest({ |
15 | 'message.html': { |
16 | canRender: true, |
17 | render: true |
18 | } |
19 | }) |
20 | |
21 | exports.create = function (api) { |
22 | return nest('message.html', { |
23 | canRender: isRenderable, |
24 | render: channel |
25 | }) |
26 | |
27 | function channel (msg, opts) { |
28 | if (!isRenderable(msg)) return |
29 | var element = api.message.html.layout(msg, extend({ |
30 | content: renderContent(msg), |
31 | layout: 'mini' |
32 | }, opts)) |
33 | |
34 | return api.message.html.decorate(element, { |
35 | msg |
36 | }) |
37 | } |
38 | |
39 | function renderContent (msg) { |
40 | var channel = '#' + msg.value.content.channel |
41 | return [ |
42 | msg.value.content.subscribed ? 'subscribed to channel' : 'unsubscribed from channel', ' ', h('a.channel', { |
43 | href: channel |
44 | }, channel) |
45 | ] |
46 | } |
47 | |
48 | function isRenderable (msg) { |
49 | return msg.value.content.type === 'channel' ? true : undefined |
50 | } |
51 | } |
52 |
Built with git-ssb-web