Files: a69b107634854812d8fe243ff4f0ce3e4e19bd8c / plugs / message / html / render / following.js
1695 bytesRaw
1 | var h = require('mutant/h') |
2 | var nest = require('depnest') |
3 | var extend = require('xtend') |
4 | var ref = require('ssb-ref') |
5 | |
6 | exports.needs = nest({ |
7 | 'message.html': { |
8 | decorate: 'reduce', |
9 | layout: 'first' |
10 | }, |
11 | 'profile.html.person': 'first', |
12 | 'intl.sync.i18n': 'first', |
13 | }) |
14 | |
15 | exports.gives = nest('message.html', { |
16 | canRender: true, |
17 | render: true |
18 | }) |
19 | |
20 | exports.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 (blocking === true) { |
43 | return [ |
44 | i18n('blocked '), api.profile.html.person(msg.value.content.contact) |
45 | ] |
46 | } else if (typeof following === 'boolean') { |
47 | return [ |
48 | following ? i18n('followed ') : i18n('unfollowed '), |
49 | api.profile.html.person(msg.value.content.contact) |
50 | ] |
51 | } else if (blocking === false) { |
52 | return [ |
53 | i18n('unblocked '), api.profile.html.person(msg.value.content.contact) |
54 | ] |
55 | } |
56 | } |
57 | |
58 | function isRenderable(msg) { |
59 | if (msg.value.content.type !== 'contact') return undefined |
60 | else if (!ref.isFeed(msg.value.content.contact)) return undefined |
61 | else if (typeof msg.value.content.following !== 'boolean' && typeof msg.value.content.blocking !== 'boolean') return undefined |
62 | return true; |
63 | } |
64 | |
65 | } |
66 |
Built with git-ssb-web