Fix conflict rate serializations
This commit is contained in:
parent
4f49137101
commit
f00984c007
|
@ -63,7 +63,7 @@ function createVideoDislike (byAccount: AccountInstance, activity: ActivityCreat
|
||||||
defaults: rate,
|
defaults: rate,
|
||||||
transaction: t
|
transaction: t
|
||||||
})
|
})
|
||||||
await video.increment('dislikes', { transaction: t })
|
if (created === true) await video.increment('dislikes', { transaction: t })
|
||||||
|
|
||||||
if (video.isOwned() && created === true) {
|
if (video.isOwned() && created === true) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
|
|
|
@ -46,7 +46,7 @@ function createVideoLike (byAccount: AccountInstance, activity: ActivityLike) {
|
||||||
defaults: rate,
|
defaults: rate,
|
||||||
transaction: t
|
transaction: t
|
||||||
})
|
})
|
||||||
await video.increment('likes', { transaction: t })
|
if (created === true) await video.increment('likes', { transaction: t })
|
||||||
|
|
||||||
if (video.isOwned() && created === true) {
|
if (video.isOwned() && created === true) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
|
|
|
@ -48,36 +48,44 @@ function generateThumbnailFromUrl (video: VideoInstance, icon: ActivityIconObjec
|
||||||
return doRequestAndSaveToFile(options, thumbnailPath)
|
return doRequestAndSaveToFile(options, thumbnailPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendVideoRateChangeToFollowers (account: AccountInstance, video: VideoInstance, likes: number, dislikes: number, t: Transaction) {
|
async function sendVideoRateChangeToFollowers (
|
||||||
const tasks: Promise<any>[] = []
|
account: AccountInstance,
|
||||||
|
video: VideoInstance,
|
||||||
|
likes: number,
|
||||||
|
dislikes: number,
|
||||||
|
t: Transaction
|
||||||
|
) {
|
||||||
|
// Keep the order: first we undo and then we create
|
||||||
|
|
||||||
// Undo Like
|
// Undo Like
|
||||||
if (likes < 0) tasks.push(sendUndoLikeToVideoFollowers(account, video, t))
|
if (likes < 0) await sendUndoLikeToVideoFollowers(account, video, t)
|
||||||
// Like
|
|
||||||
if (likes > 0) tasks.push(sendLikeToVideoFollowers(account, video, t))
|
|
||||||
|
|
||||||
// Undo Dislike
|
// Undo Dislike
|
||||||
if (dislikes < 0) tasks.push(sendUndoDislikeToVideoFollowers(account, video, t))
|
if (dislikes < 0) await sendUndoDislikeToVideoFollowers(account, video, t)
|
||||||
// Dislike
|
|
||||||
if (dislikes > 0) tasks.push(sendCreateDislikeToVideoFollowers(account, video, t))
|
|
||||||
|
|
||||||
return Promise.all(tasks)
|
// Like
|
||||||
|
if (likes > 0) await sendLikeToVideoFollowers(account, video, t)
|
||||||
|
// Dislike
|
||||||
|
if (dislikes > 0) await sendCreateDislikeToVideoFollowers(account, video, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendVideoRateChangeToOrigin (account: AccountInstance, video: VideoInstance, likes: number, dislikes: number, t: Transaction) {
|
async function sendVideoRateChangeToOrigin (
|
||||||
const tasks: Promise<any>[] = []
|
account: AccountInstance,
|
||||||
|
video: VideoInstance,
|
||||||
|
likes: number,
|
||||||
|
dislikes: number,
|
||||||
|
t: Transaction
|
||||||
|
) {
|
||||||
|
// Keep the order: first we undo and then we create
|
||||||
|
|
||||||
// Undo Like
|
// Undo Like
|
||||||
if (likes < 0) tasks.push(sendUndoLikeToOrigin(account, video, t))
|
if (likes < 0) await sendUndoLikeToOrigin(account, video, t)
|
||||||
// Like
|
|
||||||
if (likes > 0) tasks.push(sendLikeToOrigin(account, video, t))
|
|
||||||
|
|
||||||
// Undo Dislike
|
// Undo Dislike
|
||||||
if (dislikes < 0) tasks.push(sendUndoDislikeToOrigin(account, video, t))
|
if (dislikes < 0) await sendUndoDislikeToOrigin(account, video, t)
|
||||||
// Dislike
|
|
||||||
if (dislikes > 0) tasks.push(sendCreateDislikeToOrigin(account, video, t))
|
|
||||||
|
|
||||||
return Promise.all(tasks)
|
// Like
|
||||||
|
if (likes > 0) await sendLikeToOrigin(account, video, t)
|
||||||
|
// Dislike
|
||||||
|
if (dislikes > 0) await sendCreateDislikeToOrigin(account, video, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|
Loading…
Reference in New Issue