git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Tree: 19bf91406114f251a3218b5c45c4a69e95d11f84

Files: 19bf91406114f251a3218b5c45c4a69e95d11f84 / modules / page / html / render / private.js

1291 bytesRaw
1var nest = require('depnest')
2var ref = require('ssb-ref')
3
4exports.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
13exports.gives = nest('page.html.render')
14
15exports.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