Files: 4d9f238ff73f7136cd292da88f06c17fe1a8c445 / lib / depject / message / html / render / attending.js
1319 bytesRaw
1 | const h = require('mutant/h') |
2 | const nest = require('depnest') |
3 | const extend = require('xtend') |
4 | const ref = require('ssb-ref') |
5 | const addContextMenu = require('../../../../message/html/decorate/context-menu') |
6 | |
7 | exports.needs = nest({ |
8 | 'message.html': { |
9 | layout: 'first' |
10 | }, |
11 | 'about.obs.latestValue': 'first' |
12 | }) |
13 | |
14 | exports.gives = nest('message.html', { |
15 | canRender: true, |
16 | render: true |
17 | }) |
18 | |
19 | exports.create = function (api) { |
20 | return nest('message.html', { |
21 | canRender: isRenderable, |
22 | render: function about (msg, opts) { |
23 | if (!isRenderable(msg)) return |
24 | |
25 | const action = msg.value.content.attendee.remove ? 'can\'t attend' : 'is attending' |
26 | const target = msg.value.content.about |
27 | const title = api.about.obs.latestValue(target, 'title') |
28 | const element = api.message.html.layout(msg, extend({ |
29 | showActions: true, |
30 | miniContent: [action, ' ', h('a', { |
31 | href: target |
32 | }, title)], |
33 | layout: 'mini' |
34 | }, opts)) |
35 | |
36 | return addContextMenu(element, { |
37 | msg |
38 | }) |
39 | } |
40 | }) |
41 | |
42 | function isRenderable (msg) { |
43 | if (msg.value.content.type !== 'about') return |
44 | if (!ref.isMsg(msg.value.content.about)) return |
45 | if (!msg.value.content.attendee) return |
46 | if (msg.value.content.attendee.link !== msg.value.author) return |
47 | return true |
48 | } |
49 | } |
50 |
Built with git-ssb-web