]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/lib/activitypub/process/process-view.ts
Add ability to forbid followers
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-view.ts
1 import { ActorModel } from '../../../models/activitypub/actor'
2 import { getOrCreateVideoAndAccountAndChannel } from '../videos'
3 import { forwardVideoRelatedActivity } from '../send/utils'
4 import { Redis } from '../../redis'
5 import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
6
7 async function processViewActivity (activity: ActivityView | ActivityCreate, byActor: ActorModel) {
8 return processCreateView(activity, byActor)
9 }
10
11 // ---------------------------------------------------------------------------
12
13 export {
14 processViewActivity
15 }
16
17 // ---------------------------------------------------------------------------
18
19 async function processCreateView (activity: ActivityView | ActivityCreate, byActor: ActorModel) {
20 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object
21
22 const options = {
23 videoObject: videoObject,
24 fetchType: 'only-video' as 'only-video'
25 }
26 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
27
28 await Redis.Instance.addVideoView(video.id)
29
30 if (video.isOwned()) {
31 // Don't resend the activity to the sender
32 const exceptions = [ byActor ]
33 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
34 }
35 }