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