|
@@ -1,12 +1,8 @@
|
|
|
import { Transaction } from 'sequelize'
|
|
|
-import { Activity, ActivityAudience } from '../../../../shared/models/activitypub'
|
|
|
+import { Activity } from '../../../../shared/models/activitypub'
|
|
|
import { logger } from '../../../helpers/logger'
|
|
|
-import { ACTIVITY_PUB } from '../../../initializers'
|
|
|
import { ActorModel } from '../../../models/activitypub/actor'
|
|
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
|
|
-import { VideoModel } from '../../../models/video/video'
|
|
|
-import { VideoCommentModel } from '../../../models/video/video-comment'
|
|
|
-import { VideoShareModel } from '../../../models/video/video-share'
|
|
|
import { JobQueue } from '../../job-queue'
|
|
|
|
|
|
async function forwardActivity (
|
|
@@ -89,78 +85,16 @@ async function unicastTo (data: any, byActor: ActorModel, toActorUrl: string) {
|
|
|
return JobQueue.Instance.createJob({ type: 'activitypub-http-unicast', payload })
|
|
|
}
|
|
|
|
|
|
-function getOriginVideoAudience (video: VideoModel, actorsInvolvedInVideo: ActorModel[]) {
|
|
|
- return {
|
|
|
- to: [ video.VideoChannel.Account.Actor.url ],
|
|
|
- cc: actorsInvolvedInVideo.map(a => a.followersUrl)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function getVideoCommentAudience (
|
|
|
- videoComment: VideoCommentModel,
|
|
|
- threadParentComments: VideoCommentModel[],
|
|
|
- actorsInvolvedInVideo: ActorModel[],
|
|
|
- isOrigin = false
|
|
|
-) {
|
|
|
- const to = [ ACTIVITY_PUB.PUBLIC ]
|
|
|
- const cc = [ ]
|
|
|
-
|
|
|
- // Owner of the video we comment
|
|
|
- if (isOrigin === false) {
|
|
|
- cc.push(videoComment.Video.VideoChannel.Account.Actor.url)
|
|
|
- }
|
|
|
-
|
|
|
- // Followers of the poster
|
|
|
- cc.push(videoComment.Account.Actor.followersUrl)
|
|
|
-
|
|
|
- // Send to actors we reply to
|
|
|
- for (const parentComment of threadParentComments) {
|
|
|
- cc.push(parentComment.Account.Actor.url)
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- to,
|
|
|
- cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function getObjectFollowersAudience (actorsInvolvedInObject: ActorModel[]) {
|
|
|
- return {
|
|
|
- to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
|
|
|
- cc: []
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-async function getActorsInvolvedInVideo (video: VideoModel, t: Transaction) {
|
|
|
- const actors = await VideoShareModel.loadActorsByShare(video.id, t)
|
|
|
- actors.push(video.VideoChannel.Account.Actor)
|
|
|
-
|
|
|
- return actors
|
|
|
-}
|
|
|
-
|
|
|
-async function getAudience (actorSender: ActorModel, t: Transaction, isPublic = true) {
|
|
|
- return buildAudience([ actorSender.followersUrl ], isPublic)
|
|
|
-}
|
|
|
-
|
|
|
-function buildAudience (followerInboxUrls: string[], isPublic = true) {
|
|
|
- // Thanks Mastodon: https://github.com/tootsuite/mastodon/blob/master/app/lib/activitypub/tag_manager.rb#L47
|
|
|
- let to = []
|
|
|
- let cc = []
|
|
|
-
|
|
|
- if (isPublic) {
|
|
|
- to = [ ACTIVITY_PUB.PUBLIC ]
|
|
|
- cc = followerInboxUrls
|
|
|
- } else { // Unlisted
|
|
|
- to = [ ]
|
|
|
- cc = [ ]
|
|
|
- }
|
|
|
+// ---------------------------------------------------------------------------
|
|
|
|
|
|
- return { to, cc }
|
|
|
+export {
|
|
|
+ broadcastToFollowers,
|
|
|
+ unicastTo,
|
|
|
+ forwardActivity,
|
|
|
+ broadcastToActors
|
|
|
}
|
|
|
|
|
|
-function audiencify <T> (object: T, audience: ActivityAudience) {
|
|
|
- return Object.assign(object, audience)
|
|
|
-}
|
|
|
+// ---------------------------------------------------------------------------
|
|
|
|
|
|
async function computeFollowerUris (toActorFollower: ActorModel[], actorsException: ActorModel[], t: Transaction) {
|
|
|
const toActorFollowerIds = toActorFollower.map(a => a.id)
|
|
@@ -175,22 +109,5 @@ async function computeUris (toActors: ActorModel[], actorsException: ActorModel[
|
|
|
|
|
|
const sharedInboxesException = actorsException.map(f => f.sharedInboxUrl || f.inboxUrl)
|
|
|
return Array.from(toActorSharedInboxesSet)
|
|
|
- .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1)
|
|
|
-}
|
|
|
-
|
|
|
-// ---------------------------------------------------------------------------
|
|
|
-
|
|
|
-export {
|
|
|
- broadcastToFollowers,
|
|
|
- unicastTo,
|
|
|
- buildAudience,
|
|
|
- getAudience,
|
|
|
- getOriginVideoAudience,
|
|
|
- getActorsInvolvedInVideo,
|
|
|
- getObjectFollowersAudience,
|
|
|
- forwardActivity,
|
|
|
- audiencify,
|
|
|
- getVideoCommentAudience,
|
|
|
- computeUris,
|
|
|
- broadcastToActors
|
|
|
+ .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1)
|
|
|
}
|