git ssb

10+

Matt McKegg / patchwork



Tree: dabd8b0e595ab5b476fdb6634f3641257c23fa47

Files: dabd8b0e595ab5b476fdb6634f3641257c23fa47 / plugs / message / html / render / channel.js

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

Built with git-ssb-web