aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process/process-view.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-06 16:42:23 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-11-09 15:33:04 +0100
commite4bf78561763cd84d22ebceb6f371cccf9a356d8 (patch)
tree7d8ea6ed53810d1dfcc2cfa5e3150da8e87e4645 /server/lib/activitypub/process/process-view.ts
parent529f037294d9917a62235f8162887a8edc04c32f (diff)
downloadPeerTube-e4bf78561763cd84d22ebceb6f371cccf9a356d8.tar.gz
PeerTube-e4bf78561763cd84d22ebceb6f371cccf9a356d8.tar.zst
PeerTube-e4bf78561763cd84d22ebceb6f371cccf9a356d8.zip
Handle views for live videos
Diffstat (limited to 'server/lib/activitypub/process/process-view.ts')
-rw-r--r--server/lib/activitypub/process/process-view.ts19
1 files changed, 14 insertions, 5 deletions
diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts
index cc26180af..efceb21a2 100644
--- a/server/lib/activitypub/process/process-view.ts
+++ b/server/lib/activitypub/process/process-view.ts
@@ -4,6 +4,7 @@ import { Redis } from '../../redis'
4import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub' 4import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
5import { APProcessorOptions } from '../../../types/activitypub-processor.model' 5import { APProcessorOptions } from '../../../types/activitypub-processor.model'
6import { MActorSignature } from '../../../types/models' 6import { MActorSignature } from '../../../types/models'
7import { LiveManager } from '@server/lib/live-manager'
7 8
8async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) { 9async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
9 const { activity, byActor } = options 10 const { activity, byActor } = options
@@ -19,19 +20,27 @@ export {
19// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
20 21
21async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) { 22async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) {
22 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object 23 const videoObject = activity.type === 'View'
24 ? activity.object
25 : (activity.object as ViewObject).object
23 26
24 const options = { 27 const options = {
25 videoObject, 28 videoObject,
26 fetchType: 'only-immutable-attributes' as 'only-immutable-attributes', 29 fetchType: 'only-video' as 'only-video',
27 allowRefresh: false as false 30 allowRefresh: false as false
28 } 31 }
29 const { video } = await getOrCreateVideoAndAccountAndChannel(options) 32 const { video } = await getOrCreateVideoAndAccountAndChannel(options)
30 33
31 await Redis.Instance.addVideoView(video.id)
32
33 if (video.isOwned()) { 34 if (video.isOwned()) {
34 // Don't resend the activity to the sender 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
35 const exceptions = [ byActor ] 44 const exceptions = [ byActor ]
36 await forwardVideoRelatedActivity(activity, undefined, exceptions, video) 45 await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
37 } 46 }