diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/app.js | 67 |
1 files changed, 55 insertions, 12 deletions
@@ -803,21 +803,64 @@ App.prototype.isFollowing = function (src, dest, cb) { }) } +App.prototype.getVotesStream = function (id) { + var links2 = this.sbot.links2 + if (links2 && links2.read) return links2.read({ + query: [ + {$filter: { + dest: id, + rel: [{$prefix: 'vote'}] + }}, + {$map: { + value: ['rel', 1], + author: 'source' + }} + ] + }) + + var backlinks = this.sbot.backlinks + if (backlinks && backlinks.read) return backlinks.read({ + query: [ + {$filter: { + dest: id, + value: { + content: { + type: 'vote', + vote: { + link: id + } + } + } + }}, + {$map: { + author: ['value', 'author'], + value: ['value', 'content', 'vote', 'value'] + }} + ] + }) + + return pull( + this.sbot.links({ + dest: id, + rel: 'vote', + keys: false, + meta: false, + values: true + }), + pull.map(function (value) { + var vote = value && value.content && value.content.vote + return { + author: value && value.author, + vote: vote && vote.value + } + }) + ) +} + App.prototype._getVotes = function (id, cb) { var votes = {} pull( - this.sbot.links2.read({ - query: [ - {$filter: { - dest: id, - rel: [{$prefix: 'vote'}] - }}, - {$map: { - value: ['rel', 1], - author: 'source' - }} - ] - }), + this.getVotesStream(), pull.drain(function (vote) { votes[vote.author] = vote.value }, function (err) { |