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