git ssb

16+

Dominic / patchbay



Tree: 07cfe9bf013a2baa61f2d075994dc78be9aa9309

Files: 07cfe9bf013a2baa61f2d075994dc78be9aa9309 / message / html / render / contact.js

1062 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) 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