2017-11-20 03:43:39 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
2018-05-11 09:10:13 -04:00
|
|
|
import {
|
|
|
|
ActivityAnnounce,
|
|
|
|
ActivityAudience,
|
|
|
|
ActivityCreate,
|
|
|
|
ActivityFollow,
|
|
|
|
ActivityLike,
|
|
|
|
ActivityUndo
|
|
|
|
} from '../../../../shared/models/activitypub'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
|
|
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
2017-12-12 11:53:50 -05:00
|
|
|
import { VideoModel } from '../../../models/video/video'
|
2017-12-14 11:38:41 -05:00
|
|
|
import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
|
2018-05-25 05:32:36 -04:00
|
|
|
import { broadcastToFollowers, unicastTo } from './utils'
|
|
|
|
import { audiencify, getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience, getVideoAudience } from '../audience'
|
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'
|
2018-05-11 09:10:13 -04:00
|
|
|
import { VideoShareModel } from '../../../models/video/video-share'
|
|
|
|
import { buildVideoAnnounce } from './send-announce'
|
2017-11-20 03:43:39 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
|
|
|
|
const me = actorFollow.ActorFollower
|
|
|
|
const following = actorFollow.ActorFollowing
|
2017-11-20 03:43:39 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const followUrl = getActorFollowActivityPubUrl(actorFollow)
|
2017-11-20 03:43:39 -05:00
|
|
|
const undoUrl = getUndoActivityPubUrl(followUrl)
|
|
|
|
|
2017-11-30 05:31:15 -05:00
|
|
|
const object = followActivityData(followUrl, me, following)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = undoActivityData(undoUrl, me, object)
|
2017-11-20 03:43:39 -05:00
|
|
|
|
2018-01-25 09:05:18 -05:00
|
|
|
return unicastTo(data, me, following.inboxUrl)
|
2017-11-20 03:43:39 -05:00
|
|
|
}
|
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
async function sendUndoLike (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
2017-12-14 11:38:41 -05:00
|
|
|
const likeUrl = getVideoLikeActivityPubUrl(byActor, video)
|
2017-11-23 08:19:55 -05:00
|
|
|
const undoUrl = getUndoActivityPubUrl(likeUrl)
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
2018-06-12 14:04:58 -04:00
|
|
|
const object = likeActivityData(likeUrl, byActor, video)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
// Send to origin
|
|
|
|
if (video.isOwned() === false) {
|
2018-05-25 05:32:36 -04:00
|
|
|
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = undoActivityData(undoUrl, byActor, object, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
|
|
|
}
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
const audience = getObjectFollowersAudience(actorsInvolvedInVideo)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = undoActivityData(undoUrl, byActor, object, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const followersException = [ byActor ]
|
2018-03-27 07:33:56 -04:00
|
|
|
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
2017-11-23 08:19:55 -05:00
|
|
|
}
|
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
|
2017-12-14 11:38:41 -05:00
|
|
|
const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
|
2017-11-23 08:19:55 -05:00
|
|
|
const undoUrl = getUndoActivityPubUrl(dislikeUrl)
|
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
|
|
|
const dislikeActivity = createDislikeActivityData(byActor, video)
|
2018-06-12 14:04:58 -04:00
|
|
|
const object = createActivityData(dislikeUrl, byActor, dislikeActivity)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
if (video.isOwned() === false) {
|
2018-05-25 05:32:36 -04:00
|
|
|
const audience = getVideoAudience(video, actorsInvolvedInVideo)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = undoActivityData(undoUrl, byActor, object, audience)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-03-27 07:33:56 -04:00
|
|
|
return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
|
|
|
|
}
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = undoActivityData(undoUrl, byActor, object)
|
2017-11-23 08:19:55 -05:00
|
|
|
|
2017-12-14 11:38:41 -05:00
|
|
|
const followersException = [ byActor ]
|
2018-03-27 07:33:56 -04:00
|
|
|
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
2017-11-23 08:19:55 -05:00
|
|
|
}
|
|
|
|
|
2018-05-11 09:10:13 -04:00
|
|
|
async function sendUndoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
|
|
|
|
const undoUrl = getUndoActivityPubUrl(videoShare.url)
|
|
|
|
|
|
|
|
const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
|
|
|
|
const object = await buildVideoAnnounce(byActor, videoShare, video, t)
|
2018-06-12 14:04:58 -04:00
|
|
|
const data = undoActivityData(undoUrl, byActor, object)
|
2018-05-11 09:10:13 -04:00
|
|
|
|
|
|
|
const followersException = [ byActor ]
|
|
|
|
return broadcastToFollowers(data, byActor, actorsInvolvedInVideo, t, followersException)
|
|
|
|
}
|
|
|
|
|
2017-11-20 03:43:39 -05:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
2017-11-23 08:19:55 -05:00
|
|
|
sendUndoFollow,
|
2018-03-27 07:33:56 -04:00
|
|
|
sendUndoLike,
|
2018-05-11 09:10:13 -04:00
|
|
|
sendUndoDislike,
|
|
|
|
sendUndoAnnounce
|
2017-11-20 03:43:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2018-06-12 14:04:58 -04:00
|
|
|
function undoActivityData (
|
2017-11-24 07:41:10 -05:00
|
|
|
url: string,
|
2017-12-14 11:38:41 -05:00
|
|
|
byActor: ActorModel,
|
2018-05-11 09:10:13 -04:00
|
|
|
object: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
|
2017-11-24 07:41:10 -05:00
|
|
|
audience?: ActivityAudience
|
2018-06-12 14:04:58 -04:00
|
|
|
): ActivityUndo {
|
|
|
|
if (!audience) audience = getAudience(byActor)
|
|
|
|
|
|
|
|
return audiencify(
|
|
|
|
{
|
|
|
|
type: 'Undo' as 'Undo',
|
|
|
|
id: url,
|
|
|
|
actor: byActor.url,
|
|
|
|
object
|
|
|
|
},
|
|
|
|
audience
|
|
|
|
)
|
2017-11-20 03:43:39 -05:00
|
|
|
}
|