diff options
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/playlist.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-dislike.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/video-rates.ts | 15 | ||||
-rw-r--r-- | server/lib/activitypub/videos.ts | 3 |
5 files changed, 9 insertions, 15 deletions
diff --git a/server/lib/activitypub/playlist.ts b/server/lib/activitypub/playlist.ts index 53298e968..8b54a001a 100644 --- a/server/lib/activitypub/playlist.ts +++ b/server/lib/activitypub/playlist.ts | |||
@@ -99,6 +99,8 @@ async function createOrUpdateVideoPlaylist (playlistObject: PlaylistObject, byAc | |||
99 | return Promise.resolve() | 99 | return Promise.resolve() |
100 | }) | 100 | }) |
101 | 101 | ||
102 | logger.info('toto', { playlist, id: playlist.id }) | ||
103 | |||
102 | const refreshedPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(playlist.id, null) | 104 | const refreshedPlaylist = await VideoPlaylistModel.loadWithAccountAndChannel(playlist.id, null) |
103 | 105 | ||
104 | if (playlistObject.icon) { | 106 | if (playlistObject.icon) { |
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts index 635c8bfcc..089c7b881 100644 --- a/server/lib/activitypub/process/process-dislike.ts +++ b/server/lib/activitypub/process/process-dislike.ts | |||
@@ -33,7 +33,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct | |||
33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) | 33 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) |
34 | 34 | ||
35 | return sequelizeTypescript.transaction(async t => { | 35 | return sequelizeTypescript.transaction(async t => { |
36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) | 36 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) |
37 | if (existingRate && existingRate.type === 'dislike') return | 37 | if (existingRate && existingRate.type === 'dislike') return |
38 | 38 | ||
39 | await video.increment('dislikes', { transaction: t }) | 39 | await video.increment('dislikes', { transaction: t }) |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index 6acc097b1..8688b3b47 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -30,7 +30,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik | |||
30 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) | 30 | const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) |
31 | 31 | ||
32 | return sequelizeTypescript.transaction(async t => { | 32 | return sequelizeTypescript.transaction(async t => { |
33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id) | 33 | const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) |
34 | if (existingRate && existingRate.type === 'like') return | 34 | if (existingRate && existingRate.type === 'like') return |
35 | 35 | ||
36 | if (existingRate && existingRate.type === 'dislike') { | 36 | if (existingRate && existingRate.type === 'dislike') { |
diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts index 581a2bca1..e246b1313 100644 --- a/server/lib/activitypub/video-rates.ts +++ b/server/lib/activitypub/video-rates.ts | |||
@@ -13,8 +13,6 @@ import { sendDislike } from './send/send-dislike' | |||
13 | import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' | 13 | import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' |
14 | 14 | ||
15 | async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateType) { | 15 | async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateType) { |
16 | let rateCounts = 0 | ||
17 | |||
18 | await Bluebird.map(ratesUrl, async rateUrl => { | 16 | await Bluebird.map(ratesUrl, async rateUrl => { |
19 | try { | 17 | try { |
20 | // Fetch url | 18 | // Fetch url |
@@ -43,21 +41,12 @@ async function createRates (ratesUrl: string[], video: MVideo, rate: VideoRateTy | |||
43 | url: body.id | 41 | url: body.id |
44 | } | 42 | } |
45 | 43 | ||
46 | const created = await AccountVideoRateModel.upsert(entry) | 44 | // Video "likes"/"dislikes" will be updated by the caller |
47 | 45 | await AccountVideoRateModel.upsert(entry) | |
48 | if (created) rateCounts += 1 | ||
49 | } catch (err) { | 46 | } catch (err) { |
50 | logger.warn('Cannot add rate %s.', rateUrl, { err }) | 47 | logger.warn('Cannot add rate %s.', rateUrl, { err }) |
51 | } | 48 | } |
52 | }, { concurrency: CRAWL_REQUEST_CONCURRENCY }) | 49 | }, { concurrency: CRAWL_REQUEST_CONCURRENCY }) |
53 | |||
54 | logger.info('Adding %d %s to video %s.', rateCounts, rate, video.uuid) | ||
55 | |||
56 | // This is "likes" and "dislikes" | ||
57 | if (rateCounts !== 0) { | ||
58 | const field = rate === 'like' ? 'likes' : 'dislikes' | ||
59 | await video.increment(field, { by: rateCounts }) | ||
60 | } | ||
61 | } | 50 | } |
62 | 51 | ||
63 | async function sendVideoRateChange ( | 52 | async function sendVideoRateChange ( |
diff --git a/server/lib/activitypub/videos.ts b/server/lib/activitypub/videos.ts index b15d5da1c..cb462e258 100644 --- a/server/lib/activitypub/videos.ts +++ b/server/lib/activitypub/videos.ts | |||
@@ -352,6 +352,9 @@ async function updateVideoFromAP (options: { | |||
352 | video.views = videoData.views | 352 | video.views = videoData.views |
353 | video.isLive = videoData.isLive | 353 | video.isLive = videoData.isLive |
354 | 354 | ||
355 | // Ensures we update the updated video attribute | ||
356 | video.changed('updatedAt', true) | ||
357 | |||
355 | const videoUpdated = await video.save(sequelizeOptions) as MVideoFullLight | 358 | const videoUpdated = await video.save(sequelizeOptions) as MVideoFullLight |
356 | 359 | ||
357 | if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) | 360 | if (thumbnailModel) await videoUpdated.addAndSaveThumbnail(thumbnailModel, t) |