git ssb

10+

Matt McKegg / patchwork



Tree: ed9add9c301f7f06b62492824e07772071cc5719

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

1119 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: function (msg) {
22 return isRenderable(msg);
23 },
24 render: function (msg, opts) {
25 if (!isRenderable(msg)) return
26 var element = api.message.html.layout(msg, extend({
27 miniContent: messageContent(msg),
28 layout: 'mini'
29 }, opts))
30
31 return api.message.html.decorate(element, {
32 msg
33 })
34 }
35 })
36
37 function messageContent(msg) {
38 var channel = `#${msg.value.content.channel}`
39 var subscribed = msg.value.content.subscribed
40 return [
41 subscribed ? i18n('subscribed to ') : i18n('unsubscribed from '),
42 h('a', {
43 href: channel
44 }, channel)
45 ]
46 }
47}
48
49function isRenderable(msg) {
50 return msg.value.content.type === 'channel'
51}
52

Built with git-ssb-web