Files: 8de1edb8454d207982be32e1b3b5a6e3497f19ce / modules / page / html / render / private.js
1364 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, { |
34 | prepend: [compose], |
35 | bumpFilter: (msg) => msg.value.content.type !== 'vote' |
36 | }) |
37 | |
38 | view.setAnchor = function (data) { |
39 | if (data && data.compose && data.compose.to) { |
40 | var name = api.about.obs.name(data.compose.to) |
41 | compose.setText(`[@${name()}](${data.compose.to})\n\n`, true) |
42 | window.requestAnimationFrame(() => { |
43 | compose.focus() |
44 | }) |
45 | } |
46 | } |
47 | |
48 | return view |
49 | }) |
50 | } |
51 |
Built with git-ssb-web