aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2017-12-19 17:07:58 +0100
committerChocobozzz <me@florianbigard.com>2017-12-19 17:07:58 +0100
commitd7a7c248b36af5f9cf7375ba62720e4a1530eca6 (patch)
tree8e50a51ba9196965e775968797326a02fc3302cf /server/lib
parent85414add64d2215a44866471913a8470638742e4 (diff)
downloadPeerTube-d7a7c248b36af5f9cf7375ba62720e4a1530eca6.tar.gz
PeerTube-d7a7c248b36af5f9cf7375ba62720e4a1530eca6.tar.zst
PeerTube-d7a7c248b36af5f9cf7375ba62720e4a1530eca6.zip
Handle mastodon shares
Diffstat (limited to 'server/lib')
-rw-r--r--server/lib/activitypub/process/process-announce.ts19
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 @@
1import { ActivityAnnounce } from '../../../../shared/models/activitypub' 1import { ActivityAnnounce, ActivityCreate } from '../../../../shared/models/activitypub'
2import { logger, retryTransactionWrapper } from '../../../helpers' 2import { logger, retryTransactionWrapper } from '../../../helpers'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { ActorModel } from '../../../models/activitypub/actor' 4import { 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 {
35function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { 37function 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
44function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounce) { 46function 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,