Commit cf76ccf1f9b18873a3627dbf29d4c76512e50482
disable subscription buttons when external sbot without channel plugin
mix irving committed on 2/15/2018, 3:59:52 AMParent: 400d6307414c6b622a0408421a7c1881697c893e
Files changed
app/html/sideNav/sideNavDiscovery.js | changed |
app/html/warning.js | changed |
app/index.js | changed |
app/obs/pluginWarnings.js | deleted |
app/obs/pluginsOk.js | added |
app/page/channelSubscriptions.js | changed |
channel/html/subscribe.js | changed |
channel/obs/subscribed.js | changed |
translations/en.js | changed |
app/html/sideNav/sideNavDiscovery.js | |||
---|---|---|---|
@@ -12,9 +12,9 @@ | |||
12 | 12 … | }) | |
13 | 13 … | ||
14 | 14 … | exports.needs = nest({ | |
15 | 15 … | 'app.html.scroller': 'first', | |
16 | - 'app.obs.pluginWarnings': 'first', | ||
16 … | + 'app.obs.pluginsOk': 'first', | ||
17 | 17 … | 'about.html.avatar': 'first', | |
18 | 18 … | 'about.obs.name': 'first', | |
19 | 19 … | 'feed.pull.private': 'first', | |
20 | 20 … | 'history.sync.push': 'first', | |
@@ -125,18 +125,18 @@ | |||
125 | 125 … | label: strings.blogIndex.title, | |
126 | 126 … | selected: isDiscoverLocation(location), | |
127 | 127 … | location: { page: 'blogIndex' } | |
128 | 128 … | }), | |
129 | - computed(api.app.obs.pluginWarnings(), isWarning => { | ||
129 … | + computed(api.app.obs.pluginsOk(), ok => { | ||
130 | 130 … | return [ | |
131 | 131 … | // My subscriptions | |
132 | 132 … | Option({ | |
133 | 133 … | imageEl: h('i', [ | |
134 | 134 … | h('img', { src: path.join(__dirname, '../../../assets', 'my_subscribed.png') }) | |
135 | 135 … | ]), | |
136 | 136 … | label: strings.subscriptions.user, | |
137 | 137 … | selected: location.page === 'channelSubscriptions' && location.scope === 'user', | |
138 | - disabled: isWarning, | ||
138 … | + disabled: !ok, | ||
139 | 139 … | location: { page: 'channelSubscriptions', scope: 'user' } | |
140 | 140 … | }), | |
141 | 141 … | ||
142 | 142 … | // Friends subscriptions | |
@@ -145,9 +145,9 @@ | |||
145 | 145 … | h('img', { src: path.join(__dirname, '../../../assets', 'friends_subscribed.png') }) | |
146 | 146 … | ]), | |
147 | 147 … | label: strings.subscriptions.friends, | |
148 | 148 … | selected: location.page === 'channelSubscriptions' && location.scope === 'friends', | |
149 | - disabled: isWarning, | ||
149 … | + disabled: !ok, | ||
150 | 150 … | location: { page: 'channelSubscriptions', scope: 'friends' } | |
151 | 151 … | }) | |
152 | 152 … | ] | |
153 | 153 … | }) |
app/html/warning.js | ||
---|---|---|
@@ -1,12 +1,12 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | -const { h, onceTrue } = require('mutant') | |
2 … | +const { h, watch } = require('mutant') | |
3 | 3 … | |
4 | 4 … | exports.gives = nest('app.html.warning') |
5 | 5 … | |
6 | 6 … | exports.needs = nest({ |
7 | 7 … | 'app.html.lightbox': 'first', |
8 | - 'app.obs.pluginWarnings': 'first', | |
8 … | + 'app.obs.pluginsOk': 'first', | |
9 | 9 … | 'translations.sync.strings': 'first' |
10 | 10 … | }) |
11 | 11 … | |
12 | 12 … | exports.create = (api) => { |
@@ -14,9 +14,9 @@ | ||
14 | 14 … | |
15 | 15 … | return nest('app.html.warning', function warning () { |
16 | 16 … | if (seenWarning) return |
17 | 17 … | |
18 | - const t = api.translations.sync.strings().pluginWarnings | |
18 … | + const t = api.translations.sync.strings().pluginsOk | |
19 | 19 … | |
20 | 20 … | const lightbox = api.app.html.lightbox( |
21 | 21 … | h('div', [ |
22 | 22 … | h('h1', t.heading), |
@@ -31,12 +31,12 @@ | ||
31 | 31 … | ) |
32 | 32 … | ]) |
33 | 33 … | ) |
34 | 34 … | |
35 | - onceTrue( | |
36 | - api.app.obs.pluginWarnings(), | |
37 | - shouldWarn => { | |
38 | - shouldWarn ? lightbox.open() : null | |
35 … | + watch( | |
36 … | + api.app.obs.pluginsOk(), | |
37 … | + isOk => { | |
38 … | + if (isOk === false) lightbox.open() | |
39 | 39 … | } |
40 | 40 … | ) |
41 | 41 … | |
42 | 42 … | return lightbox |
app/index.js | ||
---|---|---|
@@ -23,9 +23,9 @@ | ||
23 | 23 … | }, |
24 | 24 … | warning: require('./html/warning'), |
25 | 25 … | }, |
26 | 26 … | obs: { |
27 | - pluginWarnings: require('./obs/pluginWarnings'), | |
27 … | + pluginsOk: require('./obs/pluginsOk'), | |
28 | 28 … | }, |
29 | 29 … | page: { |
30 | 30 … | addressBook: require('./page/addressBook'), |
31 | 31 … | blogIndex: require('./page/blogIndex'), |
app/obs/pluginWarnings.js | ||
---|---|---|
@@ -1,29 +1,0 @@ | ||
1 | -const nest = require('depnest') | |
2 | -const { h, onceTrue, Value } = require('mutant') | |
3 | - | |
4 | -exports.gives = nest('app.obs.pluginWarnings') | |
5 | - | |
6 | -exports.needs = nest({ | |
7 | - 'sbot.obs.connection': 'first' | |
8 | -}) | |
9 | - | |
10 | -exports.create = (api) => { | |
11 | - var warnings = Value() | |
12 | - | |
13 | - return nest('app.obs.pluginWarnings', function warning () { | |
14 | - if (warnings() == undefined) checkForTrouble() | |
15 | - | |
16 | - return warnings | |
17 | - }) | |
18 | - | |
19 | - function checkForTrouble () { | |
20 | - onceTrue( | |
21 | - api.sbot.obs.connection, | |
22 | - sbot => { | |
23 | - if (!sbot.channel) warnings.set(true) // TODO could build a list of missing plugins + effects | |
24 | - else warnings.set(false) | |
25 | - } | |
26 | - ) | |
27 | - } | |
28 | -} | |
29 | - |
app/obs/pluginsOk.js | ||
---|---|---|
@@ -1,0 +1,29 @@ | ||
1 … | +const nest = require('depnest') | |
2 … | +const { h, onceTrue, Value } = require('mutant') | |
3 … | + | |
4 … | +exports.gives = nest('app.obs.pluginsOk') | |
5 … | + | |
6 … | +exports.needs = nest({ | |
7 … | + 'sbot.obs.connection': 'first' | |
8 … | +}) | |
9 … | + | |
10 … | +exports.create = (api) => { | |
11 … | + var ok = Value() | |
12 … | + | |
13 … | + return nest('app.obs.pluginsOk', function pluginsOk () { | |
14 … | + if (ok() == undefined) checkForTrouble() | |
15 … | + | |
16 … | + return ok | |
17 … | + }) | |
18 … | + | |
19 … | + function checkForTrouble () { | |
20 … | + onceTrue( | |
21 … | + api.sbot.obs.connection, | |
22 … | + sbot => { | |
23 … | + if (!sbot.channel) ok.set(false) // TODO could build a list of missing plugins + effects | |
24 … | + else ok.set(true) | |
25 … | + } | |
26 … | + ) | |
27 … | + } | |
28 … | +} | |
29 … | + |
app/page/channelSubscriptions.js | ||
---|---|---|
@@ -10,9 +10,9 @@ | ||
10 | 10 … | 'app.html.sideNav': 'first', |
11 | 11 … | 'app.html.topNav': 'first', |
12 | 12 … | 'app.html.scroller': 'first', |
13 | 13 … | 'app.html.channelCard': 'first', |
14 | - 'app.obs.pluginWarnings': 'first', | |
14 … | + 'app.obs.pluginsOk': 'first', | |
15 | 15 … | 'history.sync.push': 'first', |
16 | 16 … | 'keys.sync.id': 'first', |
17 | 17 … | 'channel.obs.subscribed': 'first', |
18 | 18 … | 'channel.obs.recent': 'first', |
@@ -51,16 +51,15 @@ | ||
51 | 51 … | if (location.scope === 'friends') { |
52 | 52 … | // update list of other all channels |
53 | 53 … | // NOTE can't use onceTrue right now, because warnings are true/ false |
54 | 54 … | watch( |
55 | - api.app.obs.pluginWarnings(), | |
56 | - isWarnings => { | |
57 | - if (isWarnings) { | |
58 | - return | |
59 | - } | |
55 … | + api.app.obs.pluginsOk(), | |
56 … | + ok => { | |
57 … | + if (!ok) return | |
60 | 58 … | onceTrue(api.sbot.obs.connection, getChannels) |
61 | 59 … | } |
62 | 60 … | ) |
61 … | + // TODO - refactor this to use the cache in channel.obs.subscribed | |
63 | 62 … | |
64 | 63 … | const showMoreCounter = Value(1) |
65 | 64 … | const newChannels = computed([allChannels, mySubs, showMoreCounter], (all, mine, more) => { |
66 | 65 … | return difference(all, mine) |
channel/html/subscribe.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 … | |
4 | 4 … | exports.gives = nest('channel.html.subscribe') |
5 | 5 … | |
6 | 6 … | exports.needs = nest({ |
7 … | + 'app.obs.pluginsOk': 'first', | |
7 | 8 … | 'translations.sync.strings': 'first', |
8 | 9 … | 'channel.obs.isSubscribedTo': 'first', |
9 | 10 … | 'channel.async.subscribe': 'first', |
10 | 11 … | 'channel.async.unsubscribe': 'first' |
@@ -14,12 +15,13 @@ | ||
14 | 15 … | return nest('channel.html.subscribe', (channel) => { |
15 | 16 … | channel = channel.replace(/^#/, '') |
16 | 17 … | const strings = api.translations.sync.strings() |
17 | 18 … | const { subscribe, unsubscribe } = api.channel.async |
18 | - const isSubscribed = api.channel.obs.isSubscribedTo(channel) | |
19 | 19 … | |
20 | - return when(isSubscribed, | |
21 | - h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe), | |
22 | - h('Button -primary', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe) | |
20 … | + when(api.app.obs.pluginsOk(), | |
21 … | + when(api.channel.obs.isSubscribedTo(channel), | |
22 … | + h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe), | |
23 … | + h('Button -primary', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe) | |
24 … | + ) | |
23 | 25 … | ) |
24 | 26 … | }) |
25 | 27 … | } |
channel/obs/subscribed.js | ||
---|---|---|
@@ -1,15 +1,16 @@ | ||
1 | 1 … | var pull = require('pull-stream') |
2 | -var { Dict, Value, computed, resolve } = require('mutant') | |
2 … | +var { Dict, Value, computed, resolve, onceTrue } = require('mutant') | |
3 | 3 … | var get = require('lodash/get') |
4 | 4 … | var MutantPullReduce = require('mutant-pull-reduce') |
5 | 5 … | var nest = require('depnest') |
6 | 6 … | var ref = require('ssb-ref') |
7 | 7 … | |
8 | 8 … | var throttle = require('mutant/throttle') |
9 | 9 … | |
10 | 10 … | exports.needs = nest({ |
11 | - 'sbot.pull.stream': 'first' | |
11 … | + 'sbot.pull.stream': 'first', | |
12 … | + 'app.obs.pluginsOk': 'first', | |
12 | 13 … | }) |
13 | 14 … | |
14 | 15 … | exports.gives = nest({ |
15 | 16 … | 'channel.obs.subscribed': true |
@@ -52,35 +53,39 @@ | ||
52 | 53 … | |
53 | 54 … | function startCache () { |
54 | 55 … | var initialReceived = false |
55 | 56 … | |
56 | - pull( | |
57 | - api.sbot.pull.stream(sbot => { | |
58 | - return sbot.channel.stream({ live: true }) | |
59 | - }), | |
60 | - pull.drain(val => { | |
61 | - if (val === null) { | |
62 | - return | |
63 | - } | |
57 … | + onceTrue(api.app.obs.pluginsOk(), startStream) | |
58 … | + | |
59 … | + function startStream (val) { | |
60 … | + pull( | |
61 … | + api.sbot.pull.stream(sbot => { | |
62 … | + return sbot.channel.stream({ live: true }) | |
63 … | + }), | |
64 … | + pull.drain(val => { | |
65 … | + if (val === null) { | |
66 … | + return | |
67 … | + } | |
64 | 68 … | |
65 | - if (!initialReceived) { | |
66 | - initialReceived = true | |
67 | - cache.set(val) | |
68 | - cache.sync.set(true) | |
69 | - return | |
70 | - } | |
69 … | + if (!initialReceived) { | |
70 … | + initialReceived = true | |
71 … | + cache.set(val) | |
72 … | + cache.sync.set(true) | |
73 … | + return | |
74 … | + } | |
71 | 75 … | |
72 | - if (val.sync === true) { | |
73 | - cache.sync.set(true) | |
74 | - return | |
75 | - } | |
76 | - | |
77 | - // Object.assign seems to bee needed otherwise the cache.set hits some codition where the resolved value gets over-ridden | |
78 | - // before and set to {} right before the actual set happens! | |
79 | - var newCache = reduce(Object.assign({}, resolve(cache)), val) | |
80 | - cache.set(newCache) | |
81 | - }) | |
82 | - ) | |
76 … | + if (val.sync === true) { | |
77 … | + cache.sync.set(true) | |
78 … | + return | |
79 … | + } | |
80 … | + | |
81 … | + // Object.assign seems to bee needed otherwise the cache.set hits some codition where the resolved value gets over-ridden | |
82 … | + // before and set to {} right before the actual set happens! | |
83 … | + var newCache = reduce(Object.assign({}, resolve(cache)), val) | |
84 … | + cache.set(newCache) | |
85 … | + }) | |
86 … | + ) | |
87 … | + } | |
83 | 88 … | } |
84 | 89 … | } |
85 | 90 … | |
86 | 91 … |
translations/en.js | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 … | slogan: `Connecting the Unconnected |
5 | 5 … | Reconstructing a trusty social network |
6 | 6 … | ` |
7 | 7 … | }, |
8 | - pluginWarnings: { | |
8 … | + pluginsOk: { | |
9 | 9 … | heading: 'Ticktack running in limited mode', |
10 | 10 … | description: 'Another scuttlebutt app is managing your shared database. Core functionality will work, but you may find there are some features that do not work.', |
11 | 11 … | advice: 'If you are running Patchwork, close Patchwork before running Ticktack to get the full set of features', |
12 | 12 … | action: { |
Built with git-ssb-web