2017-11-20 09:43:39 +01: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 15:52:26 +01:00
|
|
|
import { processAddActivity } from './process-add'
|
|
|
|
import { processCreateActivity } from './process-create'
|
2017-11-20 10:24:29 +01:00
|
|
|
import { getOrCreateAccount } from '../account'
|
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-20 09:43:39 +01:00
|
|
|
|
|
|
|
return undefined
|
2017-11-15 17:56:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processAnnounceActivity
|
|
|
|
}
|