git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 084b3a1ac6a56d27b2b3f19de106938f343209de

Files: 084b3a1ac6a56d27b2b3f19de106938f343209de / plugs / message / html / render / about.js

2677 bytesRaw
1var h = require('mutant/h')
2var computed = require('mutant/computed')
3var nest = require('depnest')
4var extend = require('xtend')
5var ref = require('ssb-ref')
6
7exports.needs = nest({
8 'message.html': {
9 decorate: 'reduce',
10 layout: 'first',
11 markdown: 'first'
12 },
13 'keys.sync.id': 'first',
14 'profile.html.person': 'first',
15 'about.obs.name': 'first',
16 'blob.sync.url': 'first',
17 'intl.sync.i18n': 'first'
18})
19
20exports.gives = nest('message.html', {
21 canRender: true,
22 render: true
23})
24
25exports.create = function (api) {
26 const i18n = api.intl.sync.i18n
27 return nest('message.html', {
28 canRender: isRenderable,
29 render: function (msg, opts) {
30 if (!isRenderable(msg)) return
31
32 var c = msg.value.content
33 var self = msg.value.author === c.about
34
35 var miniContent = []
36 var content = []
37
38 if (c.name) {
39 var target = api.profile.html.person(c.about, c.name)
40 miniContent.push(computed([self, api.about.obs.name(c.about), c.name], (self, a, b) => {
41 if (self) {
42 return [i18n('self identifies as '), '"', target, '"']
43 } else if (a === b) {
44 return [i18n('identified '), api.profile.html.person(c.about)]
45 } else {
46 return [i18n('identifies '), api.profile.html.person(c.about), i18n(' as "'), target, '"']
47 }
48 }))
49 }
50
51 if (c.image) {
52 if (!miniContent.length) {
53 var imageAction = self ? i18n('self assigned a display image') : [i18n('assigned a display image to '), api.profile.html.person(c.about)]
54 miniContent.push(imageAction)
55 }
56
57 content.push(h('a AboutImage', {
58 href: c.about
59 }, [
60 h('img', {src: api.blob.sync.url(c.image)})
61 ]))
62 }
63
64 var elements = []
65
66 if (miniContent.length) {
67 var element = api.message.html.layout(msg, extend({
68 showActions: true,
69 miniContent,
70 content,
71 layout: 'mini'
72 }, opts))
73 elements.push(api.message.html.decorate(element, { msg }))
74 }
75
76 if (c.description) {
77 elements.push(api.message.html.decorate(api.message.html.layout(msg, extend({
78 showActions: true,
79 miniContent: self ? i18n('self assigned a description') : [i18n('assigned a description to '), api.profile.html.person(c.about)],
80 content: api.message.html.markdown(c.description),
81 layout: 'mini'
82 }, opts)), { msg }))
83 }
84
85 return elements
86 }
87 })
88
89 function isRenderable (msg) {
90 if (msg.value.content.type !== 'about') return
91 if (!ref.isFeed(msg.value.content.about)) return
92 return true
93 }
94}
95

Built with git-ssb-web