-import { ActivityCreate, ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub/activity'
-import { AccountInstance } from '../../../models'
-import { AccountFollowInstance } from '../../../models/account/account-follow-interface'
-import { broadcastToFollowers, getAccountsToForwardVideoAction, unicastTo } from './misc'
-import { followActivityData } from './send-follow'
-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'
-
-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)
+import {
+ ActivityAnnounce,
+ ActivityAudience,
+ ActivityCreate,
+ ActivityDislike,
+ ActivityFollow,
+ ActivityLike,
+ ActivityUndo
+} from '../../../../shared/models/activitypub'
+import { logger } from '../../../helpers/logger'
+import { VideoModel } from '../../../models/video/video'
+import {
+ MActor,
+ MActorAudience,
+ MActorFollowActors,
+ MActorLight,
+ MVideo,
+ MVideoAccountLight,
+ MVideoRedundancyVideo,
+ MVideoShare
+} from '../../../types/models'
+import { audiencify, getAudience } from '../audience'
+import { getUndoActivityPubUrl, getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from '../url'
+import { buildAnnounceWithVideoAudience } from './send-announce'
+import { buildCreateActivity } from './send-create'
+import { buildDislikeActivity } from './send-dislike'
+import { buildFollowActivity } from './send-follow'
+import { buildLikeActivity } from './send-like'
+import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
+
+function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) {
+ const me = actorFollow.ActorFollower
+ const following = actorFollow.ActorFollowing
+
+ // Same server as ours
+ if (!following.serverId) return
+
+ logger.info('Creating job to send an unfollow request to %s.', following.url)
+
+ const undoUrl = getUndoActivityPubUrl(actorFollow.url)
+
+ const followActivity = buildFollowActivity(actorFollow.url, me, following)
+ const undoActivity = undoActivityData(undoUrl, me, followActivity)
+
+ t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl))