2018-05-25 04:32:36 -05:00
|
|
|
import { Transaction } from 'sequelize'
|
|
|
|
import { ActivityAudience } from '../../../shared/models/activitypub'
|
2019-04-11 07:26:41 -05:00
|
|
|
import { ACTIVITY_PUB } from '../../initializers/constants'
|
2021-05-11 04:15:29 -05:00
|
|
|
import { ActorModel } from '../../models/actor/actor'
|
2018-05-25 04:32:36 -05:00
|
|
|
import { VideoModel } from '../../models/video/video'
|
|
|
|
import { VideoShareModel } from '../../models/video/video-share'
|
2020-06-18 03:45:25 -05:00
|
|
|
import { MActorFollowersUrl, MActorLight, MActorUrl, MCommentOwner, MCommentOwnerVideo, MVideoId } from '../../types/models'
|
2018-05-25 04:32:36 -05:00
|
|
|
|
2020-02-04 09:14:33 -06:00
|
|
|
function getRemoteVideoAudience (accountActor: MActorUrl, actorsInvolvedInVideo: MActorFollowersUrl[]): ActivityAudience {
|
2018-05-25 04:32:36 -05:00
|
|
|
return {
|
2020-02-04 09:14:33 -06:00
|
|
|
to: [ accountActor.url ],
|
2018-05-25 04:32:36 -05:00
|
|
|
cc: actorsInvolvedInVideo.map(a => a.followersUrl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getVideoCommentAudience (
|
2019-08-15 04:53:26 -05:00
|
|
|
videoComment: MCommentOwnerVideo,
|
|
|
|
threadParentComments: MCommentOwner[],
|
|
|
|
actorsInvolvedInVideo: MActorFollowersUrl[],
|
2018-05-25 04:32:36 -05:00
|
|
|
isOrigin = false
|
2018-09-14 09:51:35 -05:00
|
|
|
): ActivityAudience {
|
2018-05-25 04:32:36 -05:00
|
|
|
const to = [ ACTIVITY_PUB.PUBLIC ]
|
2018-07-25 15:01:25 -05:00
|
|
|
const cc: string[] = []
|
2018-05-25 04:32:36 -05:00
|
|
|
|
|
|
|
// 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) {
|
2020-03-20 08:43:12 -05:00
|
|
|
if (parentComment.isDeleted()) continue
|
|
|
|
|
2018-05-25 04:32:36 -05:00
|
|
|
cc.push(parentComment.Account.Actor.url)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
to,
|
|
|
|
cc: cc.concat(actorsInvolvedInVideo.map(a => a.followersUrl))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
function getAudienceFromFollowersOf (actorsInvolvedInObject: MActorFollowersUrl[]): ActivityAudience {
|
2018-05-25 04:32:36 -05:00
|
|
|
return {
|
|
|
|
to: [ ACTIVITY_PUB.PUBLIC ].concat(actorsInvolvedInObject.map(a => a.followersUrl)),
|
|
|
|
cc: []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-04 08:45:41 -06:00
|
|
|
async function getActorsInvolvedInVideo (video: MVideoId, t: Transaction) {
|
2019-08-15 04:53:26 -05:00
|
|
|
const actors: MActorLight[] = await VideoShareModel.loadActorsByShare(video.id, t)
|
2018-09-24 06:07:33 -05:00
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
const videoAll = video as VideoModel
|
|
|
|
|
2020-06-17 03:55:40 -05:00
|
|
|
const videoActor = videoAll.VideoChannel?.Account
|
2019-08-15 04:53:26 -05:00
|
|
|
? videoAll.VideoChannel.Account.Actor
|
|
|
|
: await ActorModel.loadFromAccountByVideoId(video.id, t)
|
2018-09-24 06:07:33 -05:00
|
|
|
|
|
|
|
actors.push(videoActor)
|
2018-05-25 04:32:36 -05:00
|
|
|
|
|
|
|
return actors
|
|
|
|
}
|
|
|
|
|
2019-08-15 04:53:26 -05:00
|
|
|
function getAudience (actorSender: MActorFollowersUrl, isPublic = true) {
|
2018-05-25 04:32:36 -05:00
|
|
|
return buildAudience([ actorSender.followersUrl ], isPublic)
|
|
|
|
}
|
|
|
|
|
2018-05-28 05:13:00 -05:00
|
|
|
function buildAudience (followerUrls: string[], isPublic = true) {
|
2018-07-25 15:01:25 -05:00
|
|
|
let to: string[] = []
|
|
|
|
let cc: string[] = []
|
2018-05-25 04:32:36 -05:00
|
|
|
|
|
|
|
if (isPublic) {
|
|
|
|
to = [ ACTIVITY_PUB.PUBLIC ]
|
2018-05-28 05:13:00 -05:00
|
|
|
cc = followerUrls
|
2018-05-25 04:32:36 -05:00
|
|
|
} else { // Unlisted
|
2018-06-12 13:04:58 -05:00
|
|
|
to = []
|
|
|
|
cc = []
|
2018-05-25 04:32:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return { to, cc }
|
|
|
|
}
|
|
|
|
|
2018-06-12 13:04:58 -05:00
|
|
|
function audiencify<T> (object: T, audience: ActivityAudience) {
|
2018-05-25 04:32:36 -05:00
|
|
|
return Object.assign(object, audience)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
buildAudience,
|
|
|
|
getAudience,
|
2018-09-14 09:51:35 -05:00
|
|
|
getRemoteVideoAudience,
|
2018-05-25 04:32:36 -05:00
|
|
|
getActorsInvolvedInVideo,
|
2018-09-14 09:51:35 -05:00
|
|
|
getAudienceFromFollowersOf,
|
2018-05-25 04:32:36 -05:00
|
|
|
audiencify,
|
|
|
|
getVideoCommentAudience
|
|
|
|
}
|