Files: 9460421baaceb73b6c5819e685d30b5179c7e7c4 / plugs / message / html / render / following.js
1628 bytesRaw
1 | var nest = require('depnest') |
2 | var extend = require('xtend') |
3 | var ref = require('ssb-ref') |
4 | |
5 | exports.needs = nest({ |
6 | 'message.html': { |
7 | decorate: 'reduce', |
8 | layout: 'first' |
9 | }, |
10 | 'profile.html.person': 'first', |
11 | 'intl.sync.i18n': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('message.html', { |
15 | canRender: true, |
16 | render: true |
17 | }) |
18 | |
19 | exports.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