-import { ActivityCreate, VideoTorrentObject } from '../../../../shared'
+import { ActivityCreate, VideoAbuseState, VideoTorrentObject } from '../../../../shared'
import { DislikeObject, VideoAbuseObject, ViewObject } from '../../../../shared/models/activitypub/objects'
import { VideoCommentObject } from '../../../../shared/models/activitypub/objects/video-comment-object'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { VideoAbuseModel } from '../../../models/video/video-abuse'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { getOrCreateActorAndServerAndModel } from '../actor'
-import { forwardActivity, getActorsInvolvedInVideo } from '../send/misc'
import { resolveThread } from '../video-comments'
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
+import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
async function processCreateActivity (activity: ActivityCreate) {
const activityObject = activity.object
if (activityType === 'View') {
return processCreateView(actor, activity)
} else if (activityType === 'Dislike') {
- return processCreateDislike(actor, activity)
+ return retryTransactionWrapper(processCreateDislike, actor, activity)
} else if (activityType === 'Video') {
return processCreateVideo(actor, activity)
} else if (activityType === 'Flag') {
- return processCreateVideoAbuse(actor, activityObject as VideoAbuseObject)
+ return retryTransactionWrapper(processCreateVideoAbuse, actor, activityObject as VideoAbuseObject)
} else if (activityType === 'Note') {
- return processCreateVideoComment(actor, activity)
+ return retryTransactionWrapper(processCreateVideoComment, actor, activity)
}
logger.warn('Unknown activity object type %s when creating activity.', activityType, { activity: activity.id })
}
async function processCreateDislike (byActor: ActorModel, activity: ActivityCreate) {
- const options = {
- arguments: [ byActor, activity ],
- errorMessage: 'Cannot dislike the video with many retries.'
- }
-
- return retryTransactionWrapper(createVideoDislike, options)
-}
-
-async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate) {
const dislike = activity.object as DislikeObject
const byAccount = byActor.Account
if (video.isOwned() && created === true) {
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- await forwardActivity(activity, t, exceptions)
+
+ await forwardVideoRelatedActivity(activity, t, exceptions, video)
}
})
}
}
}
-function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
- const options = {
- arguments: [ actor, videoAbuseToCreateData ],
- errorMessage: 'Cannot insert the remote video abuse with many retries.'
- }
-
- return retryTransactionWrapper(addRemoteVideoAbuse, options)
-}
-
-async function addRemoteVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
+async function processCreateVideoAbuse (actor: ActorModel, videoAbuseToCreateData: VideoAbuseObject) {
logger.debug('Reporting remote abuse for video %s.', videoAbuseToCreateData.object)
const account = actor.Account
const videoAbuseData = {
reporterAccountId: account.id,
reason: videoAbuseToCreateData.content,
- videoId: video.id
+ videoId: video.id,
+ state: VideoAbuseState.PENDING
}
await VideoAbuseModel.create(videoAbuseData)
})
}
-function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) {
- const options = {
- arguments: [ byActor, activity ],
- errorMessage: 'Cannot create video comment with many retries.'
- }
-
- return retryTransactionWrapper(createVideoComment, options)
-}
-
-async function createVideoComment (byActor: ActorModel, activity: ActivityCreate) {
+async function processCreateVideoComment (byActor: ActorModel, activity: ActivityCreate) {
const comment = activity.object as VideoCommentObject
const byAccount = byActor.Account
// Don't resend the activity to the sender
const exceptions = [ byActor ]
- // Mastodon does not add our announces in audience, so we forward to them manually
- const additionalActors = await getActorsInvolvedInVideo(video, t)
- const additionalFollowerUrls = additionalActors.map(a => a.followersUrl)
-
- await forwardActivity(activity, t, exceptions, additionalFollowerUrls)
+ await forwardVideoRelatedActivity(activity, t, exceptions, video)
}
})
}