git ssb

2+

mixmix / ticktack



Tree: bd34a8d22b29ba32048c072fecfaaa2d0fb0af0f

Files: bd34a8d22b29ba32048c072fecfaaa2d0fb0af0f / message / html / webshares.js

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

Built with git-ssb-web