git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 5fb3695e2fdf7e69e3db206fd680def37464d8b6

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

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

Built with git-ssb-web