From a21e25ff641854c8b01664cb18655aa420620af6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 1 Aug 2019 14:26:49 +0200 Subject: Fix like/dislike federation --- server/lib/activitypub/process/process-dislike.ts | 15 ++++++++------- server/lib/activitypub/process/process-like.ts | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) (limited to 'server/lib/activitypub') diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index c46180617..f06269f8b 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts @@ -34,19 +34,20 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct 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, - url - }, { transaction: t }) - await video.increment('dislikes', { transaction: t }) if (existingRate && existingRate.type === 'like') { await video.decrement('likes', { transaction: t }) } + const rate = existingRate || new AccountVideoRateModel() + rate.type = 'dislike' + rate.videoId = video.id + rate.accountId = byAccount.id + rate.url = url + + await rate.save({ transaction: t }) + 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 5b2ab4b66..bba54a19b 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts @@ -34,19 +34,20 @@ async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) { 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, - url - }, { transaction: t }) - - await video.increment('likes', { transaction: t }) - if (existingRate && existingRate.type === 'dislike') { await video.decrement('dislikes', { transaction: t }) } + await video.increment('likes', { transaction: t }) + + const rate = existingRate || new AccountVideoRateModel() + rate.type = 'like' + rate.videoId = video.id + rate.accountId = byAccount.id + rate.url = url + + await rate.save({ transaction: t }) + if (video.isOwned()) { // Don't resend the activity to the sender const exceptions = [ byActor ] -- cgit v1.2.3