const friends = {
addVideoToFriends,
+ updateVideoToFriends,
+ reportAbuseVideoToFriend,
hasFriends,
getMyCertificate,
makeFriends,
sendOwnedVideosToPod
}
-function addVideoToFriends (video) {
- createRequest('add', constants.REQUEST_ENDPOINTS.VIDEOS, video)
+function addVideoToFriends (videoData) {
+ createRequest('add', constants.REQUEST_ENDPOINTS.VIDEOS, videoData)
+}
+
+function updateVideoToFriends (videoData) {
+ createRequest('update', constants.REQUEST_ENDPOINTS.VIDEOS, videoData)
+}
+
+function removeVideoToFriends (videoParams) {
+ createRequest('remove', constants.REQUEST_ENDPOINTS.VIDEOS, videoParams)
+}
+
+function reportAbuseVideoToFriend (reportData, video) {
+ createRequest('report-abuse', constants.REQUEST_ENDPOINTS.VIDEOS, reportData, [ video.Author.podId ])
}
function hasFriends (callback) {
function quitFriends (callback) {
// Stop pool requests
db.Request.deactivate()
- // Flush pool requests
- db.Request.flush()
waterfall([
+ function flushRequests (callbackAsync) {
+ db.Request.flush(callbackAsync)
+ },
+
function getPodsList (callbackAsync) {
return db.Pod.list(callbackAsync)
},
})
}
-function removeVideoToFriends (videoParams) {
- createRequest('remove', constants.REQUEST_ENDPOINTS.VIDEOS, videoParams)
-}
-
function sendOwnedVideosToPod (podId) {
- db.Video.listOwnedAndPopulateAuthor(function (err, videosList) {
+ db.Video.listOwnedAndPopulateAuthorAndTags(function (err, videosList) {
if (err) {
logger.error('Cannot get the list of videos we own.')
return
}
videosList.forEach(function (video) {
- video.toRemoteJSON(function (err, remoteVideo) {
+ video.toAddRemoteJSON(function (err, remoteVideo) {
if (err) {
logger.error('Cannot convert video to remote.', { error: err })
// Don't break the process
// ---------------------------------------------------------------------------
function computeForeignPodsList (host, podsScore, callback) {
- getForeignPodsList(host, function (err, foreignPodsList) {
+ getForeignPodsList(host, function (err, res) {
if (err) return callback(err)
- if (!foreignPodsList) foreignPodsList = []
+ const foreignPodsList = res.data
// Let's give 1 point to the pod we ask the friends list
foreignPodsList.push({ host })
}
// Add our videos to the request scheduler
- sendOwnedVideosToPod(podCreated._id)
+ sendOwnedVideosToPod(podCreated.id)
return callbackEach()
})
})
}
-// Wrapper that populate "to" argument with all our friends if it is not specified
-function createRequest (type, endpoint, data, to) {
- if (to) return _createRequest(type, endpoint, data, to)
+// Wrapper that populate "toIds" argument with all our friends if it is not specified
+function createRequest (type, endpoint, data, toIds) {
+ if (toIds) return _createRequest(type, endpoint, data, toIds)
- // If the "to" pods is not specified, we send the request to all our friends
+ // If the "toIds" pods is not specified, we send the request to all our friends
db.Pod.listAllIds(function (err, podIds) {
if (err) {
logger.error('Cannot get pod ids', { error: err })
})
}
-function _createRequest (type, endpoint, data, to) {
+function _createRequest (type, endpoint, data, toIds) {
const pods = []
// If there are no destination pods abort
- if (to.length === 0) return
+ if (toIds.length === 0) return
- to.forEach(function (toPod) {
+ toIds.forEach(function (toPod) {
pods.push(db.Pod.build({ id: toPod }))
})