Files: 6502757ce947d02528d2915543f2282906ddfe53 / message / html / render / follow.js
881 bytesRaw
1 | const nest = require('depnest') |
2 | const extend = require('xtend') |
3 | const { isFeed } = require('ssb-ref') |
4 | |
5 | exports.gives = nest('message.html.render') |
6 | |
7 | exports.needs = nest({ |
8 | 'about.html.link': 'first', |
9 | 'message.html': { |
10 | decorate: 'reduce', |
11 | layout: 'first' |
12 | } |
13 | }) |
14 | |
15 | exports.create = function (api) { |
16 | return nest('message.html.render', follow) |
17 | |
18 | function follow (msg, opts) { |
19 | const { type, contact, following } = msg.value.content |
20 | if (type !== 'contact') return |
21 | if (!isFeed(contact)) return |
22 | |
23 | const element = api.message.html.layout(msg, extend({ |
24 | content: renderContent({ contact, following }), |
25 | layout: 'mini' |
26 | }, opts)) |
27 | |
28 | return api.message.html.decorate(element, { msg }) |
29 | } |
30 | |
31 | function renderContent ({ contact, following }) { |
32 | return [ |
33 | following ? 'followed ' : 'unfollowed ', |
34 | api.about.html.link(contact) |
35 | ] |
36 | } |
37 | } |
38 | |
39 |
Built with git-ssb-web