git ssb

10+

Matt McKegg / patchwork



Tree: 4557a7bfe93e3b06fc8154b38538b6b926f8c512

Files: 4557a7bfe93e3b06fc8154b38538b6b926f8c512 / plugs / message / html / render / about.js

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

Built with git-ssb-web