Files: e81b654394d0126eee1fae14be659f26ed3c31cc / overrides / patchcore / message / html / action / reply.js
977 bytesRaw
1 | var h = require('mutant/h') |
2 | var nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'intl.sync.i18n': 'first', |
6 | 'app.navigate': 'first', |
7 | 'message.sync.root': 'first' |
8 | |
9 | }) |
10 | |
11 | exports.gives = nest('message.html.action') |
12 | |
13 | exports.create = (api) => { |
14 | const i18n = api.intl.sync.i18n |
15 | return nest('message.html.action', function reply (msg) { |
16 | return h('a', { href: msg.key, anchor: 'reply', 'ev-click': {handleEvent, api, msg} }, i18n('Reply')) |
17 | }) |
18 | } |
19 | |
20 | function handleEvent (ev) { |
21 | var {api, msg} = this |
22 | var el = getMessageElement(ev.target) |
23 | |
24 | // HACK: if this is the last message in the list, reply to the root message |
25 | if (el && !el.nextElementSibling) { |
26 | api.app.navigate(api.message.sync.root(msg), 'reply') |
27 | ev.preventDefault() |
28 | } |
29 | } |
30 | |
31 | function getMessageElement (el) { |
32 | while (el && el.classList) { |
33 | if (el.classList.contains('Message') && el.parentNode && el.parentNode.classList.contains('replies')) { |
34 | return el |
35 | } |
36 | el = el.parentNode |
37 | } |
38 | } |
39 |
Built with git-ssb-web