git ssb

16+

Dominic / patchbay



Tree: eb21e4b7a7fca80a53458db55d0335b76ddcb0e8

Files: eb21e4b7a7fca80a53458db55d0335b76ddcb0e8 / app / html / settings / friend-pub.js

2644 bytesRaw
1const nest = require('depnest')
2const { h, computed, onceTrue, Value } = require('mutant')
3
4exports.gives = nest({
5 'app.html.settings': true
6})
7
8exports.needs = nest({
9 'about.html.image': 'first',
10 'about.obs.name': 'first',
11 'app.html.settings': 'map',
12 'sbot.obs.connection': 'first',
13 'settings.obs.get': 'first',
14 'settings.sync.set': 'first'
15})
16
17exports.create = function (api) {
18 return nest({
19 'app.html.settings': pubHopConnections
20 })
21
22 function pubHopConnections () {
23 const pubHopAll = 3
24 const pubHopConnections = api.settings.obs.get('patchbay.pubHopConnections', pubHopAll)
25 const changeHopSettings = (ev) => {
26 api.settings.sync.set({ patchbay: { pubHopConnections: parseInt(ev.target.value) }})
27
28 alert("please restart patchbay for this to take effect")
29 }
30
31 let pubs = Value({})
32
33 const pubHopConnectionsText = computed([pubHopConnections], function(pubHopConnections) {
34 pubHopConnections = parseInt(pubHopConnections)
35 onceTrue(api.sbot.obs.connection, sbot => {
36 if (pubHopConnections == pubHopAll)
37 pubs.set([])
38 else
39 sbot.friendPub.pubsWithinHops(pubHopConnections, (err, pubsInHops) => {
40 pubs.set(pubsInHops)
41 })
42 })
43
44 switch (pubHopConnections) {
45 case 0:
46 return "Own pub only"
47 case 1:
48 return "Pubs run by friends"
49 case 2:
50 return "Pubs run by friends of friends"
51 default: // 3
52 return "All pubs"
53 }
54 })
55
56 function pubImageLink (id, ownerId) {
57 return h('a', {
58 href: id,
59 title: computed([api.about.obs.name(id), api.about.obs.name(ownerId)], (name, ownerName) => {
60 return '@' + name + ', owner ' + ownerName
61 })
62 }, api.about.html.image(id))
63 }
64
65 const pubsHtml = computed([pubs], function(pubs) {
66 return Object.values(pubs).map(pub => pubImageLink(pub.id, pub.owner))
67 })
68
69 return {
70 title: 'Pub within hops connections',
71 body: h('FriendPub', [
72 h('div', [
73 'Only connect to pubs run by a peer within a certain number of hops',
74 h('input', {
75 type: 'range',
76 attributes: { list: 'datalist' },
77 min: 0,
78 max: 3,
79 value: pubHopConnections,
80 'ev-change': changeHopSettings
81 }),
82 h('datalist', { id: 'datalist' }, [
83 h('option', 0),
84 h('option', 1),
85 h('option', 2),
86 h('option', 3)]),
87 h('div', ["Current setting: ", pubHopConnectionsText]),
88 h('div', pubsHtml)
89 ])
90 ])
91 }
92 }
93}
94

Built with git-ssb-web