aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/friends.js39
1 files changed, 22 insertions, 17 deletions
diff --git a/server/lib/friends.js b/server/lib/friends.js
index 589b79660..4afb91b8b 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -15,6 +15,7 @@ const requests = require('../helpers/requests')
15const friends = { 15const friends = {
16 addVideoToFriends, 16 addVideoToFriends,
17 updateVideoToFriends, 17 updateVideoToFriends,
18 reportAbuseVideoToFriend,
18 hasFriends, 19 hasFriends,
19 getMyCertificate, 20 getMyCertificate,
20 makeFriends, 21 makeFriends,
@@ -23,12 +24,20 @@ const friends = {
23 sendOwnedVideosToPod 24 sendOwnedVideosToPod
24} 25}
25 26
26function addVideoToFriends (video) { 27function addVideoToFriends (videoData) {
27 createRequest('add', constants.REQUEST_ENDPOINTS.VIDEOS, video) 28 createRequest('add', constants.REQUEST_ENDPOINTS.VIDEOS, videoData)
28} 29}
29 30
30function updateVideoToFriends (video) { 31function updateVideoToFriends (videoData) {
31 createRequest('update', constants.REQUEST_ENDPOINTS.VIDEOS, video) 32 createRequest('update', constants.REQUEST_ENDPOINTS.VIDEOS, videoData)
33}
34
35function removeVideoToFriends (videoParams) {
36 createRequest('remove', constants.REQUEST_ENDPOINTS.VIDEOS, videoParams)
37}
38
39function reportAbuseVideoToFriend (reportData, video) {
40 createRequest('report-abuse', constants.REQUEST_ENDPOINTS.VIDEOS, reportData, [ video.Author.podId ])
32} 41}
33 42
34function hasFriends (callback) { 43function hasFriends (callback) {
@@ -120,10 +129,6 @@ function quitFriends (callback) {
120 }) 129 })
121} 130}
122 131
123function removeVideoToFriends (videoParams) {
124 createRequest('remove', constants.REQUEST_ENDPOINTS.VIDEOS, videoParams)
125}
126
127function sendOwnedVideosToPod (podId) { 132function sendOwnedVideosToPod (podId) {
128 db.Video.listOwnedAndPopulateAuthorAndTags(function (err, videosList) { 133 db.Video.listOwnedAndPopulateAuthorAndTags(function (err, videosList) {
129 if (err) { 134 if (err) {
@@ -152,10 +157,10 @@ module.exports = friends
152// --------------------------------------------------------------------------- 157// ---------------------------------------------------------------------------
153 158
154function computeForeignPodsList (host, podsScore, callback) { 159function computeForeignPodsList (host, podsScore, callback) {
155 getForeignPodsList(host, function (err, foreignPodsList) { 160 getForeignPodsList(host, function (err, res) {
156 if (err) return callback(err) 161 if (err) return callback(err)
157 162
158 if (!foreignPodsList) foreignPodsList = [] 163 const foreignPodsList = res.data
159 164
160 // Let's give 1 point to the pod we ask the friends list 165 // Let's give 1 point to the pod we ask the friends list
161 foreignPodsList.push({ host }) 166 foreignPodsList.push({ host })
@@ -252,11 +257,11 @@ function makeRequestsToWinningPods (cert, podsList, callback) {
252 }) 257 })
253} 258}
254 259
255// Wrapper that populate "to" argument with all our friends if it is not specified 260// Wrapper that populate "toIds" argument with all our friends if it is not specified
256function createRequest (type, endpoint, data, to) { 261function createRequest (type, endpoint, data, toIds) {
257 if (to) return _createRequest(type, endpoint, data, to) 262 if (toIds) return _createRequest(type, endpoint, data, toIds)
258 263
259 // If the "to" pods is not specified, we send the request to all our friends 264 // If the "toIds" pods is not specified, we send the request to all our friends
260 db.Pod.listAllIds(function (err, podIds) { 265 db.Pod.listAllIds(function (err, podIds) {
261 if (err) { 266 if (err) {
262 logger.error('Cannot get pod ids', { error: err }) 267 logger.error('Cannot get pod ids', { error: err })
@@ -267,13 +272,13 @@ function createRequest (type, endpoint, data, to) {
267 }) 272 })
268} 273}
269 274
270function _createRequest (type, endpoint, data, to) { 275function _createRequest (type, endpoint, data, toIds) {
271 const pods = [] 276 const pods = []
272 277
273 // If there are no destination pods abort 278 // If there are no destination pods abort
274 if (to.length === 0) return 279 if (toIds.length === 0) return
275 280
276 to.forEach(function (toPod) { 281 toIds.forEach(function (toPod) {
277 pods.push(db.Pod.build({ id: toPod })) 282 pods.push(db.Pod.build({ id: toPod }))
278 }) 283 })
279 284