PeerTube/server/lib/activitypub/process/process-announce.ts

47 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { ActivityAnnounce } from '../../../../shared/models/activitypub/activity'
import { logger } from '../../../helpers/logger'
import { database as db } from '../../../initializers/index'
import { VideoInstance } from '../../../models/index'
import { VideoChannelInstance } from '../../../models/video/video-channel-interface'
2017-11-17 08:52:26 -06:00
import { processAddActivity } from './process-add'
import { processCreateActivity } from './process-create'
2017-11-21 06:43:29 -06:00
import { getOrCreateAccountAndServer } from '../account'
2017-11-15 10:56:21 -06:00
async function processAnnounceActivity (activity: ActivityAnnounce) {
2017-11-16 08:22:39 -06:00
const announcedActivity = activity.object
2017-11-21 06:43:29 -06:00
const accountAnnouncer = await getOrCreateAccountAndServer(activity.actor)
2017-11-15 10:56:21 -06:00
2017-11-16 08:22:39 -06:00
if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'VideoChannel') {
2017-11-15 10:56:21 -06:00
// Add share entry
2017-11-16 08:22:39 -06:00
const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity)
2017-11-15 10:56:21 -06:00
await db.VideoChannelShare.create({
accountId: accountAnnouncer.id,
videoChannelId: videoChannel.id
})
2017-11-16 08:22:39 -06:00
return undefined
} else if (announcedActivity.type === 'Add' && announcedActivity.object.type === 'Video') {
2017-11-15 10:56:21 -06:00
// Add share entry
2017-11-16 08:22:39 -06:00
const video: VideoInstance = await processAddActivity(announcedActivity)
2017-11-15 10:56:21 -06:00
await db.VideoShare.create({
accountId: accountAnnouncer.id,
videoId: video.id
})
2017-11-16 08:22:39 -06:00
return undefined
2017-11-15 10:56:21 -06:00
}
2017-11-16 08:22:39 -06:00
logger.warn(
'Unknown activity object type %s -> %s when announcing activity.', announcedActivity.type, announcedActivity.object.type,
{ activity: activity.id }
)
2017-11-20 02:43:39 -06:00
return undefined
2017-11-15 10:56:21 -06:00
}
// ---------------------------------------------------------------------------
export {
processAnnounceActivity
}