git ssb

2+

mixmix / ticktack



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 AM
Parent: 9b7b6df024c1c91b5fa96dbbe3c3cbf1e5000f18

Files changed

app/page/channelSubscriptions.jschanged
app/page/channelSubscriptions.jsView
@@ -1,11 +1,14 @@
11 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')
33 const pull = require('pull-stream')
44 const Pushable = require('pull-pushable')
55 const ref = require('ssb-ref')
66 const throttle = require('mutant/throttle')
77 const MutantPullReduce = require('mutant-pull-reduce')
8+const sortBy = require('lodash/sortBy')
9+const get = require("lodash/get")
10+const map = require("lodash/map")
811
912
1013 exports.gives = nest('app.page.channelSubscriptions')
1114
@@ -13,16 +16,17 @@
1316 'app.html.sideNav': 'first',
1417 'app.html.topNav': 'first',
1518 'app.html.scroller': 'first',
1619 'app.html.channelCard': 'first',
17-
1820 'history.sync.push': 'first',
1921 'keys.sync.id': 'first',
2022 'channel.obs.subscribed': 'first',
23+ 'channel.obs.recent':'first',
2124 'channel.html.link': 'first',
2225 'translations.sync.strings': 'first',
2326 'sbot.async.friendsGet': 'first',
24- 'sbot.pull.userFeed': 'first'
27+ 'sbot.pull.userFeed': 'first',
28+ 'sbot.obs.connection': 'first'
2529 })
2630
2731 exports.create = (api) => {
2832 return nest('app.page.channelSubscriptions', function (location) {
@@ -46,41 +50,73 @@
4650 }
4751
4852 if (location.scope === "friends") {
4953
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
5256
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+ // })
5963
60- return p.source
61- }
64+ // return p.source
65+ // }
6266
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+ // }
6872
69- var channelList = api.app.html.scroller({
70- classList: ['content'],
71- stream: createStream,
72- render
73- })
73+ myChannels = Value(false)
7474
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+ }
7794 }
7895
7996 return h('Page -channelSubscriptions', { title: strings.home }, [
8097 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+ ])
82102 ])
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+ // ])
83119 }
84120 })
85121 }
86122

Built with git-ssb-web