Commit 265c3f6951545f5768f03154d5c6890be9aa8771
display about messages
Matt McKegg committed on 2/17/2017, 12:43:16 PMParent: 7aa2225778216a166b0fbc9e191bffe8f218c242
Files changed
plugs/message/html/render/about.js | added |
styles/about-image.mcss | added |
plugs/message/html/render/about.js | ||
---|---|---|
@@ -1,0 +1,61 @@ | ||
1 … | +var h = require('mutant/h') | |
2 … | +var computed = require('mutant/computed') | |
3 … | +var nest = require('depnest') | |
4 … | +var extend = require('xtend') | |
5 … | + | |
6 … | +exports.needs = nest({ | |
7 … | + 'message.html': { | |
8 … | + decorate: 'reduce', | |
9 … | + layout: 'first' | |
10 … | + }, | |
11 … | + 'keys.sync.id': 'first', | |
12 … | + 'about.html.link': 'first', | |
13 … | + 'about.obs.name': 'first', | |
14 … | + 'blob.sync.url': 'first' | |
15 … | + | |
16 … | +}) | |
17 … | + | |
18 … | +exports.gives = nest('message.html.render') | |
19 … | + | |
20 … | +exports.create = function (api) { | |
21 … | + return nest('message.html.render', function about (msg, opts) { | |
22 … | + if (msg.value.content.type !== 'about') return | |
23 … | + if (!msg.value.content.about) return | |
24 … | + | |
25 … | + var c = msg.value.content | |
26 … | + var self = msg.value.author === c.about | |
27 … | + var content = [] | |
28 … | + | |
29 … | + if (c.name) { | |
30 … | + var target = api.about.html.link(c.about, `@${c.name}`) | |
31 … | + content.push(computed([self, api.about.obs.name(c.about), c.name], (self, a, b) => { | |
32 … | + if (self) { | |
33 … | + return ['self identifies as ', target] | |
34 … | + } else if (a === b) { | |
35 … | + return ['identified ', api.about.html.link(c.about)] | |
36 … | + } else { | |
37 … | + return ['identifies ', api.about.html.link(c.about), ' as ', target] | |
38 … | + } | |
39 … | + })) | |
40 … | + } | |
41 … | + | |
42 … | + if (c.image) { | |
43 … | + if (!content.length) { | |
44 … | + var imageAction = self ? 'self assigned a display image' : ['assigned a display image to ', api.about.html.link(c.about)] | |
45 … | + content.push(imageAction) | |
46 … | + } | |
47 … | + | |
48 … | + content.push(h('a AboutImage', { | |
49 … | + href: c.about | |
50 … | + }, [ | |
51 … | + h('img', {src: api.blob.sync.url(c.image)}) | |
52 … | + ])) | |
53 … | + } | |
54 … | + | |
55 … | + var element = api.message.html.layout(msg, extend({ | |
56 … | + content, layout: 'mini' | |
57 … | + }, opts)) | |
58 … | + | |
59 … | + return api.message.html.decorate(element, { msg }) | |
60 … | + }) | |
61 … | +} |
Built with git-ssb-web