]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/lib/activitypub/process/process-view.ts
Improve viewer counter
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-view.ts
... / ...
CommitLineData
1import { VideoViewsManager } from '@server/lib/views/video-views-manager'
2import { ActivityView } from '../../../../shared/models/activitypub'
3import { APProcessorOptions } from '../../../types/activitypub-processor.model'
4import { MActorSignature } from '../../../types/models'
5import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
6import { getOrCreateAPVideo } from '../videos'
7
8async function processViewActivity (options: APProcessorOptions<ActivityView>) {
9 const { activity, byActor } = options
10
11 return processCreateView(activity, byActor)
12}
13
14// ---------------------------------------------------------------------------
15
16export {
17 processViewActivity
18}
19
20// ---------------------------------------------------------------------------
21
22async function processCreateView (activity: ActivityView, byActor: MActorSignature) {
23 const videoObject = activity.object
24
25 const { video } = await getOrCreateAPVideo({
26 videoObject,
27 fetchType: 'only-video',
28 allowRefresh: false
29 })
30
31 const viewerExpires = activity.expires
32 ? new Date(activity.expires)
33 : undefined
34
35 await VideoViewsManager.Instance.processRemoteView({ video, viewerId: activity.id, viewerExpires })
36
37 if (video.isOwned()) {
38 // Forward the view but don't resend the activity to the sender
39 const exceptions = [ byActor ]
40 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
41 }
42}