From 1e7eb25f6cb6893db8f99ff40ef0509aa2a16614 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 15 Jan 2019 14:52:33 +0100 Subject: Correctly send Flag/Dislike/View activities --- server/lib/activitypub/send/send-view.ts | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 server/lib/activitypub/send/send-view.ts (limited to 'server/lib/activitypub/send/send-view.ts') diff --git a/server/lib/activitypub/send/send-view.ts b/server/lib/activitypub/send/send-view.ts new file mode 100644 index 000000000..8ad126be0 --- /dev/null +++ b/server/lib/activitypub/send/send-view.ts @@ -0,0 +1,40 @@ +import { Transaction } from 'sequelize' +import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' +import { ActorModel } from '../../../models/activitypub/actor' +import { VideoModel } from '../../../models/video/video' +import { getVideoLikeActivityPubUrl } from '../url' +import { sendVideoRelatedActivity } from './utils' +import { audiencify, getAudience } from '../audience' +import { logger } from '../../../helpers/logger' + +async function sendView (byActor: ActorModel, video: VideoModel, t: Transaction) { + logger.info('Creating job to send view of %s.', video.url) + + const activityBuilder = (audience: ActivityAudience) => { + const url = getVideoLikeActivityPubUrl(byActor, video) + + return buildViewActivity(url, byActor, video, audience) + } + + return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t }) +} + +function buildViewActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityView { + if (!audience) audience = getAudience(byActor) + + return audiencify( + { + id: url, + type: 'View' as 'View', + actor: byActor.url, + object: video.url + }, + audience + ) +} + +// --------------------------------------------------------------------------- + +export { + sendView +} -- cgit v1.2.3