git ssb

7+

dinoworm 🐛 / patchcore



Commit e031c60a5b1665b894adc39a070671847799cc52

mentions: use ssb-backlinks index

Matt McKegg committed on 6/20/2017, 4:07:41 PM
Parent: 1c0ca68774c4b8604b4acc3288982a21f90f8401

Files changed

feed/pull/mentions.jschanged
feed/pull/mentions.jsView
@@ -3,79 +3,33 @@
33 const pull = require('pull-stream')
44 const ref = require('ssb-ref')
55
66 exports.needs = nest({
7- 'sbot.pull.log': 'first',
8- 'message.sync.unbox': 'first',
9- 'sbot.sync.cache': 'first'
7 + 'sbot.pull.backlinks': 'first'
108 })
119
1210 exports.gives = nest('feed.pull.mentions')
1311
1412 exports.create = function (api) {
1513 return nest('feed.pull.mentions', function (id) {
1614 if (!ref.isFeed(id)) throw new Error('a feed id must be specified')
17- var cache = api.sbot.sync.cache()
1815
1916 return function getStream (opts) {
20- opts = extend(opts)
21- var take = opts.limit
22- opts.limit = 5000
23-
2417 // handle last item passed in as lt
2518 var lt = (opts.lt && typeof opts.lt === 'object')
2619 ? opts.lt.timestamp
2720 : opts.lt
2821
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 + })
4631
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)
5533 }
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- }
7034 })
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- }
8135 }

Built with git-ssb-web