import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
-import { buildAnnounceWithVideoAudience, buildDislikeActivity, buildLikeActivity } from '../../lib/activitypub/send'
+import { buildAnnounceWithVideoAudience, buildLikeActivity } from '../../lib/activitypub/send'
import { audiencify, getAudience } from '../../lib/activitypub/audience'
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
import {
asyncMiddleware,
- videosShareValidator,
executeIfActivityPub,
localAccountValidator,
localVideoChannelValidator,
- videosCustomGetValidator
+ videosCustomGetValidator,
+ videosShareValidator
} from '../../middlewares'
-import {
- getAccountVideoRateValidator,
- videoCommentGetValidator,
- videosGetValidator
-} from '../../middlewares/validators'
+import { getAccountVideoRateValidator, videoCommentGetValidator, videosGetValidator } from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account'
import { ActorModel } from '../../models/activitypub/actor'
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy'
import { getServerActor } from '../../helpers/utils'
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
+import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
const activityPubClientRouter = express.Router()
const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
const APObject = rateType === 'like'
? buildLikeActivity(url, byActor, accountVideoRate.Video)
- : buildCreateActivity(url, byActor, buildDislikeActivity(url, byActor, accountVideoRate.Video))
+ : buildDislikeActivity(url, byActor, accountVideoRate.Video)
return activityPubResponse(activityPubContextify(APObject), res)
}
import { logger } from '../../../helpers/logger'
import { getFormattedObjects } from '../../../helpers/utils'
import { sequelizeTypescript } from '../../../initializers'
-import { sendVideoAbuse } from '../../../lib/activitypub/send'
import {
asyncMiddleware,
asyncRetryTransactionMiddleware,
import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'
import { UserModel } from '../../../models/account/user'
import { Notifier } from '../../../lib/notifier'
+import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag'
const auditLogger = auditLoggerFactory('abuse')
const abuseVideoRouter = express.Router()
fetchRemoteVideoDescription,
getVideoActivityPubUrl
} from '../../../lib/activitypub'
-import { sendCreateView } from '../../../lib/activitypub/send'
import { JobQueue } from '../../../lib/job-queue'
import { Redis } from '../../../lib/redis'
import {
import { move } from 'fs-extra'
import { watchingRouter } from './watching'
import { Notifier } from '../../../lib/notifier'
+import { sendView } from '../../../lib/activitypub/send/send-view'
const auditLogger = auditLoggerFactory('videos')
const videosRouter = express.Router()
])
const serverActor = await getServerActor()
- await sendCreateView(serverActor, videoInstance, undefined)
+ await sendView(serverActor, videoInstance, undefined)
return res.status(204).end()
}
import { VideoPrivacy } from '../../../../shared/models/videos'
import { ActorModel } from '../../../models/activitypub/actor'
import { VideoModel } from '../../../models/video/video'
-import { VideoAbuseModel } from '../../../models/video/video-abuse'
import { VideoCommentModel } from '../../../models/video/video-comment'
-import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience'
import { logger } from '../../../helpers/logger'
return broadcastToFollowers(createActivity, byActor, [ byActor ], t)
}
-async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) {
- if (!video.VideoChannel.Account.Actor.serverId) return // Local
-
- const url = getVideoAbuseActivityPubUrl(videoAbuse)
-
- logger.info('Creating job to send video abuse %s.', url)
-
- // Custom audience, we only send the abuse to the origin instance
- const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
- const createActivity = buildCreateActivity(url, byActor, videoAbuse.toActivityPubObject(), audience)
-
- return unicastTo(createActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
-}
-
async function sendCreateCacheFile (byActor: ActorModel, fileRedundancy: VideoRedundancyModel) {
logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
return unicastTo(createActivity, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
}
-async function sendCreateView (byActor: ActorModel, video: VideoModel, t: Transaction) {
- logger.info('Creating job to send view of %s.', video.url)
-
- const url = getVideoViewActivityPubUrl(byActor, video)
- const viewActivity = buildViewActivity(url, byActor, video)
-
- return sendVideoRelatedCreateActivity({
- // Use the server actor to send the view
- byActor,
- video,
- url,
- object: viewActivity,
- transaction: t
- })
-}
-
-async function sendCreateDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
- logger.info('Creating job to dislike %s.', video.url)
-
- const url = getVideoDislikeActivityPubUrl(byActor, video)
- const dislikeActivity = buildDislikeActivity(url, byActor, video)
-
- return sendVideoRelatedCreateActivity({
- byActor,
- video,
- url,
- object: dislikeActivity,
- transaction: t
- })
-}
-
function buildCreateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate {
if (!audience) audience = getAudience(byActor)
)
}
-function buildDislikeActivity (url: string, byActor: ActorModel, video: VideoModel) {
- return {
- id: url,
- type: 'Dislike',
- actor: byActor.url,
- object: video.url
- }
-}
-
-function buildViewActivity (url: string, byActor: ActorModel, video: VideoModel) {
- return {
- id: url,
- type: 'View',
- actor: byActor.url,
- object: video.url
- }
-}
-
// ---------------------------------------------------------------------------
export {
sendCreateVideo,
- sendVideoAbuse,
buildCreateActivity,
- sendCreateView,
- sendCreateDislike,
- buildDislikeActivity,
sendCreateVideoComment,
sendCreateCacheFile
}
--- /dev/null
+import { Transaction } from 'sequelize'
+import { ActorModel } from '../../../models/activitypub/actor'
+import { VideoModel } from '../../../models/video/video'
+import { getVideoDislikeActivityPubUrl } from '../url'
+import { logger } from '../../../helpers/logger'
+import { ActivityAudience, ActivityDislike } from '../../../../shared/models/activitypub'
+import { sendVideoRelatedActivity } from './utils'
+import { audiencify, getAudience } from '../audience'
+
+async function sendDislike (byActor: ActorModel, video: VideoModel, t: Transaction) {
+ logger.info('Creating job to dislike %s.', video.url)
+
+ const activityBuilder = (audience: ActivityAudience) => {
+ const url = getVideoDislikeActivityPubUrl(byActor, video)
+
+ return buildDislikeActivity(url, byActor, video, audience)
+ }
+
+ return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
+}
+
+function buildDislikeActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityDislike {
+ if (!audience) audience = getAudience(byActor)
+
+ return audiencify(
+ {
+ id: url,
+ type: 'Dislike' as 'Dislike',
+ actor: byActor.url,
+ object: video.url
+ },
+ audience
+ )
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ sendDislike,
+ buildDislikeActivity
+}
--- /dev/null
+import { ActorModel } from '../../../models/activitypub/actor'
+import { VideoModel } from '../../../models/video/video'
+import { VideoAbuseModel } from '../../../models/video/video-abuse'
+import { getVideoAbuseActivityPubUrl } from '../url'
+import { unicastTo } from './utils'
+import { logger } from '../../../helpers/logger'
+import { ActivityAudience, ActivityFlag } from '../../../../shared/models/activitypub'
+import { audiencify, getAudience } from '../audience'
+
+async function sendVideoAbuse (byActor: ActorModel, videoAbuse: VideoAbuseModel, video: VideoModel) {
+ if (!video.VideoChannel.Account.Actor.serverId) return // Local user
+
+ const url = getVideoAbuseActivityPubUrl(videoAbuse)
+
+ logger.info('Creating job to send video abuse %s.', url)
+
+ // Custom audience, we only send the abuse to the origin instance
+ const audience = { to: [ video.VideoChannel.Account.Actor.url ], cc: [] }
+ const flagActivity = buildFlagActivity(url, byActor, videoAbuse, audience)
+
+ return unicastTo(flagActivity, byActor, video.VideoChannel.Account.Actor.sharedInboxUrl)
+}
+
+function buildFlagActivity (url: string, byActor: ActorModel, videoAbuse: VideoAbuseModel, audience: ActivityAudience): ActivityFlag {
+ if (!audience) audience = getAudience(byActor)
+
+ const activity = Object.assign(
+ { id: url, actor: byActor.url },
+ videoAbuse.toActivityPubObject()
+ )
+
+ return audiencify(activity, audience)
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ sendVideoAbuse
+}
import {
ActivityAnnounce,
ActivityAudience,
- ActivityCreate,
+ ActivityCreate, ActivityDislike,
ActivityFollow,
ActivityLike,
ActivityUndo
import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
import { audiencify, getAudience } from '../audience'
-import { buildCreateActivity, buildDislikeActivity } from './send-create'
+import { buildCreateActivity } from './send-create'
import { buildFollowActivity } from './send-follow'
import { buildLikeActivity } from './send-like'
import { VideoShareModel } from '../../../models/video/video-share'
import { buildAnnounceWithVideoAudience } from './send-announce'
import { logger } from '../../../helpers/logger'
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
+import { buildDislikeActivity } from './send-dislike'
async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
const me = actorFollow.ActorFollower
const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
const dislikeActivity = buildDislikeActivity(dislikeUrl, byActor, video)
- const createDislikeActivity = buildCreateActivity(dislikeUrl, byActor, dislikeActivity)
- return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: createDislikeActivity, transaction: t })
+ return sendUndoVideoRelatedActivity({ byActor, video, url: dislikeUrl, activity: dislikeActivity, transaction: t })
}
async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) {
function undoActivityData (
url: string,
byActor: ActorModel,
- object: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
+ object: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce,
audience?: ActivityAudience
): ActivityUndo {
if (!audience) audience = getAudience(byActor)
byActor: ActorModel,
video: VideoModel,
url: string,
- activity: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
+ activity: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce,
transaction: Transaction
}) {
const activityBuilder = (audience: ActivityAudience) => {
--- /dev/null
+import { Transaction } from 'sequelize'
+import { ActivityAudience, ActivityView } from '../../../../shared/models/activitypub'
+import { ActorModel } from '../../../models/activitypub/actor'
+import { VideoModel } from '../../../models/video/video'
+import { getVideoLikeActivityPubUrl } from '../url'
+import { sendVideoRelatedActivity } from './utils'
+import { audiencify, getAudience } from '../audience'
+import { logger } from '../../../helpers/logger'
+
+async function sendView (byActor: ActorModel, video: VideoModel, t: Transaction) {
+ logger.info('Creating job to send view of %s.', video.url)
+
+ const activityBuilder = (audience: ActivityAudience) => {
+ const url = getVideoLikeActivityPubUrl(byActor, video)
+
+ return buildViewActivity(url, byActor, video, audience)
+ }
+
+ return sendVideoRelatedActivity(activityBuilder, { byActor, video, transaction: t })
+}
+
+function buildViewActivity (url: string, byActor: ActorModel, video: VideoModel, audience?: ActivityAudience): ActivityView {
+ if (!audience) audience = getAudience(byActor)
+
+ return audiencify(
+ {
+ id: url,
+ type: 'View' as 'View',
+ actor: byActor.url,
+ object: video.url
+ },
+ audience
+ )
+}
+
+// ---------------------------------------------------------------------------
+
+export {
+ sendView
+}
import { Transaction } from 'sequelize'
import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video'
-import { sendCreateDislike, sendLike, sendUndoDislike, sendUndoLike } from './send'
+import { sendLike, sendUndoDislike, sendUndoLike } from './send'
import { VideoRateType } from '../../../shared/models/videos'
import * as Bluebird from 'bluebird'
import { getOrCreateActorAndServerAndModel } from './actor'
import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
import { ActorModel } from '../../models/activitypub/actor'
import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url'
+import { sendDislike } from './send/send-dislike'
async function createRates (ratesUrl: string[], video: VideoModel, rate: VideoRateType) {
let rateCounts = 0
// Like
if (likes > 0) await sendLike(actor, video, t)
// Dislike
- if (dislikes > 0) await sendCreateDislike(actor, video, t)
+ if (dislikes > 0) await sendDislike(actor, video, t)
}
function getRateUrl (rateType: VideoRateType, actor: ActorModel, video: VideoModel) {