]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/lib/activitypub/process/process-announce.ts
Fix trending page
[github/Chocobozzz/PeerTube.git] / server / lib / activitypub / process / process-announce.ts
CommitLineData
cb9244de 1import { ActivityAnnounce } from '../../../../shared/models/activitypub'
da854ddd 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3fd3ab2d 3import { sequelizeTypescript } from '../../../initializers'
50d6de9c 4import { ActorModel } from '../../../models/activitypub/actor'
3fd3ab2d 5import { VideoShareModel } from '../../../models/video/video-share'
9588d4f4 6import { forwardVideoRelatedActivity } from '../send/utils'
1297eb5d 7import { getOrCreateVideoAndAccountAndChannel } from '../videos'
d8465018 8
e587e0ec 9async function processAnnounceActivity (activity: ActivityAnnounce, actorAnnouncer: ActorModel) {
90d4bb81 10 return retryTransactionWrapper(processVideoShare, actorAnnouncer, activity)
d8465018
C
11}
12
13// ---------------------------------------------------------------------------
14
15export {
16 processAnnounceActivity
17}
4e50b6a1
C
18
19// ---------------------------------------------------------------------------
20
90d4bb81 21async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) {
7acee6f1 22 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
2ccaeeb3 23
4157cdb1 24 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: objectUri })
4e50b6a1 25
3fd3ab2d 26 return sequelizeTypescript.transaction(async t => {
4e50b6a1 27 // Add share entry
4e50b6a1
C
28
29 const share = {
50d6de9c 30 actorId: actorAnnouncer.id,
4ba3b8ea
C
31 videoId: video.id,
32 url: activity.id
4e50b6a1
C
33 }
34
3fd3ab2d 35 const [ , created ] = await VideoShareModel.findOrCreate({
4ba3b8ea
C
36 where: {
37 url: activity.id
38 },
4e50b6a1
C
39 defaults: share,
40 transaction: t
41 })
42
43 if (video.isOwned() && created === true) {
44 // Don't resend the activity to the sender
50d6de9c 45 const exceptions = [ actorAnnouncer ]
9588d4f4
C
46
47 await forwardVideoRelatedActivity(activity, t, exceptions, video)
4e50b6a1
C
48 }
49
50 return undefined
51 })
52}