]>
Commit | Line | Data |
---|---|---|
848f499d C |
1 | import { getOrCreateVideoAndAccountAndChannel } from '../videos' |
2 | import { forwardVideoRelatedActivity } from '../send/utils' | |
3 | import { Redis } from '../../redis' | |
4 | import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub' | |
26d6bf65 C |
5 | import { APProcessorOptions } from '../../../types/activitypub-processor.model' |
6 | import { MActorSignature } from '../../../types/models' | |
848f499d | 7 | |
1198edf4 C |
8 | async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) { |
9 | const { activity, byActor } = options | |
848f499d C |
10 | return processCreateView(activity, byActor) |
11 | } | |
12 | ||
13 | // --------------------------------------------------------------------------- | |
14 | ||
15 | export { | |
16 | processViewActivity | |
17 | } | |
18 | ||
19 | // --------------------------------------------------------------------------- | |
20 | ||
453e83ea | 21 | async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) { |
848f499d C |
22 | const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object |
23 | ||
24 | const options = { | |
453e83ea | 25 | videoObject, |
943e5193 C |
26 | fetchType: 'only-immutable-attributes' as 'only-immutable-attributes', |
27 | allowRefresh: false as false | |
848f499d C |
28 | } |
29 | const { video } = await getOrCreateVideoAndAccountAndChannel(options) | |
30 | ||
31 | await Redis.Instance.addVideoView(video.id) | |
32 | ||
33 | if (video.isOwned()) { | |
34 | // Don't resend the activity to the sender | |
35 | const exceptions = [ byActor ] | |
36 | await forwardVideoRelatedActivity(activity, undefined, exceptions, video) | |
37 | } | |
38 | } |