]>
Commit | Line | Data |
---|---|---|
d8465018 C |
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) { | |
20494f12 | 13 | const announcedActivity = activity.object |
d8465018 C |
14 | const accountAnnouncer = await getOrCreateAccount(activity.actor) |
15 | ||
20494f12 | 16 | if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'VideoChannel') { |
d8465018 | 17 | // Add share entry |
20494f12 | 18 | const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity) |
d8465018 C |
19 | await db.VideoChannelShare.create({ |
20 | accountId: accountAnnouncer.id, | |
21 | videoChannelId: videoChannel.id | |
22 | }) | |
d8465018 | 23 | |
20494f12 C |
24 | return undefined |
25 | } else if (announcedActivity.type === 'Add' && announcedActivity.object.type === 'Video') { | |
d8465018 | 26 | // Add share entry |
20494f12 | 27 | const video: VideoInstance = await processAddActivity(announcedActivity) |
d8465018 C |
28 | await db.VideoShare.create({ |
29 | accountId: accountAnnouncer.id, | |
30 | videoId: video.id | |
31 | }) | |
20494f12 C |
32 | |
33 | return undefined | |
d8465018 C |
34 | } |
35 | ||
20494f12 C |
36 | logger.warn( |
37 | 'Unknown activity object type %s -> %s when announcing activity.', announcedActivity.type, announcedActivity.object.type, | |
38 | { activity: activity.id } | |
39 | ) | |
d8465018 C |
40 | return Promise.resolve(undefined) |
41 | } | |
42 | ||
43 | // --------------------------------------------------------------------------- | |
44 | ||
45 | export { | |
46 | processAnnounceActivity | |
47 | } |