Commit 58d09b546019da27320afef34de21bd46d0d03cf
fix including subscribed channels in patchwork main feed
fixes #579Matt McKegg committed on 7/1/2017, 9:57:57 AM
Parent: ed3ae5da08e3aa78197343e41af3a66efbe9ad11
Files changed
lib/normalize-channel.js | added |
modules/page/html/render/public.js | changed |
sbot/channels.js | changed |
sbot/roots.js | changed |
sbot/subscriptions.js | changed |
lib/normalize-channel.js | ||
---|---|---|
@@ -1,0 +1,8 @@ | ||
1 | +module.exports = function (channel) { | |
2 | + if (typeof channel === 'string') { | |
3 | + channel = channel.replace(/\s/g, '') | |
4 | + if (channel.length > 0 && channel.length < 30) { | |
5 | + return channel | |
6 | + } | |
7 | + } | |
8 | +} |
modules/page/html/render/public.js | ||
---|---|---|
@@ -68,9 +68,13 @@ | ||
68 | 68 | updateStream: api.sbot.pull.stream(sbot => sbot.patchwork.latest({ids: [id]})), |
69 | 69 | bumpFilter: function (msg) { |
70 | 70 | if (msg.value && msg.value.content && typeof msg.value.content === 'object') { |
71 | 71 | var author = msg.value.author |
72 | - return id === author || following().has(author) | |
72 | + | |
73 | + // TODO: should normalize this channel | |
74 | + var channel = msg.value.content.channel | |
75 | + var isSubscribed = channel ? subscribedChannels().has(channel) : false | |
76 | + return isSubscribed || id === author || following().has(author) | |
73 | 77 | } |
74 | 78 | }, |
75 | 79 | waitFor: computed([ |
76 | 80 | following.sync, |
sbot/channels.js | ||
---|---|---|
@@ -1,5 +1,6 @@ | ||
1 | 1 | var FlumeReduce = require('flumeview-reduce') |
2 | +var normalizeChannel = require('../lib/normalize-channel') | |
2 | 3 | |
3 | 4 | module.exports = function (ssb, config) { |
4 | 5 | return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map)) |
5 | 6 | } |
@@ -21,13 +22,13 @@ | ||
21 | 22 | return result |
22 | 23 | } |
23 | 24 | |
24 | 25 | function map (msg) { |
25 | - if (msg.value.content && typeof msg.value.content.channel === 'string') { | |
26 | - var channel = msg.value.content.channel | |
27 | - if (channel.length > 0 && channel.length < 30) { | |
26 | + if (msg.value.content) { | |
27 | + var channel = normalizeChannel(msg.value.content.channel) | |
28 | + if (channel) { | |
28 | 29 | return { |
29 | - [channel.replace(/\s/g, '')]: {timestamp: msg.timestamp} | |
30 | + [channel]: {timestamp: msg.timestamp} | |
30 | 31 | } |
31 | 32 | } |
32 | 33 | } |
33 | 34 | } |
sbot/roots.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 | var FlumeViewLevel = require('flumeview-level') |
4 | 4 | var pullCat = require('pull-cat') |
5 | 5 | var HLRU = require('hashlru') |
6 | 6 | var extend = require('xtend') |
7 | +var normalizeChannel = require('../lib/normalize-channel') | |
7 | 8 | |
8 | 9 | // HACK: pull it out of patchcore |
9 | 10 | var getRoot = require('patchcore/message/sync/root').create().message.sync.root |
10 | 11 | |
@@ -194,10 +195,10 @@ | ||
194 | 195 | if (err) return cb(err) |
195 | 196 | cb(null, function (ids, msg) { |
196 | 197 | return ( |
197 | 198 | ids.includes(msg.value.author) || |
198 | - checkFollowing(contacts, ids, msg.value.author) || | |
199 | - checkChannel(subscriptions, ids, msg.value.content.channel) | |
199 | + checkChannel(subscriptions, ids, msg.value.content.channel) || | |
200 | + checkFollowing(contacts, ids, msg.value.author) | |
200 | 201 | ) |
201 | 202 | }) |
202 | 203 | }) |
203 | 204 | }) |
@@ -210,11 +211,11 @@ | ||
210 | 211 | return value && value[0] |
211 | 212 | } |
212 | 213 | |
213 | 214 | function checkChannel (lookup, ids, channel) { |
214 | - channel = typeof channel === 'string' ? channel.replace(/\s/g, '') : null | |
215 | + channel = normalizeChannel(channel) | |
215 | 216 | if (channel) { |
216 | - var value = mostRecentValue(ids.map(id => lookup[`${id}:channel`])) | |
217 | + var value = mostRecentValue(ids.map(id => lookup[`${id}:${channel}`])) | |
217 | 218 | return value && value[1] |
218 | 219 | } |
219 | 220 | } |
220 | 221 |
sbot/subscriptions.js | ||
---|---|---|
@@ -1,29 +1,32 @@ | ||
1 | 1 | var FlumeReduce = require('flumeview-reduce') |
2 | +var normalizeChannel = require('../lib/normalize-channel') | |
2 | 3 | |
3 | 4 | module.exports = function (ssb, config) { |
4 | - return ssb._flumeUse('patchwork-subscriptions', FlumeReduce(1, reduce, map)) | |
5 | + return ssb._flumeUse('patchwork-subscriptions', FlumeReduce(3, reduce, map)) | |
5 | 6 | } |
6 | 7 | |
7 | 8 | function reduce (result, item) { |
8 | - if (!result) result = [] | |
9 | - if (Array.isArray(item)) { | |
9 | + if (!result) result = {} | |
10 | + if (item) { | |
10 | 11 | for (var key in item) { |
11 | 12 | if (!result[key] || result[key][0] < item[key][0]) { |
12 | - result[key] = item | |
13 | + result[key] = item[key] | |
13 | 14 | } |
14 | 15 | } |
15 | 16 | } |
16 | 17 | return result |
17 | 18 | } |
18 | 19 | |
19 | 20 | function map (msg) { |
20 | 21 | if (msg.value.content && msg.value.content.type === 'channel') { |
21 | - if (typeof msg.value.content.channel === 'string' && typeof msg.value.content.subscribed === 'boolean') { | |
22 | - var channel = msg.value.content.channel.replace(/\s/g, '') | |
23 | - var key = `${msg.value.author}:${channel}` | |
24 | - return [{ | |
25 | - [key]: [msg.timestamp, msg.value.content.subscribed] | |
26 | - }] | |
22 | + if (typeof msg.value.content.subscribed === 'boolean') { | |
23 | + var channel = normalizeChannel(msg.value.content.channel) | |
24 | + if (channel) { | |
25 | + var key = `${msg.value.author}:${channel}` | |
26 | + return { | |
27 | + [key]: [msg.timestamp, msg.value.content.subscribed] | |
28 | + } | |
29 | + } | |
27 | 30 | } |
28 | 31 | } |
29 | 32 | } |
Built with git-ssb-web