diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-16 15:22:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 20494f122186bb1bfd82f4c598c4744acea27b0c (patch) | |
tree | 097652a31ecf70491b970b6c8e06b22380ee004f /server/lib/activitypub/process-announce.ts | |
parent | efc32059d980c51793e8e9ac0fb6a885a8026f94 (diff) | |
download | PeerTube-20494f122186bb1bfd82f4c598c4744acea27b0c.tar.gz PeerTube-20494f122186bb1bfd82f4c598c4744acea27b0c.tar.zst PeerTube-20494f122186bb1bfd82f4c598c4744acea27b0c.zip |
Server shares user videos
Diffstat (limited to 'server/lib/activitypub/process-announce.ts')
-rw-r--r-- | server/lib/activitypub/process-announce.ts | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/server/lib/activitypub/process-announce.ts b/server/lib/activitypub/process-announce.ts index d67958aec..f9674e095 100644 --- a/server/lib/activitypub/process-announce.ts +++ b/server/lib/activitypub/process-announce.ts | |||
@@ -10,38 +10,33 @@ import { VideoChannelInstance } from '../../models/video/video-channel-interface | |||
10 | import { VideoInstance } from '../../models/index' | 10 | import { VideoInstance } from '../../models/index' |
11 | 11 | ||
12 | async function processAnnounceActivity (activity: ActivityAnnounce) { | 12 | async function processAnnounceActivity (activity: ActivityAnnounce) { |
13 | const activityType = activity.object.type | 13 | const announcedActivity = activity.object |
14 | const accountAnnouncer = await getOrCreateAccount(activity.actor) | 14 | const accountAnnouncer = await getOrCreateAccount(activity.actor) |
15 | 15 | ||
16 | if (activityType === 'VideoChannel') { | 16 | if (announcedActivity.type === 'Create' && announcedActivity.object.type === 'VideoChannel') { |
17 | const activityCreate = Object.assign(activity, { | ||
18 | type: 'Create' as 'Create', | ||
19 | actor: activity.object.actor, | ||
20 | object: activity.object as VideoChannelObject | ||
21 | }) | ||
22 | |||
23 | // Add share entry | 17 | // Add share entry |
24 | const videoChannel: VideoChannelInstance = await processCreateActivity(activityCreate) | 18 | const videoChannel: VideoChannelInstance = await processCreateActivity(announcedActivity) |
25 | await db.VideoChannelShare.create({ | 19 | await db.VideoChannelShare.create({ |
26 | accountId: accountAnnouncer.id, | 20 | accountId: accountAnnouncer.id, |
27 | videoChannelId: videoChannel.id | 21 | videoChannelId: videoChannel.id |
28 | }) | 22 | }) |
29 | } else if (activityType === 'Video') { | ||
30 | const activityAdd = Object.assign(activity, { | ||
31 | type: 'Add' as 'Add', | ||
32 | actor: activity.object.actor, | ||
33 | object: activity.object as VideoTorrentObject | ||
34 | }) | ||
35 | 23 | ||
24 | return undefined | ||
25 | } else if (announcedActivity.type === 'Add' && announcedActivity.object.type === 'Video') { | ||
36 | // Add share entry | 26 | // Add share entry |
37 | const video: VideoInstance = await processAddActivity(activityAdd) | 27 | const video: VideoInstance = await processAddActivity(announcedActivity) |
38 | await db.VideoShare.create({ | 28 | await db.VideoShare.create({ |
39 | accountId: accountAnnouncer.id, | 29 | accountId: accountAnnouncer.id, |
40 | videoId: video.id | 30 | videoId: video.id |
41 | }) | 31 | }) |
32 | |||
33 | return undefined | ||
42 | } | 34 | } |
43 | 35 | ||
44 | logger.warn('Unknown activity object type %s when announcing activity.', activityType, { activity: activity.id }) | 36 | logger.warn( |
37 | 'Unknown activity object type %s -> %s when announcing activity.', announcedActivity.type, announcedActivity.object.type, | ||
38 | { activity: activity.id } | ||
39 | ) | ||
45 | return Promise.resolve(undefined) | 40 | return Promise.resolve(undefined) |
46 | } | 41 | } |
47 | 42 | ||