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