]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/process/process-view.ts
Handle views for live videos
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-view.ts
CommitLineData
848f499d
C
1import { getOrCreateVideoAndAccountAndChannel } from '../videos'
2import { forwardVideoRelatedActivity } from '../send/utils'
3import { Redis } from '../../redis'
4import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
26d6bf65
C
5import { APProcessorOptions } from '../../../types/activitypub-processor.model'
6import { MActorSignature } from '../../../types/models'
e4bf7856 7import { LiveManager } from '@server/lib/live-manager'
848f499d 8
1198edf4
C
9async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
10 const { activity, byActor } = options
848f499d
C
11 return processCreateView(activity, byActor)
12}
13
14// ---------------------------------------------------------------------------
15
16export {
17 processViewActivity
18}
19
20// ---------------------------------------------------------------------------
21
453e83ea 22async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) {
e4bf7856
C
23 const videoObject = activity.type === 'View'
24 ? activity.object
25 : (activity.object as ViewObject).object
848f499d
C
26
27 const options = {
453e83ea 28 videoObject,
e4bf7856 29 fetchType: 'only-video' as 'only-video',
943e5193 30 allowRefresh: false as false
848f499d
C
31 }
32 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
33
848f499d 34 if (video.isOwned()) {
e4bf7856
C
35 // Our live manager will increment the counter and send the view to followers
36 if (video.isLive) {
37 LiveManager.Instance.addViewTo(video.id)
38 return
39 }
40
41 await Redis.Instance.addVideoView(video.id)
42
43 // Forward the view but don't resend the activity to the sender
848f499d
C
44 const exceptions = [ byActor ]
45 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
46 }
47}