git ssb

0+

alanz / patchwork



forked from Matt McKegg / patchwork

Commit 5a068194c2f2b857c0b9f07400fb4294f45f679f

confirm channel subscriptions, make subscriptions more responsive while onboarding

Matt McKegg committed on 3/17/2017, 6:05:01 AM
Parent: a723981b286b11d60ff33b639682947eab23a01e

Files changed

modules/channel/obs/subscribed.jsdeleted
modules/page/html/render/channel.jschanged
modules/page/html/render/public.jschanged
package.jsonchanged
modules/channel/obs/subscribed.jsView
@@ -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.jsView
@@ -6,9 +6,9 @@
66 'message.html.compose': 'first',
77 'feed.html.rollup': 'first',
88 'feed.pull.channel': 'first',
99 'sbot.pull.log': 'first',
10- 'sbot.async.publish': 'first',
10+ 'message.async.publish': 'first',
1111 'keys.sync.id': 'first'
1212 })
1313
1414 exports.gives = nest('page.html.render')
@@ -46,17 +46,19 @@
4646 return api.feed.html.rollup(api.feed.pull.channel(channel), { prepend, windowSize: 100 })
4747 })
4848
4949 function subscribe (id) {
50- api.sbot.async.publish({
50+ // confirm
51+ api.message.async.publish({
5152 type: 'channel',
5253 channel: id,
5354 subscribed: true
5455 })
5556 }
5657
5758 function unsubscribe (id) {
58- api.sbot.async.publish({
59+ // confirm
60+ api.message.async.publish({
5961 type: 'channel',
6062 channel: id,
6163 subscribed: false
6264 })
modules/page/html/render/public.jsView
@@ -9,11 +9,8 @@
99 log: 'first',
1010 feed: 'first',
1111 userFeed: 'first'
1212 },
13- async: {
14- publish: 'first'
15- },
1613 obs: {
1714 connectedPeers: 'first',
1815 localPeers: 'first'
1916 }
@@ -22,8 +19,9 @@
2219 'about.obs.name': 'first',
2320 'invite.sheet': 'first',
2421
2522 'message.html.compose': 'first',
23+ 'message.async.publish': 'first',
2624 'progress.html.peer': 'first',
2725
2826 'feed.html.rollup': 'first',
2927 'profile.obs.recentlyUpdated': 'first',
@@ -216,17 +214,17 @@
216214 api.sbot.pull.userFeed({id: feedId, gte: 0, limit: 1})(null, cb)
217215 }
218216
219217 function subscribe (id) {
220- api.sbot.async.publish({
218+ api.message.async.publish({
221219 type: 'channel',
222220 channel: id,
223221 subscribed: true
224222 })
225223 }
226224
227225 function unsubscribe (id) {
228- api.sbot.async.publish({
226+ api.message.async.publish({
229227 type: 'channel',
230228 channel: id,
231229 subscribed: false
232230 })
package.jsonView
@@ -35,9 +35,9 @@
3535 "mutant-pull-reduce": "^1.1.0",
3636 "non-private-ip": "^1.4.1",
3737 "on-change-network": "0.0.2",
3838 "on-wakeup": "^1.0.1",
39- "patchcore": "~0.4.6",
39+ "patchcore": "~0.4.7",
4040 "prebuild": "github:mmckegg/prebuild#use-npm-conf",
4141 "pull-abortable": "^4.1.0",
4242 "pull-defer": "^0.2.2",
4343 "pull-file": "~1.0.0",

Built with git-ssb-web