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