aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-11-18 18:42:45 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2018-11-18 18:42:45 -1000
commit6f41c9179b21ade843d0e446342cef6b241c5615 (patch)
tree40869a25bf1c0ebb564b6545def889dc29f8ce3a /lib
parent3ad7cdec4ec8b4fa393caa8e3d5f0ff7351d9379 (diff)
downloadpatchfoo-6f41c9179b21ade843d0e446342cef6b241c5615.tar.gz
patchfoo-6f41c9179b21ade843d0e446342cef6b241c5615.zip
Add ssb-links fallback for votes calculation
Diffstat (limited to 'lib')
-rw-r--r--lib/app.js67
1 files changed, 55 insertions, 12 deletions
diff --git a/lib/app.js b/lib/app.js
index fa26b25..d895fa7 100644
--- a/lib/app.js
+++ b/lib/app.js
@@ -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) {