Commit 217c274425bfc6f97a221190b58a329730ab0482
make channels/hashtags case insensitive (uses ssb-ref normalizeChannel)
Matt McKegg committed on 11/20/2017, 3:31:45 AMParent: ab49d98e85de76db59f84cc035e271040023fad3
Files changed
lib/normalize-channel.js | deleted |
modules/page/html/render/channel.js | changed |
modules/page/html/render/public.js | changed |
package.json | changed |
sbot/channels.js | changed |
sbot/roots.js | changed |
sbot/subscriptions.js | changed |
lib/normalize-channel.js | ||
---|---|---|
@@ -1,8 +1,0 @@ | ||
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/channel.js | ||
---|---|---|
@@ -3,8 +3,9 @@ | ||
3 | 3 | |
4 | 4 | exports.needs = nest({ |
5 | 5 | 'channel.obs.subscribed': 'first', |
6 | 6 | 'message.html.compose': 'first', |
7 | + 'channel.sync.normalize': 'first', | |
7 | 8 | 'feed.html.rollup': 'first', |
8 | 9 | 'feed.pull.channel': 'first', |
9 | 10 | 'sbot.pull.log': 'first', |
10 | 11 | 'message.async.publish': 'first', |
@@ -18,9 +19,9 @@ | ||
18 | 19 | const i18n = api.intl.sync.i18n |
19 | 20 | return nest('page.html.render', function channel (path) { |
20 | 21 | if (path[0] !== '#') return |
21 | 22 | |
22 | - var channel = path.substr(1) | |
23 | + var channel = api.channel.sync.normalize(path.substr(1)) | |
23 | 24 | var subscribedChannels = api.channel.obs.subscribed(api.keys.sync.id()) |
24 | 25 | |
25 | 26 | var prepend = [ |
26 | 27 | h('PageHeading', [ |
@@ -53,12 +54,12 @@ | ||
53 | 54 | |
54 | 55 | function mentionFilter (msg) { |
55 | 56 | // filter out likes |
56 | 57 | if (msg.value.content.type === 'vote') return false |
57 | - if (msg.value.content.channel === channel) return true | |
58 | + if (api.channel.sync.normalize(msg.value.content.channel) === channel) return true | |
58 | 59 | if (Array.isArray(msg.value.content.mentions)) { |
59 | 60 | if (msg.value.content.mentions.some(mention => { |
60 | - return mention && mention.link === `#${channel}` | |
61 | + return mention && api.channel.sync.normalize(mention.link) === `#${channel}` | |
61 | 62 | })) { |
62 | 63 | return 'channel-mention' |
63 | 64 | } |
64 | 65 | } |
modules/page/html/render/public.js | ||
---|---|---|
@@ -1,8 +1,7 @@ | ||
1 | 1 | var nest = require('depnest') |
2 | 2 | var extend = require('xtend') |
3 | 3 | var pull = require('pull-stream') |
4 | -var normalizeChannel = require('../../../../lib/normalize-channel') | |
5 | 4 | var { h, send, when, computed, map } = require('mutant') |
6 | 5 | |
7 | 6 | exports.needs = nest({ |
8 | 7 | sbot: { |
@@ -29,8 +28,9 @@ | ||
29 | 28 | 'channel.obs': { |
30 | 29 | subscribed: 'first', |
31 | 30 | recent: 'first' |
32 | 31 | }, |
32 | + 'channel.sync.normalize': 'first', | |
33 | 33 | 'keys.sync.id': 'first', |
34 | 34 | 'settings.obs.get': 'first', |
35 | 35 | 'intl.sync.i18n': 'first' |
36 | 36 | }) |
@@ -88,9 +88,9 @@ | ||
88 | 88 | var type = msg.value.content.type |
89 | 89 | if (type === 'vote') return false |
90 | 90 | |
91 | 91 | var author = msg.value.author |
92 | - var channel = normalizeChannel(msg.value.content.channel) | |
92 | + var channel = api.channel.sync.normalize(msg.value.content.channel) | |
93 | 93 | var tagged = checkTag(msg.value.content.mentions) |
94 | 94 | var isSubscribed = channel ? subscribedChannels().has(channel) : false |
95 | 95 | return isSubscribed || id === author || following().includes(author) || tagged |
96 | 96 | } |
@@ -138,9 +138,9 @@ | ||
138 | 138 | function checkTag (mentions) { |
139 | 139 | if (Array.isArray(mentions)) { |
140 | 140 | return mentions.some((mention) => { |
141 | 141 | if (mention && typeof mention.link === 'string' && mention.link.startsWith('#')) { |
142 | - var channel = normalizeChannel(mention.link.slice(1)) | |
142 | + var channel = api.channel.sync.normalize(mention.link.slice(1)) | |
143 | 143 | return channel ? subscribedChannels().has(channel) : false |
144 | 144 | } |
145 | 145 | }) |
146 | 146 | } |
package.json | ||
---|---|---|
@@ -41,9 +41,9 @@ | ||
41 | 41 | "mutant": "^3.21.2", |
42 | 42 | "mutant-pull-reduce": "^1.1.0", |
43 | 43 | "obv": "0.0.1", |
44 | 44 | "patch-settings": "^1.0.1", |
45 | - "patchcore": "~1.16.0", | |
45 | + "patchcore": "~1.17.0", | |
46 | 46 | "pull-abortable": "^4.1.0", |
47 | 47 | "pull-defer": "^0.2.2", |
48 | 48 | "pull-file": "~1.0.0", |
49 | 49 | "pull-identify-filetype": "^1.1.0", |
@@ -57,17 +57,17 @@ | ||
57 | 57 | "sorted-array-functions": "~1.0.0", |
58 | 58 | "spacetime": "^1.0.7", |
59 | 59 | "ssb-about": "~0.1.1", |
60 | 60 | "ssb-avatar": "^0.2.0", |
61 | - "ssb-backlinks": "~0.4.1", | |
61 | + "ssb-backlinks": "~0.5.0", | |
62 | 62 | "ssb-blobs": "~1.1.4", |
63 | 63 | "ssb-friends": "^2.3.5", |
64 | 64 | "ssb-keys": "^7.0.13", |
65 | 65 | "ssb-mentions": "^0.4.0", |
66 | 66 | "ssb-msgs": "^5.2.0", |
67 | 67 | "ssb-private": "0.1.4", |
68 | 68 | "ssb-query": "^1.0.0", |
69 | - "ssb-ref": "~2.7.1", | |
69 | + "ssb-ref": "^2.8.0", | |
70 | 70 | "ssb-sort": "^1.0.0", |
71 | 71 | "statistics": "^3.3.0", |
72 | 72 | "suggest-box": "^2.2.3", |
73 | 73 | "text-node-searcher": "^1.1.1" |
sbot/channels.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | 1 | var FlumeReduce = require('flumeview-reduce') |
2 | -var normalizeChannel = require('../lib/normalize-channel') | |
2 | +var normalizeChannel = require('ssb-ref').normalizeChannel | |
3 | 3 | |
4 | 4 | module.exports = function (ssb, config) { |
5 | 5 | return ssb._flumeUse('patchwork-channels', FlumeReduce(1, reduce, map)) |
6 | 6 | } |
sbot/roots.js | ||
---|---|---|
@@ -3,9 +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 | +var normalizeChannel = require('ssb-ref').normalizeChannel | |
8 | 8 | var Defer = require('pull-defer') |
9 | 9 | |
10 | 10 | // HACK: pull it out of patchcore |
11 | 11 | var getRoot = require('patchcore/message/sync/root').create().message.sync.root |
sbot/subscriptions.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | 1 | var FlumeReduce = require('flumeview-reduce') |
2 | -var normalizeChannel = require('../lib/normalize-channel') | |
2 | +var normalizeChannel = require('ssb-ref').normalizeChannel | |
3 | 3 | |
4 | 4 | module.exports = function (ssb, config) { |
5 | 5 | return ssb._flumeUse('patchwork-subscriptions', FlumeReduce(3, reduce, map)) |
6 | 6 | } |
Built with git-ssb-web