git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 7a3e6e95924f553c415e339923bd07c0bebef60e

Files: 7a3e6e95924f553c415e339923bd07c0bebef60e / plugs / message / html / render / about.js

2260 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 showActions: true,
61 content,
62 layout: 'mini'
63 }, opts))
64 elements.push(api.message.html.decorate(element, { msg }))
65 }
66
67 if (c.description) {
68 elements.push(api.message.html.decorate(api.message.html.layout(msg, extend({
69 showActions: true,
70 content: [
71 self ? 'self assigned a description' : ['assigned a description to ', api.profile.html.person(c.about)],
72 api.message.html.markdown(c.description)
73 ],
74 layout: 'mini'
75 }, opts)), { msg }))
76 }
77
78 return elements
79 })
80}
81

Built with git-ssb-web