diff options
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 48 |
3 files changed, 30 insertions, 22 deletions
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index c88082bbf..4740dc432 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -63,7 +63,7 @@ function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreat | |||
63 | defaults: rate, | 63 | defaults: rate, |
64 | transaction: t | 64 | transaction: t |
65 | }) | 65 | }) |
66 | await video.increment('dislikes', { transaction: t }) | 66 | if (created === true) await video.increment('dislikes', { transaction: t }) |
67 | 67 | ||
68 | if (video.isOwned() && created === true) { | 68 | if (video.isOwned() && created === true) { |
69 | // Don't resend the activity to the sender | 69 | // Don't resend the activity to the sender |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 0347f95be..5f2ffe7ea 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -46,7 +46,7 @@ function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) { | |||
46 | defaults: rate, | 46 | defaults: rate, |
47 | transaction: t | 47 | transaction: t |
48 | }) | 48 | }) |
49 | await video.increment('likes', { transaction: t }) | 49 | if (created === true) await video.increment('likes', { transaction: t }) |
50 | 50 | ||
51 | if (video.isOwned() && created === true) { | 51 | if (video.isOwned() && created === true) { |
52 | // Don't resend the activity to the sender | 52 | // Don't resend the activity to the sender |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index acee4fe16..6b82f12d5 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -48,36 +48,44 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec | |||
48 | return doRequestAndSaveToFile(options, thumbnailPath) | 48 | return doRequestAndSaveToFile(options, thumbnailPath) |
49 | } | 49 | } |
50 | 50 | ||
51 | function sendVideoRateChangeToFollowers (account: AccountInstance, video: VideoInstance, likes: number, dislikes: number, t: Transaction) { | 51 | async function sendVideoRateChangeToFollowers ( |
52 | const tasks: Promise<any>[] = [] | 52 | account: AccountInstance, |
53 | video: VideoInstance, | ||
54 | likes: number, | ||
55 | dislikes: number, | ||
56 | t: Transaction | ||
57 | ) { | ||
58 | // Keep the order: first we undo and then we create | ||
53 | 59 | ||
54 | // Undo Like | 60 | // Undo Like |
55 | if (likes < 0) tasks.push(sendUndoLikeToVideoFollowers(account, video, t)) | 61 | if (likes < 0) await sendUndoLikeToVideoFollowers(account, video, t) |
56 | // Like | ||
57 | if (likes > 0) tasks.push(sendLikeToVideoFollowers(account, video, t)) | ||
58 | |||
59 | // Undo Dislike | 62 | // Undo Dislike |
60 | if (dislikes < 0) tasks.push(sendUndoDislikeToVideoFollowers(account, video, t)) | 63 | if (dislikes < 0) await sendUndoDislikeToVideoFollowers(account, video, t) |
61 | // Dislike | ||
62 | if (dislikes > 0) tasks.push(sendCreateDislikeToVideoFollowers(account, video, t)) | ||
63 | 64 | ||
64 | return Promise.all(tasks) | 65 | // Like |
66 | if (likes > 0) await sendLikeToVideoFollowers(account, video, t) | ||
67 | // Dislike | ||
68 | if (dislikes > 0) await sendCreateDislikeToVideoFollowers(account, video, t) | ||
65 | } | 69 | } |
66 | 70 | ||
67 | function sendVideoRateChangeToOrigin (account: AccountInstance, video: VideoInstance, likes: number, dislikes: number, t: Transaction) { | 71 | async function sendVideoRateChangeToOrigin ( |
68 | const tasks: Promise<any>[] = [] | 72 | account: AccountInstance, |
73 | video: VideoInstance, | ||
74 | likes: number, | ||
75 | dislikes: number, | ||
76 | t: Transaction | ||
77 | ) { | ||
78 | // Keep the order: first we undo and then we create | ||
69 | 79 | ||
70 | // Undo Like | 80 | // Undo Like |
71 | if (likes < 0) tasks.push(sendUndoLikeToOrigin(account, video, t)) | 81 | if (likes < 0) await sendUndoLikeToOrigin(account, video, t) |
72 | // Like | ||
73 | if (likes > 0) tasks.push(sendLikeToOrigin(account, video, t)) | ||
74 | |||
75 | // Undo Dislike | 82 | // Undo Dislike |
76 | if (dislikes < 0) tasks.push(sendUndoDislikeToOrigin(account, video, t)) | 83 | if (dislikes < 0) await sendUndoDislikeToOrigin(account, video, t) |
77 | // Dislike | ||
78 | if (dislikes > 0) tasks.push(sendCreateDislikeToOrigin(account, video, t)) | ||
79 | 84 | ||
80 | return Promise.all(tasks) | 85 | // Like |
86 | if (likes > 0) await sendLikeToOrigin(account, video, t) | ||
87 | // Dislike | ||
88 | if (dislikes > 0) await sendCreateDislikeToOrigin(account, video, t) | ||
81 | } | 89 | } |
82 | 90 | ||
83 | export { | 91 | export { |