X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-create.ts;h=9a72cb899b56c7c3fb6f3fb6bebc937643827c60;hb=92e07c3b5d9dbf2febedb1b5b87ec676eb6d1ac8;hp=ceb5413ca6d153b889305502e949ac74adfdeecb;hpb=e5565833f62b97f62ea75eba5b479963ae78b873;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index ceb5413ca..9a72cb899 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -9,9 +9,12 @@ import { ActorModel } from '../../../models/activitypub/actor' 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 @@ -65,9 +68,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea 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 }) @@ -84,19 +88,10 @@ async function processCreateDislike (byActor: ActorModel, activity: ActivityCrea 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) { @@ -105,7 +100,7 @@ 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()) {