diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-22 16:25:03 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:53 +0100 |
commit | 40ff57078e15d5b86ee6b71e198b95d3feb78eaf (patch) | |
tree | 88031d4eac6a26597e8a1f2fc63674664e3eae26 /server/lib/activitypub/process | |
parent | c46edbc2f6ca310b2f0331f979ac6caf27f6eb92 (diff) | |
download | PeerTube-40ff57078e15d5b86ee6b71e198b95d3feb78eaf.tar.gz PeerTube-40ff57078e15d5b86ee6b71e198b95d3feb78eaf.tar.zst PeerTube-40ff57078e15d5b86ee6b71e198b95d3feb78eaf.zip |
Federate video views
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/misc.ts | 7 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 19 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 6 |
3 files changed, 30 insertions, 2 deletions
diff --git a/server/lib/activitypub/process/misc.ts b/server/lib/activitypub/process/misc.ts index e90a793fc..eefbe2884 100644 --- a/server/lib/activitypub/process/misc.ts +++ b/server/lib/activitypub/process/misc.ts | |||
@@ -33,13 +33,18 @@ async function videoActivityObjectToDBAttributes ( | |||
33 | else if (cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1) privacy = VideoPrivacy.UNLISTED | 33 | else if (cc.indexOf(ACTIVITY_PUB.PUBLIC) !== -1) privacy = VideoPrivacy.UNLISTED |
34 | 34 | ||
35 | const duration = videoObject.duration.replace(/[^\d]+/, '') | 35 | const duration = videoObject.duration.replace(/[^\d]+/, '') |
36 | let language = null | ||
37 | if (videoObject.language) { | ||
38 | language = parseInt(videoObject.language.identifier, 10) | ||
39 | } | ||
40 | |||
36 | const videoData: VideoAttributes = { | 41 | const videoData: VideoAttributes = { |
37 | name: videoObject.name, | 42 | name: videoObject.name, |
38 | uuid: videoObject.uuid, | 43 | uuid: videoObject.uuid, |
39 | url: videoObject.id, | 44 | url: videoObject.id, |
40 | category: parseInt(videoObject.category.identifier, 10), | 45 | category: parseInt(videoObject.category.identifier, 10), |
41 | licence: parseInt(videoObject.licence.identifier, 10), | 46 | licence: parseInt(videoObject.licence.identifier, 10), |
42 | language: parseInt(videoObject.language.identifier, 10), | 47 | language, |
43 | nsfw: videoObject.nsfw, | 48 | nsfw: videoObject.nsfw, |
44 | description: videoObject.content, | 49 | description: videoObject.content, |
45 | channelId: videoChannel.id, | 50 | channelId: videoChannel.id, |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index ddf7c74f6..1777733a0 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -1,9 +1,11 @@ | |||
1 | import { ActivityCreate, VideoChannelObject } from '../../../../shared' | 1 | import { ActivityCreate, VideoChannelObject } from '../../../../shared' |
2 | import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects/video-abuse-object' | 2 | import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects/video-abuse-object' |
3 | import { ViewObject } from '../../../../shared/models/activitypub/objects/view-object' | ||
3 | import { logger, retryTransactionWrapper } from '../../../helpers' | 4 | import { logger, retryTransactionWrapper } from '../../../helpers' |
4 | import { database as db } from '../../../initializers' | 5 | import { database as db } from '../../../initializers' |
5 | import { AccountInstance } from '../../../models/account/account-interface' | 6 | import { AccountInstance } from '../../../models/account/account-interface' |
6 | import { getOrCreateAccountAndServer } from '../account' | 7 | import { getOrCreateAccountAndServer } from '../account' |
8 | import { sendCreateViewToVideoFollowers } from '../send/send-create' | ||
7 | import { getVideoChannelActivityPubUrl } from '../url' | 9 | import { getVideoChannelActivityPubUrl } from '../url' |
8 | import { videoChannelActivityObjectToDBAttributes } from './misc' | 10 | import { videoChannelActivityObjectToDBAttributes } from './misc' |
9 | 11 | ||
@@ -12,7 +14,9 @@ async function processCreateActivity (activity: ActivityCreate) { | |||
12 | const activityType = activityObject.type | 14 | const activityType = activityObject.type |
13 | const account = await getOrCreateAccountAndServer(activity.actor) | 15 | const account = await getOrCreateAccountAndServer(activity.actor) |
14 | 16 | ||
15 | if (activityType === 'VideoChannel') { | 17 | if (activityType === 'View') { |
18 | return processCreateView(activityObject as ViewObject) | ||
19 | } else if (activityType === 'VideoChannel') { | ||
16 | return processCreateVideoChannel(account, activityObject as VideoChannelObject) | 20 | return processCreateVideoChannel(account, activityObject as VideoChannelObject) |
17 | } else if (activityType === 'Flag') { | 21 | } else if (activityType === 'Flag') { |
18 | return processCreateVideoAbuse(account, activityObject as VideoAbuseObject) | 22 | return processCreateVideoAbuse(account, activityObject as VideoAbuseObject) |
@@ -30,6 +34,19 @@ export { | |||
30 | 34 | ||
31 | // --------------------------------------------------------------------------- | 35 | // --------------------------------------------------------------------------- |
32 | 36 | ||
37 | async function processCreateView (view: ViewObject) { | ||
38 | const video = await db.Video.loadByUrlAndPopulateAccount(view.object) | ||
39 | |||
40 | if (!video) throw new Error('Unknown video ' + view.object) | ||
41 | |||
42 | const account = await db.Account.loadByUrl(view.actor) | ||
43 | if (!account) throw new Error('Unknown account ' + view.actor) | ||
44 | |||
45 | await video.increment('views') | ||
46 | |||
47 | if (video.isOwned()) await sendCreateViewToVideoFollowers(account, video, undefined) | ||
48 | } | ||
49 | |||
33 | function processCreateVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { | 50 | function processCreateVideoChannel (account: AccountInstance, videoChannelToCreateData: VideoChannelObject) { |
34 | const options = { | 51 | const options = { |
35 | arguments: [ account, videoChannelToCreateData ], | 52 | arguments: [ account, videoChannelToCreateData ], |
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index 248004226..320dc1138 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -49,6 +49,12 @@ async function follow (account: AccountInstance, targetAccountURL: string) { | |||
49 | }, | 49 | }, |
50 | transaction: t | 50 | transaction: t |
51 | }) | 51 | }) |
52 | |||
53 | if (accountFollow.state !== 'accepted') { | ||
54 | accountFollow.state = 'accepted' | ||
55 | await accountFollow.save({ transaction: t }) | ||
56 | } | ||
57 | |||
52 | accountFollow.AccountFollower = account | 58 | accountFollow.AccountFollower = account |
53 | accountFollow.AccountFollowing = targetAccount | 59 | accountFollow.AccountFollowing = targetAccount |
54 | 60 | ||