git ssb

16+

Dominic / patchbay



Tree: f908da1b6acb8d66648da8935886433ec6af0c9c

Files: f908da1b6acb8d66648da8935886433ec6af0c9c / app / html / settings / friend-hops.js

2407 bytesRaw
1const nest = require('depnest')
2const { h, computed, onceTrue, Value, watch } = require('mutant')
3const merge = require('lodash/merge')
4
5exports.gives = nest({
6 'app.html.settings': true
7})
8
9exports.needs = nest({
10 'app.html.settings': 'map',
11 'config.sync.get': 'first',
12 'config.sync.getCustom': 'first',
13 'config.sync.setCustom': 'first'
14})
15
16const friendsHops = 2
17exports.create = function (api) {
18 return nest({
19 'app.html.settings': friendHopsConnections
20 })
21
22 function friendHopsConnections () {
23 let hops = Value(api.config.sync.get('friends.hops', friendsHops))
24 hops.initial = hops()
25
26 watch(hops, hops => {
27 const intHops = parseInt(hops)
28 updateConfig(intHops)
29 })
30
31 return {
32 title: 'Friend Hops',
33 body: h('FriendHops', [
34 h('div.description', [
35 'Specify whose content you replicate, and thus the size and shape of your network.'
36 ]),
37 h('div.slider', [
38 h('datalist', { id: 'friends-hop-datalist' }, [
39 h('option', { value: 0, label: '0 - Only your messages' }),
40 h('option', { value: 1, label: '1 - You and your friend\'s messages' }),
41 h('option', { value: 2, label: '2 - You, your friend\'s, and your friend\'s friend\'s messages' }),
42 h('option', { value: 3, label: '3 - You, your friend\'s, your friend\'s friend\'s, and their friend\'s messages' })
43 ]),
44 h('input', {
45 type: 'range',
46 attributes: { list: 'friends-hop-datalist' },
47 min: 0,
48 max: 3,
49 value: hops,
50 'ev-change': (ev) => hops.set(ev.target.value)
51 })
52 ]),
53 computed(hops, (_hops) => {
54 if (_hops === hops.initial) return
55 return h('div.alert', [
56 h('i.fa.fa-warning'),
57 ' please restart patchbay for this to take effect'
58 ])
59 }),
60 ])
61 }
62
63 function updateHops (hops) {
64 onceTrue(api.sbot.obs.connection, sbot => {
65 if (hops === go) pubs.set({})
66 else {
67 sbot.friendPub.pubsWithinHops(hops, (_, pubsInHops) => {
68 pubs.set(pubsInHops)
69 })
70 }
71 })
72 }
73 }
74
75 function updateConfig (hops) {
76 const configCustom = api.config.sync.getCustom()
77
78 const next = merge({}, configCustom, {
79 friends: { hops }
80 })
81
82 api.config.sync.setCustom(next)
83 }
84}
85

Built with git-ssb-web