1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-05 02:39:33 +02:00

Handle views for live videos

This commit is contained in:
Chocobozzz 2020-11-06 16:42:23 +01:00 committed by Chocobozzz
parent 529f037294
commit e4bf785617
7 changed files with 190 additions and 24 deletions

View file

@ -4,6 +4,7 @@ import { Redis } from '../../redis'
import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
import { APProcessorOptions } from '../../../types/activitypub-processor.model'
import { MActorSignature } from '../../../types/models'
import { LiveManager } from '@server/lib/live-manager'
async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
const { activity, byActor } = options
@ -19,19 +20,27 @@ export {
// ---------------------------------------------------------------------------
async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) {
const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object
const videoObject = activity.type === 'View'
? activity.object
: (activity.object as ViewObject).object
const options = {
videoObject,
fetchType: 'only-immutable-attributes' as 'only-immutable-attributes',
fetchType: 'only-video' as 'only-video',
allowRefresh: false as false
}
const { video } = await getOrCreateVideoAndAccountAndChannel(options)
await Redis.Instance.addVideoView(video.id)
if (video.isOwned()) {
// Don't resend the activity to the sender
// Our live manager will increment the counter and send the view to followers
if (video.isLive) {
LiveManager.Instance.addViewTo(video.id)
return
}
await Redis.Instance.addVideoView(video.id)
// Forward the view but don't resend the activity to the sender
const exceptions = [ byActor ]
await forwardVideoRelatedActivity(activity, undefined, exceptions, video)
}