Files: bf773c764144ae29c9dbe4469dba56760ba6a6df / app / page / channelSubscriptions.js
3596 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, watch, when, computed, Value, onceTrue } = require('mutant') |
3 | const pull = require('pull-stream') |
4 | const Pushable = require('pull-pushable') |
5 | const ref = require('ssb-ref') |
6 | const throttle = require('mutant/throttle') |
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") |
11 | |
12 | |
13 | exports.gives = nest('app.page.channelSubscriptions') |
14 | |
15 | exports.needs = nest({ |
16 | 'app.html.sideNav': 'first', |
17 | 'app.html.topNav': 'first', |
18 | 'app.html.scroller': 'first', |
19 | 'app.html.channelCard': 'first', |
20 | 'history.sync.push': 'first', |
21 | 'keys.sync.id': 'first', |
22 | 'channel.obs.subscribed': 'first', |
23 | 'channel.obs.recent':'first', |
24 | 'channel.html.link': 'first', |
25 | 'translations.sync.strings': 'first', |
26 | 'sbot.async.friendsGet': 'first', |
27 | 'sbot.pull.userFeed': 'first', |
28 | 'sbot.obs.connection': 'first' |
29 | }) |
30 | |
31 | exports.create = (api) => { |
32 | return nest('app.page.channelSubscriptions', function (location) { |
33 | const strings = api.translations.sync.strings() |
34 | const myId = api.keys.sync.id() |
35 | const { subscribed } = api.channel.obs |
36 | let myChannels, displaySubscriptions |
37 | |
38 | if (location.scope === "user") { |
39 | myChannels = subscribed(myId) |
40 | displaySubscriptions = () => [...myChannels().values()].map(c => api.app.html.channelCard(c)) |
41 | |
42 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
43 | api.app.html.sideNav(location), |
44 | h('div.content', [ |
45 | //api.app.html.topNav(location), |
46 | when(myChannels, displaySubscriptions, h("p", "Loading...")) |
47 | ]) |
48 | ]) |
49 | |
50 | } |
51 | |
52 | if (location.scope === "friends") { |
53 | |
54 | // function createStream() { |
55 | // var p = Pushable(true) // optionally pass `onDone` after it |
56 | |
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 | // }) |
63 | |
64 | // return p.source |
65 | // } |
66 | |
67 | // var stream = createStream() |
68 | // var opts = { |
69 | // startValue: new Set(), |
70 | // nextTick: true |
71 | // } |
72 | |
73 | myChannels = Value(false) |
74 | |
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 | } |
94 | } |
95 | |
96 | return h('Page -channelSubscriptions', { title: strings.home }, [ |
97 | api.app.html.sideNav(location), |
98 | h('div.content', [ |
99 | //api.app.html.topNav(location), |
100 | when(myChannels, displaySubscriptions, h("p", "Loading...")) |
101 | ]) |
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 | // ]) |
119 | } |
120 | }) |
121 | } |
122 | |
123 | |
124 | |
125 | |
126 |
Built with git-ssb-web