Files: c493e24e3dd3c7732099cf62acbabe7501d136f3 / message / html / render / contact.js
1104 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, blocking } = 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, blocking }), |
25 | layout: 'mini' |
26 | }, opts)) |
27 | |
28 | return api.message.html.decorate(element, { msg }) |
29 | } |
30 | |
31 | function renderContent ({ contact, following, blocking }) { |
32 | const name = api.about.html.link(contact) |
33 | |
34 | if (blocking !== undefined) { |
35 | return [ |
36 | blocking ? 'blocked ' : 'unblocked ', |
37 | name |
38 | ] |
39 | } |
40 | if (following !== undefined) { |
41 | return [ |
42 | following ? 'followed ' : 'unfollowed ', |
43 | name |
44 | ] |
45 | } |
46 | } |
47 | } |
48 |
Built with git-ssb-web