git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: ed9add9c301f7f06b62492824e07772071cc5719

Files: ed9add9c301f7f06b62492824e07772071cc5719 / plugs / message / html / render / following.js

1573 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: function(msg) {
24 return isRenderable(msg);
25 },
26 render: function (msg, opts) {
27 if (!isRenderable(msg)) return
28
29 var element = api.message.html.layout(msg, extend({
30 miniContent: messageContent(msg),
31 layout: 'mini'
32 }, opts))
33
34 return api.message.html.decorate(element, {
35 msg
36 })
37 }
38 })
39
40 function messageContent (msg) {
41 var following = msg.value.content.following
42 var blocking = msg.value.content.blocking
43
44 if (typeof blocking === 'boolean') {
45 return [
46 blocking ? i18n('blocked ') : i18n('unblocked '),
47 api.profile.html.person(msg.value.content.contact)
48 ]
49 } else {
50 return [
51 following ? i18n('followed ') : i18n('unfollowed '),
52 api.profile.html.person(msg.value.content.contact)
53 ]
54 }
55 }
56
57function isRenderable(msg) {
58 if (msg.value.content.type !== 'contact') return
59 else if (!ref.isFeed(msg.value.content.contact)) return
60 else if (typeof msg.value.content.following !== 'boolean' && typeof msg.value.content.blocking !== 'boolean') return
61 return true;
62}
63
64}
65

Built with git-ssb-web