aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-11-20 11:21:08 +0100
committerChocobozzz <me@florianbigard.com>2020-11-20 11:21:08 +0100
commitde94ac86a211dec657332d964693857ec235ce40 (patch)
tree3bff96a40e7c862d83561a26249992b07331b0a2 /server/lib/activitypub
parent3fba4b6bce69247b1d37f923894d8f44818a891c (diff)
downloadPeerTube-de94ac86a211dec657332d964693857ec235ce40.tar.gz
PeerTube-de94ac86a211dec657332d964693857ec235ce40.tar.zst
PeerTube-de94ac86a211dec657332d964693857ec235ce40.zip
Fix incorrect IDs in AP federation
Diffstat (limited to 'server/lib/activitypub')
-rw-r--r--server/lib/activitypub/process/process-dislike.ts16
-rw-r--r--server/lib/activitypub/process/process-follow.ts16
-rw-r--r--server/lib/activitypub/process/process-like.ts13
-rw-r--r--server/lib/activitypub/send/send-accept.ts11
-rw-r--r--server/lib/activitypub/send/send-dislike.ts4
-rw-r--r--server/lib/activitypub/send/send-flag.ts4
-rw-r--r--server/lib/activitypub/send/send-follow.ts8
-rw-r--r--server/lib/activitypub/send/send-like.ts4
-rw-r--r--server/lib/activitypub/send/send-reject.ts11
-rw-r--r--server/lib/activitypub/send/send-undo.ts30
-rw-r--r--server/lib/activitypub/send/send-view.ts10
-rw-r--r--server/lib/activitypub/share.ts6
-rw-r--r--server/lib/activitypub/url.ts93
-rw-r--r--server/lib/activitypub/video-rates.ts10
14 files changed, 118 insertions, 118 deletions
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts
index 0cd204501..635c8bfcc 100644
--- a/server/lib/activitypub/process/process-dislike.ts
+++ b/server/lib/activitypub/process/process-dislike.ts
@@ -3,11 +3,10 @@ import { DislikeObject } from '../../../../shared/models/activitypub/objects'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { sequelizeTypescript } from '../../../initializers/database' 4import { sequelizeTypescript } from '../../../initializers/database'
5import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 5import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
6import { getOrCreateVideoAndAccountAndChannel } from '../videos'
7import { forwardVideoRelatedActivity } from '../send/utils'
8import { getVideoDislikeActivityPubUrl } from '../url'
9import { APProcessorOptions } from '../../../types/activitypub-processor.model' 6import { APProcessorOptions } from '../../../types/activitypub-processor.model'
10import { MActorSignature } from '../../../types/models' 7import { MActorSignature } from '../../../types/models'
8import { forwardVideoRelatedActivity } from '../send/utils'
9import { getOrCreateVideoAndAccountAndChannel } from '../videos'
11 10
12async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { 11async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) {
13 const { activity, byActor } = options 12 const { activity, byActor } = options
@@ -23,7 +22,10 @@ export {
23// --------------------------------------------------------------------------- 22// ---------------------------------------------------------------------------
24 23
25async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) { 24async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: MActorSignature) {
26 const dislikeObject = activity.type === 'Dislike' ? activity.object : (activity.object as DislikeObject).object 25 const dislikeObject = activity.type === 'Dislike'
26 ? activity.object
27 : (activity.object as DislikeObject).object
28
27 const byAccount = byActor.Account 29 const byAccount = byActor.Account
28 30
29 if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) 31 if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url)
@@ -31,9 +33,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
31 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject }) 33 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: dislikeObject })
32 34
33 return sequelizeTypescript.transaction(async t => { 35 return sequelizeTypescript.transaction(async t => {
34 const url = getVideoDislikeActivityPubUrl(byActor, video) 36 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id)
35
36 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
37 if (existingRate && existingRate.type === 'dislike') return 37 if (existingRate && existingRate.type === 'dislike') return
38 38
39 await video.increment('dislikes', { transaction: t }) 39 await video.increment('dislikes', { transaction: t })
@@ -46,7 +46,7 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
46 rate.type = 'dislike' 46 rate.type = 'dislike'
47 rate.videoId = video.id 47 rate.videoId = video.id
48 rate.accountId = byAccount.id 48 rate.accountId = byAccount.id
49 rate.url = url 49 rate.url = activity.id
50 50
51 await rate.save({ transaction: t }) 51 await rate.save({ transaction: t })
52 52
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 7eb7e828d..076ad9cf4 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -15,9 +15,11 @@ import { getServerActor } from '@server/models/application/application'
15 15
16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { 16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) {
17 const { activity, byActor } = options 17 const { activity, byActor } = options
18 const activityObject = getAPId(activity.object)
19 18
20 return retryTransactionWrapper(processFollow, byActor, activityObject) 19 const activityId = activity.id
20 const objectId = getAPId(activity.object)
21
22 return retryTransactionWrapper(processFollow, byActor, activityId, objectId)
21} 23}
22 24
23// --------------------------------------------------------------------------- 25// ---------------------------------------------------------------------------
@@ -28,7 +30,7 @@ export {
28 30
29// --------------------------------------------------------------------------- 31// ---------------------------------------------------------------------------
30 32
31async function processFollow (byActor: MActorSignature, targetActorURL: string) { 33async function processFollow (byActor: MActorSignature, activityId: string, targetActorURL: string) {
32 const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => { 34 const { actorFollow, created, isFollowingInstance, targetActor } = await sequelizeTypescript.transaction(async t => {
33 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) 35 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
34 36
@@ -41,7 +43,7 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string)
41 if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { 43 if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
42 logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) 44 logger.info('Rejecting %s because instance followers are disabled.', targetActor.url)
43 45
44 await sendReject(byActor, targetActor) 46 await sendReject(activityId, byActor, targetActor)
45 47
46 return { actorFollow: undefined as MActorFollowActors } 48 return { actorFollow: undefined as MActorFollowActors }
47 } 49 }
@@ -54,7 +56,11 @@ async function processFollow (byActor: MActorSignature, targetActorURL: string)
54 defaults: { 56 defaults: {
55 actorId: byActor.id, 57 actorId: byActor.id,
56 targetActorId: targetActor.id, 58 targetActorId: targetActor.id,
57 state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' 59 url: activityId,
60
61 state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL
62 ? 'pending'
63 : 'accepted'
58 }, 64 },
59 transaction: t 65 transaction: t
60 }) 66 })
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index b800a5618..6acc097b1 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -1,13 +1,12 @@
1import { ActivityLike } from '../../../../shared/models/activitypub' 1import { ActivityLike } from '../../../../shared/models/activitypub'
2import { getAPId } from '../../../helpers/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { sequelizeTypescript } from '../../../initializers/database' 4import { sequelizeTypescript } from '../../../initializers/database'
4import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 5import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
5import { forwardVideoRelatedActivity } from '../send/utils'
6import { getOrCreateVideoAndAccountAndChannel } from '../videos'
7import { getVideoLikeActivityPubUrl } from '../url'
8import { getAPId } from '../../../helpers/activitypub'
9import { APProcessorOptions } from '../../../types/activitypub-processor.model' 6import { APProcessorOptions } from '../../../types/activitypub-processor.model'
10import { MActorSignature } from '../../../types/models' 7import { MActorSignature } from '../../../types/models'
8import { forwardVideoRelatedActivity } from '../send/utils'
9import { getOrCreateVideoAndAccountAndChannel } from '../videos'
11 10
12async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { 11async function processLikeActivity (options: APProcessorOptions<ActivityLike>) {
13 const { activity, byActor } = options 12 const { activity, byActor } = options
@@ -31,9 +30,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik
31 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl }) 30 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: videoUrl })
32 31
33 return sequelizeTypescript.transaction(async t => { 32 return sequelizeTypescript.transaction(async t => {
34 const url = getVideoLikeActivityPubUrl(byActor, video) 33 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id)
35
36 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, url)
37 if (existingRate && existingRate.type === 'like') return 34 if (existingRate && existingRate.type === 'like') return
38 35
39 if (existingRate && existingRate.type === 'dislike') { 36 if (existingRate && existingRate.type === 'dislike') {
@@ -46,7 +43,7 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik
46 rate.type = 'like' 43 rate.type = 'like'
47 rate.videoId = video.id 44 rate.videoId = video.id
48 rate.accountId = byAccount.id 45 rate.accountId = byAccount.id
49 rate.url = url 46 rate.url = activity.id
50 47
51 await rate.save({ transaction: t }) 48 await rate.save({ transaction: t })
52 49
diff --git a/server/lib/activitypub/send/send-accept.ts b/server/lib/activitypub/send/send-accept.ts
index 50e192bdd..bb387e2c0 100644
--- a/server/lib/activitypub/send/send-accept.ts
+++ b/server/lib/activitypub/send/send-accept.ts
@@ -1,9 +1,9 @@
1import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub' 1import { ActivityAccept, ActivityFollow } from '../../../../shared/models/activitypub'
2import { getActorFollowAcceptActivityPubUrl, getActorFollowActivityPubUrl } from '../url'
3import { unicastTo } from './utils'
4import { buildFollowActivity } from './send-follow'
5import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
6import { MActor, MActorFollowActors } from '../../../types/models' 3import { MActor, MActorFollowActors } from '../../../types/models'
4import { getLocalActorFollowAcceptActivityPubUrl } from '../url'
5import { buildFollowActivity } from './send-follow'
6import { unicastTo } from './utils'
7 7
8function sendAccept (actorFollow: MActorFollowActors) { 8function sendAccept (actorFollow: MActorFollowActors) {
9 const follower = actorFollow.ActorFollower 9 const follower = actorFollow.ActorFollower
@@ -16,10 +16,9 @@ function sendAccept (actorFollow: MActorFollowActors) {
16 16
17 logger.info('Creating job to accept follower %s.', follower.url) 17 logger.info('Creating job to accept follower %s.', follower.url)
18 18
19 const followUrl = getActorFollowActivityPubUrl(follower, me) 19 const followData = buildFollowActivity(actorFollow.url, follower, me)
20 const followData = buildFollowActivity(followUrl, follower, me)
21 20
22 const url = getActorFollowAcceptActivityPubUrl(actorFollow) 21 const url = getLocalActorFollowAcceptActivityPubUrl(actorFollow)
23 const data = buildAcceptActivity(url, me, followData) 22 const data = buildAcceptActivity(url, me, followData)
24 23
25 return unicastTo(data, me, follower.inboxUrl) 24 return unicastTo(data, me, follower.inboxUrl)
diff --git a/server/lib/activitypub/send/send-dislike.ts b/server/lib/activitypub/send/send-dislike.ts
index 1bb7dc937..274230535 100644
--- a/server/lib/activitypub/send/send-dislike.ts
+++ b/server/lib/activitypub/send/send-dislike.ts
@@ -1,5 +1,5 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { getVideoDislikeActivityPubUrl } from '../url' 2import { getVideoDislikeActivityPubUrlByLocalActor } from '../url'
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub' 4import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub'
5import { sendVideoRelatedActivity } from './utils' 5import { sendVideoRelatedActivity } from './utils'
@@ -10,7 +10,7 @@ function sendDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction
10 logger.info('Creating job to dislike %s.', video.url) 10 logger.info('Creating job to dislike %s.', video.url)
11 11
12 const activityBuilder = (audience: ActivityAudience) => { 12 const activityBuilder = (audience: ActivityAudience) => {
13 const url = getVideoDislikeActivityPubUrl(byActor, video) 13 const url = getVideoDislikeActivityPubUrlByLocalActor(byActor, video)
14 14
15 return buildDislikeActivity(url, byActor, video, audience) 15 return buildDislikeActivity(url, byActor, video, audience)
16 } 16 }
diff --git a/server/lib/activitypub/send/send-flag.ts b/server/lib/activitypub/send/send-flag.ts
index 821637ec8..b0483b5a0 100644
--- a/server/lib/activitypub/send/send-flag.ts
+++ b/server/lib/activitypub/send/send-flag.ts
@@ -3,13 +3,13 @@ import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activi
3import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
4import { MAbuseAP, MAccountLight, MActor } from '../../../types/models' 4import { MAbuseAP, MAccountLight, MActor } from '../../../types/models'
5import { audiencify, getAudience } from '../audience' 5import { audiencify, getAudience } from '../audience'
6import { getAbuseActivityPubUrl } from '../url' 6import { getLocalAbuseActivityPubUrl } from '../url'
7import { unicastTo } from './utils' 7import { unicastTo } from './utils'
8 8
9function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) { 9function sendAbuse (byActor: MActor, abuse: MAbuseAP, flaggedAccount: MAccountLight, t: Transaction) {
10 if (!flaggedAccount.Actor.serverId) return // Local user 10 if (!flaggedAccount.Actor.serverId) return // Local user
11 11
12 const url = getAbuseActivityPubUrl(abuse) 12 const url = getLocalAbuseActivityPubUrl(abuse)
13 13
14 logger.info('Creating job to send abuse %s.', url) 14 logger.info('Creating job to send abuse %s.', url)
15 15
diff --git a/server/lib/activitypub/send/send-follow.ts b/server/lib/activitypub/send/send-follow.ts
index 08f1d83f9..9219640dd 100644
--- a/server/lib/activitypub/send/send-follow.ts
+++ b/server/lib/activitypub/send/send-follow.ts
@@ -1,9 +1,8 @@
1import { Transaction } from 'sequelize'
1import { ActivityFollow } from '../../../../shared/models/activitypub' 2import { ActivityFollow } from '../../../../shared/models/activitypub'
2import { getActorFollowActivityPubUrl } from '../url'
3import { unicastTo } from './utils'
4import { logger } from '../../../helpers/logger' 3import { logger } from '../../../helpers/logger'
5import { Transaction } from 'sequelize'
6import { MActor, MActorFollowActors } from '../../../types/models' 4import { MActor, MActorFollowActors } from '../../../types/models'
5import { unicastTo } from './utils'
7 6
8function sendFollow (actorFollow: MActorFollowActors, t: Transaction) { 7function sendFollow (actorFollow: MActorFollowActors, t: Transaction) {
9 const me = actorFollow.ActorFollower 8 const me = actorFollow.ActorFollower
@@ -14,8 +13,7 @@ function sendFollow (actorFollow: MActorFollowActors, t: Transaction) {
14 13
15 logger.info('Creating job to send follow request to %s.', following.url) 14 logger.info('Creating job to send follow request to %s.', following.url)
16 15
17 const url = getActorFollowActivityPubUrl(me, following) 16 const data = buildFollowActivity(actorFollow.url, me, following)
18 const data = buildFollowActivity(url, me, following)
19 17
20 t.afterCommit(() => unicastTo(data, me, following.inboxUrl)) 18 t.afterCommit(() => unicastTo(data, me, following.inboxUrl))
21} 19}
diff --git a/server/lib/activitypub/send/send-like.ts b/server/lib/activitypub/send/send-like.ts
index 29fcfc404..ed6dfcf56 100644
--- a/server/lib/activitypub/send/send-like.ts
+++ b/server/lib/activitypub/send/send-like.ts
@@ -1,6 +1,6 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub' 2import { ActivityAudience, ActivityLike } from '../../../../shared/models/activitypub'
3import { getVideoLikeActivityPubUrl } from '../url' 3import { getVideoLikeActivityPubUrlByLocalActor } from '../url'
4import { sendVideoRelatedActivity } from './utils' 4import { sendVideoRelatedActivity } from './utils'
5import { audiencify, getAudience } from '../audience' 5import { audiencify, getAudience } from '../audience'
6import { logger } from '../../../helpers/logger' 6import { logger } from '../../../helpers/logger'
@@ -10,7 +10,7 @@ function sendLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
10 logger.info('Creating job to like %s.', video.url) 10 logger.info('Creating job to like %s.', video.url)
11 11
12 const activityBuilder = (audience: ActivityAudience) => { 12 const activityBuilder = (audience: ActivityAudience) => {
13 const url = getVideoLikeActivityPubUrl(byActor, video) 13 const url = getVideoLikeActivityPubUrlByLocalActor(byActor, video)
14 14
15 return buildLikeActivity(url, byActor, video, audience) 15 return buildLikeActivity(url, byActor, video, audience)
16 } 16 }
diff --git a/server/lib/activitypub/send/send-reject.ts b/server/lib/activitypub/send/send-reject.ts
index befbcb8da..8d74a7848 100644
--- a/server/lib/activitypub/send/send-reject.ts
+++ b/server/lib/activitypub/send/send-reject.ts
@@ -1,11 +1,11 @@
1import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub' 1import { ActivityFollow, ActivityReject } from '../../../../shared/models/activitypub'
2import { getActorFollowActivityPubUrl, getActorFollowRejectActivityPubUrl } from '../url'
3import { unicastTo } from './utils'
4import { buildFollowActivity } from './send-follow'
5import { logger } from '../../../helpers/logger' 2import { logger } from '../../../helpers/logger'
6import { MActor } from '../../../types/models' 3import { MActor } from '../../../types/models'
4import { getLocalActorFollowRejectActivityPubUrl } from '../url'
5import { buildFollowActivity } from './send-follow'
6import { unicastTo } from './utils'
7 7
8function sendReject (follower: MActor, following: MActor) { 8function sendReject (followUrl: string, follower: MActor, following: MActor) {
9 if (!follower.serverId) { // This should never happen 9 if (!follower.serverId) { // This should never happen
10 logger.warn('Do not sending reject to local follower.') 10 logger.warn('Do not sending reject to local follower.')
11 return 11 return
@@ -13,10 +13,9 @@ function sendReject (follower: MActor, following: MActor) {
13 13
14 logger.info('Creating job to reject follower %s.', follower.url) 14 logger.info('Creating job to reject follower %s.', follower.url)
15 15
16 const followUrl = getActorFollowActivityPubUrl(follower, following)
17 const followData = buildFollowActivity(followUrl, follower, following) 16 const followData = buildFollowActivity(followUrl, follower, following)
18 17
19 const url = getActorFollowRejectActivityPubUrl(follower, following) 18 const url = getLocalActorFollowRejectActivityPubUrl(follower, following)
20 const data = buildRejectActivity(url, following, followData) 19 const data = buildRejectActivity(url, following, followData)
21 20
22 return unicastTo(data, following, follower.inboxUrl) 21 return unicastTo(data, following, follower.inboxUrl)
diff --git a/server/lib/activitypub/send/send-undo.ts b/server/lib/activitypub/send/send-undo.ts
index 6ed343300..352c158fd 100644
--- a/server/lib/activitypub/send/send-undo.ts
+++ b/server/lib/activitypub/send/send-undo.ts
@@ -8,18 +8,11 @@ import {
8 ActivityLike, 8 ActivityLike,
9 ActivityUndo 9 ActivityUndo
10} from '../../../../shared/models/activitypub' 10} from '../../../../shared/models/activitypub'
11import { VideoModel } from '../../../models/video/video'
12import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
13import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
14import { audiencify, getAudience } from '../audience'
15import { buildCreateActivity } from './send-create'
16import { buildFollowActivity } from './send-follow'
17import { buildLikeActivity } from './send-like'
18import { buildAnnounceWithVideoAudience } from './send-announce'
19import { logger } from '../../../helpers/logger' 11import { logger } from '../../../helpers/logger'
20import { buildDislikeActivity } from './send-dislike' 12import { VideoModel } from '../../../models/video/video'
21import { 13import {
22 MActor, MActorAudience, 14 MActor,
15 MActorAudience,
23 MActorFollowActors, 16 MActorFollowActors,
24 MActorLight, 17 MActorLight,
25 MVideo, 18 MVideo,
@@ -27,6 +20,14 @@ import {
27 MVideoRedundancyVideo, 20 MVideoRedundancyVideo,
28 MVideoShare 21 MVideoShare
29} from '../../../types/models' 22} from '../../../types/models'
23import { audiencify, getAudience } from '../audience'
24import { getUndoActivityPubUrl, getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from '../url'
25import { buildAnnounceWithVideoAudience } from './send-announce'
26import { buildCreateActivity } from './send-create'
27import { buildDislikeActivity } from './send-dislike'
28import { buildFollowActivity } from './send-follow'
29import { buildLikeActivity } from './send-like'
30import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
30 31
31function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) { 32function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) {
32 const me = actorFollow.ActorFollower 33 const me = actorFollow.ActorFollower
@@ -37,10 +38,9 @@ function sendUndoFollow (actorFollow: MActorFollowActors, t: Transaction) {
37 38
38 logger.info('Creating job to send an unfollow request to %s.', following.url) 39 logger.info('Creating job to send an unfollow request to %s.', following.url)
39 40
40 const followUrl = getActorFollowActivityPubUrl(me, following) 41 const undoUrl = getUndoActivityPubUrl(actorFollow.url)
41 const undoUrl = getUndoActivityPubUrl(followUrl)
42 42
43 const followActivity = buildFollowActivity(followUrl, me, following) 43 const followActivity = buildFollowActivity(actorFollow.url, me, following)
44 const undoActivity = undoActivityData(undoUrl, me, followActivity) 44 const undoActivity = undoActivityData(undoUrl, me, followActivity)
45 45
46 t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl)) 46 t.afterCommit(() => unicastTo(undoActivity, me, following.inboxUrl))
@@ -61,7 +61,7 @@ async function sendUndoAnnounce (byActor: MActorLight, videoShare: MVideoShare,
61async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { 61async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
62 logger.info('Creating job to undo a like of video %s.', video.url) 62 logger.info('Creating job to undo a like of video %s.', video.url)
63 63
64 const likeUrl = getVideoLikeActivityPubUrl(byActor, video) 64 const likeUrl = getVideoLikeActivityPubUrlByLocalActor(byActor, video)
65 const likeActivity = buildLikeActivity(likeUrl, byActor, video) 65 const likeActivity = buildLikeActivity(likeUrl, byActor, video)
66 66
67 return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t }) 67 return sendUndoVideoRelatedActivity({ byActor, video, url: likeUrl, activity: likeActivity, transaction: t })
@@ -70,7 +70,7 @@ async function sendUndoLike (byActor: MActor, video: MVideoAccountLight, t: Tran
70async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) { 70async function sendUndoDislike (byActor: MActor, video: MVideoAccountLight, t: Transaction) {
71 logger.info('Creating job to undo a dislike of video %s.', video.url) 71 logger.info('Creating job to undo a dislike of video %s.', video.url)
72 72
73 const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video) 73 const dislikeUrl = getVideoDislikeActivityPubUrlByLocalActor(byActor, video)
74 const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video) 74 const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video)
75 75
76 return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t }) 76 return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t })
diff --git a/server/lib/activitypub/send/send-view.ts b/server/lib/activitypub/send/send-view.ts
index 3358188a2..9254dc7c5 100644
--- a/server/lib/activitypub/send/send-view.ts
+++ b/server/lib/activitypub/send/send-view.ts
@@ -1,17 +1,17 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models'
2import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub' 3import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub'
4import { logger } from '../../../helpers/logger'
3import { ActorModel } from '../../../models/activitypub/actor' 5import { ActorModel } from '../../../models/activitypub/actor'
4import { getVideoLikeActivityPubUrl } from '../url'
5import { sendVideoRelatedActivity } from './utils'
6import { audiencify, getAudience } from '../audience' 6import { audiencify, getAudience } from '../audience'
7import { logger } from '../../../helpers/logger' 7import { getLocalVideoViewActivityPubUrl } from '../url'
8import { MActorAudience, MVideoImmutable, MVideoUrl } from '@server/types/models' 8import { sendVideoRelatedActivity } from './utils'
9 9
10async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) { 10async function sendView (byActor: ActorModel, video: MVideoImmutable, t: Transaction) {
11 logger.info('Creating job to send view of %s.', video.url) 11 logger.info('Creating job to send view of %s.', video.url)
12 12
13 const activityBuilder = (audience: ActivityAudience) => { 13 const activityBuilder = (audience: ActivityAudience) => {
14 const url = getVideoLikeActivityPubUrl(byActor, video) 14 const url = getLocalVideoViewActivityPubUrl(byActor, video)
15 15
16 return buildViewActivity(url, byActor, video, audience) 16 return buildViewActivity(url, byActor, video, audience)
17 } 17 }
diff --git a/server/lib/activitypub/share.ts b/server/lib/activitypub/share.ts
index 5e426f5db..1f8a8f3c4 100644
--- a/server/lib/activitypub/share.ts
+++ b/server/lib/activitypub/share.ts
@@ -1,7 +1,7 @@
1import { Transaction } from 'sequelize' 1import { Transaction } from 'sequelize'
2import { VideoShareModel } from '../../models/video/video-share' 2import { VideoShareModel } from '../../models/video/video-share'
3import { sendUndoAnnounce, sendVideoAnnounce } from './send' 3import { sendUndoAnnounce, sendVideoAnnounce } from './send'
4import { getVideoAnnounceActivityPubUrl } from './url' 4import { getLocalVideoAnnounceActivityPubUrl } from './url'
5import * as Bluebird from 'bluebird' 5import * as Bluebird from 'bluebird'
6import { doRequest } from '../../helpers/requests' 6import { doRequest } from '../../helpers/requests'
7import { getOrCreateActorAndServerAndModel } from './actor' 7import { getOrCreateActorAndServerAndModel } from './actor'
@@ -74,7 +74,7 @@ export {
74async function shareByServer (video: MVideo, t: Transaction) { 74async function shareByServer (video: MVideo, t: Transaction) {
75 const serverActor = await getServerActor() 75 const serverActor = await getServerActor()
76 76
77 const serverShareUrl = getVideoAnnounceActivityPubUrl(serverActor, video) 77 const serverShareUrl = getLocalVideoAnnounceActivityPubUrl(serverActor, video)
78 const [ serverShare ] = await VideoShareModel.findOrCreate({ 78 const [ serverShare ] = await VideoShareModel.findOrCreate({
79 defaults: { 79 defaults: {
80 actorId: serverActor.id, 80 actorId: serverActor.id,
@@ -91,7 +91,7 @@ async function shareByServer (video: MVideo, t: Transaction) {
91} 91}
92 92
93async function shareByVideoChannel (video: MVideoAccountLight, t: Transaction) { 93async function shareByVideoChannel (video: MVideoAccountLight, t: Transaction) {
94 const videoChannelShareUrl = getVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video) 94 const videoChannelShareUrl = getLocalVideoAnnounceActivityPubUrl(video.VideoChannel.Actor, video)
95 const [ videoChannelShare ] = await VideoShareModel.findOrCreate({ 95 const [ videoChannelShare ] = await VideoShareModel.findOrCreate({
96 defaults: { 96 defaults: {
97 actorId: video.VideoChannel.actorId, 97 actorId: video.VideoChannel.actorId,
diff --git a/server/lib/activitypub/url.ts b/server/lib/activitypub/url.ts
index 58030be2c..ad6a1d1fd 100644
--- a/server/lib/activitypub/url.ts
+++ b/server/lib/activitypub/url.ts
@@ -1,102 +1,102 @@
1import { WEBSERVER } from '../../initializers/constants' 1import { WEBSERVER } from '../../initializers/constants'
2import { 2import {
3 MAbuseId,
3 MActor, 4 MActor,
4 MActorFollowActors, 5 MActorFollowActors,
5 MActorId, 6 MActorId,
6 MActorUrl, 7 MActorUrl,
7 MCommentId, 8 MCommentId,
8 MVideoId, 9 MVideoId,
10 MVideoPlaylistElement,
9 MVideoUrl, 11 MVideoUrl,
10 MVideoUUID, 12 MVideoUUID
11 MAbuseId,
12 MVideoPlaylistElement
13} from '../../types/models' 13} from '../../types/models'
14import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
15import { MVideoFileVideoUUID } from '../../types/models/video/video-file' 14import { MVideoFileVideoUUID } from '../../types/models/video/video-file'
15import { MVideoPlaylist, MVideoPlaylistUUID } from '../../types/models/video/video-playlist'
16import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist' 16import { MStreamingPlaylist } from '../../types/models/video/video-streaming-playlist'
17 17
18function getVideoActivityPubUrl (video: MVideoUUID) { 18function getLocalVideoActivityPubUrl (video: MVideoUUID) {
19 return WEBSERVER.URL + '/videos/watch/' + video.uuid 19 return WEBSERVER.URL + '/videos/watch/' + video.uuid
20} 20}
21 21
22function getVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) { 22function getLocalVideoPlaylistActivityPubUrl (videoPlaylist: MVideoPlaylist) {
23 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid 23 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid
24} 24}
25 25
26function getVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) { 26function getLocalVideoPlaylistElementActivityPubUrl (videoPlaylist: MVideoPlaylistUUID, videoPlaylistElement: MVideoPlaylistElement) {
27 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id 27 return WEBSERVER.URL + '/video-playlists/' + videoPlaylist.uuid + '/videos/' + videoPlaylistElement.id
28} 28}
29 29
30function getVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) { 30function getLocalVideoCacheFileActivityPubUrl (videoFile: MVideoFileVideoUUID) {
31 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : '' 31 const suffixFPS = videoFile.fps && videoFile.fps !== -1 ? '-' + videoFile.fps : ''
32 32
33 return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}` 33 return `${WEBSERVER.URL}/redundancy/videos/${videoFile.Video.uuid}/${videoFile.resolution}${suffixFPS}`
34} 34}
35 35
36function getVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) { 36function getLocalVideoCacheStreamingPlaylistActivityPubUrl (video: MVideoUUID, playlist: MStreamingPlaylist) {
37 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}` 37 return `${WEBSERVER.URL}/redundancy/streaming-playlists/${playlist.getStringType()}/${video.uuid}`
38} 38}
39 39
40function getVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) { 40function getLocalVideoCommentActivityPubUrl (video: MVideoUUID, videoComment: MCommentId) {
41 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id 41 return WEBSERVER.URL + '/videos/watch/' + video.uuid + '/comments/' + videoComment.id
42} 42}
43 43
44function getVideoChannelActivityPubUrl (videoChannelName: string) { 44function getLocalVideoChannelActivityPubUrl (videoChannelName: string) {
45 return WEBSERVER.URL + '/video-channels/' + videoChannelName 45 return WEBSERVER.URL + '/video-channels/' + videoChannelName
46} 46}
47 47
48function getAccountActivityPubUrl (accountName: string) { 48function getLocalAccountActivityPubUrl (accountName: string) {
49 return WEBSERVER.URL + '/accounts/' + accountName 49 return WEBSERVER.URL + '/accounts/' + accountName
50} 50}
51 51
52function getAbuseActivityPubUrl (abuse: MAbuseId) { 52function getLocalAbuseActivityPubUrl (abuse: MAbuseId) {
53 return WEBSERVER.URL + '/admin/abuses/' + abuse.id 53 return WEBSERVER.URL + '/admin/abuses/' + abuse.id
54} 54}
55 55
56function getVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) { 56function getLocalVideoViewActivityPubUrl (byActor: MActorUrl, video: MVideoId) {
57 return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString() 57 return byActor.url + '/views/videos/' + video.id + '/' + new Date().toISOString()
58} 58}
59 59
60function getVideoLikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { 60function getVideoLikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
61 return byActor.url + '/likes/' + video.id 61 return byActor.url + '/likes/' + video.id
62} 62}
63 63
64function getVideoDislikeActivityPubUrl (byActor: MActorUrl, video: MVideoId) { 64function getVideoDislikeActivityPubUrlByLocalActor (byActor: MActorUrl, video: MVideoId) {
65 return byActor.url + '/dislikes/' + video.id 65 return byActor.url + '/dislikes/' + video.id
66} 66}
67 67
68function getVideoSharesActivityPubUrl (video: MVideoUrl) { 68function getLocalVideoSharesActivityPubUrl (video: MVideoUrl) {
69 return video.url + '/announces' 69 return video.url + '/announces'
70} 70}
71 71
72function getVideoCommentsActivityPubUrl (video: MVideoUrl) { 72function getLocalVideoCommentsActivityPubUrl (video: MVideoUrl) {
73 return video.url + '/comments' 73 return video.url + '/comments'
74} 74}
75 75
76function getVideoLikesActivityPubUrl (video: MVideoUrl) { 76function getLocalVideoLikesActivityPubUrl (video: MVideoUrl) {
77 return video.url + '/likes' 77 return video.url + '/likes'
78} 78}
79 79
80function getVideoDislikesActivityPubUrl (video: MVideoUrl) { 80function getLocalVideoDislikesActivityPubUrl (video: MVideoUrl) {
81 return video.url + '/dislikes' 81 return video.url + '/dislikes'
82} 82}
83 83
84function getActorFollowActivityPubUrl (follower: MActor, following: MActorId) { 84function getLocalActorFollowActivityPubUrl (follower: MActor, following: MActorId) {
85 return follower.url + '/follows/' + following.id 85 return follower.url + '/follows/' + following.id
86} 86}
87 87
88function getActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) { 88function getLocalActorFollowAcceptActivityPubUrl (actorFollow: MActorFollowActors) {
89 const follower = actorFollow.ActorFollower 89 const follower = actorFollow.ActorFollower
90 const me = actorFollow.ActorFollowing 90 const me = actorFollow.ActorFollowing
91 91
92 return follower.url + '/accepts/follows/' + me.id 92 return WEBSERVER.URL + '/accepts/follows/' + follower.id + '/' + me.id
93} 93}
94 94
95function getActorFollowRejectActivityPubUrl (follower: MActorUrl, following: MActorId) { 95function getLocalActorFollowRejectActivityPubUrl (follower: MActorId, following: MActorId) {
96 return follower.url + '/rejects/follows/' + following.id 96 return WEBSERVER.URL + '/rejects/follows/' + follower.id + '/' + following.id
97} 97}
98 98
99function getVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) { 99function getLocalVideoAnnounceActivityPubUrl (byActor: MActorId, video: MVideoUrl) {
100 return video.url + '/announces/' + byActor.id 100 return video.url + '/announces/' + byActor.id
101} 101}
102 102
@@ -113,27 +113,28 @@ function getUndoActivityPubUrl (originalUrl: string) {
113} 113}
114 114
115export { 115export {
116 getVideoActivityPubUrl, 116 getLocalVideoActivityPubUrl,
117 getVideoPlaylistElementActivityPubUrl, 117 getLocalVideoPlaylistActivityPubUrl,
118 getVideoPlaylistActivityPubUrl, 118 getLocalVideoPlaylistElementActivityPubUrl,
119 getVideoCacheStreamingPlaylistActivityPubUrl, 119 getLocalVideoCacheFileActivityPubUrl,
120 getVideoChannelActivityPubUrl, 120 getLocalVideoCacheStreamingPlaylistActivityPubUrl,
121 getAccountActivityPubUrl, 121 getLocalVideoCommentActivityPubUrl,
122 getAbuseActivityPubUrl, 122 getLocalVideoChannelActivityPubUrl,
123 getActorFollowActivityPubUrl, 123 getLocalAccountActivityPubUrl,
124 getActorFollowAcceptActivityPubUrl, 124 getLocalAbuseActivityPubUrl,
125 getVideoAnnounceActivityPubUrl, 125 getLocalActorFollowActivityPubUrl,
126 getLocalActorFollowAcceptActivityPubUrl,
127 getLocalVideoAnnounceActivityPubUrl,
126 getUpdateActivityPubUrl, 128 getUpdateActivityPubUrl,
127 getUndoActivityPubUrl, 129 getUndoActivityPubUrl,
128 getVideoViewActivityPubUrl, 130 getVideoLikeActivityPubUrlByLocalActor,
129 getVideoLikeActivityPubUrl, 131 getLocalVideoViewActivityPubUrl,
130 getVideoDislikeActivityPubUrl, 132 getVideoDislikeActivityPubUrlByLocalActor,
131 getActorFollowRejectActivityPubUrl, 133 getLocalActorFollowRejectActivityPubUrl,
132 getVideoCommentActivityPubUrl,
133 getDeleteActivityPubUrl, 134 getDeleteActivityPubUrl,
134 getVideoSharesActivityPubUrl, 135 getLocalVideoSharesActivityPubUrl,
135 getVideoCommentsActivityPubUrl, 136 getLocalVideoCommentsActivityPubUrl,
136 getVideoLikesActivityPubUrl, 137 getLocalVideoLikesActivityPubUrl,
137 getVideoDislikesActivityPubUrl, 138 getLocalVideoDislikesActivityPubUrl,
138 getVideoCacheFileActivityPubUrl 139
139} 140}
diff --git a/server/lib/activitypub/video-rates.ts b/server/lib/activitypub/video-rates.ts
index e09e5d9ec..581a2bca1 100644
--- a/server/lib/activitypub/video-rates.ts
+++ b/server/lib/activitypub/video-rates.ts
@@ -8,7 +8,7 @@ import { logger } from '../../helpers/logger'
8import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants' 8import { CRAWL_REQUEST_CONCURRENCY } from '../../initializers/constants'
9import { doRequest } from '../../helpers/requests' 9import { doRequest } from '../../helpers/requests'
10import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub' 10import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
11import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url' 11import { getVideoDislikeActivityPubUrlByLocalActor, getVideoLikeActivityPubUrlByLocalActor } from './url'
12import { sendDislike } from './send/send-dislike' 12import { sendDislike } from './send/send-dislike'
13import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models' 13import { MAccountActor, MActorUrl, MVideo, MVideoAccountLight, MVideoId } from '../../types/models'
14 14
@@ -82,14 +82,14 @@ async function sendVideoRateChange (
82 if (dislikes > 0) await sendDislike(actor, video, t) 82 if (dislikes > 0) await sendDislike(actor, video, t)
83} 83}
84 84
85function getRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) { 85function getLocalRateUrl (rateType: VideoRateType, actor: MActorUrl, video: MVideoId) {
86 return rateType === 'like' 86 return rateType === 'like'
87 ? getVideoLikeActivityPubUrl(actor, video) 87 ? getVideoLikeActivityPubUrlByLocalActor(actor, video)
88 : getVideoDislikeActivityPubUrl(actor, video) 88 : getVideoDislikeActivityPubUrlByLocalActor(actor, video)
89} 89}
90 90
91export { 91export {
92 getRateUrl, 92 getLocalRateUrl,
93 createRates, 93 createRates,
94 sendVideoRateChange 94 sendVideoRateChange
95} 95}