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