X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Flib%2Factivitypub%2Fsend%2Futils.ts;h=db0e91b717ba5ec8df5e7e3e5dea4a60575f451e;hb=1c5e49e75284100b7b1fc8b4e73c8ba53fe22e89;hp=9436daf1713aad59ae062a2d1f96824477c59b6c;hpb=943e5193905908dd1f2800d8810c635d86e3b28f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/lib/activitypub/send/utils.ts b/server/lib/activitypub/send/utils.ts index 9436daf17..db0e91b71 100644 --- a/server/lib/activitypub/send/utils.ts +++ b/server/lib/activitypub/send/utils.ts @@ -1,18 +1,18 @@ import { Transaction } from 'sequelize' +import { getServerActor } from '@server/models/application/application' +import { ContextType } from '@shared/models/activitypub/context' import { Activity, ActivityAudience } from '../../../../shared/models/activitypub' +import { afterCommitIfTransaction } from '../../../helpers/database-utils' import { logger } from '../../../helpers/logger' -import { ActorModel } from '../../../models/activitypub/actor' -import { ActorFollowModel } from '../../../models/activitypub/actor-follow' +import { ActorModel } from '../../../models/actor/actor' +import { ActorFollowModel } from '../../../models/actor/actor-follow' +import { MActor, MActorId, MActorLight, MActorWithInboxes, MVideoAccountLight, MVideoId, MVideoImmutable } from '../../../types/models' import { JobQueue } from '../../job-queue' import { getActorsInvolvedInVideo, getAudienceFromFollowersOf, getRemoteVideoAudience } from '../audience' -import { getServerActor } from '../../../helpers/utils' -import { afterCommitIfTransaction } from '../../../helpers/database-utils' -import { MActorWithInboxes, MActor, MActorId, MActorLight, MVideo, MVideoAccountLight, MVideoId } from '../../../typings/models' -import { ContextType } from '@server/helpers/activitypub' async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAudience) => Activity, options: { byActor: MActorLight - video: MVideoAccountLight + video: MVideoImmutable | MVideoAccountLight transaction?: Transaction contextType?: ContextType }) { @@ -22,11 +22,13 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud // Send to origin if (video.isOwned() === false) { - const audience = getRemoteVideoAudience(video, actorsInvolvedInVideo) + const accountActor = (video as MVideoAccountLight).VideoChannel?.Account?.Actor || await ActorModel.loadAccountActorByVideoId(video.id) + + const audience = getRemoteVideoAudience(accountActor, actorsInvolvedInVideo) const activity = activityBuilder(audience) return afterCommitIfTransaction(transaction, () => { - return unicastTo(activity, byActor, video.VideoChannel.Account.Actor.getSharedInbox(), contextType) + return unicastTo(activity, byActor, accountActor.getSharedInbox(), contextType) }) } @@ -42,7 +44,7 @@ async function sendVideoRelatedActivity (activityBuilder: (audience: ActivityAud async function forwardVideoRelatedActivity ( activity: Activity, t: Transaction, - followersException: MActorWithInboxes[] = [], + followersException: MActorWithInboxes[], video: MVideoId ) { // Mastodon does not add our announces in audience, so we forward to them manually @@ -159,7 +161,7 @@ async function computeFollowerUris (toFollowersOf: MActorId[], actorsException: const result = await ActorFollowModel.listAcceptedFollowerSharedInboxUrls(toActorFollowerIds, t) const sharedInboxesException = await buildSharedInboxesException(actorsException) - return result.data.filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) + return result.data.filter(sharedInbox => sharedInboxesException.includes(sharedInbox) === false) } async function computeUris (toActors: MActor[], actorsException: MActorWithInboxes[] = []) { @@ -172,7 +174,7 @@ async function computeUris (toActors: MActor[], actorsException: MActorWithInbox const sharedInboxesException = await buildSharedInboxesException(actorsException) return Array.from(toActorSharedInboxesSet) - .filter(sharedInbox => sharedInboxesException.indexOf(sharedInbox) === -1) + .filter(sharedInbox => sharedInboxesException.includes(sharedInbox) === false) } async function buildSharedInboxesException (actorsException: MActorWithInboxes[]) {