git ssb

1+

Daan Patchwork / patchwork



Tree: 4d9f238ff73f7136cd292da88f06c17fe1a8c445

Files: 4d9f238ff73f7136cd292da88f06c17fe1a8c445 / lib / depject / message / html / render / following.js

1686 bytesRaw
1const nest = require('depnest')
2const extend = require('xtend')
3const ref = require('ssb-ref')
4const addContextMenu = require('../../../../message/html/decorate/context-menu')
5
6exports.needs = nest({
7 'message.html': {
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 const element = api.message.html.layout(msg, extend({
27 miniContent: messageContent(msg),
28 layout: 'mini'
29 }, opts))
30
31 return addContextMenu(element, {
32 msg
33 })
34 }
35 })
36
37 function messageContent (msg) {
38 const following = msg.value.content.following
39 const 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