git ssb

10+

Matt McKegg / patchwork



Tree: 159e6917c8854f4e90d61a60d2d82e6bd235b6e1

Files: 159e6917c8854f4e90d61a60d2d82e6bd235b6e1 / modules / page / html / render / private.js

1491 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]
26
27 msg.mentions.forEach(mention => {
28 mention = typeof mention === 'string' ? mention : mention.link
29 if (ref.isFeed(mention) && !msg.recps.includes(mention)) {
30 msg.recps.push(mention)
31 }
32 })
33
34 return msg
35 },
36 placeholder: i18n('Write a private message')
37 })
38
39 var view = api.feed.html.rollup(api.feed.pull.private, {
40 prepend: [compose],
41 bumpFilter: (msg) => msg.value.content.type !== 'vote'
42 })
43
44 view.setAnchor = function (data) {
45 if (data && data.compose && data.compose.to) {
46 var name = api.about.obs.name(data.compose.to)
47 compose.setText(`[@${name()}](${data.compose.to})\n\n`, true)
48 window.requestAnimationFrame(() => {
49 compose.focus()
50 })
51 }
52 }
53
54 return view
55 })
56}
57

Built with git-ssb-web