X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Fsend-undo.ts;h=e9ab5b3c59acaee8da7edce9fa7b2436313f4060;hb=5c5e587307a27e173333789b5b5167d35f468b01;hp=ecbf605d664da5f8e6b1aab4672a141673535b2c;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts index ecbf605d6..e9ab5b3c5 100644 --- a/server/lib/activitypub/send/send-undo.ts +++ b/server/lib/activitypub/send/send-undo.ts @@ -2,13 +2,12 @@ import { Transaction } from 'sequelize' import { ActivityAnnounce, ActivityAudience, - ActivityCreate, ActivityDislike, + ActivityCreate, + ActivityDislike, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' -import { ActorModel } from '../../../models/activitypub/actor' -import { ActorFollowModel } from '../../../models/activitypub/actor-follow' import { VideoModel } from '../../../models/video/video' import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url' import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils' @@ -16,13 +15,20 @@ import { audiencify, getAudience } from '../audience' import { buildCreateActivity } from './send-create' import { buildFollowActivity } from './send-follow' import { buildLikeActivity } from './send-like' -import { VideoShareModel } from '../../../models/video/video-share' import { buildAnnounceWithVideoAudience } from './send-announce' import { logger } from '../../../helpers/logger' -import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' import { buildDislikeActivity } from './send-dislike' - -async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { +import { + MActor, MActorAudience, + MActorFollowActors, + MActorLight, + MVideo, + MVideoAccountLight, + MVideoRedundancyVideo, + MVideoShare +} from '../../../typings/models' + +async function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { const me = actorFollow.ActorFollower const following = actorFollow.ActorFollowing @@ -31,16 +37,16 @@ async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) { logger.info('Creating job to send an unfollow request to %s.', following.url) - const followUrl = getActorFollowActivityPubUrl(actorFollow) + const followUrl = getActorFollowActivityPubUrl(me, following) const undoUrl = getUndoActivityPubUrl(followUrl) const followActivity = buildFollowActivity(followUrl, me, following) const undoActivity = undoActivityData(undoUrl, me, followActivity) - return unicastTo(undoActivity, me, following.inboxUrl) + t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) } -async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) { +async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare, video: MVideo, t: Transaction) { logger.info('Creating job to undo announce %s.', videoShare.url) const undoUrl = getUndoActivityPubUrl(videoShare.url) @@ -52,7 +58,7 @@ async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareMode return broadcastToFollowers(undoActivity, byActor, actorsInvolvedInVideo, t, followersException) } -async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) { +async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { logger.info('Creating job to undo a like of video %s.', video.url) const likeUrl = getVideoLikeActivityPubUrl(byActor, video) @@ -61,7 +67,7 @@ async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transact return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) } -async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) { +async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { logger.info('Creating job to undo a dislike of video %s.', video.url) const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) @@ -70,7 +76,7 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) } -async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) { +async function sendUndoCacheFile (byActor: MActor, redundancyModel: MVideoRedundancyVideo, t: Transaction) { logger.info('Creating job to undo cache file %s.', redundancyModel.url) const videoId = redundancyModel.getVideo().id @@ -94,7 +100,7 @@ export { function undoActivityData ( url: string, - byActor: ActorModel, + byActor: MActorAudience, object: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce, audience?: ActivityAudience ): ActivityUndo { @@ -112,8 +118,8 @@ function undoActivityData ( } async function sendUndoVideoRelatedActivity (options: { - byActor: ActorModel, - video: VideoModel, + byActor: MActor, + video: MVideoAccountLight, url: string, activity: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce, transaction: Transaction