-import * as Bluebird from 'bluebird'
-import { getOrCreateActorAndServerAndModel } from './actor'
-import { AccountVideoRateModel } from '../../models/account/account-video-rate'
-import { logger } from '../../helpers/logger'
-import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers'
-import { doRequest } from '../../helpers/requests'
-import { checkUrlsSameHost, getActorUrl } from '../../helpers/activitypub'
-import { ActorModel } from '../../models/activitypub/actor'
-import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url'
-
-async function createRates (ratesUrl: string[], video: VideoModel, rate: VideoRateType) {
- let rateCounts = 0
-
- await Bluebird.map(ratesUrl, async rateUrl => {
- try {
- // Fetch url
- const { body } = await doRequest({
- uri: rateUrl,
- json: true,
- activityPub: true
- })
- if (!body || !body.actor) throw new Error('Body or body actor is invalid')
-
- const actorUrl = getActorUrl(body.actor)
- if (checkUrlsSameHost(actorUrl, rateUrl) !== true) {
- throw new Error(`Rate url ${rateUrl} has not the same host than actor url ${actorUrl}`)
- }
-
- if (checkUrlsSameHost(body.id, rateUrl) !== true) {
- throw new Error(`Rate url ${rateUrl} host is different from the AP object id ${body.id}`)
- }
-
- const actor = await getOrCreateActorAndServerAndModel(actorUrl)
+import { MAccountActor, MActorUrl, MVideoAccountLight, MVideoFullLight, MVideoId } from '../../types/models'
+import { sendLike, sendUndoDislike, sendUndoLike } from './send'
+import { sendDislike } from './send/send-dislike'
+import { getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from './url'
+import { federateVideoIfNeeded } from './videos'
+
+async function sendVideoRateChange (
+ account: MAccountActor,
+ video: MVideoFullLight,
+ likes: number,
+ dislikes: number,
+ t: Transaction
+) {
+ if (video.isOwned()) return federateVideoIfNeeded(video, false, t)
+
+ return sendVideoRateChangeToOrigin(account, video, likes, dislikes, t)
+}