Commit bf773c764144ae29c9dbe4469dba56760ba6a6df
issue #70: friends subscription working. Showing top 100 channels by number of friends subscribers
andre alves garzia committed on 2/2/2018, 4:43:43 AMParent: 9b7b6df024c1c91b5fa96dbbe3c3cbf1e5000f18
Files changed
app/page/channelSubscriptions.js | changed |
app/page/channelSubscriptions.js | ||
---|---|---|
@@ -1,11 +1,14 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | -const { h, watch, when, computed, Value, Set: MutantSet } = require('mutant') | |
2 | +const { h, watch, when, computed, Value, onceTrue } = require('mutant') | |
3 | 3 | const pull = require('pull-stream') |
4 | 4 | const Pushable = require('pull-pushable') |
5 | 5 | const ref = require('ssb-ref') |
6 | 6 | const throttle = require('mutant/throttle') |
7 | 7 | const MutantPullReduce = require('mutant-pull-reduce') |
8 | +const sortBy = require('lodash/sortBy') | |
9 | +const get = require("lodash/get") | |
10 | +const map = require("lodash/map") | |
8 | 11 | |
9 | 12 | |
10 | 13 | exports.gives = nest('app.page.channelSubscriptions') |
11 | 14 | |
@@ -13,16 +16,17 @@ | ||
13 | 16 | 'app.html.sideNav': 'first', |
14 | 17 | 'app.html.topNav': 'first', |
15 | 18 | 'app.html.scroller': 'first', |
16 | 19 | 'app.html.channelCard': 'first', |
17 | - | |
18 | 20 | 'history.sync.push': 'first', |
19 | 21 | 'keys.sync.id': 'first', |
20 | 22 | 'channel.obs.subscribed': 'first', |
23 | + 'channel.obs.recent':'first', | |
21 | 24 | 'channel.html.link': 'first', |
22 | 25 | 'translations.sync.strings': 'first', |
23 | 26 | 'sbot.async.friendsGet': 'first', |
24 | - 'sbot.pull.userFeed': 'first' | |
27 | + 'sbot.pull.userFeed': 'first', | |
28 | + 'sbot.obs.connection': 'first' | |
25 | 29 | }) |
26 | 30 | |
27 | 31 | exports.create = (api) => { |
28 | 32 | return nest('app.page.channelSubscriptions', function (location) { |
@@ -46,41 +50,73 @@ | ||
46 | 50 | } |
47 | 51 | |
48 | 52 | if (location.scope === "friends") { |
49 | 53 | |
50 | - function createStream() { | |
51 | - var p = Pushable(true) // optionally pass `onDone` after it | |
54 | + // function createStream() { | |
55 | + // var p = Pushable(true) // optionally pass `onDone` after it | |
52 | 56 | |
53 | - api.sbot.async.friendsGet({ dest: myId }, (err, friends) => { | |
54 | - for (f in friends) { | |
55 | - var s = subscribed(f) | |
56 | - s(c => [...c].map(x => p.push(x))) | |
57 | - } | |
58 | - }) | |
57 | + // api.sbot.async.friendsGet({ dest: myId }, (err, friends) => { | |
58 | + // for (f in friends) { | |
59 | + // var s = subscribed(f) | |
60 | + // s(c => [...c].map(x => p.push(x))) | |
61 | + // } | |
62 | + // }) | |
59 | 63 | |
60 | - return p.source | |
61 | - } | |
64 | + // return p.source | |
65 | + // } | |
62 | 66 | |
63 | - var stream = createStream() | |
64 | - var opts = { | |
65 | - startValue: new Set(), | |
66 | - nextTick: true | |
67 | - } | |
67 | + // var stream = createStream() | |
68 | + // var opts = { | |
69 | + // startValue: new Set(), | |
70 | + // nextTick: true | |
71 | + // } | |
68 | 72 | |
69 | - var channelList = api.app.html.scroller({ | |
70 | - classList: ['content'], | |
71 | - stream: createStream, | |
72 | - render | |
73 | - }) | |
73 | + myChannels = Value(false) | |
74 | 74 | |
75 | - function render(channel) { | |
76 | - return api.app.html.channelCard(channel) | |
75 | + onceTrue( | |
76 | + api.sbot.obs.connection, | |
77 | + sbot => { | |
78 | + sbot.channel.get((err, c) => { | |
79 | + if (err) throw err | |
80 | + let b = map(c, (v,k) => {return {channel: k, users: v}}) | |
81 | + b = sortBy(b, o => o.users.length) | |
82 | + myChannels.set(b.reverse().slice(1,101)) | |
83 | + // console.log(`want blog ${blog}, callback: ${success}`) | |
84 | + }) | |
85 | + } | |
86 | + ) | |
87 | + | |
88 | + | |
89 | + displaySubscriptions = () => { | |
90 | + if (myChannels()) { | |
91 | + let subs = myChannels() | |
92 | + return subs.map(c => api.app.html.channelCard(c.channel)) | |
93 | + } | |
77 | 94 | } |
78 | 95 | |
79 | 96 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
80 | 97 | api.app.html.sideNav(location), |
81 | - channelList | |
98 | + h('div.content', [ | |
99 | + //api.app.html.topNav(location), | |
100 | + when(myChannels, displaySubscriptions, h("p", "Loading...")) | |
101 | + ]) | |
82 | 102 | ]) |
103 | + | |
104 | + // var channelList = api.app.html.scroller({ | |
105 | + // classList: ['content'], | |
106 | + // stream: sbot.channel.stream, | |
107 | + // render | |
108 | + // }) | |
109 | + | |
110 | + // function render(channel) { | |
111 | + // console.assert.log("render", channel) | |
112 | + // return api.app.html.channelCard(channel) | |
113 | + // } | |
114 | + | |
115 | + // return h('Page -channelSubscriptions', { title: strings.home }, [ | |
116 | + // api.app.html.sideNav(location), | |
117 | + // //channelList | |
118 | + // ]) | |
83 | 119 | } |
84 | 120 | }) |
85 | 121 | } |
86 | 122 |
Built with git-ssb-web