]>
Commit | Line | Data |
---|---|---|
304a84d5 | 1 | import { getOrCreateAPVideo } from '../videos' |
848f499d C |
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' | |
e4bf7856 | 7 | import { LiveManager } from '@server/lib/live-manager' |
848f499d | 8 | |
1198edf4 C |
9 | async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) { |
10 | const { activity, byActor } = options | |
848f499d C |
11 | return processCreateView(activity, byActor) |
12 | } | |
13 | ||
14 | // --------------------------------------------------------------------------- | |
15 | ||
16 | export { | |
17 | processViewActivity | |
18 | } | |
19 | ||
20 | // --------------------------------------------------------------------------- | |
21 | ||
453e83ea | 22 | async function processCreateView (activity: ActivityView | ActivityCreate, byActor: MActorSignature) { |
e4bf7856 C |
23 | const videoObject = activity.type === 'View' |
24 | ? activity.object | |
25 | : (activity.object as ViewObject).object | |
848f499d | 26 | |
28dfb44b | 27 | const { video } = await getOrCreateAPVideo({ |
453e83ea | 28 | videoObject, |
28dfb44b C |
29 | fetchType: 'only-video', |
30 | allowRefresh: false | |
31 | }) | |
848f499d | 32 | |
c655c9ef C |
33 | if (!video.isLive) { |
34 | await Redis.Instance.addVideoView(video.id) | |
35 | } | |
36 | ||
848f499d | 37 | if (video.isOwned()) { |
e4bf7856 C |
38 | // Our live manager will increment the counter and send the view to followers |
39 | if (video.isLive) { | |
40 | LiveManager.Instance.addViewTo(video.id) | |
41 | return | |
42 | } | |
43 | ||
e4bf7856 | 44 | // Forward the view but don't resend the activity to the sender |
848f499d C |
45 | const exceptions = [ byActor ] |
46 | await forwardVideoRelatedActivity(activity, undefined, exceptions, video) | |
47 | } | |
48 | } |