diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-03-08 21:35:43 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-03-08 21:35:43 +0100 |
commit | d38b82810638b9f664c9016fac2684454c273a77 (patch) | |
tree | 9465c367e5033675309efca4d66790c6fdd5230d /server/lib | |
parent | 8f9064432122cba0f518a24ac4378357dadec589 (diff) | |
download | PeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.gz PeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.zst PeerTube-d38b82810638b9f664c9016fac2684454c273a77.zip |
Add like/dislike system for videos
Diffstat (limited to 'server/lib')
-rw-r--r-- | server/lib/friends.js | 43 | ||||
-rw-r--r-- | server/lib/request-video-qadu-scheduler.js | 7 |
2 files changed, 42 insertions, 8 deletions
diff --git a/server/lib/friends.js b/server/lib/friends.js index 7bd087d8c..23accfa45 100644 --- a/server/lib/friends.js +++ b/server/lib/friends.js | |||
@@ -3,6 +3,7 @@ | |||
3 | const each = require('async/each') | 3 | const each = require('async/each') |
4 | const eachLimit = require('async/eachLimit') | 4 | const eachLimit = require('async/eachLimit') |
5 | const eachSeries = require('async/eachSeries') | 5 | const eachSeries = require('async/eachSeries') |
6 | const series = require('async/series') | ||
6 | const request = require('request') | 7 | const request = require('request') |
7 | const waterfall = require('async/waterfall') | 8 | const waterfall = require('async/waterfall') |
8 | 9 | ||
@@ -28,7 +29,9 @@ const friends = { | |||
28 | updateVideoToFriends, | 29 | updateVideoToFriends, |
29 | reportAbuseVideoToFriend, | 30 | reportAbuseVideoToFriend, |
30 | quickAndDirtyUpdateVideoToFriends, | 31 | quickAndDirtyUpdateVideoToFriends, |
32 | quickAndDirtyUpdatesVideoToFriends, | ||
31 | addEventToRemoteVideo, | 33 | addEventToRemoteVideo, |
34 | addEventsToRemoteVideo, | ||
32 | hasFriends, | 35 | hasFriends, |
33 | makeFriends, | 36 | makeFriends, |
34 | quitFriends, | 37 | quitFriends, |
@@ -84,24 +87,52 @@ function reportAbuseVideoToFriend (reportData, video) { | |||
84 | createRequest(options) | 87 | createRequest(options) |
85 | } | 88 | } |
86 | 89 | ||
87 | function quickAndDirtyUpdateVideoToFriends (videoId, type, transaction, callback) { | 90 | function quickAndDirtyUpdateVideoToFriends (qaduParams, transaction, callback) { |
88 | const options = { | 91 | const options = { |
89 | videoId, | 92 | videoId: qaduParams.videoId, |
90 | type, | 93 | type: qaduParams.type, |
91 | transaction | 94 | transaction |
92 | } | 95 | } |
93 | return createVideoQaduRequest(options, callback) | 96 | return createVideoQaduRequest(options, callback) |
94 | } | 97 | } |
95 | 98 | ||
96 | function addEventToRemoteVideo (videoId, type, transaction, callback) { | 99 | function quickAndDirtyUpdatesVideoToFriends (qadusParams, transaction, finalCallback) { |
100 | const tasks = [] | ||
101 | |||
102 | qadusParams.forEach(function (qaduParams) { | ||
103 | const fun = function (callback) { | ||
104 | quickAndDirtyUpdateVideoToFriends(qaduParams, transaction, callback) | ||
105 | } | ||
106 | |||
107 | tasks.push(fun) | ||
108 | }) | ||
109 | |||
110 | series(tasks, finalCallback) | ||
111 | } | ||
112 | |||
113 | function addEventToRemoteVideo (eventParams, transaction, callback) { | ||
97 | const options = { | 114 | const options = { |
98 | videoId, | 115 | videoId: eventParams.videoId, |
99 | type, | 116 | type: eventParams.type, |
100 | transaction | 117 | transaction |
101 | } | 118 | } |
102 | createVideoEventRequest(options, callback) | 119 | createVideoEventRequest(options, callback) |
103 | } | 120 | } |
104 | 121 | ||
122 | function addEventsToRemoteVideo (eventsParams, transaction, finalCallback) { | ||
123 | const tasks = [] | ||
124 | |||
125 | eventsParams.forEach(function (eventParams) { | ||
126 | const fun = function (callback) { | ||
127 | addEventToRemoteVideo(eventParams, transaction, callback) | ||
128 | } | ||
129 | |||
130 | tasks.push(fun) | ||
131 | }) | ||
132 | |||
133 | series(tasks, finalCallback) | ||
134 | } | ||
135 | |||
105 | function hasFriends (callback) { | 136 | function hasFriends (callback) { |
106 | db.Pod.countAll(function (err, count) { | 137 | db.Pod.countAll(function (err, count) { |
107 | if (err) return callback(err) | 138 | if (err) return callback(err) |
diff --git a/server/lib/request-video-qadu-scheduler.js b/server/lib/request-video-qadu-scheduler.js index ac50cfc11..a85d35160 100644 --- a/server/lib/request-video-qadu-scheduler.js +++ b/server/lib/request-video-qadu-scheduler.js | |||
@@ -44,14 +44,17 @@ module.exports = class RequestVideoQaduScheduler extends BaseRequestScheduler { | |||
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | const videoData = {} | 47 | // Maybe another attribute was filled for this video |
48 | let videoData = requestsToMakeGrouped[hashKey].videos[video.id] | ||
49 | if (!videoData) videoData = {} | ||
50 | |||
48 | switch (request.type) { | 51 | switch (request.type) { |
49 | case constants.REQUEST_VIDEO_QADU_TYPES.LIKES: | 52 | case constants.REQUEST_VIDEO_QADU_TYPES.LIKES: |
50 | videoData.likes = video.likes | 53 | videoData.likes = video.likes |
51 | break | 54 | break |
52 | 55 | ||
53 | case constants.REQUEST_VIDEO_QADU_TYPES.DISLIKES: | 56 | case constants.REQUEST_VIDEO_QADU_TYPES.DISLIKES: |
54 | videoData.likes = video.dislikes | 57 | videoData.dislikes = video.dislikes |
55 | break | 58 | break |
56 | 59 | ||
57 | case constants.REQUEST_VIDEO_QADU_TYPES.VIEWS: | 60 | case constants.REQUEST_VIDEO_QADU_TYPES.VIEWS: |