diff options
Diffstat (limited to 'server/lib/activitypub/process')
-rw-r--r-- | server/lib/activitypub/process/misc.ts | 79 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-announce.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-create.ts | 13 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-delete.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-follow.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-like.ts | 2 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-undo.ts | 3 | ||||
-rw-r--r-- | server/lib/activitypub/process/process-update.ts | 4 | ||||
-rw-r--r-- | server/lib/activitypub/process/process.ts | 2 |
9 files changed, 95 insertions, 17 deletions
diff --git a/server/lib/activitypub/process/misc.ts b/server/lib/activitypub/process/misc.ts index a9c6f913c..f65395c99 100644 --- a/server/lib/activitypub/process/misc.ts +++ b/server/lib/activitypub/process/misc.ts | |||
@@ -1,11 +1,15 @@ | |||
1 | import * as magnetUtil from 'magnet-uri' | 1 | import * as magnetUtil from 'magnet-uri' |
2 | import { VideoTorrentObject } from '../../../../shared' | 2 | import { VideoTorrentObject } from '../../../../shared' |
3 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | ||
3 | import { VideoPrivacy } from '../../../../shared/models/videos' | 4 | import { VideoPrivacy } from '../../../../shared/models/videos' |
4 | import { doRequest } from '../../../helpers' | ||
5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' | 5 | import { isVideoFileInfoHashValid } from '../../../helpers/custom-validators/videos' |
6 | import { logger } from '../../../helpers/logger' | ||
7 | import { doRequest } from '../../../helpers/requests' | ||
6 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' | 8 | import { ACTIVITY_PUB, VIDEO_MIMETYPE_EXT } from '../../../initializers' |
9 | import { ActorModel } from '../../../models/activitypub/actor' | ||
7 | import { VideoModel } from '../../../models/video/video' | 10 | import { VideoModel } from '../../../models/video/video' |
8 | import { VideoChannelModel } from '../../../models/video/video-channel' | 11 | import { VideoChannelModel } from '../../../models/video/video-channel' |
12 | import { VideoCommentModel } from '../../../models/video/video-comment' | ||
9 | import { VideoShareModel } from '../../../models/video/video-share' | 13 | import { VideoShareModel } from '../../../models/video/video-share' |
10 | import { getOrCreateActorAndServerAndModel } from '../actor' | 14 | import { getOrCreateActorAndServerAndModel } from '../actor' |
11 | 15 | ||
@@ -97,14 +101,43 @@ function videoFileActivityUrlToDBAttributes (videoCreated: VideoModel, videoObje | |||
97 | return attributes | 101 | return attributes |
98 | } | 102 | } |
99 | 103 | ||
100 | async function addVideoShares (instance: VideoModel, shares: string[]) { | 104 | async function videoCommentActivityObjectToDBAttributes (video: VideoModel, actor: ActorModel, comment: VideoCommentObject) { |
101 | for (const share of shares) { | 105 | let originCommentId: number = null |
106 | let inReplyToCommentId: number = null | ||
107 | |||
108 | // If this is not a reply to the video (thread), create or get the parent comment | ||
109 | if (video.url !== comment.inReplyTo) { | ||
110 | const [ parent ] = await addVideoComment(video, comment.inReplyTo) | ||
111 | if (!parent) { | ||
112 | logger.warn('Cannot fetch or get parent comment %s of comment %s.', comment.inReplyTo, comment.id) | ||
113 | return undefined | ||
114 | } | ||
115 | |||
116 | originCommentId = parent.originCommentId || parent.id | ||
117 | inReplyToCommentId = parent.id | ||
118 | } | ||
119 | |||
120 | return { | ||
121 | url: comment.url, | ||
122 | text: comment.content, | ||
123 | videoId: video.id, | ||
124 | accountId: actor.Account.id, | ||
125 | inReplyToCommentId, | ||
126 | originCommentId, | ||
127 | createdAt: new Date(comment.published), | ||
128 | updatedAt: new Date(comment.updated) | ||
129 | } | ||
130 | } | ||
131 | |||
132 | async function addVideoShares (instance: VideoModel, shareUrls: string[]) { | ||
133 | for (const shareUrl of shareUrls) { | ||
102 | // Fetch url | 134 | // Fetch url |
103 | const json = await doRequest({ | 135 | const { body } = await doRequest({ |
104 | uri: share, | 136 | uri: shareUrl, |
105 | json: true | 137 | json: true, |
138 | activityPub: true | ||
106 | }) | 139 | }) |
107 | const actorUrl = json['actor'] | 140 | const actorUrl = body.actor |
108 | if (!actorUrl) continue | 141 | if (!actorUrl) continue |
109 | 142 | ||
110 | const actor = await getOrCreateActorAndServerAndModel(actorUrl) | 143 | const actor = await getOrCreateActorAndServerAndModel(actorUrl) |
@@ -121,10 +154,40 @@ async function addVideoShares (instance: VideoModel, shares: string[]) { | |||
121 | } | 154 | } |
122 | } | 155 | } |
123 | 156 | ||
157 | async function addVideoComments (instance: VideoModel, commentUrls: string[]) { | ||
158 | for (const commentUrl of commentUrls) { | ||
159 | await addVideoComment(instance, commentUrl) | ||
160 | } | ||
161 | } | ||
162 | |||
163 | async function addVideoComment (instance: VideoModel, commentUrl: string) { | ||
164 | // Fetch url | ||
165 | const { body } = await doRequest({ | ||
166 | uri: commentUrl, | ||
167 | json: true, | ||
168 | activityPub: true | ||
169 | }) | ||
170 | |||
171 | const actorUrl = body.attributedTo | ||
172 | if (!actorUrl) return [] | ||
173 | |||
174 | const actor = await getOrCreateActorAndServerAndModel(actorUrl) | ||
175 | const entry = await videoCommentActivityObjectToDBAttributes(instance, actor, body) | ||
176 | if (!entry) return [] | ||
177 | |||
178 | return VideoCommentModel.findOrCreate({ | ||
179 | where: { | ||
180 | url: body.id | ||
181 | }, | ||
182 | defaults: entry | ||
183 | }) | ||
184 | } | ||
185 | |||
124 | // --------------------------------------------------------------------------- | 186 | // --------------------------------------------------------------------------- |
125 | 187 | ||
126 | export { | 188 | export { |
127 | videoFileActivityUrlToDBAttributes, | 189 | videoFileActivityUrlToDBAttributes, |
128 | videoActivityObjectToDBAttributes, | 190 | videoActivityObjectToDBAttributes, |
129 | addVideoShares | 191 | addVideoShares, |
192 | addVideoComments | ||
130 | } | 193 | } |
diff --git a/server/lib/activitypub/process/process-announce.ts b/server/lib/activitypub/process/process-announce.ts index 55f8a62d2..9adb40e01 100644 --- a/server/lib/activitypub/process/process-announce.ts +++ b/server/lib/activitypub/process/process-announce.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' | 1 | import { ActivityAnnounce } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { VideoModel } from '../../../models/video/video' | 6 | import { VideoModel } from '../../../models/video/video' |
diff --git a/server/lib/activitypub/process/process-create.ts b/server/lib/activitypub/process/process-create.ts index 628942a58..ffd20fe74 100644 --- a/server/lib/activitypub/process/process-create.ts +++ b/server/lib/activitypub/process/process-create.ts | |||
@@ -3,7 +3,8 @@ import { ActivityCreate, VideoTorrentObject } from '../../../../shared' | |||
3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' | 3 | import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects' |
4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' | 4 | import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object' |
5 | import { VideoRateType } from '../../../../shared/models/videos' | 5 | import { VideoRateType } from '../../../../shared/models/videos' |
6 | import { logger, retryTransactionWrapper } from '../../../helpers' | 6 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
7 | import { logger } from '../../../helpers/logger' | ||
7 | import { sequelizeTypescript } from '../../../initializers' | 8 | import { sequelizeTypescript } from '../../../initializers' |
8 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 9 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
9 | import { ActorModel } from '../../../models/activitypub/actor' | 10 | import { ActorModel } from '../../../models/activitypub/actor' |
@@ -15,7 +16,7 @@ import { VideoFileModel } from '../../../models/video/video-file' | |||
15 | import { getOrCreateActorAndServerAndModel } from '../actor' | 16 | import { getOrCreateActorAndServerAndModel } from '../actor' |
16 | import { forwardActivity } from '../send/misc' | 17 | import { forwardActivity } from '../send/misc' |
17 | import { generateThumbnailFromUrl } from '../videos' | 18 | import { generateThumbnailFromUrl } from '../videos' |
18 | import { addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' | 19 | import { addVideoComments, addVideoShares, videoActivityObjectToDBAttributes, videoFileActivityUrlToDBAttributes } from './misc' |
19 | 20 | ||
20 | async function processCreateActivity (activity: ActivityCreate) { | 21 | async function processCreateActivity (activity: ActivityCreate) { |
21 | const activityObject = activity.object | 22 | const activityObject = activity.object |
@@ -66,17 +67,25 @@ async function processCreateVideo ( | |||
66 | 67 | ||
67 | // Process outside the transaction because we could fetch remote data | 68 | // Process outside the transaction because we could fetch remote data |
68 | if (videoToCreateData.likes && Array.isArray(videoToCreateData.likes.orderedItems)) { | 69 | if (videoToCreateData.likes && Array.isArray(videoToCreateData.likes.orderedItems)) { |
70 | logger.info('Adding likes of video %s.', video.uuid) | ||
69 | await createRates(videoToCreateData.likes.orderedItems, video, 'like') | 71 | await createRates(videoToCreateData.likes.orderedItems, video, 'like') |
70 | } | 72 | } |
71 | 73 | ||
72 | if (videoToCreateData.dislikes && Array.isArray(videoToCreateData.dislikes.orderedItems)) { | 74 | if (videoToCreateData.dislikes && Array.isArray(videoToCreateData.dislikes.orderedItems)) { |
75 | logger.info('Adding dislikes of video %s.', video.uuid) | ||
73 | await createRates(videoToCreateData.dislikes.orderedItems, video, 'dislike') | 76 | await createRates(videoToCreateData.dislikes.orderedItems, video, 'dislike') |
74 | } | 77 | } |
75 | 78 | ||
76 | if (videoToCreateData.shares && Array.isArray(videoToCreateData.shares.orderedItems)) { | 79 | if (videoToCreateData.shares && Array.isArray(videoToCreateData.shares.orderedItems)) { |
80 | logger.info('Adding shares of video %s.', video.uuid) | ||
77 | await addVideoShares(video, videoToCreateData.shares.orderedItems) | 81 | await addVideoShares(video, videoToCreateData.shares.orderedItems) |
78 | } | 82 | } |
79 | 83 | ||
84 | if (videoToCreateData.comments && Array.isArray(videoToCreateData.comments.orderedItems)) { | ||
85 | logger.info('Adding comments of video %s.', video.uuid) | ||
86 | await addVideoComments(video, videoToCreateData.comments.orderedItems) | ||
87 | } | ||
88 | |||
80 | return video | 89 | return video |
81 | } | 90 | } |
82 | 91 | ||
diff --git a/server/lib/activitypub/process/process-delete.ts b/server/lib/activitypub/process/process-delete.ts index 65a4e5bcc..523a31822 100644 --- a/server/lib/activitypub/process/process-delete.ts +++ b/server/lib/activitypub/process/process-delete.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { ActivityDelete } from '../../../../shared/models/activitypub' | 1 | import { ActivityDelete } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountModel } from '../../../models/account/account' | 5 | import { AccountModel } from '../../../models/account/account' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 6 | import { ActorModel } from '../../../models/activitypub/actor' |
diff --git a/server/lib/activitypub/process/process-follow.ts b/server/lib/activitypub/process/process-follow.ts index e78005dd0..5085c5da9 100644 --- a/server/lib/activitypub/process/process-follow.ts +++ b/server/lib/activitypub/process/process-follow.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { ActivityFollow } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow } from '../../../../shared/models/activitypub' |
2 | import { logger, retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { logger } from '../../../helpers/logger' | ||
3 | import { sequelizeTypescript } from '../../../initializers' | 4 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
5 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' | 6 | import { ActorFollowModel } from '../../../models/activitypub/actor-follow' |
diff --git a/server/lib/activitypub/process/process-like.ts b/server/lib/activitypub/process/process-like.ts index a7fcec21c..77fadabe1 100644 --- a/server/lib/activitypub/process/process-like.ts +++ b/server/lib/activitypub/process/process-like.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { ActivityLike } from '../../../../shared/models/activitypub' | 1 | import { ActivityLike } from '../../../../shared/models/activitypub' |
2 | import { retryTransactionWrapper } from '../../../helpers' | 2 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
3 | import { sequelizeTypescript } from '../../../initializers' | 3 | import { sequelizeTypescript } from '../../../initializers' |
4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 4 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 5 | import { ActorModel } from '../../../models/activitypub/actor' |
diff --git a/server/lib/activitypub/process/process-undo.ts b/server/lib/activitypub/process/process-undo.ts index 4a0181137..9cad59233 100644 --- a/server/lib/activitypub/process/process-undo.ts +++ b/server/lib/activitypub/process/process-undo.ts | |||
@@ -1,6 +1,7 @@ | |||
1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' | 1 | import { ActivityFollow, ActivityLike, ActivityUndo } from '../../../../shared/models/activitypub' |
2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' | 2 | import { DislikeObject } from '../../../../shared/models/activitypub/objects' |
3 | import { logger, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 5 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { AccountModel } from '../../../models/account/account' | 6 | import { AccountModel } from '../../../models/account/account' |
6 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' | 7 | import { AccountVideoRateModel } from '../../../models/account/account-video-rate' |
diff --git a/server/lib/activitypub/process/process-update.ts b/server/lib/activitypub/process/process-update.ts index 35912ee87..a5ad406cb 100644 --- a/server/lib/activitypub/process/process-update.ts +++ b/server/lib/activitypub/process/process-update.ts | |||
@@ -1,6 +1,8 @@ | |||
1 | import * as Bluebird from 'bluebird' | 1 | import * as Bluebird from 'bluebird' |
2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' | 2 | import { ActivityUpdate } from '../../../../shared/models/activitypub' |
3 | import { logger, resetSequelizeInstance, retryTransactionWrapper } from '../../../helpers' | 3 | import { retryTransactionWrapper } from '../../../helpers/database-utils' |
4 | import { logger } from '../../../helpers/logger' | ||
5 | import { resetSequelizeInstance } from '../../../helpers/utils' | ||
4 | import { sequelizeTypescript } from '../../../initializers' | 6 | import { sequelizeTypescript } from '../../../initializers' |
5 | import { ActorModel } from '../../../models/activitypub/actor' | 7 | import { ActorModel } from '../../../models/activitypub/actor' |
6 | import { TagModel } from '../../../models/video/tag' | 8 | import { TagModel } from '../../../models/video/tag' |
diff --git a/server/lib/activitypub/process/process.ts b/server/lib/activitypub/process/process.ts index dfb60c1bf..62d310f21 100644 --- a/server/lib/activitypub/process/process.ts +++ b/server/lib/activitypub/process/process.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' | 1 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
2 | import { logger } from '../../../helpers' | 2 | import { logger } from '../../../helpers/logger' |
3 | import { ActorModel } from '../../../models/activitypub/actor' | 3 | import { ActorModel } from '../../../models/activitypub/actor' |
4 | import { processAcceptActivity } from './process-accept' | 4 | import { processAcceptActivity } from './process-accept' |
5 | import { processAnnounceActivity } from './process-announce' | 5 | import { processAnnounceActivity } from './process-announce' |