1 import { Transaction } from 'sequelize'
9 } from '../../../../shared/models/activitypub'
10 import { ActorModel } from '../../../models/activitypub/actor'
11 import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
12 import { VideoModel } from '../../../models/video/video'
13 import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
14 import { broadcastToFollowers, unicastTo } from './utils'
15 import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
16 import { createActivityData, createDislikeActivityData } from './send-create'
17 import { followActivityData } from './send-follow'
18 import { likeActivityData } from './send-like'
19 import { VideoShareModel } from '../../../models/video/video-share'
20 import { buildVideoAnnounce } from './send-announce'
21 import { logger } from '../../../helpers/logger'
23 async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
24 const me = actorFollow.ActorFollower
25 const following = actorFollow.ActorFollowing
27 // Same server as ours
28 if (!following.serverId) return
30 logger.info('Creating job to send an unfollow request to %s.', following.url)
32 const followUrl = getActorFollowActivityPubUrl(actorFollow)
33 const undoUrl = getUndoActivityPubUrl(followUrl)
35 const object = followActivityData(followUrl, me, following)
36 const data = undoActivityData(undoUrl, me, object)
38 return unicastTo(data, me, following.inboxUrl)
41 async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
42 logger.info('Creating job to undo a like of video %s.', video.url)
44 const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
45 const undoUrl = getUndoActivityPubUrl(likeUrl)
47 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
48 const object = likeActivityData(likeUrl, byActor, video)
51 if (video.isOwned() === false) {
52 const audience = getVideoAudience(video, actorsInvolvedInVideo)
53 const data = undoActivityData(undoUrl, byActor, object, audience)
55 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
58 const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
59 const data = undoActivityData(undoUrl, byActor, object, audience)
61 const followersException = [ byActor ]
62 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
65 async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
66 logger.info('Creating job to undo a dislike of video %s.', video.url)
68 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
69 const undoUrl = getUndoActivityPubUrl(dislikeUrl)
71 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
72 const dislikeActivity = createDislikeActivityData(byActor, video)
73 const object = createActivityData(dislikeUrl, byActor, dislikeActivity)
75 if (video.isOwned() === false) {
76 const audience = getVideoAudience(video, actorsInvolvedInVideo)
77 const data = undoActivityData(undoUrl, byActor, object, audience)
79 return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
82 const data = undoActivityData(undoUrl, byActor, object)
84 const followersException = [ byActor ]
85 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
88 async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
89 logger.info('Creating job to undo announce %s.', videoShare.url)
91 const undoUrl = getUndoActivityPubUrl(videoShare.url)
93 const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
94 const object = await buildVideoAnnounce(byActor, videoShare, video, t)
95 const data = undoActivityData(undoUrl, byActor, object)
97 const followersException = [ byActor ]
98 return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
101 // ---------------------------------------------------------------------------
110 // ---------------------------------------------------------------------------
112 function undoActivityData (
115 object: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
116 audience?: ActivityAudience
118 if (!audience) audience = getAudience(byActor)
122 type: 'Undo' as 'Undo',