diff options
author | Chocobozzz <me@florianbigard.com> | 2019-08-01 14:26:49 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-08-01 14:26:49 +0200 |
commit | a21e25ff641854c8b01664cb18655aa420620af6 (patch) | |
tree | 9caba3e48691564af8ef4f53dc200c4cf31f8152 /server/lib/activitypub/process | |
parent | 29d4e1375fdac88595347184c3d1b214804794b0 (diff) | |
download | PeerTube-a21e25ff641854c8b01664cb18655aa420620af6.tar.gz PeerTube-a21e25ff641854c8b01664cb18655aa420620af6.tar.zst PeerTube-a21e25ff641854c8b01664cb18655aa420620af6.zip |
Fix like/dislike federation
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 15 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 19 |
2 files changed, 18 insertions, 16 deletions
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 | |||
34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | 34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) |
35 | if (existingRate && existingRate.type === 'dislike') return | 35 | if (existingRate && existingRate.type === 'dislike') return |
36 | 36 | ||
37 | await AccountVideoRateModel.create({ | ||
38 | type: 'dislike' as 'dislike', | ||
39 | videoId: video.id, | ||
40 | accountId: byAccount.id, | ||
41 | url | ||
42 | }, { transaction: t }) | ||
43 | |||
44 | await video.increment('dislikes', { transaction: t }) | 37 | await video.increment('dislikes', { transaction: t }) |
45 | 38 | ||
46 | if (existingRate && existingRate.type === 'like') { | 39 | if (existingRate && existingRate.type === 'like') { |
47 | await video.decrement('likes', { transaction: t }) | 40 | await video.decrement('likes', { transaction: t }) |
48 | } | 41 | } |
49 | 42 | ||
43 | const rate = existingRate || new AccountVideoRateModel() | ||
44 | rate.type = 'dislike' | ||
45 | rate.videoId = video.id | ||
46 | rate.accountId = byAccount.id | ||
47 | rate.url = url | ||
48 | |||
49 | await rate.save({ transaction: t }) | ||
50 | |||
50 | if (video.isOwned()) { | 51 | if (video.isOwned()) { |
51 | // Don't resend the activity to the sender | 52 | // Don't resend the activity to the sender |
52 | const exceptions = [ byActor ] | 53 | 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) { | |||
34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) | 34 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url) |
35 | if (existingRate && existingRate.type === 'like') return | 35 | if (existingRate && existingRate.type === 'like') return |
36 | 36 | ||
37 | await AccountVideoRateModel.create({ | ||
38 | type: 'like' as 'like', | ||
39 | videoId: video.id, | ||
40 | accountId: byAccount.id, | ||
41 | url | ||
42 | }, { transaction: t }) | ||
43 | |||
44 | await video.increment('likes', { transaction: t }) | ||
45 | |||
46 | if (existingRate && existingRate.type === 'dislike') { | 37 | if (existingRate && existingRate.type === 'dislike') { |
47 | await video.decrement('dislikes', { transaction: t }) | 38 | await video.decrement('dislikes', { transaction: t }) |
48 | } | 39 | } |
49 | 40 | ||
41 | await video.increment('likes', { transaction: t }) | ||
42 | |||
43 | const rate = existingRate || new AccountVideoRateModel() | ||
44 | rate.type = 'like' | ||
45 | rate.videoId = video.id | ||
46 | rate.accountId = byAccount.id | ||
47 | rate.url = url | ||
48 | |||
49 | await rate.save({ transaction: t }) | ||
50 | |||
50 | if (video.isOwned()) { | 51 | if (video.isOwned()) { |
51 | // Don't resend the activity to the sender | 52 | // Don't resend the activity to the sender |
52 | const exceptions = [ byActor ] | 53 | const exceptions = [ byActor ] |