Commit 5a068194c2f2b857c0b9f07400fb4294f45f679f
confirm channel subscriptions, make subscriptions more responsive while onboarding
Matt McKegg committed on 3/17/2017, 6:05:01 AMParent: a723981b286b11d60ff33b639682947eab23a01e
Files changed
modules/channel/obs/subscribed.js | deleted |
modules/page/html/render/channel.js | changed |
modules/page/html/render/public.js | changed |
package.json | changed |
modules/channel/obs/subscribed.js | ||
---|---|---|
@@ -1,65 +1,0 @@ | ||
1 | -var pull = require('pull-stream') | |
2 | -var computed = require('mutant/computed') | |
3 | -var MutantPullReduce = require('mutant-pull-reduce') | |
4 | -var nest = require('depnest') | |
5 | - | |
6 | -var throttle = require('mutant/throttle') | |
7 | - | |
8 | -exports.needs = nest({ | |
9 | - 'sbot.pull.userFeed': 'first' | |
10 | -}) | |
11 | - | |
12 | -exports.gives = nest({ | |
13 | - 'channel.obs': ['subscribed'] | |
14 | -}) | |
15 | - | |
16 | -exports.create = function (api) { | |
17 | - var cache = {} | |
18 | - | |
19 | - return nest({ | |
20 | - 'channel.obs': {subscribed} | |
21 | - }) | |
22 | - | |
23 | - function subscribed (userId) { | |
24 | - if (cache[userId]) { | |
25 | - return cache[userId] | |
26 | - } else { | |
27 | - var stream = pull( | |
28 | - api.sbot.pull.userFeed({id: userId, live: true}), | |
29 | - pull.filter((msg) => { | |
30 | - return !msg.value || msg.value.content.type === 'channel' | |
31 | - }) | |
32 | - ) | |
33 | - | |
34 | - var result = MutantPullReduce(stream, (result, msg) => { | |
35 | - var c = msg.value.content | |
36 | - if (typeof c.channel === 'string' && c.channel) { | |
37 | - var channel = c.channel.trim() | |
38 | - if (channel) { | |
39 | - if (typeof c.subscribed === 'boolean') { | |
40 | - if (c.subscribed) { | |
41 | - result.add(channel) | |
42 | - } else { | |
43 | - result.delete(channel) | |
44 | - } | |
45 | - } | |
46 | - } | |
47 | - } | |
48 | - return result | |
49 | - }, { | |
50 | - startValue: new Set(), | |
51 | - nextTick: true | |
52 | - }) | |
53 | - | |
54 | - var instance = throttle(result, 2000) | |
55 | - instance.sync = result.sync | |
56 | - | |
57 | - instance.has = function (value) { | |
58 | - return computed(instance, x => x.has(value)) | |
59 | - } | |
60 | - | |
61 | - cache[userId] = instance | |
62 | - return instance | |
63 | - } | |
64 | - } | |
65 | -} |
modules/page/html/render/channel.js | ||
---|---|---|
@@ -6,9 +6,9 @@ | ||
6 | 6 | 'message.html.compose': 'first', |
7 | 7 | 'feed.html.rollup': 'first', |
8 | 8 | 'feed.pull.channel': 'first', |
9 | 9 | 'sbot.pull.log': 'first', |
10 | - 'sbot.async.publish': 'first', | |
10 | + 'message.async.publish': 'first', | |
11 | 11 | 'keys.sync.id': 'first' |
12 | 12 | }) |
13 | 13 | |
14 | 14 | exports.gives = nest('page.html.render') |
@@ -46,17 +46,19 @@ | ||
46 | 46 | return api.feed.html.rollup(api.feed.pull.channel(channel), { prepend, windowSize: 100 }) |
47 | 47 | }) |
48 | 48 | |
49 | 49 | function subscribe (id) { |
50 | - api.sbot.async.publish({ | |
50 | + // confirm | |
51 | + api.message.async.publish({ | |
51 | 52 | type: 'channel', |
52 | 53 | channel: id, |
53 | 54 | subscribed: true |
54 | 55 | }) |
55 | 56 | } |
56 | 57 | |
57 | 58 | function unsubscribe (id) { |
58 | - api.sbot.async.publish({ | |
59 | + // confirm | |
60 | + api.message.async.publish({ | |
59 | 61 | type: 'channel', |
60 | 62 | channel: id, |
61 | 63 | subscribed: false |
62 | 64 | }) |
modules/page/html/render/public.js | ||
---|---|---|
@@ -9,11 +9,8 @@ | ||
9 | 9 | log: 'first', |
10 | 10 | feed: 'first', |
11 | 11 | userFeed: 'first' |
12 | 12 | }, |
13 | - async: { | |
14 | - publish: 'first' | |
15 | - }, | |
16 | 13 | obs: { |
17 | 14 | connectedPeers: 'first', |
18 | 15 | localPeers: 'first' |
19 | 16 | } |
@@ -22,8 +19,9 @@ | ||
22 | 19 | 'about.obs.name': 'first', |
23 | 20 | 'invite.sheet': 'first', |
24 | 21 | |
25 | 22 | 'message.html.compose': 'first', |
23 | + 'message.async.publish': 'first', | |
26 | 24 | 'progress.html.peer': 'first', |
27 | 25 | |
28 | 26 | 'feed.html.rollup': 'first', |
29 | 27 | 'profile.obs.recentlyUpdated': 'first', |
@@ -216,17 +214,17 @@ | ||
216 | 214 | api.sbot.pull.userFeed({id: feedId, gte: 0, limit: 1})(null, cb) |
217 | 215 | } |
218 | 216 | |
219 | 217 | function subscribe (id) { |
220 | - api.sbot.async.publish({ | |
218 | + api.message.async.publish({ | |
221 | 219 | type: 'channel', |
222 | 220 | channel: id, |
223 | 221 | subscribed: true |
224 | 222 | }) |
225 | 223 | } |
226 | 224 | |
227 | 225 | function unsubscribe (id) { |
228 | - api.sbot.async.publish({ | |
226 | + api.message.async.publish({ | |
229 | 227 | type: 'channel', |
230 | 228 | channel: id, |
231 | 229 | subscribed: false |
232 | 230 | }) |
package.json | ||
---|---|---|
@@ -35,9 +35,9 @@ | ||
35 | 35 | "mutant-pull-reduce": "^1.1.0", |
36 | 36 | "non-private-ip": "^1.4.1", |
37 | 37 | "on-change-network": "0.0.2", |
38 | 38 | "on-wakeup": "^1.0.1", |
39 | - "patchcore": "~0.4.6", | |
39 | + "patchcore": "~0.4.7", | |
40 | 40 | "prebuild": "github:mmckegg/prebuild#use-npm-conf", |
41 | 41 | "pull-abortable": "^4.1.0", |
42 | 42 | "pull-defer": "^0.2.2", |
43 | 43 | "pull-file": "~1.0.0", |
Built with git-ssb-web