mirror of https://github.com/Chocobozzz/PeerTube
Merge branch 'feature/correctly-send-activities' into develop
commit
28f3d1b36a
|
@ -3,22 +3,18 @@ import * as express from 'express'
|
|||
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'
|
||||
|
@ -40,6 +36,7 @@ import { VideoCaptionModel } from '../../models/video/video-caption'
|
|||
import { videoFileRedundancyGetValidator, videoPlaylistRedundancyGetValidator } 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()
|
||||
|
||||
|
@ -160,7 +157,7 @@ function getAccountVideoRate (rateType: VideoRateType) {
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared
|
|||
import { logger } from '../../../helpers/logger'
|
||||
import { getFormattedObjects } from '../../../helpers/utils'
|
||||
import { sequelizeTypescript } from '../../../initializers'
|
||||
import { sendVideoAbuse } from '../../../lib/activitypub/send'
|
||||
import {
|
||||
asyncMiddleware,
|
||||
asyncRetryTransactionMiddleware,
|
||||
|
@ -23,6 +22,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
|||
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()
|
||||
|
|
|
@ -23,7 +23,6 @@ import {
|
|||
fetchRemoteVideoDescription,
|
||||
getVideoActivityPubUrl
|
||||
} from '../../../lib/activitypub'
|
||||
import { sendCreateView } from '../../../lib/activitypub/send'
|
||||
import { JobQueue } from '../../../lib/job-queue'
|
||||
import { Redis } from '../../../lib/redis'
|
||||
import {
|
||||
|
@ -60,6 +59,7 @@ import { resetSequelizeInstance } from '../../../helpers/database-utils'
|
|||
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()
|
||||
|
@ -425,7 +425,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
|||
])
|
||||
|
||||
const serverActor = await getServerActor()
|
||||
await sendCreateView(serverActor, videoInstance, undefined)
|
||||
await sendView(serverActor, videoInstance, undefined)
|
||||
|
||||
return res.status(204).end()
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { Transaction } from 'sequelize'
|
||||
import { ActivityAudience, ActivityCreate } from '../../../../shared/models/activitypub'
|
||||
import { Video, VideoPrivacy } from '../../../../shared/models/videos'
|
||||
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'
|
||||
|
@ -25,20 +23,6 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) {
|
|||
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, video: VideoModel, fileRedundancy: VideoRedundancyModel) {
|
||||
logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
|
||||
|
||||
|
@ -88,37 +72,6 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio
|
|||
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)
|
||||
|
||||
|
@ -133,33 +86,11 @@ function buildCreateActivity (url: string, byActor: ActorModel, object: any, aud
|
|||
)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
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
|
||||
}
|
|
@ -2,7 +2,7 @@ import { Transaction } from 'sequelize'
|
|||
import {
|
||||
ActivityAnnounce,
|
||||
ActivityAudience,
|
||||
ActivityCreate,
|
||||
ActivityCreate, ActivityDislike,
|
||||
ActivityFollow,
|
||||
ActivityLike,
|
||||
ActivityUndo
|
||||
|
@ -13,13 +13,14 @@ import { VideoModel } from '../../../models/video/video'
|
|||
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
|
||||
|
@ -65,9 +66,8 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans
|
|||
|
||||
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) {
|
||||
|
@ -95,7 +95,7 @@ export {
|
|||
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)
|
||||
|
@ -115,7 +115,7 @@ async function sendUndoVideoRelatedActivity (options: {
|
|||
byActor: ActorModel,
|
||||
video: VideoModel,
|
||||
url: string,
|
||||
activity: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
|
||||
activity: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce,
|
||||
transaction: Transaction
|
||||
}) {
|
||||
const activityBuilder = (audience: ActivityAudience) => {
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
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'
|
||||
|
@ -12,6 +12,7 @@ import { doRequest } from '../../helpers/requests'
|
|||
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
|
||||
|
@ -82,7 +83,7 @@ async function sendVideoRateChange (account: AccountModel,
|
|||
// 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) {
|
||||
|
|
Loading…
Reference in New Issue