Files: 528c7d732181d5b5524373c1b35cd5dbde446f1f / plugs / message / html / render / following.js
1483 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.render') |
16 | |
17 | exports.create = function (api) { |
18 | const i18n = api.intl.sync.i18n |
19 | return nest('message.html.render', function renderMessage (msg, opts) { |
20 | if (msg.value.content.type !== 'contact') return |
21 | if (!ref.isFeed(msg.value.content.contact)) return |
22 | if (typeof msg.value.content.following !== 'boolean' && typeof msg.value.content.blocking !== 'boolean') return |
23 | |
24 | var element = api.message.html.layout(msg, extend({ |
25 | miniContent: messageContent(msg), |
26 | layout: 'mini' |
27 | }, opts)) |
28 | |
29 | return api.message.html.decorate(element, { msg }) |
30 | }) |
31 | |
32 | function messageContent (msg) { |
33 | var following = msg.value.content.following |
34 | var blocking = msg.value.content.blocking |
35 | |
36 | if (blocking === true) { |
37 | return [ |
38 | i18n('blocked '), api.profile.html.person(msg.value.content.contact) |
39 | ] |
40 | } else if (typeof following === 'boolean') { |
41 | return [ |
42 | following ? i18n('followed ') : i18n('unfollowed '), |
43 | api.profile.html.person(msg.value.content.contact) |
44 | ] |
45 | } else if (blocking === false) { |
46 | return [ |
47 | i18n('unblocked '), api.profile.html.person(msg.value.content.contact) |
48 | ] |
49 | } |
50 | } |
51 | } |
52 |
Built with git-ssb-web