Commit 8c68dbb9a3b69a0cf0e0dd503ef059a873189cd5
fix channel handling!
mix irving committed on 2/13/2018, 10:00:26 PMParent: dba1ec48c08d0594936b838fc855835948a3aef2
Files changed
app/page/blogIndex.mcss | changed |
app/page/blogSearch.mcss | changed |
app/page/channelShow.js | changed |
app/page/channelShow.mcss | changed |
background-process.js | changed |
channel/async.js | changed |
channel/html/subscribe.js | changed |
channel/obs.js | changed |
message/html/channel.js | changed |
router/sync/routes.js | changed |
app/page/blogIndex.mcss | ||
---|---|---|
@@ -9,8 +9,12 @@ | ||
9 | 9 … | section.content { |
10 | 10 … | div.BlogCard { |
11 | 11 … | flex-basis: 100% |
12 | 12 … | border-bottom: 1px solid rgba(0,0,0, .1) |
13 … | + | |
14 … | + :last-child { | |
15 … | + border-bottom: none | |
16 … | + } | |
13 | 17 … | } |
14 | 18 … | } |
15 | 19 … | |
16 | 20 … | section.bottom { |
app/page/blogSearch.mcss | ||
---|---|---|
@@ -47,8 +47,12 @@ | ||
47 | 47 … | div.BlogCard { |
48 | 48 … | flex-basis: 100% |
49 | 49 … | |
50 | 50 … | border-bottom: 1px solid gainsboro |
51 … | + | |
52 … | + :last-child { | |
53 … | + border-bottom: none | |
54 … | + } | |
51 | 55 … | } |
52 | 56 … | } |
53 | 57 … | |
54 | 58 … | section.bottom { |
app/page/channelShow.js | |||
---|---|---|---|
@@ -8,31 +8,29 @@ | |||
8 | 8 … | 'app.html.sideNav': 'first', | |
9 | 9 … | 'app.html.topNav': 'first', | |
10 | 10 … | 'app.html.scroller': 'first', | |
11 | 11 … | 'app.html.blogCard': 'first', | |
12 … | + 'channel.html.subscribe': 'first', | ||
12 | 13 … | 'feed.pull.channel': 'first', | |
13 | 14 … | 'history.sync.push': 'first', | |
14 | - 'translations.sync.strings': 'first', | ||
15 | - 'channel.obs.recent': 'first', | ||
16 | - 'channel.html.subscribe': 'first' | ||
15 … | + 'translations.sync.strings': 'first' | ||
17 | 16 … | }) | |
18 | 17 … | ||
19 | 18 … | exports.create = (api) => { | |
20 | 19 … | return nest('app.page.channelShow', channelShow) | |
21 | 20 … | ||
22 | 21 … | function channelShow(location) { | |
23 | - var strings = api.translations.sync.strings() | ||
22 … | + const strings = api.translations.sync.strings() | ||
23 … | + const { channel } = location | ||
24 | 24 … | ||
25 | - var searchVal = resolve(location.channel) | ||
26 | - | ||
27 | - createStream = api.feed.pull.channel(location.channel) | ||
25 … | + createStream = api.feed.pull.channel(channel) | ||
28 | 26 … | ||
29 | 27 … | const prepend = [ | |
30 | 28 … | api.app.html.topNav(location), | |
31 | 29 … | h('section.about', [ | |
32 | - h('h1', location.channel), | ||
30 … | + h('h1', channel), | ||
33 | 31 … | h('div.actions', [ | |
34 | - api.channel.html.subscribe(location.channel) | ||
32 … | + api.channel.html.subscribe(channel) | ||
35 | 33 … | ]) | |
36 | 34 … | ]), | |
37 | 35 … | ] | |
38 | 36 … | ||
@@ -54,8 +52,12 @@ | |||
54 | 52 … | // updateBottom: updateRecentMsgCache, | |
55 | 53 … | render | |
56 | 54 … | }) | |
57 | 55 … | ||
56 … | + location.page = location.page || 'channelShow' | ||
57 … | + // covers case where router.sync.normalise delivers a loc = { channel: '#channelName' } | ||
58 … | + // HACK: helps sideNav | ||
59 … | + | ||
58 | 60 … | return h('Page -channelShow', { title: strings.home }, [ | |
59 | 61 … | api.app.html.sideNav(location), | |
60 | 62 … | channelPosts | |
61 | 63 … | ]) |
app/page/channelShow.mcss | ||
---|---|---|
@@ -8,37 +8,34 @@ | ||
8 | 8 … | right: 0 |
9 | 9 … | top: 0 |
10 | 10 … | z-index: 99 |
11 | 11 … | |
12 | - | |
12 … | + padding-bottom: 1rem | |
13 … | + margin-bottom: 1rem | |
13 | 14 … | |
14 | 15 … | section.about { |
15 | - | |
16 … | + padding-bottom: 1rem | |
17 … | + | |
16 | 18 … | display: flex |
17 | 19 … | flex-direction: column |
18 | 20 … | align-items: center |
19 | - padding-bottom: 1rem | |
20 | - | |
21 | 21 … | |
22 | 22 … | h1 { |
23 | 23 … | font-weight: bold |
24 | 24 … | font-size: 1.5rem |
25 | 25 … | padding: 1rem |
26 | 26 … | |
27 | 27 … | margin: auto |
28 | - | |
29 | 28 … | } |
30 | 29 … | |
31 | 30 … | div.actions { |
32 | 31 … | display: flex |
33 | 32 … | |
34 | 33 … | div.Button { |
35 | 34 … | margin: auto |
36 | 35 … | } |
37 | - | |
38 | 36 … | } |
39 | 37 … | } |
40 | - | |
41 | 38 … | } |
42 | 39 … | |
43 | 40 … | section.content { |
44 | 41 … | background-color: #fff |
@@ -52,8 +49,12 @@ | ||
52 | 49 … | div.BlogCard { |
53 | 50 … | flex-basis: 100% |
54 | 51 … | |
55 | 52 … | border-bottom: 1px solid gainsboro |
53 … | + | |
54 … | + :last-child { | |
55 … | + border-bottom: none | |
56 … | + } | |
56 | 57 … | } |
57 | 58 … | } |
58 | 59 … | |
59 | 60 … | section.bottom { |
background-process.js | ||
---|---|---|
@@ -25,4 +25,5 @@ | ||
25 | 25 … | var sbot = createSbot(config) |
26 | 26 … | var manifest = sbot.getManifest() |
27 | 27 … | fs.writeFileSync(Path.join(config.path, 'manifest.json'), JSON.stringify(manifest)) |
28 | 28 … | electron.ipcRenderer.send('server-started') |
29 … | + |
channel/async.js | ||
---|---|---|
@@ -16,8 +16,9 @@ | ||
16 | 16 … | 'channel.async': {subscribe, unsubscribe} |
17 | 17 … | }) |
18 | 18 … | |
19 | 19 … | function subscribe (channel, cb) { |
20 … | + channel = channel.replace(/^#/, '') | |
20 | 21 … | if (!channel) throw new Error('a channel must be specified') |
21 | 22 … | api.sbot.async.publish({ |
22 | 23 … | type: 'channel', |
23 | 24 … | channel: channel, |
@@ -25,8 +26,9 @@ | ||
25 | 26 … | }, cb) |
26 | 27 … | } |
27 | 28 … | |
28 | 29 … | function unsubscribe (channel, cb) { |
30 … | + channel = channel.replace(/^#/, '') | |
29 | 31 … | if (!channel) throw new Error('a channel must be specified') |
30 | 32 … | api.sbot.async.publish({ |
31 | 33 … | type: 'channel', |
32 | 34 … | channel: channel, |
channel/html/subscribe.js | ||
---|---|---|
@@ -3,9 +3,8 @@ | ||
3 | 3 … | |
4 | 4 … | exports.gives = nest('channel.html.subscribe') |
5 | 5 … | |
6 | 6 … | exports.needs = nest({ |
7 | - 'keys.sync.id': 'first', | |
8 | 7 … | 'translations.sync.strings': 'first', |
9 | 8 … | 'channel.obs.isSubscribedTo': 'first', |
10 | 9 … | 'channel.async.subscribe': 'first', |
11 | 10 … | 'channel.async.unsubscribe': 'first', |
@@ -13,13 +12,18 @@ | ||
13 | 12 … | |
14 | 13 … | exports.create = function (api) { |
15 | 14 … | |
16 | 15 … | return nest('channel.html.subscribe', (channel) => { |
16 … | + channel = channel.replace(/^#/, '') | |
17 | 17 … | const strings = api.translations.sync.strings() |
18 | - const myId = api.keys.sync.id() | |
19 | 18 … | const { subscribe, unsubscribe } = api.channel.async |
20 | - | |
21 | - return when(api.channel.obs.isSubscribedTo(channel, myId), | |
19 … | + const isSubscribed = api.channel.obs.isSubscribedTo(channel) | |
20 … | + | |
21 … | + isSubscribed(val => { | |
22 … | + console.log(channel, 'subscribed:', val) | |
23 … | + }) | |
24 … | + | |
25 … | + return when(isSubscribed, | |
22 | 26 … | h('Button', { 'ev-click': () => unsubscribe(channel) }, strings.channelShow.action.unsubscribe), |
23 | 27 … | h('Button -primary', { 'ev-click': () => subscribe(channel) }, strings.channelShow.action.subscribe) |
24 | 28 … | ) |
25 | 29 … | }) |
channel/obs.js | ||
---|---|---|
@@ -1,11 +1,12 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | 2 … | const ref = require('ssb-ref') |
3 | -const computed = require('mutant/computed') | |
3 … | +const { computed, onceTrue } = require('mutant') | |
4 | 4 … | |
5 | 5 … | exports.needs = nest({ |
6 | 6 … | 'keys.sync.id': 'first', |
7 | 7 … | 'channel.obs.subscribed': 'first', |
8 … | + 'sbot.obs.connection': 'first', | |
8 | 9 … | }) |
9 | 10 … | |
10 | 11 … | exports.gives = nest('channel.obs.isSubscribedTo') |
11 | 12 … | |
@@ -15,13 +16,17 @@ | ||
15 | 16 … | |
16 | 17 … | return nest('channel.obs.isSubscribedTo', isSubscribedTo) |
17 | 18 … | |
18 | 19 … | function isSubscribedTo (channel, id) { |
20 … | + channel = channel.replace(/^#/, '') | |
19 | 21 … | if (!ref.isFeed(id)) { |
20 | 22 … | id = getMyId() |
21 | 23 … | } |
22 | - | |
23 | - return computed(getSubscriptions(id), (v) => v.has(channel)) | |
24 … | + | |
25 … | + // TODO - use ssb-server-channel index to make a better subscribed obs | |
26 … | + return computed(getSubscriptions(id), set => { | |
27 … | + return set.has(channel) | |
28 … | + }) | |
24 | 29 … | } |
25 | 30 … | |
26 | 31 … | //cache getters |
27 | 32 … | |
@@ -30,9 +35,9 @@ | ||
30 | 35 … | return myId |
31 | 36 … | } |
32 | 37 … | |
33 | 38 … | function getSubscriptions (id) { |
34 | - if (!subscriptions[id]) subscriptions[id] = api.channel.obs.subscribed(id) | |
39 … | + if (subscriptions[id] === undefined) subscriptions[id] = api.channel.obs.subscribed(id) | |
35 | 40 … | return subscriptions[id] |
36 | 41 … | } |
37 | 42 … | } |
38 | 43 … |
message/html/channel.js | ||
---|---|---|
@@ -10,17 +10,18 @@ | ||
10 | 10 … | exports.create = function (api) { |
11 | 11 … | return nest('message.html.channel', channel) |
12 | 12 … | |
13 | 13 … | function channel (msgOrChannel, opts = {} ) { |
14 | - const channel = typeof msgOrChannel === 'string' | |
14 … | + var channel= typeof msgOrChannel === 'string' | |
15 | 15 … | ? msgOrChannel |
16 | 16 … | : msgOrChannel.value.content.channel |
17 … | + channel = channel.replace(/^#/ , '') | |
17 | 18 … | |
18 | 19 … | if (!channel) return |
19 | 20 … | |
20 | 21 … | const { |
21 | 22 … | classList = [], |
22 | - location = { page: 'blogSearch', channel } | |
23 … | + location = { page: 'channelShow', channel } | |
23 | 24 … | } = opts |
24 | 25 … | |
25 | 26 … | const goToChannel = (e) => { |
26 | 27 … | e.stopPropagation() |
router/sync/routes.js | ||
---|---|---|
@@ -52,10 +52,10 @@ | ||
52 | 52 … | |
53 | 53 … | // Channel related pages |
54 | 54 … | [ location => location.page === 'channelSubscriptions', pages.channelSubscriptions], |
55 | 55 … | [ location => location.page === 'channelShow', pages.channelShow ], |
56 … | + [ location => location.channel, pages.channelShow ], | |
56 | 57 … | |
57 | - | |
58 | 58 … | // AddressBook pages |
59 | 59 … | [ location => location.page === 'addressBook', pages.addressBook ], |
60 | 60 … | |
61 | 61 … | // Private Thread pages |
Built with git-ssb-web