From b211106695bb82f6c32e53306081b5262c3d109d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 24 Mar 2022 13:36:47 +0100 Subject: Support video views/viewers stats in server * Add "currentTime" and "event" body params to view endpoint * Merge watching and view endpoints * Introduce WatchAction AP activity * Add tables to store viewer information of local videos * Add endpoints to fetch video views/viewers stats of local videos * Refactor views/viewers handlers * Support "views" and "viewers" counters for both VOD and live videos --- server/lib/activitypub/send/send-create.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'server/lib/activitypub/send/send-create.ts') diff --git a/server/lib/activitypub/send/send-create.ts b/server/lib/activitypub/send/send-create.ts index 5d8763495..7c3a6bdd0 100644 --- a/server/lib/activitypub/send/send-create.ts +++ b/server/lib/activitypub/send/send-create.ts @@ -6,6 +6,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment' import { MActorLight, MCommentOwnerVideo, + MLocalVideoViewerWithWatchSections, MVideoAccountLight, MVideoAP, MVideoPlaylistFull, @@ -19,6 +20,7 @@ import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getVideoCommentAudience, + sendVideoActivityToOrigin, sendVideoRelatedActivity, unicastTo } from './shared' @@ -61,6 +63,18 @@ async function sendCreateCacheFile ( }) } +async function sendCreateWatchAction (stats: MLocalVideoViewerWithWatchSections, transaction: Transaction) { + logger.info('Creating job to send create watch action %s.', stats.url, lTags(stats.uuid)) + + const byActor = await getServerActor() + + const activityBuilder = (audience: ActivityAudience) => { + return buildCreateActivity(stats.url, byActor, stats.toActivityPubObject(), audience) + } + + return sendVideoActivityToOrigin(activityBuilder, { byActor, video: stats.Video, transaction, contextType: 'WatchAction' }) +} + async function sendCreateVideoPlaylist (playlist: MVideoPlaylistFull, transaction: Transaction) { if (playlist.privacy === VideoPlaylistPrivacy.PRIVATE) return undefined @@ -175,7 +189,8 @@ export { buildCreateActivity, sendCreateVideoComment, sendCreateVideoPlaylist, - sendCreateCacheFile + sendCreateCacheFile, + sendCreateWatchAction } // --------------------------------------------------------------------------- -- cgit v1.2.3