PeerTube/server/lib/activitypub/send/send-delete.ts

55 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-11-20 09:43:39 +01:00
import { Transaction } from 'sequelize'
2017-12-12 17:53:50 +01:00
import { ActivityDelete } from '../../../../shared/models/activitypub'
import { AccountModel } from '../../../models/account/account'
import { VideoModel } from '../../../models/video/video'
import { VideoChannelModel } from '../../../models/video/video-channel'
import { VideoChannelShareModel } from '../../../models/video/video-channel-share'
import { VideoShareModel } from '../../../models/video/video-share'
2017-11-20 09:43:39 +01:00
import { broadcastToFollowers } from './misc'
2017-12-12 17:53:50 +01:00
async function sendDeleteVideoChannel (videoChannel: VideoChannelModel, t: Transaction) {
2017-11-20 09:43:39 +01:00
const byAccount = videoChannel.Account
const data = deleteActivityData(videoChannel.url, byAccount)
2017-11-20 09:43:39 +01:00
2017-12-12 17:53:50 +01:00
const accountsInvolved = await VideoChannelShareModel.loadAccountsByShare(videoChannel.id, t)
2017-11-20 09:43:39 +01:00
accountsInvolved.push(byAccount)
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
}
2017-12-12 17:53:50 +01:00
async function sendDeleteVideo (video: VideoModel, t: Transaction) {
2017-11-20 09:43:39 +01:00
const byAccount = video.VideoChannel.Account
const data = deleteActivityData(video.url, byAccount)
2017-11-20 09:43:39 +01:00
2017-12-12 17:53:50 +01:00
const accountsInvolved = await VideoShareModel.loadAccountsByShare(video.id, t)
2017-11-20 09:43:39 +01:00
accountsInvolved.push(byAccount)
return broadcastToFollowers(data, byAccount, accountsInvolved, t)
}
2017-12-12 17:53:50 +01:00
async function sendDeleteAccount (account: AccountModel, t: Transaction) {
2017-11-30 13:16:23 +01:00
const data = deleteActivityData(account.url, account)
2017-11-20 09:43:39 +01:00
return broadcastToFollowers(data, account, [ account ], t)
}
// ---------------------------------------------------------------------------
export {
sendDeleteVideoChannel,
sendDeleteVideo,
sendDeleteAccount
}
// ---------------------------------------------------------------------------
2017-12-12 17:53:50 +01:00
function deleteActivityData (url: string, byAccount: AccountModel): ActivityDelete {
return {
2017-11-20 09:43:39 +01:00
type: 'Delete',
id: url,
actor: byAccount.url
}
}