]>
Commit | Line | Data |
---|---|---|
1 | import { ActivityAnnounce } from '../../../shared/models/activitypub/activity' | |
2 | import { VideoChannelObject } from '../../../shared/models/activitypub/objects/video-channel-object' | |
3 | import { VideoTorrentObject } from '../../../shared/models/activitypub/objects/video-torrent-object' | |
4 | import { logger } from '../../helpers/logger' | |
5 | import { processAddActivity } from './process-add' | |
6 | import { processCreateActivity } from './process-create' | |
7 | import { database as db } from '../../initializers/index' | |
8 | import { getOrCreateAccount } from '../../helpers/activitypub' | |
9 | import { VideoChannelInstance } from '../../models/video/video-channel-interface' | |
10 | import { VideoInstance } from '../../models/index' | |
11 | ||
12 | async function processAnnounceActivity (activity: ActivityAnnounce) { | |
13 | const announcedActivity = activity.object | |
14 | const accountAnnouncer = await getOrCreateAccount(activity.actor) | |
15 | ||
16 | if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'VideoChannel') { | |
17 | // Add share entry | |
18 | const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity) | |
19 | await db.VideoChannelShare.create({ | |
20 | accountId: accountAnnouncer.id, | |
21 | videoChannelId: videoChannel.id | |
22 | }) | |
23 | ||
24 | return undefined | |
25 | } else if (announcedActivity.type === 'Add' && announcedActivity.object.type === 'Video') { | |
26 | // Add share entry | |
27 | const video: VideoInstance = await processAddActivity(announcedActivity) | |
28 | await db.VideoShare.create({ | |
29 | accountId: accountAnnouncer.id, | |
30 | videoId: video.id | |
31 | }) | |
32 | ||
33 | return undefined | |
34 | } | |
35 | ||
36 | logger.warn( | |
37 | 'Unknown activity object type %s -> %s when announcing activity.', announcedActivity.type, announcedActivity.object.type, | |
38 | { activity: activity.id } | |
39 | ) | |
40 | return Promise.resolve(undefined) | |
41 | } | |
42 | ||
43 | // --------------------------------------------------------------------------- | |
44 | ||
45 | export { | |
46 | processAnnounceActivity | |
47 | } |