Files: 9de99ae493db260032c0423eedf4a3aa6f5d714f / plugs / message / html / render / channel.js
1098 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 | }, |
10 | 'intl.sync.i18n': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('message.html', { |
14 | canRender: true, |
15 | render: true |
16 | }) |
17 | |
18 | exports.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 | |
47 | function isRenderable (msg) { |
48 | return msg.value.content.type === 'channel' ? true : undefined |
49 | } |
50 |
Built with git-ssb-web