git ssb

16+

Dominic / patchbay



Tree: 11a18b6002794331feb9f11d67fbfa08986633e9

Files: 11a18b6002794331feb9f11d67fbfa08986633e9 / message / html / render / about.js

2250 bytesRaw
1const nest = require('depnest')
2const extend = require('xtend')
3const { isFeed, isBlob } = require('ssb-ref')
4const { h } = require('mutant')
5
6exports.gives = nest('message.html.render')
7
8exports.needs = nest({
9 'about.html.link': 'first',
10 'blob.sync.url': 'first',
11 'message.html': {
12 decorate: 'reduce',
13 layout: 'first'
14 }
15})
16
17exports.create = function (api) {
18 return nest('message.html.render', about)
19
20 function about (msg, opts) {
21 // TODO write schemas for different sorts of about message
22 if (msg.value.content.type !== 'about') return
23
24 const { name, description, image, about } = msg.value.content
25 if (!name && !description && !image) return
26 if (!isFeed(about)) return
27 // mix : note this looked like it was intended to deal with all about message but the logic sucked
28 // I've made it explicitly handle only about messages for people, as that's what it was actually doing
29
30 const element = api.message.html.layout(msg, extend({
31 content: renderContent(msg),
32 layout: 'default'
33 }, opts))
34
35 return api.message.html.decorate(element, { msg })
36 }
37
38 function renderContent (msg) {
39 const { author, content } = msg.value
40 var { about, link, name, description, image } = content
41 if (!about) return
42
43 // TODO : build better normalizers
44 if (image && isBlob(image.link)) image = image.link
45 about = about || link
46
47 const metaData = [
48 typeof name === 'string'
49 ? h('div', [ h('strong', 'Name: '), name ])
50 : undefined,
51 typeof description === 'string'
52 ? h('div', [ h('strong', 'Description: '), description ])
53 : undefined,
54 typeof image === 'string'
55 ? h('img', { src: api.blob.sync.url(image), style: { 'margin-top': '.5rem' } })
56 : undefined
57 ]
58
59 // if (!isFeed(about)) {
60 // return [
61 // h('p', [
62 // 'Describes ',
63 // h('a', { href: about }, [about.slice(0, 7), '...']),
64 // ' as: '
65 // ]),
66 // ...metaData
67 // ]
68 // }
69
70 const target = author === about
71 ? 'themself '
72 : api.about.html.link(about)
73
74 return [
75 h('p', [
76 'Declares the following about ',
77 target
78 ]),
79 ...metaData
80 ]
81 }
82}
83

Built with git-ssb-web