aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-08-09 08:17:16 +0200
committerChocobozzz <me@florianbigard.com>2019-08-09 08:17:16 +0200
commit5224c394b3bbac6ec1543e41fa0ec6db436e84fa (patch)
tree36eaecfe095547aca903a8a43fb6e0b0b01899a9 /server/lib/activitypub/process
parent511765c9f86fb07d5d856decd9dbf0ec2092f4fe (diff)
downloadPeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.tar.gz
PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.tar.zst
PeerTube-5224c394b3bbac6ec1543e41fa0ec6db436e84fa.zip
Stronger actor association typing in AP functions
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r--server/lib/activitypub/process/process-accept.ts3
-rw-r--r--server/lib/activitypub/process/process-announce.ts4
-rw-r--r--server/lib/activitypub/process/process-create.ts8
-rw-r--r--server/lib/activitypub/process/process-delete.ts3
-rw-r--r--server/lib/activitypub/process/process-dislike.ts4
-rw-r--r--server/lib/activitypub/process/process-flag.ts4
-rw-r--r--server/lib/activitypub/process/process-follow.ts16
-rw-r--r--server/lib/activitypub/process/process-like.ts4
-rw-r--r--server/lib/activitypub/process/process-reject.ts4
-rw-r--r--server/lib/activitypub/process/process-undo.ts11
-rw-r--r--server/lib/activitypub/process/process-update.ts7
-rw-r--r--server/lib/activitypub/process/process-view.ts4
-rw-r--r--server/lib/activitypub/process/process.ts5
13 files changed, 42 insertions, 35 deletions
diff --git a/server/lib/activitypub/process/process-accept.ts b/server/lib/activitypub/process/process-accept.ts
index 72bb1975e..cf27e6c32 100644
--- a/server/lib/activitypub/process/process-accept.ts
+++ b/server/lib/activitypub/process/process-accept.ts
@@ -3,6 +3,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
3import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
4import { addFetchOutboxJob } from '../actor' 4import { addFetchOutboxJob } from '../actor'
5import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 5import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
6import { SignatureActorModel } from '../../../typings/models'
6 7
7async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) { 8async function processAcceptActivity (options: APProcessorOptions<ActivityAccept>) {
8 const { byActor: targetActor, inboxActor } = options 9 const { byActor: targetActor, inboxActor } = options
@@ -19,7 +20,7 @@ export {
19 20
20// --------------------------------------------------------------------------- 21// ---------------------------------------------------------------------------
21 22
22async function processAccept (actor: ActorModel, targetActor: ActorModel) { 23async function processAccept (actor: ActorModel, targetActor: SignatureActorModel) {
23 const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id) 24 const follow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id)
24 if (!follow) throw new Error('Cannot find associated follow.') 25 if (!follow) throw new Error('Cannot find associated follow.')
25 26
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 7a59bb84d..b3cdc4441 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -1,7 +1,6 @@
1import { ActivityAnnounce } from '../../../../shared/models/activitypub' 1import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { ActorModel } from '../../../models/activitypub/actor'
5import { VideoShareModel } from '../../../models/video/video-share' 4import { VideoShareModel } from '../../../models/video/video-share'
6import { forwardVideoRelatedActivity } from '../send/utils' 5import { forwardVideoRelatedActivity } from '../send/utils'
7import { getOrCreateVideoAndAccountAndChannel } from '../videos' 6import { getOrCreateVideoAndAccountAndChannel } from '../videos'
@@ -9,6 +8,7 @@ import { Notifier } from '../../notifier'
9import { VideoModel } from '../../../models/video/video' 8import { VideoModel } from '../../../models/video/video'
10import { logger } from '../../../helpers/logger' 9import { logger } from '../../../helpers/logger'
11import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 10import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
11import { SignatureActorModel } from '../../../typings/models'
12 12
13async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) { 13async function processAnnounceActivity (options: APProcessorOptions<ActivityAnnounce>) {
14 const { activity, byActor: actorAnnouncer } = options 14 const { activity, byActor: actorAnnouncer } = options
@@ -26,7 +26,7 @@ export {
26 26
27// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
28 28
29async function processVideoShare (actorAnnouncer: ActorModel, activity: ActivityAnnounce, notify: boolean) { 29async function processVideoShare (actorAnnouncer: SignatureActorModel, activity: ActivityAnnounce, notify: boolean) {
30 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id 30 const objectUri = typeof activity.object === 'string' ? activity.object : activity.object.id
31 31
32 let video: VideoModel 32 let video: VideoModel
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index b81021163..6815c6997 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -3,7 +3,6 @@ import { VideoCommentObject } from '../../../../shared/models/activitypub/object
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
6import { ActorModel } from '../../../models/activitypub/actor'
7import { resolveThread } from '../video-comments' 6import { resolveThread } from '../video-comments'
8import { getOrCreateVideoAndAccountAndChannel } from '../videos' 7import { getOrCreateVideoAndAccountAndChannel } from '../videos'
9import { forwardVideoRelatedActivity } from '../send/utils' 8import { forwardVideoRelatedActivity } from '../send/utils'
@@ -14,6 +13,7 @@ import { createOrUpdateVideoPlaylist } from '../playlist'
14import { VideoModel } from '../../../models/video/video' 13import { VideoModel } from '../../../models/video/video'
15import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 14import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
16import { VideoCommentModel } from '../../../models/video/video-comment' 15import { VideoCommentModel } from '../../../models/video/video-comment'
16import { SignatureActorModel } from '../../../typings/models'
17 17
18async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) { 18async function processCreateActivity (options: APProcessorOptions<ActivityCreate>) {
19 const { activity, byActor } = options 19 const { activity, byActor } = options
@@ -61,7 +61,7 @@ async function processCreateVideo (activity: ActivityCreate, notify: boolean) {
61 return video 61 return video
62} 62}
63 63
64async function processCreateCacheFile (activity: ActivityCreate, byActor: ActorModel) { 64async function processCreateCacheFile (activity: ActivityCreate, byActor: SignatureActorModel) {
65 const cacheFile = activity.object as CacheFileObject 65 const cacheFile = activity.object as CacheFileObject
66 66
67 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object }) 67 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFile.object })
@@ -77,7 +77,7 @@ async function processCreateCacheFile (activity: ActivityCreate, byActor: ActorM
77 } 77 }
78} 78}
79 79
80async function processCreateVideoComment (activity: ActivityCreate, byActor: ActorModel, notify: boolean) { 80async function processCreateVideoComment (activity: ActivityCreate, byActor: SignatureActorModel, notify: boolean) {
81 const commentObject = activity.object as VideoCommentObject 81 const commentObject = activity.object as VideoCommentObject
82 const byAccount = byActor.Account 82 const byAccount = byActor.Account
83 83
@@ -110,7 +110,7 @@ async function processCreateVideoComment (activity: ActivityCreate, byActor: Act
110 if (created && notify) Notifier.Instance.notifyOnNewComment(comment) 110 if (created && notify) Notifier.Instance.notifyOnNewComment(comment)
111} 111}
112 112
113async function processCreatePlaylist (activity: ActivityCreate, byActor: ActorModel) { 113async function processCreatePlaylist (activity: ActivityCreate, byActor: SignatureActorModel) {
114 const playlistObject = activity.object as PlaylistObject 114 const playlistObject = activity.object as PlaylistObject
115 const byAccount = byActor.Account 115 const byAccount = byActor.Account
116 116
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 9fcfd9e3a..344d14322 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -10,6 +10,7 @@ import { VideoCommentModel } from '../../../models/video/video-comment'
10import { forwardVideoRelatedActivity } from '../send/utils' 10import { forwardVideoRelatedActivity } from '../send/utils'
11import { VideoPlaylistModel } from '../../../models/video/video-playlist' 11import { VideoPlaylistModel } from '../../../models/video/video-playlist'
12import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 12import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
13import { SignatureActorModel } from '../../../typings/models'
13 14
14async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) { 15async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
15 const { activity, byActor } = options 16 const { activity, byActor } = options
@@ -117,7 +118,7 @@ async function processDeleteVideoChannel (videoChannelToRemove: VideoChannelMode
117 logger.info('Remote video channel %s removed.', videoChannelToRemove.Actor.url) 118 logger.info('Remote video channel %s removed.', videoChannelToRemove.Actor.url)
118} 119}
119 120
120function processDeleteVideoComment (byActor: ActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) { 121function processDeleteVideoComment (byActor: SignatureActorModel, videoComment: VideoCommentModel, activity: ActivityDelete) {
121 logger.debug('Removing remote video comment "%s".', videoComment.url) 122 logger.debug('Removing remote video comment "%s".', videoComment.url)
122 123
123 return sequelizeTypescript.transaction(async t => { 124 return sequelizeTypescript.transaction(async t => {
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts
index a457e5f17..727fcfee0 100644
--- a/server/lib/activitypub/process/process-dislike.ts
+++ b/server/lib/activitypub/process/process-dislike.ts
@@ -3,11 +3,11 @@ import { DislikeObject } from '../../../../shared/models/activitypub/objects'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { sequelizeTypescript } from '../../../initializers' 4import { sequelizeTypescript } from '../../../initializers'
5import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 5import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
6import { ActorModel } from '../../../models/activitypub/actor'
7import { getOrCreateVideoAndAccountAndChannel } from '../videos' 6import { getOrCreateVideoAndAccountAndChannel } from '../videos'
8import { forwardVideoRelatedActivity } from '../send/utils' 7import { forwardVideoRelatedActivity } from '../send/utils'
9import { getVideoDislikeActivityPubUrl } from '../url' 8import { getVideoDislikeActivityPubUrl } from '../url'
10import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 9import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
10import { SignatureActorModel } from '../../../typings/models'
11 11
12async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { 12async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) {
13 const { activity, byActor } = options 13 const { activity, byActor } = options
@@ -22,7 +22,7 @@ export {
22 22
23// --------------------------------------------------------------------------- 23// ---------------------------------------------------------------------------
24 24
25async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: ActorModel) { 25async function processDislike (activity: ActivityCreate | ActivityDislike, byActor: SignatureActorModel) {
26 const dislikeObject = activity.type === 'Dislike' ? activity.object : (activity.object as DislikeObject).object 26 const dislikeObject = activity.type === 'Dislike' ? activity.object : (activity.object as DislikeObject).object
27 const byAccount = byActor.Account 27 const byAccount = byActor.Account
28 28
diff --git a/server/lib/activitypub/process/process-flag.ts b/server/lib/activitypub/process/process-flag.ts
index 532545e58..1f8a80c14 100644
--- a/server/lib/activitypub/process/process-flag.ts
+++ b/server/lib/activitypub/process/process-flag.ts
@@ -3,12 +3,12 @@ import { VideoAbuseObject } from '../../../../shared/models/activitypub/objects'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 3import { retryTransactionWrapper } from '../../../helpers/database-utils'
4import { logger } from '../../../helpers/logger' 4import { logger } from '../../../helpers/logger'
5import { sequelizeTypescript } from '../../../initializers' 5import { sequelizeTypescript } from '../../../initializers'
6import { ActorModel } from '../../../models/activitypub/actor'
7import { VideoAbuseModel } from '../../../models/video/video-abuse' 6import { VideoAbuseModel } from '../../../models/video/video-abuse'
8import { getOrCreateVideoAndAccountAndChannel } from '../videos' 7import { getOrCreateVideoAndAccountAndChannel } from '../videos'
9import { Notifier } from '../../notifier' 8import { Notifier } from '../../notifier'
10import { getAPId } from '../../../helpers/activitypub' 9import { getAPId } from '../../../helpers/activitypub'
11import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 10import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
11import { SignatureActorModel } from '../../../typings/models'
12 12
13async function processFlagActivity (options: APProcessorOptions<ActivityCreate | ActivityFlag>) { 13async function processFlagActivity (options: APProcessorOptions<ActivityCreate | ActivityFlag>) {
14 const { activity, byActor } = options 14 const { activity, byActor } = options
@@ -23,7 +23,7 @@ export {
23 23
24// --------------------------------------------------------------------------- 24// ---------------------------------------------------------------------------
25 25
26async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, byActor: ActorModel) { 26async function processCreateVideoAbuse (activity: ActivityCreate | ActivityFlag, byActor: SignatureActorModel) {
27 const flag = activity.type === 'Flag' ? activity : (activity.object as VideoAbuseObject) 27 const flag = activity.type === 'Flag' ? activity : (activity.object as VideoAbuseObject)
28 28
29 logger.debug('Reporting remote abuse for video %s.', getAPId(flag.object)) 29 logger.debug('Reporting remote abuse for video %s.', getAPId(flag.object))
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts
index 8fe9975f6..240aa5799 100644
--- a/server/lib/activitypub/process/process-follow.ts
+++ b/server/lib/activitypub/process/process-follow.ts
@@ -10,6 +10,8 @@ import { getAPId } from '../../../helpers/activitypub'
10import { getServerActor } from '../../../helpers/utils' 10import { getServerActor } from '../../../helpers/utils'
11import { CONFIG } from '../../../initializers/config' 11import { CONFIG } from '../../../initializers/config'
12import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 12import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
13import { SignatureActorModel } from '../../../typings/models'
14import { ActorFollowModelLight } from '../../../typings/models/actor-follow'
13 15
14async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) { 16async function processFollowActivity (options: APProcessorOptions<ActivityFollow>) {
15 const { activity, byActor } = options 17 const { activity, byActor } = options
@@ -26,7 +28,7 @@ export {
26 28
27// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
28 30
29async function processFollow (actor: ActorModel, targetActorURL: string) { 31async function processFollow (byActor: SignatureActorModel, targetActorURL: string) {
30 const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => { 32 const { actorFollow, created, isFollowingInstance } = await sequelizeTypescript.transaction(async t => {
31 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t) 33 const targetActor = await ActorModel.loadByUrlAndPopulateAccountAndChannel(targetActorURL, t)
32 34
@@ -39,30 +41,30 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
39 if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) { 41 if (isFollowingInstance && CONFIG.FOLLOWERS.INSTANCE.ENABLED === false) {
40 logger.info('Rejecting %s because instance followers are disabled.', targetActor.url) 42 logger.info('Rejecting %s because instance followers are disabled.', targetActor.url)
41 43
42 await sendReject(actor, targetActor) 44 await sendReject(byActor, targetActor)
43 45
44 return { actorFollow: undefined } 46 return { actorFollow: undefined }
45 } 47 }
46 48
47 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({ 49 const [ actorFollow, created ] = await ActorFollowModel.findOrCreate({
48 where: { 50 where: {
49 actorId: actor.id, 51 actorId: byActor.id,
50 targetActorId: targetActor.id 52 targetActorId: targetActor.id
51 }, 53 },
52 defaults: { 54 defaults: {
53 actorId: actor.id, 55 actorId: byActor.id,
54 targetActorId: targetActor.id, 56 targetActorId: targetActor.id,
55 state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted' 57 state: CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL ? 'pending' : 'accepted'
56 }, 58 },
57 transaction: t 59 transaction: t
58 }) 60 }) as [ ActorFollowModelLight, boolean ]
59 61
60 if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) { 62 if (actorFollow.state !== 'accepted' && CONFIG.FOLLOWERS.INSTANCE.MANUAL_APPROVAL === false) {
61 actorFollow.state = 'accepted' 63 actorFollow.state = 'accepted'
62 await actorFollow.save({ transaction: t }) 64 await actorFollow.save({ transaction: t })
63 } 65 }
64 66
65 actorFollow.ActorFollower = actor 67 actorFollow.ActorFollower = byActor
66 actorFollow.ActorFollowing = targetActor 68 actorFollow.ActorFollowing = targetActor
67 69
68 // Target sends to actor he accepted the follow request 70 // Target sends to actor he accepted the follow request
@@ -79,5 +81,5 @@ async function processFollow (actor: ActorModel, targetActorURL: string) {
79 else Notifier.Instance.notifyOfNewUserFollow(actorFollow) 81 else Notifier.Instance.notifyOfNewUserFollow(actorFollow)
80 } 82 }
81 83
82 logger.info('Actor %s is followed by actor %s.', targetActorURL, actor.url) 84 logger.info('Actor %s is followed by actor %s.', targetActorURL, byActor.url)
83} 85}
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index 706e63c41..cf559af72 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -2,12 +2,12 @@ import { ActivityLike } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { sequelizeTypescript } from '../../../initializers' 3import { sequelizeTypescript } from '../../../initializers'
4import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 4import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
5import { ActorModel } from '../../../models/activitypub/actor'
6import { forwardVideoRelatedActivity } from '../send/utils' 5import { forwardVideoRelatedActivity } from '../send/utils'
7import { getOrCreateVideoAndAccountAndChannel } from '../videos' 6import { getOrCreateVideoAndAccountAndChannel } from '../videos'
8import { getVideoLikeActivityPubUrl } from '../url' 7import { getVideoLikeActivityPubUrl } from '../url'
9import { getAPId } from '../../../helpers/activitypub' 8import { getAPId } from '../../../helpers/activitypub'
10import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 9import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
10import { SignatureActorModel } from '../../../typings/models'
11 11
12async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { 12async function processLikeActivity (options: APProcessorOptions<ActivityLike>) {
13 const { activity, byActor } = options 13 const { activity, byActor } = options
@@ -22,7 +22,7 @@ export {
22 22
23// --------------------------------------------------------------------------- 23// ---------------------------------------------------------------------------
24 24
25async function processLikeVideo (byActor: ActorModel, activity: ActivityLike) { 25async function processLikeVideo (byActor: SignatureActorModel, activity: ActivityLike) {
26 const videoUrl = getAPId(activity.object) 26 const videoUrl = getAPId(activity.object)
27 27
28 const byAccount = byActor.Account 28 const byAccount = byActor.Account
diff --git a/server/lib/activitypub/process/process-reject.ts b/server/lib/activitypub/process/process-reject.ts
index 9181906b4..22e311ceb 100644
--- a/server/lib/activitypub/process/process-reject.ts
+++ b/server/lib/activitypub/process/process-reject.ts
@@ -1,8 +1,8 @@
1import { ActivityReject } from '../../../../shared/models/activitypub/activity' 1import { ActivityReject } from '../../../../shared/models/activitypub/activity'
2import { sequelizeTypescript } from '../../../initializers' 2import { sequelizeTypescript } from '../../../initializers'
3import { ActorModel } from '../../../models/activitypub/actor'
4import { ActorFollowModel } from '../../../models/activitypub/actor-follow' 3import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
5import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 4import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
5import { ActorModelOnly } from '../../../typings/models'
6 6
7async function processRejectActivity (options: APProcessorOptions<ActivityReject>) { 7async function processRejectActivity (options: APProcessorOptions<ActivityReject>) {
8 const { byActor: targetActor, inboxActor } = options 8 const { byActor: targetActor, inboxActor } = options
@@ -19,7 +19,7 @@ export {
19 19
20// --------------------------------------------------------------------------- 20// ---------------------------------------------------------------------------
21 21
22async function processReject (follower: ActorModel, targetActor: ActorModel) { 22async function processReject (follower: ActorModelOnly, targetActor: ActorModelOnly) {
23 return sequelizeTypescript.transaction(async t => { 23 return sequelizeTypescript.transaction(async t => {
24 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, targetActor.id, t) 24 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, targetActor.id, t)
25 25
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts
index 7a0f90adf..c37ee38bb 100644
--- a/server/lib/activitypub/process/process-undo.ts
+++ b/server/lib/activitypub/process/process-undo.ts
@@ -11,6 +11,7 @@ import { getOrCreateVideoAndAccountAndChannel } from '../videos'
11import { VideoShareModel } from '../../../models/video/video-share' 11import { VideoShareModel } from '../../../models/video/video-share'
12import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy' 12import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
13import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 13import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
14import { SignatureActorModel } from '../../../typings/models'
14 15
15async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) { 16async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) {
16 const { activity, byActor } = options 17 const { activity, byActor } = options
@@ -53,7 +54,7 @@ export {
53 54
54// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------
55 56
56async function processUndoLike (byActor: ActorModel, activity: ActivityUndo) { 57async function processUndoLike (byActor: SignatureActorModel, activity: ActivityUndo) {
57 const likeActivity = activity.object as ActivityLike 58 const likeActivity = activity.object as ActivityLike
58 59
59 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: likeActivity.object }) 60 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: likeActivity.object })
@@ -76,7 +77,7 @@ async function processUndoLike (byActor: ActorModel, activity: ActivityUndo) {
76 }) 77 })
77} 78}
78 79
79async function processUndoDislike (byActor: ActorModel, activity: ActivityUndo) { 80async function processUndoDislike (byActor: SignatureActorModel, activity: ActivityUndo) {
80 const dislike = activity.object.type === 'Dislike' 81 const dislike = activity.object.type === 'Dislike'
81 ? activity.object 82 ? activity.object
82 : activity.object.object as DislikeObject 83 : activity.object.object as DislikeObject
@@ -101,7 +102,7 @@ async function processUndoDislike (byActor: ActorModel, activity: ActivityUndo)
101 }) 102 })
102} 103}
103 104
104async function processUndoCacheFile (byActor: ActorModel, activity: ActivityUndo) { 105async function processUndoCacheFile (byActor: SignatureActorModel, activity: ActivityUndo) {
105 const cacheFileObject = activity.object.object as CacheFileObject 106 const cacheFileObject = activity.object.object as CacheFileObject
106 107
107 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFileObject.object }) 108 const { video } = await getOrCreateVideoAndAccountAndChannel({ videoObject: cacheFileObject.object })
@@ -126,7 +127,7 @@ async function processUndoCacheFile (byActor: ActorModel, activity: ActivityUndo
126 }) 127 })
127} 128}
128 129
129function processUndoFollow (follower: ActorModel, followActivity: ActivityFollow) { 130function processUndoFollow (follower: SignatureActorModel, followActivity: ActivityFollow) {
130 return sequelizeTypescript.transaction(async t => { 131 return sequelizeTypescript.transaction(async t => {
131 const following = await ActorModel.loadByUrlAndPopulateAccountAndChannel(followActivity.object, t) 132 const following = await ActorModel.loadByUrlAndPopulateAccountAndChannel(followActivity.object, t)
132 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t) 133 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t)
@@ -139,7 +140,7 @@ function processUndoFollow (follower: ActorModel, followActivity: ActivityFollow
139 }) 140 })
140} 141}
141 142
142function processUndoAnnounce (byActor: ActorModel, announceActivity: ActivityAnnounce) { 143function processUndoAnnounce (byActor: SignatureActorModel, announceActivity: ActivityAnnounce) {
143 return sequelizeTypescript.transaction(async t => { 144 return sequelizeTypescript.transaction(async t => {
144 const share = await VideoShareModel.loadByUrl(announceActivity.id, t) 145 const share = await VideoShareModel.loadByUrl(announceActivity.id, t)
145 if (!share) throw new Error(`Unknown video share ${announceActivity.id}.`) 146 if (!share) throw new Error(`Unknown video share ${announceActivity.id}.`)
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index 1e11dd1fd..e3c862221 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -15,6 +15,7 @@ import { forwardVideoRelatedActivity } from '../send/utils'
15import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object' 15import { PlaylistObject } from '../../../../shared/models/activitypub/objects/playlist-object'
16import { createOrUpdateVideoPlaylist } from '../playlist' 16import { createOrUpdateVideoPlaylist } from '../playlist'
17import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 17import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
18import { SignatureActorModel } from '../../../typings/models'
18 19
19async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) { 20async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) {
20 const { activity, byActor } = options 21 const { activity, byActor } = options
@@ -52,7 +53,7 @@ export {
52 53
53// --------------------------------------------------------------------------- 54// ---------------------------------------------------------------------------
54 55
55async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate) { 56async function processUpdateVideo (actor: SignatureActorModel, activity: ActivityUpdate) {
56 const videoObject = activity.object as VideoTorrentObject 57 const videoObject = activity.object as VideoTorrentObject
57 58
58 if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) { 59 if (sanitizeAndCheckVideoTorrentObject(videoObject) === false) {
@@ -73,7 +74,7 @@ async function processUpdateVideo (actor: ActorModel, activity: ActivityUpdate)
73 return updateVideoFromAP(updateOptions) 74 return updateVideoFromAP(updateOptions)
74} 75}
75 76
76async function processUpdateCacheFile (byActor: ActorModel, activity: ActivityUpdate) { 77async function processUpdateCacheFile (byActor: SignatureActorModel, activity: ActivityUpdate) {
77 const cacheFileObject = activity.object as CacheFileObject 78 const cacheFileObject = activity.object as CacheFileObject
78 79
79 if (!isCacheFileObjectValid(cacheFileObject)) { 80 if (!isCacheFileObjectValid(cacheFileObject)) {
@@ -147,7 +148,7 @@ async function processUpdateActor (actor: ActorModel, activity: ActivityUpdate)
147 } 148 }
148} 149}
149 150
150async function processUpdatePlaylist (byActor: ActorModel, activity: ActivityUpdate) { 151async function processUpdatePlaylist (byActor: SignatureActorModel, activity: ActivityUpdate) {
151 const playlistObject = activity.object as PlaylistObject 152 const playlistObject = activity.object as PlaylistObject
152 const byAccount = byActor.Account 153 const byAccount = byActor.Account
153 154
diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts
index 0170b74f4..e4997b828 100644
--- a/server/lib/activitypub/process/process-view.ts
+++ b/server/lib/activitypub/process/process-view.ts
@@ -1,9 +1,9 @@
1import { ActorModel } from '../../../models/activitypub/actor'
2import { getOrCreateVideoAndAccountAndChannel } from '../videos' 1import { getOrCreateVideoAndAccountAndChannel } from '../videos'
3import { forwardVideoRelatedActivity } from '../send/utils' 2import { forwardVideoRelatedActivity } from '../send/utils'
4import { Redis } from '../../redis' 3import { Redis } from '../../redis'
5import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub' 4import { ActivityCreate, ActivityView, ViewObject } from '../../../../shared/models/activitypub'
6import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 5import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
6import { SignatureActorModel } from '../../../typings/models'
7 7
8async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) { 8async function processViewActivity (options: APProcessorOptions<ActivityCreate | ActivityView>) {
9 const { activity, byActor } = options 9 const { activity, byActor } = options
@@ -18,7 +18,7 @@ export {
18 18
19// --------------------------------------------------------------------------- 19// ---------------------------------------------------------------------------
20 20
21async function processCreateView (activity: ActivityView | ActivityCreate, byActor: ActorModel) { 21async function processCreateView (activity: ActivityView | ActivityCreate, byActor: SignatureActorModel) {
22 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object 22 const videoObject = activity.type === 'View' ? activity.object : (activity.object as ViewObject).object
23 23
24 const options = { 24 const options = {
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts
index f4a92e341..d108fe321 100644
--- a/server/lib/activitypub/process/process.ts
+++ b/server/lib/activitypub/process/process.ts
@@ -16,6 +16,7 @@ import { processDislikeActivity } from './process-dislike'
16import { processFlagActivity } from './process-flag' 16import { processFlagActivity } from './process-flag'
17import { processViewActivity } from './process-view' 17import { processViewActivity } from './process-view'
18import { APProcessorOptions } from '../../../typings/activitypub-processor.model' 18import { APProcessorOptions } from '../../../typings/activitypub-processor.model'
19import { SignatureActorModel } from '../../../typings/models'
19 20
20const processActivity: { [ P in ActivityType ]: (options: APProcessorOptions<Activity>) => Promise<any> } = { 21const processActivity: { [ P in ActivityType ]: (options: APProcessorOptions<Activity>) => Promise<any> } = {
21 Create: processCreateActivity, 22 Create: processCreateActivity,
@@ -35,7 +36,7 @@ const processActivity: { [ P in ActivityType ]: (options: APProcessorOptions<Act
35async function processActivities ( 36async function processActivities (
36 activities: Activity[], 37 activities: Activity[],
37 options: { 38 options: {
38 signatureActor?: ActorModel 39 signatureActor?: SignatureActorModel
39 inboxActor?: ActorModel 40 inboxActor?: ActorModel
40 outboxUrl?: string 41 outboxUrl?: string
41 fromFetch?: boolean 42 fromFetch?: boolean
@@ -43,7 +44,7 @@ async function processActivities (
43) { 44) {
44 const { outboxUrl, signatureActor, inboxActor, fromFetch = false } = options 45 const { outboxUrl, signatureActor, inboxActor, fromFetch = false } = options
45 46
46 const actorsCache: { [ url: string ]: ActorModel } = {} 47 const actorsCache: { [ url: string ]: SignatureActorModel } = {}
47 48
48 for (const activity of activities) { 49 for (const activity of activities) {
49 if (!signatureActor && [ 'Create', 'Announce', 'Like' ].includes(activity.type) === false) { 50 if (!signatureActor && [ 'Create', 'Announce', 'Like' ].includes(activity.type) === false) {