diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-01 10:15:28 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-01 10:15:28 +0200 |
commit | 970ceac0a6bf4990b8924738591df4949491ec9b (patch) | |
tree | 444070d8409fced91971c4401e65640d6fd13cbf /server/lib/activitypub | |
parent | bfbd912886eba17b4aa9a40dcef2fddc685d85bf (diff) | |
download | PeerTube-970ceac0a6bf4990b8924738591df4949491ec9b.tar.gz PeerTube-970ceac0a6bf4990b8924738591df4949491ec9b.tar.zst PeerTube-970ceac0a6bf4990b8924738591df4949491ec9b.zip |
Fix multiple server tests
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 21 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 24 | ||||
-rw-r--r-- | server/lib/activitypub/video-comments.ts | 2 |
3 files changed, 25 insertions, 22 deletions
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index bfd69e07a..ed8afd3d2 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts | |||
@@ -29,20 +29,21 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
29 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 29 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) |
30 | 30 | ||
31 | return sequelizeTypescript.transaction(async t => { | 31 | return sequelizeTypescript.transaction(async t => { |
32 | const rate = { | 32 | const url = getVideoDislikeActivityPubUrl(byActor, video) |
33 | |||
34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | ||
35 | if (existingRate && existingRate.type === 'dislike') return | ||
36 | |||
37 | await AccountVideoRateModel.create({ | ||
33 | type: 'dislike' as 'dislike', | 38 | type: 'dislike' as 'dislike', |
34 | videoId: video.id, | 39 | videoId: video.id, |
35 | accountId: byAccount.id | 40 | accountId: byAccount.id, |
36 | } | 41 | url |
42 | }, { transaction: t }) | ||
37 | 43 | ||
38 | const [ , created ] = await AccountVideoRateModel.findOrCreate({ | 44 | await video.increment('dislikes', { transaction: t }) |
39 | where: rate, | ||
40 | defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }), | ||
41 | transaction: t | ||
42 | }) | ||
43 | if (created === true) await video.increment('dislikes', { transaction: t }) | ||
44 | 45 | ||
45 | if (video.isOwned() && created === true) { | 46 | if (video.isOwned()) { |
46 | // Don't resend the activity to the sender | 47 | // Don't resend the activity to the sender |
47 | const exceptions = [ byActor ] | 48 | const exceptions = [ byActor ] |
48 | 49 | ||
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 2a04167d7..8b97aae55 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -29,19 +29,21 @@ async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) { | |||
29 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) | 29 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) |
30 | 30 | ||
31 | return sequelizeTypescript.transaction(async t => { | 31 | return sequelizeTypescript.transaction(async t => { |
32 | const rate = { | 32 | const url = getVideoLikeActivityPubUrl(byActor, video) |
33 | |||
34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | ||
35 | if (existingRate && existingRate.type === 'like') return | ||
36 | |||
37 | await AccountVideoRateModel.create({ | ||
33 | type: 'like' as 'like', | 38 | type: 'like' as 'like', |
34 | videoId: video.id, | 39 | videoId: video.id, |
35 | accountId: byAccount.id | 40 | accountId: byAccount.id, |
36 | } | 41 | url |
37 | const [ , created ] = await AccountVideoRateModel.findOrCreate({ | 42 | }, { transaction: t }) |
38 | where: rate, | 43 | |
39 | defaults: Object.assign({}, rate, { url: getVideoLikeActivityPubUrl(byActor, video) }), | 44 | await video.increment('likes', { transaction: t }) |
40 | transaction: t | 45 | |
41 | }) | 46 | if (video.isOwned()) { |
42 | if (created === true) await video.increment('likes', { transaction: t }) | ||
43 | |||
44 | if (video.isOwned() && created === true) { | ||
45 | // Don't resend the activity to the sender | 47 | // Don't resend the activity to the sender |
46 | const exceptions = [ byActor ] | 48 | const exceptions = [ byActor ] |
47 | 49 | ||
diff --git a/server/lib/activitypub/video-comments.ts b/server/lib/activitypub/video-comments.ts index 2f26ddefd..921abdb8d 100644 --- a/server/lib/activitypub/video-comments.ts +++ b/server/lib/activitypub/video-comments.ts | |||
@@ -54,7 +54,7 @@ async function addVideoComment (videoInstance: VideoModel, commentUrl: string) { | |||
54 | }) | 54 | }) |
55 | 55 | ||
56 | if (sanitizeAndCheckVideoCommentObject(body) === false) { | 56 | if (sanitizeAndCheckVideoCommentObject(body) === false) { |
57 | logger.debug('Remote video comment JSON is not valid.', { body }) | 57 | logger.debug('Remote video comment JSON %s is not valid.', commentUrl, { body }) |
58 | return { created: false } | 58 | return { created: false } |
59 | } | 59 | } |
60 | 60 | ||