git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 7ceec7443b73d5a618748aaefea62cbfa9b909b7

Files: 7ceec7443b73d5a618748aaefea62cbfa9b909b7 / plugs / message / html / render / following.js

1572 bytesRaw
1var h = require('mutant/h')
2var nest = require('depnest')
3var extend = require('xtend')
4var ref = require('ssb-ref')
5
6exports.needs = nest({
7 'message.html': {
8 decorate: 'reduce',
9 layout: 'first'
10 },
11 'profile.html.person': 'first',
12 'intl.sync.i18n': 'first',
13})
14
15exports.gives = nest('message.html', {
16 canRender: true,
17 render: true
18})
19
20exports.create = function(api) {
21 const i18n = api.intl.sync.i18n
22 return nest('message.html', {
23 canRender: isRenderable,
24 render: function(msg, opts) {
25 if (!isRenderable(msg)) return
26
27 var element = api.message.html.layout(msg, extend({
28 miniContent: messageContent(msg),
29 layout: 'mini'
30 }, opts))
31
32 return api.message.html.decorate(element, {
33 msg
34 })
35 }
36 })
37
38 function messageContent(msg) {
39 var following = msg.value.content.following
40 var blocking = msg.value.content.blocking
41
42 if (typeof blocking === 'boolean') {
43 return [
44 blocking ? i18n('blocked ') : i18n('unblocked '),
45 api.profile.html.person(msg.value.content.contact)
46 ]
47 } else {
48 return [
49 following ? i18n('followed ') : i18n('unfollowed '),
50 api.profile.html.person(msg.value.content.contact)
51 ]
52 }
53 }
54
55 function isRenderable(msg) {
56 if (msg.value.content.type !== 'contact') return undefined
57 else if (!ref.isFeed(msg.value.content.contact)) return undefined
58 else if (typeof msg.value.content.following !== 'boolean' && typeof msg.value.content.blocking !== 'boolean') return undefined
59 return true;
60 }
61
62}
63

Built with git-ssb-web