git ssb

2+

mixmix / ticktack



Tree: 6e4c70b8d1f36db6aa1bba43786d168752b19240

Files: 6e4c70b8d1f36db6aa1bba43786d168752b19240 / message / html / webshares.js

2878 bytesRaw
1var { h, computed, when, Value, resolve } = require('mutant')
2var nest = require('depnest')
3var { clipboard, shell } = require('electron')
4
5exports.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 'settings.sync.get': '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.fa-share-alt', { className: when(iShared, '', 'faint') }),
46 h('div.count', count),
47 lb
48 ])
49 })
50
51 function publishShare(msg, action) {
52 var sharingScope = api.settings.sync.get('websharingmetrics')
53 var url = `http://share2.ticktack.im:8807/${msg.key}`
54 var share = {
55 type: 'share',
56 share: { link: msg.key, content: "blog", url: url }
57 }
58 // if it was a private message, then share as private ...
59 if (msg.value.content.recps) {
60 share.recps = msg.value.content.recps.map(function (e) {
61 return e && typeof e !== 'string' ? e.link : e
62 })
63 share.private = true
64 } else {
65 // ... else obey configuration settings.
66 switch (sharingScope) {
67 case "private":
68 share.private = true
69 break
70 case "author":
71 share.recps = [
72 id,
73 msg.value.author
74 ]
75 share.private = true
76 break
77 case "public":
78 default:
79 break
80 }
81 }
82 api.sbot.async.publish(share)
83
84 if (action == "copy") {
85 console.log("copying to clipboard")
86 clipboard.writeText(url)
87 } else {
88 console.log("opening external")
89 shell.openExternal(url, err => console.log("error", err))
90 }
91 }
92}
93

Built with git-ssb-web