X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-undo.ts;h=3a0597fbae6078ddc17ae0573ec4b85f5353a7b6;hb=f40bbe3146553ef45515ee6b6d93ce6028f045ca;hp=699f920f0648678876b65e304a3fc4fff175dd2b;hpb=3fd3ab2d34d512b160a5e6084d7609be7b4f4452;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index 699f920f0..3a0597fba 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts @@ -6,13 +6,14 @@ import { ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' -import { AccountModel } from '../../../models/account/account' -import { AccountFollowModel } from '../../../models/account/account-follow' +import { ActorModel } from '../../../models/activitypub/actor' +import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { VideoModel } from '../../../models/video/video' -import { getAccountFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' +import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' import { + audiencify, broadcastToFollowers, - getAccountsInvolvedInVideo, + getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getOriginVideoAudience, @@ -22,11 +23,11 @@ import { createActivityData, createDislikeActivityData } from './send-create' import { followActivityData } from './send-follow' import { likeActivityData } from './send-like' -async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction) { - const me = accountFollow.AccountFollower - const following = accountFollow.AccountFollowing +async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { + const me = actorFollow.ActorFollower + const following = actorFollow.ActorFollowing - const followUrl = getAccountFollowActivityPubUrl(accountFollow) + const followUrl = getActorFollowActivityPubUrl(actorFollow) const undoUrl = getUndoActivityPubUrl(followUrl) const object = followActivityData(followUrl, me, following) @@ -35,58 +36,58 @@ async function sendUndoFollow (accountFollow: AccountFollowModel, t: Transaction return unicastTo(data, me, following.inboxUrl, t) } -async function sendUndoLikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) +async function sendUndoLikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const likeUrl = getVideoLikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(likeUrl) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const object = await likeActivityData(likeUrl, byAccount, video, t) - const data = await undoActivityData(undoUrl, byAccount, object, t, audience) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const object = await likeActivityData(likeUrl, byActor, video, t) + const data = await undoActivityData(undoUrl, byActor, object, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendUndoLikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const likeUrl = getVideoLikeActivityPubUrl(byAccount, video) +async function sendUndoLikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const likeUrl = getVideoLikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(likeUrl) - const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) - const audience = getObjectFollowersAudience(toAccountsFollowers) - const object = await likeActivityData(likeUrl, byAccount, video, t) - const data = await undoActivityData(undoUrl, byAccount, object, t, audience) + const toActorsFollowers = await getActorsInvolvedInVideo(video, t) + const audience = getObjectFollowersAudience(toActorsFollowers) + const object = await likeActivityData(likeUrl, byActor, video, t) + const data = await undoActivityData(undoUrl, byActor, object, t, audience) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) } -async function sendUndoDislikeToOrigin (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) +async function sendUndoDislikeToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) { + const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(dislikeUrl) - const accountsInvolvedInVideo = await getAccountsInvolvedInVideo(video, t) - const audience = getOriginVideoAudience(video, accountsInvolvedInVideo) - const dislikeActivity = createDislikeActivityData(byAccount, video) - const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) + const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t) + const audience = getOriginVideoAudience(video, actorsInvolvedInVideo) + const dislikeActivity = createDislikeActivityData(byActor, video) + const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) - const data = await undoActivityData(undoUrl, byAccount, object, t, audience) + const data = await undoActivityData(undoUrl, byActor, object, t, audience) - return unicastTo(data, byAccount, video.VideoChannel.Account.sharedInboxUrl, t) + return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t) } -async function sendUndoDislikeToVideoFollowers (byAccount: AccountModel, video: VideoModel, t: Transaction) { - const dislikeUrl = getVideoDislikeActivityPubUrl(byAccount, video) +async function sendUndoDislikeToVideoFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) { + const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) const undoUrl = getUndoActivityPubUrl(dislikeUrl) - const dislikeActivity = createDislikeActivityData(byAccount, video) - const object = await createActivityData(undoUrl, byAccount, dislikeActivity, t) + const dislikeActivity = createDislikeActivityData(byActor, video) + const object = await createActivityData(undoUrl, byActor, dislikeActivity, t) - const data = await undoActivityData(undoUrl, byAccount, object, t) + const data = await undoActivityData(undoUrl, byActor, object, t) - const toAccountsFollowers = await getAccountsInvolvedInVideo(video, t) + const toActorsFollowers = await getActorsInvolvedInVideo(video, t) - const followersException = [ byAccount ] - return broadcastToFollowers(data, byAccount, toAccountsFollowers, t, followersException) + const followersException = [ byActor ] + return broadcastToFollowers(data, byActor, toActorsFollowers, t, followersException) } // --------------------------------------------------------------------------- @@ -103,21 +104,19 @@ export { async function undoActivityData ( url: string, - byAccount: AccountModel, + byActor: ActorModel, object: ActivityFollow | ActivityLike | ActivityCreate, t: Transaction, audience?: ActivityAudience ): Promise { if (!audience) { - audience = await getAudience(byAccount, t) + audience = await getAudience(byActor, t) } - return { + return audiencify({ type: 'Undo', id: url, - actor: byAccount.url, - to: audience.to, - cc: audience.cc, + actor: byActor.url, object - } + }, audience) }