aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r--server/lib/activitypub/process/process-dislike.ts21
-rw-r--r--server/lib/activitypub/process/process-like.ts24
2 files changed, 24 insertions, 21 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