import { VideoAbuseModel } from '../../../models/video/video-abuse'
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 { immutableAssign } from '../../../../shared/utils'
+import { getVideoDislikeActivityPubUrl } from '../url'
+import { VideoModel } from '../../../models/video/video'
async function processCreateActivity (activity: ActivityCreate, byActor: ActorModel) {
const activityObject = activity.object
videoId: video.id,
accountId: byAccount.id
}
+
const [ , created ] = await AccountVideoRateModel.findOrCreate({
where: rate,
- defaults: rate,
+ defaults: immutableAssign(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 options = {
- videoObject: view.object,
- fetchType: 'only-video' as 'only-video'
- }
- const { video } = await getOrCreateVideoAndAccountAndChannel(options)
+ const video = await VideoModel.loadByUrl(view.object)
+ if (!video || video.isOwned() === false) return
await Redis.Instance.addVideoView(video.id)
-
- if (video.isOwned()) {
- // Don't resend the activity to the sender
- const exceptions = [ byActor ]
- await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
- }
}
async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) {
const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
await sequelizeTypescript.transaction(async t => {
- return createCacheFile(cacheFile, video, byActor, t)
+ return createOrUpdateCacheFile(cacheFile, video, byActor, t)
})
if (video.isOwned()) {