From 40ff57078e15d5b86ee6b71e198b95d3feb78eaf Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Nov 2017 16:25:03 +0100 Subject: Federate video views --- server/lib/activitypub/process/process-create.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'server/lib/activitypub/process/process-create.ts') diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index ddf7c74f6..1777733a0 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts @@ -1,9 +1,11 @@ import { ActivityCreate, VideoChannelObject } from '../../../../shared' import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects/video-abuse-object' +import { ViewObject } from '../../../../shared/models/activitypub/objects/view-object' import { logger, retryTransactionWrapper } from '../../../helpers' import { database as db } from '../../../initializers' import { AccountInstance } from '../../../models/account/account-interface' import { getOrCreateAccountAndServer } from '../account' +import { sendCreateViewToVideoFollowers } from '../send/send-create' import { getVideoChannelActivityPubUrl } from '../url' import { videoChannelActivityObjectToDBAttributes } from './misc' @@ -12,7 +14,9 @@ async function processCreateActivity (activity: ActivityCreate) { const activityType = activityObject.type const account = await getOrCreateAccountAndServer(activity.actor) - if (activityType === 'VideoChannel') { + if (activityType === 'View') { + return processCreateView(activityObject as ViewObject) + } else if (activityType === 'VideoChannel') { return processCreateVideoChannel(account, activityObject as VideoChannelObject) } else if (activityType === 'Flag') { return processCreateVideoAbuse(account, activityObject as VideoAbuseObject) @@ -30,6 +34,19 @@ export { // --------------------------------------------------------------------------- +async function processCreateView (view: ViewObject) { + const video = await db.Video.loadByUrlAndPopulateAccount(view.object) + + if (!video) throw new Error('Unknown video ' + view.object) + + const account = await db.Account.loadByUrl(view.actor) + if (!account) throw new Error('Unknown account ' + view.actor) + + await video.increment('views') + + if (video.isOwned()) await sendCreateViewToVideoFollowers(account, video, undefined) +} + function processCreateVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { const options = { arguments: [ account, videoChannelToCreateData ], -- cgit v1.2.3