Files: 17e939d97aceac4619d4a5ad7698fea625d570c7 / message / html / shares.js
2137 bytesRaw
1 | var { h, computed, when, Value, resolve } = require('mutant') |
2 | var nest = require('depnest') |
3 | |
4 | |
5 | exports.needs = nest({ |
6 | 'keys.sync.id': 'first', |
7 | 'message.obs.shares': 'first', |
8 | 'sbot.async.publish': 'first', |
9 | 'translations.sync.strings': 'first', |
10 | 'app.html.lightbox': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('message.html.shares') |
14 | |
15 | exports.create = (api) => { |
16 | return nest('message.html.shares', function shares(msg) { |
17 | var id = api.keys.sync.id() |
18 | var shares = api.message.obs.shares(msg.key) |
19 | |
20 | var iShared = computed(shares, shares => shares.includes(id)) |
21 | var count = computed(shares, shares => shares.length ? shares.length : '') |
22 | var isOpen = Value(false) |
23 | var strings = api.translations.sync.strings() |
24 | var captionRaw = Value('') |
25 | var captionInput = h('textarea#caption', { |
26 | style: { |
27 | width: '90%' |
28 | }, |
29 | placeholder: strings.share.captionPlaceholder, |
30 | value: captionRaw, |
31 | 'ev-input': () => captionRaw.set(captionInput.value), |
32 | }) |
33 | |
34 | var confirmationDialog = h('div.dialog', [ |
35 | h('div.message', [ |
36 | h('p', strings.share.shareLabel), |
37 | ]), |
38 | h('div.form', [ |
39 | captionInput |
40 | ]), |
41 | h('div.actions', [ |
42 | h('Button', { 'ev-click': () => isOpen.set(false) }, strings.userShow.action.cancel), |
43 | h('Button -primary', { 'ev-click': () => publishShare(msg, resolve(captionRaw), () => isOpen.set(false)) }, strings.share.action.share) |
44 | ]) |
45 | ]) |
46 | |
47 | var lb = api.app.html.lightbox(confirmationDialog, isOpen) |
48 | |
49 | |
50 | return h('Shares', { 'ev-click': () => isOpen.set(!iShared()) }, [ |
51 | h('i.fa.fa-retweet', { className: when(iShared, '', 'faint') }), |
52 | h('div.count', count), |
53 | lb |
54 | ]) |
55 | }) |
56 | |
57 | function publishShare(msg, text, cb) { |
58 | var share = { |
59 | type: 'share', |
60 | share: { link: msg.key, content: "blog", text: text } |
61 | } |
62 | if (msg.value.content.recps) { |
63 | share.recps = msg.value.content.recps.map(function (e) { |
64 | return e && typeof e !== 'string' ? e.link : e |
65 | }) |
66 | share.private = true |
67 | } |
68 | console.log("publishing share", share) |
69 | api.sbot.async.publish(share, cb) |
70 | } |
71 | } |
72 |
Built with git-ssb-web