git ssb

10+

Matt McKegg / patchwork



Tree: 149c021b55e9957ad4d75789d066cf9794507064

Files: 149c021b55e9957ad4d75789d066cf9794507064 / plugs / message / html / render / about.js

2312 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
29 var miniContent = []
30 var content = []
31
32 if (c.name) {
33 var target = api.profile.html.person(c.about, c.name)
34 miniContent.push(computed([self, api.about.obs.name(c.about), c.name], (self, a, b) => {
35 if (self) {
36 return ['self identifies as "', target, '"']
37 } else if (a === b) {
38 return ['identified ', api.profile.html.person(c.about)]
39 } else {
40 return ['identifies ', api.profile.html.person(c.about), ' as "', target, '"']
41 }
42 }))
43 }
44
45 if (c.image) {
46 if (!miniContent.length) {
47 var imageAction = self ? 'self assigned a display image' : ['assigned a display image to ', api.profile.html.person(c.about)]
48 miniContent.push(imageAction)
49 }
50
51 content.push(h('a AboutImage', {
52 href: c.about
53 }, [
54 h('img', {src: api.blob.sync.url(c.image)})
55 ]))
56 }
57
58 var elements = []
59
60 if (miniContent.length) {
61 var element = api.message.html.layout(msg, extend({
62 showActions: true,
63 miniContent,
64 content,
65 layout: 'mini'
66 }, opts))
67 elements.push(api.message.html.decorate(element, { msg }))
68 }
69
70 if (c.description) {
71 elements.push(api.message.html.decorate(api.message.html.layout(msg, extend({
72 showActions: true,
73 miniContent: self ? 'self assigned a description' : ['assigned a description to ', api.profile.html.person(c.about)],
74 content: api.message.html.markdown(c.description),
75 layout: 'mini'
76 }, opts)), { msg }))
77 }
78
79 return elements
80 })
81}
82

Built with git-ssb-web