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