diff options
Diffstat (limited to 'server/lib/activitypub/video-rates.ts')
-rw-r--r-- | server/lib/activitypub/video-rates.ts | 15 |
1 files changed, 2 insertions, 13 deletions
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 ( |