feat(vote): restored voting (now working over p2p)

This commit is contained in:
Alexey Kasyanchuk
2018-04-13 15:56:45 +03:00
parent 5407ef8c59
commit c8e37ae4b2
5 changed files with 38 additions and 17 deletions

View File

@ -643,26 +643,35 @@ module.exports = ({
const action = isGood ? 'good' : 'bad';
const votes = await p2pStore.find(`vote:${hash}`)
let good = isGood ? 1 : 0
let bad = !isGood ? 1 : 0
let good = 0
let bad = 0
let selfVote = false
if(votes)
{
console.log(votes)
votes.forEach(({vote}) => {
votes.forEach(({vote, _peerId}) => {
if(_peerId === p2p.peerId)
selfVote = true
if(vote == 'bad')
bad++
else
good++
})
}
console.log(bad, good)
console.log('votes before', bad, good)
if(!selfVote)
{
p2pStore.store({
type: 'vote',
torrentHash: hash,
vote: action,
_index: `vote:${hash}`
})
good += isGood ? 1 : 0
bad += !isGood ? 1 : 0
}
p2pStore.store({
type: 'vote',
torrentHash: hash,
vote: action,
_index: `vote:${hash}`
})
send('vote', {
hash, good, bad
});