diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-19 17:07:58 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-19 17:07:58 +0100 |
commit | d7a7c248b36af5f9cf7375ba62720e4a1530eca6 (patch) | |
tree | 8e50a51ba9196965e775968797326a02fc3302cf /server/lib/activitypub | |
parent | 85414add64d2215a44866471913a8470638742e4 (diff) | |
download | PeerTube-d7a7c248b36af5f9cf7375ba62720e4a1530eca6.tar.gz PeerTube-d7a7c248b36af5f9cf7375ba62720e4a1530eca6.tar.zst PeerTube-d7a7c248b36af5f9cf7375ba62720e4a1530eca6.zip |
Handle mastodon shares
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 7dfee2f60..5568ff538 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' | 1 | import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { logger, retryTransactionWrapper } from '../../../helpers' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 4 | import { ActorModel } from '../../../models/activitypub/actor' |
@@ -12,7 +12,9 @@ async function processAnnounceActivity (activity: ActivityAnnounce) { | |||
12 | const announcedActivity = activity.object | 12 | const announcedActivity = activity.object |
13 | const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) | 13 | const actorAnnouncer = await getOrCreateActorAndServerAndModel(activity.actor) |
14 | 14 | ||
15 | if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') { | 15 | if (typeof announcedActivity === 'string') { |
16 | return processVideoShare(actorAnnouncer, activity) | ||
17 | } else if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'Video') { | ||
16 | return processVideoShare(actorAnnouncer, activity) | 18 | return processVideoShare(actorAnnouncer, activity) |
17 | } | 19 | } |
18 | 20 | ||
@@ -35,18 +37,25 @@ export { | |||
35 | function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { | 37 | function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { |
36 | const options = { | 38 | const options = { |
37 | arguments: [ actorAnnouncer, activity ], | 39 | arguments: [ actorAnnouncer, activity ], |
38 | errorMessage: 'Cannot share the video with many retries.' | 40 | errorMessage: 'Cannot share the video activity with many retries.' |
39 | } | 41 | } |
40 | 42 | ||
41 | return retryTransactionWrapper(shareVideo, options) | 43 | return retryTransactionWrapper(shareVideo, options) |
42 | } | 44 | } |
43 | 45 | ||
44 | function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { | 46 | function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { |
45 | const announcedActivity = activity.object | 47 | const announced = activity.object |
46 | 48 | ||
47 | return sequelizeTypescript.transaction(async t => { | 49 | return sequelizeTypescript.transaction(async t => { |
48 | // Add share entry | 50 | // Add share entry |
49 | const video: VideoModel = await processCreateActivity(announcedActivity) | 51 | let video: VideoModel |
52 | |||
53 | if (typeof announced === 'string') { | ||
54 | video = await VideoModel.loadByUrlAndPopulateAccount(announced as string) | ||
55 | if (!video) throw new Error('Unknown video to share ' + announced) | ||
56 | } else { | ||
57 | video = await processCreateActivity(announced as ActivityCreate) | ||
58 | } | ||
50 | 59 | ||
51 | const share = { | 60 | const share = { |
52 | actorId: actorAnnouncer.id, | 61 | actorId: actorAnnouncer.id, |