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