X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fprocess%2Fprocess-view.ts;h=c2d41dd2845fe2e629416795eb81863e07d3e91c;hb=304a84d59c3a800b7f7aef48cf55f307534c0926;hp=8f66d3630ecdbea67096f6237ba65203aa55bcf0;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts index 8f66d3630..c2d41dd28 100644 --- a/server/lib/activitypub/process/process-view.ts +++ b/server/lib/activitypub/process/process-view.ts @@ -1,10 +1,13 @@ -import { ActorModel } from '../../../models/activitypub/actor' -import { getOrCreateVideoAndAccountAndChannel } from '../videos' +import { getOrCreateAPVideo } from '../videos' import { forwardVideoRelatedActivity } from '../send/utils' import { Redis } from '../../redis' import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub' +import { APProcessorOptions } from '../../../types/activitypub-processor.model' +import { MActorSignature } from '../../../types/models' +import { LiveManager } from '@server/lib/live-manager' -async function processViewActivity (activity: ActivityView | ActivityCreate, byActor: ActorModel) { +async function processViewActivity (options: APProcessorOptions) { + const { activity, byActor } = options return processCreateView(activity, byActor) } @@ -16,19 +19,30 @@ export { // --------------------------------------------------------------------------- -async function processCreateView (activity: ActivityView | ActivityCreate, byActor: ActorModel) { - const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object +async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) { + const videoObject = activity.type === 'View' + ? activity.object + : (activity.object as ViewObject).object const options = { - videoObject: videoObject, - fetchType: 'only-video' as 'only-video' + videoObject, + fetchType: 'only-video' as 'only-video', + allowRefresh: false as false } - const { video } = await getOrCreateVideoAndAccountAndChannel(options) + const { video } = await getOrCreateAPVideo(options) - await Redis.Instance.addVideoView(video.id) + if (!video.isLive) { + await Redis.Instance.addVideoView(video.id) + } if (video.isOwned()) { - // Don't resend the activity to the sender + // Our live manager will increment the counter and send the view to followers + if (video.isLive) { + LiveManager.Instance.addViewTo(video.id) + return + } + + // Forward the view but don't resend the activity to the sender const exceptions = [ byActor ] await forwardVideoRelatedActivity(activity, undefined, exceptions, video) }