Commit e031c60a5b1665b894adc39a070671847799cc52
mentions: use ssb-backlinks index
Matt McKegg committed on 6/20/2017, 4:07:41 PMParent: 1c0ca68774c4b8604b4acc3288982a21f90f8401
Files changed
feed/pull/mentions.js | changed |
feed/pull/mentions.js | ||
---|---|---|
@@ -3,79 +3,33 @@ | ||
3 | 3 … | const pull = require('pull-stream') |
4 | 4 … | const ref = require('ssb-ref') |
5 | 5 … | |
6 | 6 … | exports.needs = nest({ |
7 | - 'sbot.pull.log': 'first', | |
8 | - 'message.sync.unbox': 'first', | |
9 | - 'sbot.sync.cache': 'first' | |
7 … | + 'sbot.pull.backlinks': 'first' | |
10 | 8 … | }) |
11 | 9 … | |
12 | 10 … | exports.gives = nest('feed.pull.mentions') |
13 | 11 … | |
14 | 12 … | exports.create = function (api) { |
15 | 13 … | return nest('feed.pull.mentions', function (id) { |
16 | 14 … | if (!ref.isFeed(id)) throw new Error('a feed id must be specified') |
17 | - var cache = api.sbot.sync.cache() | |
18 | 15 … | |
19 | 16 … | return function getStream (opts) { |
20 | - opts = extend(opts) | |
21 | - var take = opts.limit | |
22 | - opts.limit = 5000 | |
23 | - | |
24 | 17 … | // handle last item passed in as lt |
25 | 18 … | var lt = (opts.lt && typeof opts.lt === 'object') |
26 | 19 … | ? opts.lt.timestamp |
27 | 20 … | : opts.lt |
28 | 21 … | |
29 | - var stream = pull( | |
30 | - api.sbot.pull.log(opts), | |
31 | - unboxIfNeeded(), | |
32 | - pull.filter((msg) => { | |
33 | - if (!msg) return false | |
34 | - if (msg.sync) return true | |
35 | - return msg.value.author !== id && belongsToUs([ | |
36 | - msg.value.content.mentions, | |
37 | - msg.value.content.root, | |
38 | - msg.value.content.branch, | |
39 | - msg.value.content.repo, | |
40 | - msg.value.content.vote, | |
41 | - msg.value.content.about, | |
42 | - msg.value.content.contact | |
43 | - ]) | |
44 | - }) | |
45 | - ) | |
22 … | + opts = extend(opts, { | |
23 … | + lt: undefined, | |
24 … | + query: [ | |
25 … | + {$filter: { | |
26 … | + dest: id, | |
27 … | + timestamp: lt ? {$lt: lt, $gt: 0} : {$gt: 0} | |
28 … | + }} | |
29 … | + ] | |
30 … | + }) | |
46 | 31 … | |
47 | - if (take) { | |
48 | - return pull( | |
49 | - stream, | |
50 | - pull.take(take) | |
51 | - ) | |
52 | - } else { | |
53 | - return stream | |
54 | - } | |
32 … | + return api.sbot.pull.backlinks(opts) | |
55 | 33 … | } |
56 | - | |
57 | - function belongsToUs (link) { | |
58 | - if (Array.isArray(link)) { | |
59 | - return link.some(belongsToUs) | |
60 | - } | |
61 | - if (link) { | |
62 | - link = typeof link === 'object' ? link.link : link | |
63 | - if (link === id) return true | |
64 | - var item = cache[link] | |
65 | - if (item) { | |
66 | - return (item.author === id) | |
67 | - } | |
68 | - } | |
69 | - } | |
70 | 34 … | }) |
71 | - | |
72 | - function unboxIfNeeded () { | |
73 | - return pull.map(function (msg) { | |
74 | - if (msg.sync || (msg.value && typeof msg.value.content === 'object')) { | |
75 | - return msg | |
76 | - } else { | |
77 | - return api.message.sync.unbox(msg) | |
78 | - } | |
79 | - }) | |
80 | - } | |
81 | 35 … | } |
Built with git-ssb-web