git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 5e06ff6caacaf2d29ccced2d9c39800bbf1923de

Files: 5e06ff6caacaf2d29ccced2d9c39800bbf1923de / plugs / message / html / render / about.js

2198 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})
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 (!ref.isFeed(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.profile.html.person(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.profile.html.person(c.about)]
37 } else {
38 return ['identifies ', api.profile.html.person(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.profile.html.person(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.profile.html.person(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