git ssb

10+

Matt McKegg / patchwork



Tree: 78c1c971ce74b33515d5785a53347186166297db

Files: 78c1c971ce74b33515d5785a53347186166297db / plugs / message / html / render / following.js

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

Built with git-ssb-web