git ssb

16+

Dominic / patchbay



Tree: 22980df7086fb15c08c87bb6c2d59fa79296d840

Files: 22980df7086fb15c08c87bb6c2d59fa79296d840 / message / html / render / contact.js

1102 bytesRaw
1const nest = require('depnest')
2const extend = require('xtend')
3const { isFeed } = require('ssb-ref')
4
5exports.gives = nest('message.html.render')
6
7exports.needs = nest({
8 'about.html.link': 'first',
9 'message.html': {
10 decorate: 'reduce',
11 layout: 'first'
12 }
13})
14
15exports.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