]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/activitypub/send/send-announce.ts
Add refresh video on search
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / send / send-announce.ts
index 578fbc630a032c471465e0dd6579ffe66273e1a5..1ab05ca3ccc2751e1c37af4aa8747e4373ab7db1 100644 (file)
@@ -1,60 +1,30 @@
 import { Transaction } from 'sequelize'
-import { ActivityAnnounce, ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
-import { VideoPrivacy } from '../../../../shared/models/videos'
+import { ActivityAnnounce, ActivityAudience } from '../../../../shared/models/activitypub'
 import { ActorModel } from '../../../models/activitypub/actor'
 import { VideoModel } from '../../../models/video/video'
-import { getAnnounceActivityPubUrl } from '../url'
-import {
-  broadcastToFollowers,
-  getActorsInvolvedInVideo,
-  getAudience,
-  getObjectFollowersAudience,
-  getOriginVideoAudience,
-  unicastTo
-} from './misc'
-import { createActivityData } from './send-create'
+import { VideoShareModel } from '../../../models/video/video-share'
+import { broadcastToFollowers } from './utils'
+import { getActorsInvolvedInVideo, getAudience, getObjectFollowersAudience } from '../audience'
+import { logger } from '../../../helpers/logger'
 
-async function buildVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
-  const url = getAnnounceActivityPubUrl(video.url, byActor)
-  const videoObject = video.toActivityPubObject()
-
-  const announcedAudience = await getAudience(byActor, t, video.privacy === VideoPrivacy.PUBLIC)
-  const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t, announcedAudience)
+async function buildVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
+  const announcedObject = video.url
 
   const accountsToForwardView = await getActorsInvolvedInVideo(video, t)
   const audience = getObjectFollowersAudience(accountsToForwardView)
-  return announceActivityData(url, byActor, announcedActivity, t, audience)
-}
-
-async function sendVideoAnnounceToFollowers (byActor: ActorModel, video: VideoModel, t: Transaction) {
-  const data = await buildVideoAnnounceToFollowers(byActor, video, t)
-
-  return broadcastToFollowers(data, byActor, [ byActor ], t)
+  return announceActivityData(videoShare.url, byActor, announcedObject, audience)
 }
 
-async function sendVideoAnnounceToOrigin (byActor: ActorModel, video: VideoModel, t: Transaction) {
-  const url = getAnnounceActivityPubUrl(video.url, byActor)
-
-  const videoObject = video.toActivityPubObject()
-  const announcedActivity = await createActivityData(url, video.VideoChannel.Account.Actor, videoObject, t)
+async function sendVideoAnnounce (byActor: ActorModel, videoShare: VideoShareModel, video: VideoModel, t: Transaction) {
+  const data = await buildVideoAnnounce(byActor, videoShare, video, t)
 
-  const actorsInvolvedInVideo = await getActorsInvolvedInVideo(video, t)
-  const audience = getOriginVideoAudience(video, actorsInvolvedInVideo)
-  const data = await createActivityData(url, byActor, announcedActivity, t, audience)
+  logger.info('Creating job to send announce %s.', videoShare.url)
 
-  return unicastTo(data, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl, t)
+  return broadcastToFollowers(data, byActor, [ byActor ], t)
 }
 
-async function announceActivityData (
-  url: string,
-  byActor: ActorModel,
-  object: ActivityCreate,
-  t: Transaction,
-  audience?: ActivityAudience
-): Promise<ActivityAnnounce> {
-  if (!audience) {
-    audience = await getAudience(byActor, t)
-  }
+function announceActivityData (url: string, byActor: ActorModel, object: string, audience?: ActivityAudience): ActivityAnnounce {
+  if (!audience) audience = getAudience(byActor)
 
   return {
     type: 'Announce',
@@ -69,8 +39,7 @@ async function announceActivityData (
 // ---------------------------------------------------------------------------
 
 export {
-  sendVideoAnnounceToFollowers,
-  sendVideoAnnounceToOrigin,
+  sendVideoAnnounce,
   announceActivityData,
-  buildVideoAnnounceToFollowers
+  buildVideoAnnounce
 }