]>
Commit | Line | Data |
---|---|---|
1 | import { VideoViewsManager } from '@server/lib/views/video-views-manager' | |
2 | import { ActivityView } from '../../../../shared/models/activitypub' | |
3 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' | |
4 | import { MActorSignature } from '../../../types/models' | |
5 | import { forwardVideoRelatedActivity } from '../send/shared/send-utils' | |
6 | import { getOrCreateAPVideo } from '../videos' | |
7 | ||
8 | async function processViewActivity (options: APProcessorOptions<ActivityView>) { | |
9 | const { activity, byActor } = options | |
10 | ||
11 | return processCreateView(activity, byActor) | |
12 | } | |
13 | ||
14 | // --------------------------------------------------------------------------- | |
15 | ||
16 | export { | |
17 | processViewActivity | |
18 | } | |
19 | ||
20 | // --------------------------------------------------------------------------- | |
21 | ||
22 | async function processCreateView (activity: ActivityView, byActor: MActorSignature) { | |
23 | const videoObject = activity.object | |
24 | ||
25 | const { video } = await getOrCreateAPVideo({ | |
26 | videoObject, | |
27 | fetchType: 'only-video', | |
28 | allowRefresh: false | |
29 | }) | |
30 | ||
31 | const viewerExpires = activity.expires | |
32 | ? new Date(activity.expires) | |
33 | : undefined | |
34 | ||
35 | await VideoViewsManager.Instance.processRemoteView({ video, viewerId: activity.id, viewerExpires }) | |
36 | ||
37 | if (video.isOwned()) { | |
38 | // Forward the view but don't resend the activity to the sender | |
39 | const exceptions = [ byActor ] | |
40 | await forwardVideoRelatedActivity(activity, undefined, exceptions, video) | |
41 | } | |
42 | } |