git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 8665e16c051517ccfc22cad096c48bf2e476f5b7

Files: 8665e16c051517ccfc22cad096c48bf2e476f5b7 / plugs / message / html / render / about.js

2128 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 'about.html.link': 'first',
14 'about.obs.name': 'first',
15 'blob.sync.url': 'first'
16
17})
18
19exports.gives = nest('message.html.render')
20
21exports.create = function (api) {
22 return nest('message.html.render', function about (msg, opts) {
23 if (msg.value.content.type !== 'about') return
24 if (!msg.value.content.about) return
25
26 var c = msg.value.content
27 var self = msg.value.author === c.about
28 var content = []
29
30 if (c.name) {
31 var target = api.about.html.link(c.about, `@${c.name}`)
32 content.push(computed([self, api.about.obs.name(c.about), c.name], (self, a, b) => {
33 if (self) {
34 return ['self identifies as ', target]
35 } else if (a === b) {
36 return ['identified ', api.about.html.link(c.about)]
37 } else {
38 return ['identifies ', api.about.html.link(c.about), ' as ', target]
39 }
40 }))
41 }
42
43 if (c.image) {
44 if (!content.length) {
45 var imageAction = self ? 'self assigned a display image' : ['assigned a display image to ', api.about.html.link(c.about)]
46 content.push(imageAction)
47 }
48
49 content.push(h('a AboutImage', {
50 href: c.about
51 }, [
52 h('img', {src: api.blob.sync.url(c.image)})
53 ]))
54 }
55
56 var elements = []
57
58 if (content.length) {
59 var element = api.message.html.layout(msg, extend({
60 content, layout: 'mini'
61 }, opts))
62 elements.push(api.message.html.decorate(element, { msg }))
63 }
64
65 if (c.description) {
66 elements.push(api.message.html.decorate(api.message.html.layout(msg, extend({
67 content: [
68 self ? 'self assigned a description' : ['assigned a description to ', api.about.html.link(c.about)],
69 api.message.html.markdown(c.description)
70 ],
71 layout: 'mini'
72 }, opts)), { msg }))
73 }
74
75 return elements
76 })
77}
78

Built with git-ssb-web