git ssb

1+

Daan Patchwork / patchwork



Tree: 000777db8b0f37f6c1d99fc608e4395c87512348

Files: 000777db8b0f37f6c1d99fc608e4395c87512348 / lib / depject / message / sheet / preview.js

3416 bytesRaw
1const h = require('mutant/h')
2const nest = require('depnest')
3const when = require('mutant/when')
4const emoji = require('node-emoji')
5const displaySheet = require('../../../sheet/display')
6
7exports.needs = nest({
8 'message.html.render': 'first',
9 'intl.sync.i18n': 'first',
10 'intl.sync.i18n_n': 'first'
11})
12
13exports.gives = nest('message.sheet.preview')
14
15exports.create = function (api) {
16 const i18n = api.intl.sync.i18n
17 const plural = api.intl.sync.i18n_n
18
19 return nest('message.sheet.preview', function (msg, cb) {
20 displaySheet(function (close) {
21 const isPrivate = msg.value.private
22 const isRoot = !msg.value.content.root
23 const exists = !!msg.key
24 const recps = (msg.value.content.recps || []).filter(id => id !== msg.value.author)
25
26 // handle too many private recipients
27 if (isPrivate && recps.length >= 7) {
28 return {
29 content: [
30 h('h2', [i18n('Too many recipients')]),
31 h('div.info', [
32 h('p', [
33 i18n('Private messages can only be addressed to up to 7 people. '),
34 plural('Your message has %s recipients, including yourself', recps.length)
35 ]),
36 h('p', [i18n('Please go back and remove some of the recipients.')])
37 ])
38 ],
39 classList: ['-private'],
40 footer: [h('button -cancel', { 'ev-click': cancel }, i18n('Close'))]
41 }
42 }
43
44 const messageElement = api.message.html.render(msg)
45
46 // allow inspecting of raw message that is about to be sent
47 messageElement.msg = msg
48
49 const cancelButton = h('button -cancel', { 'ev-click': cancel }, i18n('Cancel'))
50 return {
51 content: [
52 messageElement
53 ],
54 classList: [
55 when(isPrivate, '-private', '-public')
56 ],
57 footer: [
58 when(isPrivate,
59 h('span.Emoji', emoji.get('closed_lock_with_key')),
60 h('span.Emoji', emoji.get('globe_with_meridians'))
61 ),
62 when(isPrivate,
63 h('div.info -private', [
64 recps.length
65 ? when(!exists && isRoot,
66 plural('Only visible to you and %s people that have been mentioned', recps.length),
67 plural('Only visible to you and %s other thread participants', recps.length)
68 )
69 : i18n('This message will only be visible to you')
70 ]),
71 h('div.info -public', [
72 when(msg.publiclyEditable,
73 i18n('This message will be public and can be edited by anyone'),
74 i18n('This message will be public and cannot be edited or deleted')
75 )
76 ])
77 ),
78 h('button -save', { 'ev-click': publish }, i18n('Confirm')),
79 cancelButton
80 ],
81 onMount: () => {
82 cancelButton.focus()
83 },
84 attributes: {
85 'ev-keydown': ev => {
86 if (ev.key === 'Enter' && (ev.ctrlKey || ev.metaKey)) {
87 publish()
88 ev.preventDefault()
89 } else if (ev.key === 'Escape') {
90 cancel()
91 ev.preventDefault()
92 }
93 }
94 }
95 }
96
97 function publish () {
98 close()
99 cb(null, true)
100 }
101
102 function cancel () {
103 close()
104 cb(null, false)
105 }
106 })
107 return true
108 })
109}
110

Built with git-ssb-web