diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-11-18 18:42:45 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2018-11-18 18:42:45 -1000 |
commit | 6f41c9179b21ade843d0e446342cef6b241c5615 (patch) | |
tree | 40869a25bf1c0ebb564b6545def889dc29f8ce3a | |
parent | 3ad7cdec4ec8b4fa393caa8e3d5f0ff7351d9379 (diff) | |
download | patchfoo-6f41c9179b21ade843d0e446342cef6b241c5615.tar.gz patchfoo-6f41c9179b21ade843d0e446342cef6b241c5615.zip |
Add ssb-links fallback for votes calculation
-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) { |