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

101 lines
4.1 KiB
TypeScript
Raw Normal View History

2017-11-20 02:43:39 -06:00
import { Transaction } from 'sequelize'
2017-11-23 07:19:55 -06:00
import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
2017-11-20 02:43:39 -06:00
import { AccountInstance } from '../../../models'
import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
2017-11-23 07:19:55 -06:00
import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc'
2017-11-20 02:43:39 -06:00
import { followActivityData } from './send-follow'
2017-11-23 07:19:55 -06:00
import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
import { VideoInstance } from '../../../models/video/video-interface'
import { likeActivityData } from './send-like'
import { createActivityData, createDislikeActivityData } from './send-create'
import { getServerAccount } from '../../../helpers/utils'
2017-11-20 02:43:39 -06:00
async function sendUndoFollow (accountFollow: AccountFollowInstance, t: Transaction) {
const me = accountFollow.AccountFollower
const following = accountFollow.AccountFollowing
const followUrl = getAccountFollowActivityPubUrl(accountFollow)
const undoUrl = getUndoActivityPubUrl(followUrl)
const object = await followActivityData(followUrl, me, following)
const data = await undoActivityData(undoUrl, me, object)
return unicastTo(data, me, following.inboxUrl, t)
}
2017-11-23 07:19:55 -06:00
async function sendUndoLikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
const undoUrl = getUndoActivityPubUrl(likeUrl)
const object = await likeActivityData(likeUrl, byAccount, video)
const data = await undoActivityData(undoUrl, byAccount, object)
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
}
async function sendUndoLikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
const undoUrl = getUndoActivityPubUrl(likeUrl)
const object = await likeActivityData(likeUrl, byAccount, video)
const data = await undoActivityData(undoUrl, byAccount, object)
const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
const serverAccount = await getServerAccount()
const followersException = [ byAccount ]
return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
}
async function sendUndoDislikeToOrigin (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
const dislikeActivity = createDislikeActivityData(byAccount, video)
const object = await createActivityData(undoUrl, byAccount, dislikeActivity)
const data = await undoActivityData(undoUrl, byAccount, object)
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
}
async function sendUndoDislikeToVideoFollowers (byAccount: AccountInstance, video: VideoInstance, t: Transaction) {
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
const dislikeActivity = createDislikeActivityData(byAccount, video)
const object = await createActivityData(undoUrl, byAccount, dislikeActivity)
const data = await undoActivityData(undoUrl, byAccount, object)
const accountsToForwardView = await getAccountsToForwardVideoAction(byAccount, video)
const serverAccount = await getServerAccount()
const followersException = [ byAccount ]
return broadcastToFollowers(data, serverAccount, accountsToForwardView, t, followersException)
}
2017-11-20 02:43:39 -06:00
// ---------------------------------------------------------------------------
export {
2017-11-23 07:19:55 -06:00
sendUndoFollow,
sendUndoLikeToOrigin,
sendUndoLikeToVideoFollowers,
sendUndoDislikeToOrigin,
sendUndoDislikeToVideoFollowers
2017-11-20 02:43:39 -06:00
}
// ---------------------------------------------------------------------------
2017-11-23 07:19:55 -06:00
async function undoActivityData (url: string, byAccount: AccountInstance, object: ActivityFollow | ActivityLike | ActivityCreate) {
2017-11-20 02:43:39 -06:00
const activity: ActivityUndo = {
type: 'Undo',
id: url,
actor: byAccount.url,
object
}
return activity
}