2017-11-20 03:43:39 -05: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 09:52:26 -05:00
|
|
|
import { processAddActivity } from './process-add'
|
|
|
|
import { processCreateActivity } from './process-create'
|
2017-11-21 07:43:29 -05:00
|
|
|
import { getOrCreateAccountAndServer } from '../account'
|
2017-11-15 11:56:21 -05:00
|
|
|
|
|
|
|
async function processAnnounceActivity (activity: ActivityAnnounce) {
|
2017-11-16 09:22:39 -05:00
|
|
|
const announcedActivity = activity.object
|
2017-11-21 07:43:29 -05:00
|
|
|
const accountAnnouncer = await getOrCreateAccountAndServer(activity.actor)
|
2017-11-15 11:56:21 -05:00
|
|
|
|
2017-11-16 09:22:39 -05:00
|
|
|
if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'VideoChannel') {
|
2017-11-15 11:56:21 -05:00
|
|
|
// Add share entry
|
2017-11-16 09:22:39 -05:00
|
|
|
const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity)
|
2017-11-15 11:56:21 -05:00
|
|
|
await db.VideoChannelShare.create({
|
|
|
|
accountId: accountAnnouncer.id,
|
|
|
|
videoChannelId: videoChannel.id
|
|
|
|
})
|
|
|
|
|
2017-11-16 09:22:39 -05:00
|
|
|
return undefined
|
|
|
|
} else if (announcedActivity.type === 'Add' && announcedActivity.object.type === 'Video') {
|
2017-11-15 11:56:21 -05:00
|
|
|
// Add share entry
|
2017-11-16 09:22:39 -05:00
|
|
|
const video: VideoInstance = await processAddActivity(announcedActivity)
|
2017-11-15 11:56:21 -05:00
|
|
|
await db.VideoShare.create({
|
|
|
|
accountId: accountAnnouncer.id,
|
|
|
|
videoId: video.id
|
|
|
|
})
|
2017-11-16 09:22:39 -05:00
|
|
|
|
|
|
|
return undefined
|
2017-11-15 11:56:21 -05:00
|
|
|
}
|
|
|
|
|
2017-11-16 09:22:39 -05:00
|
|
|
logger.warn(
|
|
|
|
'Unknown activity object type %s -> %s when announcing activity.', announcedActivity.type, announcedActivity.object.type,
|
|
|
|
{ activity: activity.id }
|
|
|
|
)
|
2017-11-20 03:43:39 -05:00
|
|
|
|
|
|
|
return undefined
|
2017-11-15 11:56:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
processAnnounceActivity
|
|
|
|
}
|