Files: dd397a2115ecf17019cddf13acf3ac9fc781f403 / message / html / render / contact.js
1062 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) return [ |
35 | blocking ? 'blocked ' : 'unblocked ', |
36 | name |
37 | ] |
38 | if (following != undefined) return [ |
39 | following ? 'followed ' : 'unfollowed ', |
40 | name |
41 | ] |
42 | } |
43 | } |
44 |
Built with git-ssb-web