import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
import { ActorModel } from '../../../models/activitypub/actor'
import { VideoAbuseModel } from '../../../models/video/video-abuse'
-import { getOrCreateActorAndServerAndModel } from '../actor'
import { addVideoComment, resolveThread } from '../video-comments'
import { getOrCreateVideoAndAccountAndChannel } from '../videos'
-import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
+import { forwardVideoRelatedActivity } from '../send/utils'
import { Redis } from '../../redis'
-import { createCacheFile } from '../cache-file'
+import { createOrUpdateCacheFile } from '../cache-file'
+import { getVideoDislikeActivityPubUrl } from '../url'
-async function processCreateActivity (activity: ActivityCreate) {
+async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
const activityObject = activity.object
const activityType = activityObject.type
- const actor = await getOrCreateActorAndServerAndModel(activity.actor)
if (activityType === 'View') {
- return processCreateView(actor, activity)
+ return processCreateView(byActor, activity)
} else if (activityType === 'Dislike') {
- return retryTransactionWrapper(processCreateDislike, actor, activity)
+ return retryTransactionWrapper(processCreateDislike, byActor, activity)
} else if (activityType === 'Video') {
return processCreateVideo(activity)
} else if (activityType === 'Flag') {
- return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject)
+ return retryTransactionWrapper(processCreateVideoAbuse, byActor, activityObject as VideoAbuseObject)
} else if (activityType === 'Note') {
- return retryTransactionWrapper(processCreateVideoComment, actor, activity)
+ return retryTransactionWrapper(processCreateVideoComment, byActor, activity)
} else if (activityType === 'CacheFile') {
- return retryTransactionWrapper(processCacheFile, actor, activity)
+ return retryTransactionWrapper(processCacheFile, byActor, activity)
}
logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
videoId: video.id,
accountId: byAccount.id
}
+
const [ , created ] = await AccountVideoRateModel.findOrCreate({
where: rate,
- defaults: rate,
+ defaults: Object.assign({}, rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
transaction: t
})
if (created === true) await video.increment('dislikes', { transaction: t })
async function processCreateView (byActor: ActorModel, activity: ActivityCreate) {
const view = activity.object as ViewObject
- const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: view.object })
-
- const actor = await ActorModel.loadByUrl(view.actor)
- if (!actor) throw new Error('Unknown actor ' + view.actor)
+ const options = {
+ videoObject: view.object,
+ fetchType: 'only-video' as 'only-video'
+ }
+ const { video } = await getOrCreateVideoAndAccountAndChannel(options)
await Redis.Instance.addVideoView(video.id)
if (video.isOwned()) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardActivity(activity, undefined, exceptions)
+ await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
}
}
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
- await createCacheFile(cacheFile, video, byActor)
+ await sequelizeTypescript.transaction(async t => {
+ return createOrUpdateCacheFile(cacheFile, video, byActor, t)
+ })
if (video.isOwned()) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardActivity(activity, undefined, exceptions)
+ await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
}
}
-async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
+async function processCreateVideoAbuse (byActor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
- const account = actor.Account
- if (!account) throw new Error('Cannot create dislike with the non account actor ' + actor.url)
+ const account = byActor.Account
+ if (!account) throw new Error('Cannot create dislike with the non account actor ' + byActor.url)
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoAbuseToCreateData.object })