git ssb

16+

Dominic / patchbay



Tree: ca490d878aac9b2af156d85f1eece0bb9c20f1d6

Files: ca490d878aac9b2af156d85f1eece0bb9c20f1d6 / modules_basic / about.js

1520 bytesRaw
1var h = require('../h')
2
3exports.needs = {
4 blob_url: 'first'
5}
6
7exports.gives = {
8 mcss: true,
9 message_content: true
10}
11
12var mcss = `
13 About {
14 display: flex
15 flex-wrap: wrap
16
17 header {
18 margin-right: .4rem
19 }
20 }
21`
22
23exports.create = function (api) {
24 return {
25 message_content,
26 mcss: function () { return mcss }
27 }
28
29 function message_content (msg) {
30 if(msg.value.content.type !== 'about') return
31
32 var { value } = msg
33 var { content: about, author: authorId } = value
34 var { about: aboutId, name, image, description } = about
35 // TODO does about default to the message author?
36 // var { about: aboutId = authorId, name, image, description } = about
37
38 return h('About', [
39 verb({ aboutId, authorId: msg.value.author }),
40 profile({ aboutId, name, image, description })
41 ])
42 }
43
44 function profile ({ aboutId, name, image, description }) {
45 return h('div', [
46 name
47 ? h('a', {href:'#'+aboutId}, name)
48 : null,
49 image
50 ? h('a', {href:'#'+aboutId}, h('img.avatar--fullsize', {src: api.blob_url(image)}))
51 : null,
52 description || null
53 ])
54 }
55}
56
57
58function verb ({ aboutId, authorId }) {
59 var content = authorId === aboutId
60 ? 'self-identifies as'
61 : ['identifies ', idLink(aboutId), ' as']
62
63 return h('header', content)
64}
65
66function idLink (id) {
67 if (!id) return null
68
69 return h('a', {href:'#'+id}, id.slice(0,9) + '...')
70}
71
72function asLink (ln) {
73 return typeof ln === 'string' ? ln : ln.link
74}
75
76

Built with git-ssb-web