git ssb

2+

mixmix / ticktack



Commit cf76ccf1f9b18873a3627dbf29d4c76512e50482

disable subscription buttons when external sbot without channel plugin

mix irving committed on 2/15/2018, 3:59:52 AM
Parent: 400d6307414c6b622a0408421a7c1881697c893e

Files changed

app/html/sideNav/sideNavDiscovery.jschanged
app/html/warning.jschanged
app/index.jschanged
app/obs/pluginWarnings.jsdeleted
app/obs/pluginsOk.jsadded
app/page/channelSubscriptions.jschanged
channel/html/subscribe.jschanged
channel/obs/subscribed.jschanged
translations/en.jschanged
app/html/sideNav/sideNavDiscovery.jsView
@@ -12,9 +12,9 @@
1212 })
1313
1414 exports.needs = nest({
1515 'app.html.scroller': 'first',
16- 'app.obs.pluginWarnings': 'first',
16 + 'app.obs.pluginsOk': 'first',
1717 'about.html.avatar': 'first',
1818 'about.obs.name': 'first',
1919 'feed.pull.private': 'first',
2020 'history.sync.push': 'first',
@@ -125,18 +125,18 @@
125125 label: strings.blogIndex.title,
126126 selected: isDiscoverLocation(location),
127127 location: { page: 'blogIndex' }
128128 }),
129- computed(api.app.obs.pluginWarnings(), isWarning => {
129 + computed(api.app.obs.pluginsOk(), ok => {
130130 return [
131131 // My subscriptions
132132 Option({
133133 imageEl: h('i', [
134134 h('img', { src: path.join(__dirname, '../../../assets', 'my_subscribed.png') })
135135 ]),
136136 label: strings.subscriptions.user,
137137 selected: location.page === 'channelSubscriptions' && location.scope === 'user',
138- disabled: isWarning,
138 + disabled: !ok,
139139 location: { page: 'channelSubscriptions', scope: 'user' }
140140 }),
141141
142142 // Friends subscriptions
@@ -145,9 +145,9 @@
145145 h('img', { src: path.join(__dirname, '../../../assets', 'friends_subscribed.png') })
146146 ]),
147147 label: strings.subscriptions.friends,
148148 selected: location.page === 'channelSubscriptions' && location.scope === 'friends',
149- disabled: isWarning,
149 + disabled: !ok,
150150 location: { page: 'channelSubscriptions', scope: 'friends' }
151151 })
152152 ]
153153 })
app/html/warning.jsView
@@ -1,12 +1,12 @@
11 const nest = require('depnest')
2-const { h, onceTrue } = require('mutant')
2 +const { h, watch } = require('mutant')
33
44 exports.gives = nest('app.html.warning')
55
66 exports.needs = nest({
77 'app.html.lightbox': 'first',
8- 'app.obs.pluginWarnings': 'first',
8 + 'app.obs.pluginsOk': 'first',
99 'translations.sync.strings': 'first'
1010 })
1111
1212 exports.create = (api) => {
@@ -14,9 +14,9 @@
1414
1515 return nest('app.html.warning', function warning () {
1616 if (seenWarning) return
1717
18- const t = api.translations.sync.strings().pluginWarnings
18 + const t = api.translations.sync.strings().pluginsOk
1919
2020 const lightbox = api.app.html.lightbox(
2121 h('div', [
2222 h('h1', t.heading),
@@ -31,12 +31,12 @@
3131 )
3232 ])
3333 )
3434
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()
3939 }
4040 )
4141
4242 return lightbox
app/index.jsView
@@ -23,9 +23,9 @@
2323 },
2424 warning: require('./html/warning'),
2525 },
2626 obs: {
27- pluginWarnings: require('./obs/pluginWarnings'),
27 + pluginsOk: require('./obs/pluginsOk'),
2828 },
2929 page: {
3030 addressBook: require('./page/addressBook'),
3131 blogIndex: require('./page/blogIndex'),
app/obs/pluginWarnings.jsView
@@ -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.jsView
@@ -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.jsView
@@ -10,9 +10,9 @@
1010 'app.html.sideNav': 'first',
1111 'app.html.topNav': 'first',
1212 'app.html.scroller': 'first',
1313 'app.html.channelCard': 'first',
14- 'app.obs.pluginWarnings': 'first',
14 + 'app.obs.pluginsOk': 'first',
1515 'history.sync.push': 'first',
1616 'keys.sync.id': 'first',
1717 'channel.obs.subscribed': 'first',
1818 'channel.obs.recent': 'first',
@@ -51,16 +51,15 @@
5151 if (location.scope === 'friends') {
5252 // update list of other all channels
5353 // NOTE can't use onceTrue right now, because warnings are true/ false
5454 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
6058 onceTrue(api.sbot.obs.connection, getChannels)
6159 }
6260 )
61 + // TODO - refactor this to use the cache in channel.obs.subscribed
6362
6463 const showMoreCounter = Value(1)
6564 const newChannels = computed([allChannels, mySubs, showMoreCounter], (all, mine, more) => {
6665 return difference(all, mine)
channel/html/subscribe.jsView
@@ -3,8 +3,9 @@
33
44 exports.gives = nest('channel.html.subscribe')
55
66 exports.needs = nest({
7 + 'app.obs.pluginsOk': 'first',
78 'translations.sync.strings': 'first',
89 'channel.obs.isSubscribedTo': 'first',
910 'channel.async.subscribe': 'first',
1011 'channel.async.unsubscribe': 'first'
@@ -14,12 +15,13 @@
1415 return nest('channel.html.subscribe', (channel) => {
1516 channel = channel.replace(/^#/, '')
1617 const strings = api.translations.sync.strings()
1718 const { subscribe, unsubscribe } = api.channel.async
18- const isSubscribed = api.channel.obs.isSubscribedTo(channel)
1919
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 + )
2325 )
2426 })
2527 }
channel/obs/subscribed.jsView
@@ -1,15 +1,16 @@
11 var pull = require('pull-stream')
2-var { Dict, Value, computed, resolve } = require('mutant')
2 +var { Dict, Value, computed, resolve, onceTrue } = require('mutant')
33 var get = require('lodash/get')
44 var MutantPullReduce = require('mutant-pull-reduce')
55 var nest = require('depnest')
66 var ref = require('ssb-ref')
77
88 var throttle = require('mutant/throttle')
99
1010 exports.needs = nest({
11- 'sbot.pull.stream': 'first'
11 + 'sbot.pull.stream': 'first',
12 + 'app.obs.pluginsOk': 'first',
1213 })
1314
1415 exports.gives = nest({
1516 'channel.obs.subscribed': true
@@ -52,35 +53,39 @@
5253
5354 function startCache () {
5455 var initialReceived = false
5556
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 + }
6468
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 + }
7175
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 + }
8388 }
8489 }
8590
8691
translations/en.jsView
@@ -4,9 +4,9 @@
44 slogan: `Connecting the Unconnected
55 Reconstructing a trusty social network
66 `
77 },
8- pluginWarnings: {
8 + pluginsOk: {
99 heading: 'Ticktack running in limited mode',
1010 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.',
1111 advice: 'If you are running Patchwork, close Patchwork before running Ticktack to get the full set of features',
1212 action: {

Built with git-ssb-web