2017-11-20 03:43:39 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
2017-11-24 07:41:10 -05:00
|
|
|
import {
|
|
|
|
ActivityAudience,
|
|
|
|
ActivityCreate,
|
|
|
|
ActivityFollow,
|
|
|
|
ActivityLike,
|
|
|
|
ActivityUndo
|
2017-12-12 11:53:50 -05:00
|
|
|
} from '../../../../shared/models/activitypub'
|
|
|
|
import { AccountModel } from '../../../models/account/account'
|
|
|
|
import { AccountFollowModel } from '../../../models/account/account-follow'
|
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2017-11-23 08:37:00 -05:00
|
|
|
import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
|
2017-11-28 02:45:03 -05:00
|
|
|
import {
|
|
|
|
broadcastToFollowers,
|
|
|
|
getAccountsInvolvedInVideo,
|
|
|
|
getAudience,
|
|
|
|
getObjectFollowersAudience,
|
|
|
|
getOriginVideoAudience,
|
|
|
|
unicastTo
|
|
|
|
} from './misc'
|
2017-11-23 08:37:00 -05:00
|
|
|
import { createActivityData, createDislikeActivityData } from './send-create'
|
2017-11-20 03:43:39 -05:00
|
|
|
import { followActivityData } from './send-follow'
|
2017-11-23 08:19:55 -05:00
|
|
|
import { likeActivityData } from './send-like'
|
2017-11-20 03:43:39 -05:00
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction) {
|
2017-11-20 03:43:39 -05:00
|
|
|
const me = accountFollow.AccountFollower
|
|
|
|
const following = accountFollow.AccountFollowing
|
|
|
|
|
|
|
|
const followUrl = getAccountFollowActivityPubUrl(accountFollow)
|
|
|
|
const undoUrl = getUndoActivityPubUrl(followUrl)
|
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const object = followActivityData(followUrl, me, following)
|
|
|
|
const data = await undoActivityData(undoUrl, me, object, t)
|
2017-11-20 03:43:39 -05:00
|
|
|
|
|
|
|
return unicastTo(data, me, following.inboxUrl, t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
async function sendUndoLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-23 08:19:55 -05:00
|
|
|
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
|
|
|
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
2017-11-28 02:45:03 -05:00
|
|
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
2017-11-30 05:31:15 -05:00
|
|
|
const object = await likeActivityData(likeUrl, byAccount, video, t)
|
|
|
|
const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
|
|
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
async function sendUndoLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-23 08:19:55 -05:00
|
|
|
const likeUrl = getVideoLikeActivityPubUrl(byAccount, video)
|
|
|
|
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
|
2017-11-27 08:44:51 -05:00
|
|
|
const audience = getObjectFollowersAudience(toAccountsFollowers)
|
2017-11-30 05:31:15 -05:00
|
|
|
const object = await likeActivityData(likeUrl, byAccount, video, t)
|
|
|
|
const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
|
|
|
const followersException = [ byAccount ]
|
2017-11-24 07:41:10 -05:00
|
|
|
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
2017-11-23 08:19:55 -05:00
|
|
|
}
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
async function sendUndoDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-23 08:19:55 -05:00
|
|
|
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
|
|
|
|
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t)
|
2017-11-28 02:45:03 -05:00
|
|
|
const audience = getOriginVideoAudience(video, accountsInvolvedInVideo)
|
2017-11-23 08:19:55 -05:00
|
|
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
2017-11-30 08:15:17 -05:00
|
|
|
const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-11-30 08:15:17 -05:00
|
|
|
const data = await undoActivityData(undoUrl, byAccount, object, t, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
|
|
|
return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t)
|
|
|
|
}
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
async function sendUndoDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) {
|
2017-11-23 08:19:55 -05:00
|
|
|
const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video)
|
|
|
|
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
|
|
|
|
|
|
|
const dislikeActivity = createDislikeActivityData(byAccount, video)
|
2017-11-30 05:31:15 -05:00
|
|
|
const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const data = await undoActivityData(undoUrl, byAccount, object, t)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
|
|
|
const followersException = [ byAccount ]
|
2017-11-24 07:41:10 -05:00
|
|
|
return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException)
|
2017-11-23 08:19:55 -05:00
|
|
|
}
|
|
|
|
|
2017-11-20 03:43:39 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2017-11-23 08:19:55 -05:00
|
|
|
sendUndoFollow,
|
|
|
|
sendUndoLikeToOrigin,
|
|
|
|
sendUndoLikeToVideoFollowers,
|
|
|
|
sendUndoDislikeToOrigin,
|
|
|
|
sendUndoDislikeToVideoFollowers
|
2017-11-20 03:43:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2017-11-24 07:41:10 -05:00
|
|
|
async function undoActivityData (
|
|
|
|
url: string,
|
2017-12-12 11:53:50 -05:00
|
|
|
byAccount: AccountModel,
|
2017-11-24 07:41:10 -05:00
|
|
|
object: ActivityFollow | ActivityLike | ActivityCreate,
|
2017-11-30 05:31:15 -05:00
|
|
|
t: Transaction,
|
2017-11-24 07:41:10 -05:00
|
|
|
audience?: ActivityAudience
|
2017-12-12 11:53:50 -05:00
|
|
|
): Promise<ActivityUndo> {
|
2017-11-24 07:41:10 -05:00
|
|
|
if (!audience) {
|
2017-11-30 05:31:15 -05:00
|
|
|
audience = await getAudience(byAccount, t)
|
2017-11-24 07:41:10 -05:00
|
|
|
}
|
|
|
|
|
2017-12-12 11:53:50 -05:00
|
|
|
return {
|
2017-11-20 03:43:39 -05:00
|
|
|
type: 'Undo',
|
|
|
|
id: url,
|
|
|
|
actor: byAccount.url,
|
2017-11-24 07:41:10 -05:00
|
|
|
to: audience.to,
|
|
|
|
cc: audience.cc,
|
2017-11-20 03:43:39 -05:00
|
|
|
object
|
|
|
|
}
|
|
|
|
}
|