aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/lib/activitypub/process
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r--server/lib/activitypub/process/process-announce.ts2
-rw-r--r--server/lib/activitypub/process/process-create.ts4
-rw-r--r--server/lib/activitypub/process/process-delete.ts2
-rw-r--r--server/lib/activitypub/process/process-dislike.ts20
-rw-r--r--server/lib/activitypub/process/process-like.ts21
-rw-r--r--server/lib/activitypub/process/process-undo.ts61
-rw-r--r--server/lib/activitypub/process/process-update.ts2
-rw-r--r--server/lib/activitypub/process/process-view.ts2
8 files changed, 61 insertions, 53 deletions
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts
index 2619d9754..200f8ce11 100644
--- a/server/lib/activitypub/process/process-announce.ts
+++ b/server/lib/activitypub/process/process-announce.ts
@@ -2,7 +2,7 @@ import { ActivityAnnounce } from '../../../../shared/models/activitypub'
2import { retryTransactionWrapper } from '../../../helpers/database-utils' 2import { retryTransactionWrapper } from '../../../helpers/database-utils'
3import { sequelizeTypescript } from '../../../initializers/database' 3import { sequelizeTypescript } from '../../../initializers/database'
4import { VideoShareModel } from '../../../models/video/video-share' 4import { VideoShareModel } from '../../../models/video/video-share'
5import { forwardVideoRelatedActivity } from '../send/utils' 5import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
6import { getOrCreateAPVideo } from '../videos' 6import { getOrCreateAPVideo } from '../videos'
7import { Notifier } from '../../notifier' 7import { Notifier } from '../../notifier'
8import { logger } from '../../../helpers/logger' 8import { logger } from '../../../helpers/logger'
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts
index 3e8ad184c..b5b1a0feb 100644
--- a/server/lib/activitypub/process/process-create.ts
+++ b/server/lib/activitypub/process/process-create.ts
@@ -9,7 +9,7 @@ import { MActorSignature, MCommentOwnerVideo, MVideoAccountLightBlacklistAllFile
9import { Notifier } from '../../notifier' 9import { Notifier } from '../../notifier'
10import { createOrUpdateCacheFile } from '../cache-file' 10import { createOrUpdateCacheFile } from '../cache-file'
11import { createOrUpdateVideoPlaylist } from '../playlists' 11import { createOrUpdateVideoPlaylist } from '../playlists'
12import { forwardVideoRelatedActivity } from '../send/utils' 12import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
13import { resolveThread } from '../video-comments' 13import { resolveThread } from '../video-comments'
14import { getOrCreateAPVideo } from '../videos' 14import { getOrCreateAPVideo } from '../videos'
15 15
@@ -55,7 +55,7 @@ export {
55async function processCreateVideo (activity: ActivityCreate, notify: boolean) { 55async function processCreateVideo (activity: ActivityCreate, notify: boolean) {
56 const videoToCreateData = activity.object as VideoObject 56 const videoToCreateData = activity.object as VideoObject
57 57
58 const syncParam = { likes: false, dislikes: false, shares: false, comments: false, thumbnail: true, refreshVideo: false } 58 const syncParam = { rates: false, shares: false, comments: false, thumbnail: true, refreshVideo: false }
59 const { video, created } = await getOrCreateAPVideo({ videoObject: videoToCreateData, syncParam }) 59 const { video, created } = await getOrCreateAPVideo({ videoObject: videoToCreateData, syncParam })
60 60
61 if (created && notify) Notifier.Instance.notifyOnNewVideoIfNeeded(video) 61 if (created && notify) Notifier.Instance.notifyOnNewVideoIfNeeded(video)
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts
index 1d2279df5..ac0e7e235 100644
--- a/server/lib/activitypub/process/process-delete.ts
+++ b/server/lib/activitypub/process/process-delete.ts
@@ -16,7 +16,7 @@ import {
16 MChannelActor, 16 MChannelActor,
17 MCommentOwnerVideo 17 MCommentOwnerVideo
18} from '../../../types/models' 18} from '../../../types/models'
19import { forwardVideoRelatedActivity } from '../send/utils' 19import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
20 20
21async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) { 21async function processDeleteActivity (options: APProcessorOptions<ActivityDelete>) {
22 const { activity, byActor } = options 22 const { activity, byActor } = options
diff --git a/server/lib/activitypub/process/process-dislike.ts b/server/lib/activitypub/process/process-dislike.ts
index 2f46b83d1..97a994e94 100644
--- a/server/lib/activitypub/process/process-dislike.ts
+++ b/server/lib/activitypub/process/process-dislike.ts
@@ -1,11 +1,11 @@
1import { VideoModel } from '@server/models/video/video'
1import { ActivityCreate, ActivityDislike, DislikeObject } from '@shared/models' 2import { ActivityCreate, ActivityDislike, DislikeObject } from '@shared/models'
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 { APProcessorOptions } from '../../../types/activitypub-processor.model' 6import { APProcessorOptions } from '../../../types/activitypub-processor.model'
6import { MActorSignature } from '../../../types/models' 7import { MActorSignature } from '../../../types/models'
7import { forwardVideoRelatedActivity } from '../send/utils' 8import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos'
8import { getOrCreateAPVideo } from '../videos'
9 9
10async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) { 10async function processDislikeActivity (options: APProcessorOptions<ActivityCreate | ActivityDislike>) {
11 const { activity, byActor } = options 11 const { activity, byActor } = options
@@ -29,16 +29,23 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
29 29
30 if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url) 30 if (!byAccount) throw new Error('Cannot create dislike with the non account actor ' + byActor.url)
31 31
32 const { video } = await getOrCreateAPVideo({ videoObject: dislikeObject }) 32 const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislikeObject, fetchType: 'only-video' })
33
34 // We don't care about dislikes of remote videos
35 if (!onlyVideo.isOwned()) return
33 36
34 return sequelizeTypescript.transaction(async t => { 37 return sequelizeTypescript.transaction(async t => {
38 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(onlyVideo.id, t)
39
35 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) 40 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t)
36 if (existingRate && existingRate.type === 'dislike') return 41 if (existingRate && existingRate.type === 'dislike') return
37 42
38 await video.increment('dislikes', { transaction: t }) 43 await video.increment('dislikes', { transaction: t })
44 video.dislikes++
39 45
40 if (existingRate && existingRate.type === 'like') { 46 if (existingRate && existingRate.type === 'like') {
41 await video.decrement('likes', { transaction: t }) 47 await video.decrement('likes', { transaction: t })
48 video.likes--
42 } 49 }
43 50
44 const rate = existingRate || new AccountVideoRateModel() 51 const rate = existingRate || new AccountVideoRateModel()
@@ -49,11 +56,6 @@ async function processDislike (activity: ActivityCreate | ActivityDislike, byAct
49 56
50 await rate.save({ transaction: t }) 57 await rate.save({ transaction: t })
51 58
52 if (video.isOwned()) { 59 await federateVideoIfNeeded(video, false, t)
53 // Don't resend the activity to the sender
54 const exceptions = [ byActor ]
55
56 await forwardVideoRelatedActivity(activity, t, exceptions, video)
57 }
58 }) 60 })
59} 61}
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts
index cd4e86cbb..93afb5edf 100644
--- a/server/lib/activitypub/process/process-like.ts
+++ b/server/lib/activitypub/process/process-like.ts
@@ -1,3 +1,4 @@
1import { VideoModel } from '@server/models/video/video'
1import { ActivityLike } from '../../../../shared/models/activitypub' 2import { ActivityLike } from '../../../../shared/models/activitypub'
2import { getAPId } from '../../../helpers/activitypub' 3import { getAPId } from '../../../helpers/activitypub'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
@@ -5,11 +6,11 @@ import { sequelizeTypescript } from '../../../initializers/database'
5import { AccountVideoRateModel } from '../../../models/account/account-video-rate' 6import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
6import { APProcessorOptions } from '../../../types/activitypub-processor.model' 7import { APProcessorOptions } from '../../../types/activitypub-processor.model'
7import { MActorSignature } from '../../../types/models' 8import { MActorSignature } from '../../../types/models'
8import { forwardVideoRelatedActivity } from '../send/utils' 9import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos'
9import { getOrCreateAPVideo } from '../videos'
10 10
11async function processLikeActivity (options: APProcessorOptions<ActivityLike>) { 11async function processLikeActivity (options: APProcessorOptions<ActivityLike>) {
12 const { activity, byActor } = options 12 const { activity, byActor } = options
13
13 return retryTransactionWrapper(processLikeVideo, byActor, activity) 14 return retryTransactionWrapper(processLikeVideo, byActor, activity)
14} 15}
15 16
@@ -27,17 +28,24 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik
27 const byAccount = byActor.Account 28 const byAccount = byActor.Account
28 if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url) 29 if (!byAccount) throw new Error('Cannot create like with the non account actor ' + byActor.url)
29 30
30 const { video } = await getOrCreateAPVideo({ videoObject: videoUrl }) 31 const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: videoUrl, fetchType: 'only-video' })
32
33 // We don't care about likes of remote videos
34 if (!onlyVideo.isOwned()) return
31 35
32 return sequelizeTypescript.transaction(async t => { 36 return sequelizeTypescript.transaction(async t => {
37 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(onlyVideo.id, t)
38
33 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t) 39 const existingRate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byAccount.id, video.id, activity.id, t)
34 if (existingRate && existingRate.type === 'like') return 40 if (existingRate && existingRate.type === 'like') return
35 41
36 if (existingRate && existingRate.type === 'dislike') { 42 if (existingRate && existingRate.type === 'dislike') {
37 await video.decrement('dislikes', { transaction: t }) 43 await video.decrement('dislikes', { transaction: t })
44 video.dislikes--
38 } 45 }
39 46
40 await video.increment('likes', { transaction: t }) 47 await video.increment('likes', { transaction: t })
48 video.likes++
41 49
42 const rate = existingRate || new AccountVideoRateModel() 50 const rate = existingRate || new AccountVideoRateModel()
43 rate.type = 'like' 51 rate.type = 'like'
@@ -47,11 +55,6 @@ async function processLikeVideo (byActor: MActorSignature, activity: ActivityLik
47 55
48 await rate.save({ transaction: t }) 56 await rate.save({ transaction: t })
49 57
50 if (video.isOwned()) { 58 await federateVideoIfNeeded(video, false, t)
51 // Don't resend the activity to the sender
52 const exceptions = [ byActor ]
53
54 await forwardVideoRelatedActivity(activity, t, exceptions, video)
55 }
56 }) 59 })
57} 60}
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts
index d4b2a795f..257eb6c2b 100644
--- a/server/lib/activitypub/process/process-undo.ts
+++ b/server/lib/activitypub/process/process-undo.ts
@@ -1,3 +1,4 @@
1import { VideoModel } from '@server/models/video/video'
1import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo, CacheFileObject } from '../../../../shared/models/activitypub' 2import { ActivityAnnounce, ActivityFollow, ActivityLike, ActivityUndo, CacheFileObject } from '../../../../shared/models/activitypub'
2import { DislikeObject } from '../../../../shared/models/activitypub/objects' 3import { DislikeObject } from '../../../../shared/models/activitypub/objects'
3import { retryTransactionWrapper } from '../../../helpers/database-utils' 4import { retryTransactionWrapper } from '../../../helpers/database-utils'
@@ -10,8 +11,8 @@ import { VideoRedundancyModel } from '../../../models/redundancy/video-redundanc
10import { VideoShareModel } from '../../../models/video/video-share' 11import { VideoShareModel } from '../../../models/video/video-share'
11import { APProcessorOptions } from '../../../types/activitypub-processor.model' 12import { APProcessorOptions } from '../../../types/activitypub-processor.model'
12import { MActorSignature } from '../../../types/models' 13import { MActorSignature } from '../../../types/models'
13import { forwardVideoRelatedActivity } from '../send/utils' 14import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
14import { getOrCreateAPVideo } from '../videos' 15import { federateVideoIfNeeded, getOrCreateAPVideo } from '../videos'
15 16
16async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) { 17async function processUndoActivity (options: APProcessorOptions<ActivityUndo>) {
17 const { activity, byActor } = options 18 const { activity, byActor } = options
@@ -55,23 +56,22 @@ export {
55async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo) { 56async function processUndoLike (byActor: MActorSignature, activity: ActivityUndo) {
56 const likeActivity = activity.object as ActivityLike 57 const likeActivity = activity.object as ActivityLike
57 58
58 const { video } = await getOrCreateAPVideo({ videoObject: likeActivity.object }) 59 const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: likeActivity.object })
60 // We don't care about likes of remote videos
61 if (!onlyVideo.isOwned()) return
59 62
60 return sequelizeTypescript.transaction(async t => { 63 return sequelizeTypescript.transaction(async t => {
61 if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) 64 if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)
62 65
66 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(onlyVideo.id, t)
63 const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t) 67 const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, likeActivity.id, t)
64 if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`) 68 if (!rate || rate.type !== 'like') throw new Error(`Unknown like by account ${byActor.Account.id} for video ${video.id}.`)
65 69
66 await rate.destroy({ transaction: t }) 70 await rate.destroy({ transaction: t })
67 await video.decrement('likes', { transaction: t }) 71 await video.decrement('likes', { transaction: t })
68 72
69 if (video.isOwned()) { 73 video.likes--
70 // Don't resend the activity to the sender 74 await federateVideoIfNeeded(video, false, t)
71 const exceptions = [ byActor ]
72
73 await forwardVideoRelatedActivity(activity, t, exceptions, video)
74 }
75 }) 75 })
76} 76}
77 77
@@ -80,26 +80,27 @@ async function processUndoDislike (byActor: MActorSignature, activity: ActivityU
80 ? activity.object 80 ? activity.object
81 : activity.object.object as DislikeObject 81 : activity.object.object as DislikeObject
82 82
83 const { video } = await getOrCreateAPVideo({ videoObject: dislike.object }) 83 const { video: onlyVideo } = await getOrCreateAPVideo({ videoObject: dislike.object })
84 // We don't care about likes of remote videos
85 if (!onlyVideo.isOwned()) return
84 86
85 return sequelizeTypescript.transaction(async t => { 87 return sequelizeTypescript.transaction(async t => {
86 if (!byActor.Account) throw new Error('Unknown account ' + byActor.url) 88 if (!byActor.Account) throw new Error('Unknown account ' + byActor.url)
87 89
90 const video = await VideoModel.loadAndPopulateAccountAndServerAndTags(onlyVideo.id, t)
88 const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t) 91 const rate = await AccountVideoRateModel.loadByAccountAndVideoOrUrl(byActor.Account.id, video.id, dislike.id, t)
89 if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`) 92 if (!rate || rate.type !== 'dislike') throw new Error(`Unknown dislike by account ${byActor.Account.id} for video ${video.id}.`)
90 93
91 await rate.destroy({ transaction: t }) 94 await rate.destroy({ transaction: t })
92 await video.decrement('dislikes', { transaction: t }) 95 await video.decrement('dislikes', { transaction: t })
96 video.dislikes--
93 97
94 if (video.isOwned()) { 98 await federateVideoIfNeeded(video, false, t)
95 // Don't resend the activity to the sender
96 const exceptions = [ byActor ]
97
98 await forwardVideoRelatedActivity(activity, t, exceptions, video)
99 }
100 }) 99 })
101} 100}
102 101
102// ---------------------------------------------------------------------------
103
103async function processUndoCacheFile (byActor: MActorSignature, activity: ActivityUndo) { 104async function processUndoCacheFile (byActor: MActorSignature, activity: ActivityUndo) {
104 const cacheFileObject = activity.object.object as CacheFileObject 105 const cacheFileObject = activity.object.object as CacheFileObject
105 106
@@ -125,19 +126,6 @@ async function processUndoCacheFile (byActor: MActorSignature, activity: Activit
125 }) 126 })
126} 127}
127 128
128function processUndoFollow (follower: MActorSignature, followActivity: ActivityFollow) {
129 return sequelizeTypescript.transaction(async t => {
130 const following = await ActorModel.loadByUrlAndPopulateAccountAndChannel(followActivity.object, t)
131 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t)
132
133 if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${following.id}.`)
134
135 await actorFollow.destroy({ transaction: t })
136
137 return undefined
138 })
139}
140
141function processUndoAnnounce (byActor: MActorSignature, announceActivity: ActivityAnnounce) { 129function processUndoAnnounce (byActor: MActorSignature, announceActivity: ActivityAnnounce) {
142 return sequelizeTypescript.transaction(async t => { 130 return sequelizeTypescript.transaction(async t => {
143 const share = await VideoShareModel.loadByUrl(announceActivity.id, t) 131 const share = await VideoShareModel.loadByUrl(announceActivity.id, t)
@@ -155,3 +143,18 @@ function processUndoAnnounce (byActor: MActorSignature, announceActivity: Activi
155 } 143 }
156 }) 144 })
157} 145}
146
147// ---------------------------------------------------------------------------
148
149function processUndoFollow (follower: MActorSignature, followActivity: ActivityFollow) {
150 return sequelizeTypescript.transaction(async t => {
151 const following = await ActorModel.loadByUrlAndPopulateAccountAndChannel(followActivity.object, t)
152 const actorFollow = await ActorFollowModel.loadByActorAndTarget(follower.id, following.id, t)
153
154 if (!actorFollow) throw new Error(`'Unknown actor follow ${follower.id} -> ${following.id}.`)
155
156 await actorFollow.destroy({ transaction: t })
157
158 return undefined
159 })
160}
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts
index f40008a6b..4afdbd430 100644
--- a/server/lib/activitypub/process/process-update.ts
+++ b/server/lib/activitypub/process/process-update.ts
@@ -13,7 +13,7 @@ import { MActorFull, MActorSignature } from '../../../types/models'
13import { APActorUpdater } from '../actors/updater' 13import { APActorUpdater } from '../actors/updater'
14import { createOrUpdateCacheFile } from '../cache-file' 14import { createOrUpdateCacheFile } from '../cache-file'
15import { createOrUpdateVideoPlaylist } from '../playlists' 15import { createOrUpdateVideoPlaylist } from '../playlists'
16import { forwardVideoRelatedActivity } from '../send/utils' 16import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
17import { APVideoUpdater, getOrCreateAPVideo } from '../videos' 17import { APVideoUpdater, getOrCreateAPVideo } from '../videos'
18 18
19async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) { 19async function processUpdateActivity (options: APProcessorOptions<ActivityUpdate>) {
diff --git a/server/lib/activitypub/process/process-view.ts b/server/lib/activitypub/process/process-view.ts
index 720385f9b..c59940164 100644
--- a/server/lib/activitypub/process/process-view.ts
+++ b/server/lib/activitypub/process/process-view.ts
@@ -2,7 +2,7 @@ import { VideoViews } from '@server/lib/video-views'
2import { ActivityView } from '../../../../shared/models/activitypub' 2import { ActivityView } from '../../../../shared/models/activitypub'
3import { APProcessorOptions } from '../../../types/activitypub-processor.model' 3import { APProcessorOptions } from '../../../types/activitypub-processor.model'
4import { MActorSignature } from '../../../types/models' 4import { MActorSignature } from '../../../types/models'
5import { forwardVideoRelatedActivity } from '../send/utils' 5import { forwardVideoRelatedActivity } from '../send/shared/send-utils'
6import { getOrCreateAPVideo } from '../videos' 6import { getOrCreateAPVideo } from '../videos'
7 7
8async function processViewActivity (options: APProcessorOptions<ActivityView>) { 8async function processViewActivity (options: APProcessorOptions<ActivityView>) {