import { forwardVideoRelatedActivity } from '../send/utils'
import { Redis } from '../../redis'
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
const [ , created ] = await AccountVideoRateModel.findOrCreate({
where: rate,
- defaults: immutableAssign(rate, { url: getVideoDislikeActivityPubUrl(byActor, video) }),
+ 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 VideoModel.loadByUrl(view.object)
- if (!video || video.isOwned() === false) return
+ 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 forwardVideoRelatedActivity(activity, undefined, exceptions, video)
+ }
}
async function processCacheFile (byActor: ActorModel, activity: ActivityCreate) {