Files: ec22930fce654eefee73dc9cc02061810988d4bd / modules / page / html / render / private.js
1291 bytesRaw
1 | var nest = require('depnest') |
2 | var ref = require('ssb-ref') |
3 | |
4 | exports.needs = nest({ |
5 | 'feed.html.rollup': 'first', |
6 | 'feed.pull.private': 'first', |
7 | 'message.html.compose': 'first', |
8 | 'keys.sync.id': 'first', |
9 | 'intl.sync.i18n': 'first', |
10 | 'about.obs.name': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('page.html.render') |
14 | |
15 | exports.create = function (api) { |
16 | return nest('page.html.render', function channel (path) { |
17 | if (path !== '/private') return |
18 | |
19 | const i18n = api.intl.sync.i18n |
20 | var id = api.keys.sync.id() |
21 | var compose = api.message.html.compose({ |
22 | meta: {type: 'post'}, |
23 | isPrivate: true, |
24 | prepublish: function (msg) { |
25 | msg.recps = [id].concat(msg.mentions).filter(function (e) { |
26 | return ref.isFeed(typeof e === 'string' ? e : e.link) |
27 | }) |
28 | return msg |
29 | }, |
30 | placeholder: i18n('Write a private message') |
31 | }) |
32 | |
33 | var view = api.feed.html.rollup(api.feed.pull.private, { prepend: [compose] }) |
34 | |
35 | view.setAnchor = function (data) { |
36 | if (data && data.compose && data.compose.to) { |
37 | var name = api.about.obs.name(data.compose.to) |
38 | compose.setText(`[${name()}](${data.compose.to})\n\n`, true) |
39 | window.requestAnimationFrame(() => { |
40 | compose.focus() |
41 | }) |
42 | } |
43 | } |
44 | |
45 | return view |
46 | }) |
47 | } |
48 |
Built with git-ssb-web