Files: 4caad32bdc583a475ce49a53d2293c67c0f52cb6 / message / html / webshares.js
2340 bytesRaw
1 | var { h, computed, when, Value, resolve } = require('mutant') |
2 | var nest = require('depnest') |
3 | var { clipboard, shell } = require('electron') |
4 | |
5 | exports.needs = nest({ |
6 | 'keys.sync.id': 'first', |
7 | 'message.obs.webshares': 'first', |
8 | 'sbot.async.publish': 'first', |
9 | 'translations.sync.strings': 'first', |
10 | 'app.html.lightbox': 'first' |
11 | }) |
12 | |
13 | exports.gives = nest('message.html.webshares') |
14 | |
15 | exports.create = (api) => { |
16 | return nest('message.html.webshares', function shares(msg) { |
17 | var id = api.keys.sync.id() |
18 | var shares = api.message.obs.webshares(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 publishAndClose = (msg, action) => { |
25 | publishShare(msg, action) |
26 | isOpen.set(false) |
27 | } |
28 | var confirmationDialog = h('div.dialog', [ |
29 | h('div.message', [ |
30 | h('p', strings.share.externalShareLabel), |
31 | ]), |
32 | h('div.actions', [ |
33 | h('Button', { 'ev-click': () => isOpen.set(false) }, strings.userShow.action.cancel), |
34 | h('Button', { style: { 'margin-left': '10px', 'margin-right': '10px' }, 'ev-click': () => publishAndClose(msg, 'copy') }, strings.share.action.copy), |
35 | h('Button -primary', { 'ev-click': () => publishAndClose(msg, 'open') }, strings.share.action.open) |
36 | |
37 | ]) |
38 | ]) |
39 | |
40 | var lb = api.app.html.lightbox(confirmationDialog, isOpen) |
41 | |
42 | |
43 | return h('WebShares', { 'ev-click': () => isOpen.set(true) }, [ |
44 | h('i.fa.fa-share-alt', { className: when(iShared, '', 'faint') }), |
45 | h('div.count', count), |
46 | lb |
47 | ]) |
48 | }) |
49 | |
50 | function publishShare(msg, action) { |
51 | var url = `http://share2.ticktack.im:8807/${msg.key}` |
52 | var share = { |
53 | type: 'share', |
54 | share: { link: msg.key, content: "blog", url: url } |
55 | } |
56 | if (msg.value.content.recps) { |
57 | share.recps = msg.value.content.recps.map(function (e) { |
58 | return e && typeof e !== 'string' ? e.link : e |
59 | }) |
60 | share.private = true |
61 | } |
62 | api.sbot.async.publish(share) |
63 | |
64 | if (action == "copy") { |
65 | console.log("copying to clipboard") |
66 | clipboard.writeText(url) |
67 | } else { |
68 | console.log("opening external") |
69 | shell.openExternal(url, err => console.log("error", err)) |
70 | } |
71 | } |
72 | } |
73 |
Built with git-ssb-web