From 970ceac0a6bf4990b8924738591df4949491ec9b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 1 Aug 2019 10:15:28 +0200 Subject: Fix multiple server tests --- server/lib/activitypub/process/process-dislike.ts | 21 ++++++++++---------- server/lib/activitypub/process/process-like.ts | 24 ++++++++++++----------- server/lib/activitypub/video-comments.ts | 2 +- server/lib/video-comment.ts | 6 +++--- 4 files changed, 28 insertions(+), 25 deletions(-) (limited to 'server/lib') 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 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) return sequelizeTypescript.transaction(async t => { - const rate = { + const url = getVideoDislikeActivityPubUrl(byActor, video) + + const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) + if (existingRate && existingRate.type === 'dislike') return + + await AccountVideoRateModel.create({ type: 'dislike' as 'dislike', videoId: video.id, - accountId: byAccount.id - } + accountId: byAccount.id, + url + }, { transaction: t }) - const [ , created ] = await AccountVideoRateModel.findOrCreate({ - where: rate, - defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }), - transaction: t - }) - if (created === true) await video.increment('dislikes', { transaction: t }) + await video.increment('dislikes', { transaction: t }) - if (video.isOwned() && created === true) { + if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] 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) { const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) return sequelizeTypescript.transaction(async t => { - const rate = { + const url = getVideoLikeActivityPubUrl(byActor, video) + + const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) + if (existingRate && existingRate.type === 'like') return + + await AccountVideoRateModel.create({ type: 'like' as 'like', videoId: video.id, - accountId: byAccount.id - } - const [ , created ] = await AccountVideoRateModel.findOrCreate({ - where: rate, - defaults: Object.assign({}, rate, { url: getVideoLikeActivityPubUrl(byActor, video) }), - transaction: t - }) - if (created === true) await video.increment('likes', { transaction: t }) - - if (video.isOwned() && created === true) { + accountId: byAccount.id, + url + }, { transaction: t }) + + await video.increment('likes', { transaction: t }) + + if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] 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) { }) if (sanitizeAndCheckVideoCommentObject(body) === false) { - logger.debug('Remote video comment JSON is not valid.', { body }) + logger.debug('Remote video comment JSON %s is not valid.', commentUrl, { body }) return { created: false } } diff --git a/server/lib/video-comment.ts b/server/lib/video-comment.ts index bfe22d225..449aa74cb 100644 --- a/server/lib/video-comment.ts +++ b/server/lib/video-comment.ts @@ -27,10 +27,10 @@ async function createVideoComment (obj: { inReplyToCommentId, videoId: obj.video.id, accountId: obj.account.id, - url: 'fake url' - }, { transaction: t, validate: false } as any) // FIXME: sequelize typings + url: new Date().toISOString() + }, { transaction: t, validate: false }) - comment.set('url', getVideoCommentActivityPubUrl(obj.video, comment)) + comment.url = getVideoCommentActivityPubUrl(obj.video, comment) const savedComment = await comment.save({ transaction: t }) savedComment.InReplyToVideoComment = obj.inReplyToComment -- cgit v1.2.3