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

46 lines
1.6 KiB
TypeScript
Raw Normal View History

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