mirror of https://github.com/Chocobozzz/PeerTube
Fix like/dislike federation
This commit is contained in:
parent
29d4e1375f
commit
a21e25ff64
|
@ -34,19 +34,20 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
|
||||||
const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
|
const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
|
||||||
if (existingRate && existingRate.type === 'dislike') return
|
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 })
|
await video.increment('dislikes', { transaction: t })
|
||||||
|
|
||||||
if (existingRate && existingRate.type === 'like') {
|
if (existingRate && existingRate.type === 'like') {
|
||||||
await video.decrement('likes', { transaction: t })
|
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()) {
|
if (video.isOwned()) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
const exceptions = [ byActor ]
|
||||||
|
|
|
@ -34,19 +34,20 @@ async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) {
|
||||||
const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
|
const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
|
||||||
if (existingRate && existingRate.type === 'like') return
|
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') {
|
if (existingRate && existingRate.type === 'dislike') {
|
||||||
await video.decrement('dislikes', { transaction: t })
|
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()) {
|
if (video.isOwned()) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
const exceptions = [ byActor ]
|
||||||
|
|
Loading…
Reference in New Issue