Correctly send Flag/Dislike/View activities
This commit is contained in:
parent
848f499def
commit
1e7eb25f6c
|
@ -3,22 +3,18 @@ import * as express from 'express'
|
||||||
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
|
import { VideoPrivacy, VideoRateType } from '../../../shared/models/videos'
|
||||||
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
|
import { activityPubCollectionPagination, activityPubContextify } from '../../helpers/activitypub'
|
||||||
import { CONFIG, ROUTE_CACHE_LIFETIME } from '../../initializers'
|
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 { audiencify, getAudience } from '../../lib/activitypub/audience'
|
||||||
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
|
import { buildCreateActivity } from '../../lib/activitypub/send/send-create'
|
||||||
import {
|
import {
|
||||||
asyncMiddleware,
|
asyncMiddleware,
|
||||||
videosShareValidator,
|
|
||||||
executeIfActivityPub,
|
executeIfActivityPub,
|
||||||
localAccountValidator,
|
localAccountValidator,
|
||||||
localVideoChannelValidator,
|
localVideoChannelValidator,
|
||||||
videosCustomGetValidator
|
videosCustomGetValidator,
|
||||||
|
videosShareValidator
|
||||||
} from '../../middlewares'
|
} from '../../middlewares'
|
||||||
import {
|
import { getAccountVideoRateValidator, videoCommentGetValidator, videosGetValidator } from '../../middlewares/validators'
|
||||||
getAccountVideoRateValidator,
|
|
||||||
videoCommentGetValidator,
|
|
||||||
videosGetValidator
|
|
||||||
} from '../../middlewares/validators'
|
|
||||||
import { AccountModel } from '../../models/account/account'
|
import { AccountModel } from '../../models/account/account'
|
||||||
import { ActorModel } from '../../models/activitypub/actor'
|
import { ActorModel } from '../../models/activitypub/actor'
|
||||||
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
|
import { ActorFollowModel } from '../../models/activitypub/actor-follow'
|
||||||
|
@ -40,6 +36,7 @@ import { VideoCaptionModel } from '../../models/video/video-caption'
|
||||||
import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy'
|
import { videoRedundancyGetValidator } from '../../middlewares/validators/redundancy'
|
||||||
import { getServerActor } from '../../helpers/utils'
|
import { getServerActor } from '../../helpers/utils'
|
||||||
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
|
import { VideoRedundancyModel } from '../../models/redundancy/video-redundancy'
|
||||||
|
import { buildDislikeActivity } from '../../lib/activitypub/send/send-dislike'
|
||||||
|
|
||||||
const activityPubClientRouter = express.Router()
|
const activityPubClientRouter = express.Router()
|
||||||
|
|
||||||
|
@ -156,7 +153,7 @@ function getAccountVideoRate (rateType: VideoRateType) {
|
||||||
const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
|
const url = getRateUrl(rateType, byActor, accountVideoRate.Video)
|
||||||
const APObject = rateType === 'like'
|
const APObject = rateType === 'like'
|
||||||
? buildLikeActivity(url, byActor, accountVideoRate.Video)
|
? buildLikeActivity(url, byActor, accountVideoRate.Video)
|
||||||
: buildCreateActivity(url, byActor, buildDislikeActivity(url, byActor, accountVideoRate.Video))
|
: buildDislikeActivity(url, byActor, accountVideoRate.Video)
|
||||||
|
|
||||||
return activityPubResponse(activityPubContextify(APObject), res)
|
return activityPubResponse(activityPubContextify(APObject), res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { UserRight, VideoAbuseCreate, VideoAbuseState } from '../../../../shared
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { getFormattedObjects } from '../../../helpers/utils'
|
import { getFormattedObjects } from '../../../helpers/utils'
|
||||||
import { sequelizeTypescript } from '../../../initializers'
|
import { sequelizeTypescript } from '../../../initializers'
|
||||||
import { sendVideoAbuse } from '../../../lib/activitypub/send'
|
|
||||||
import {
|
import {
|
||||||
asyncMiddleware,
|
asyncMiddleware,
|
||||||
asyncRetryTransactionMiddleware,
|
asyncRetryTransactionMiddleware,
|
||||||
|
@ -23,6 +22,7 @@ import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
||||||
import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'
|
import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'
|
||||||
import { UserModel } from '../../../models/account/user'
|
import { UserModel } from '../../../models/account/user'
|
||||||
import { Notifier } from '../../../lib/notifier'
|
import { Notifier } from '../../../lib/notifier'
|
||||||
|
import { sendVideoAbuse } from '../../../lib/activitypub/send/send-flag'
|
||||||
|
|
||||||
const auditLogger = auditLoggerFactory('abuse')
|
const auditLogger = auditLoggerFactory('abuse')
|
||||||
const abuseVideoRouter = express.Router()
|
const abuseVideoRouter = express.Router()
|
||||||
|
|
|
@ -23,7 +23,6 @@ import {
|
||||||
fetchRemoteVideoDescription,
|
fetchRemoteVideoDescription,
|
||||||
getVideoActivityPubUrl
|
getVideoActivityPubUrl
|
||||||
} from '../../../lib/activitypub'
|
} from '../../../lib/activitypub'
|
||||||
import { sendCreateView } from '../../../lib/activitypub/send'
|
|
||||||
import { JobQueue } from '../../../lib/job-queue'
|
import { JobQueue } from '../../../lib/job-queue'
|
||||||
import { Redis } from '../../../lib/redis'
|
import { Redis } from '../../../lib/redis'
|
||||||
import {
|
import {
|
||||||
|
@ -59,6 +58,7 @@ import { resetSequelizeInstance } from '../../../helpers/database-utils'
|
||||||
import { move } from 'fs-extra'
|
import { move } from 'fs-extra'
|
||||||
import { watchingRouter } from './watching'
|
import { watchingRouter } from './watching'
|
||||||
import { Notifier } from '../../../lib/notifier'
|
import { Notifier } from '../../../lib/notifier'
|
||||||
|
import { sendView } from '../../../lib/activitypub/send/send-view'
|
||||||
|
|
||||||
const auditLogger = auditLoggerFactory('videos')
|
const auditLogger = auditLoggerFactory('videos')
|
||||||
const videosRouter = express.Router()
|
const videosRouter = express.Router()
|
||||||
|
@ -422,7 +422,7 @@ async function viewVideo (req: express.Request, res: express.Response) {
|
||||||
])
|
])
|
||||||
|
|
||||||
const serverActor = await getServerActor()
|
const serverActor = await getServerActor()
|
||||||
await sendCreateView(serverActor, videoInstance, undefined)
|
await sendView(serverActor, videoInstance, undefined)
|
||||||
|
|
||||||
return res.status(204).end()
|
return res.status(204).end()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@ import { ActivityAudience, ActivityCreate } from '../../../../shared/models/acti
|
||||||
import { VideoPrivacy } from '../../../../shared/models/videos'
|
import { VideoPrivacy } from '../../../../shared/models/videos'
|
||||||
import { ActorModel } from '../../../models/activitypub/actor'
|
import { ActorModel } from '../../../models/activitypub/actor'
|
||||||
import { VideoModel } from '../../../models/video/video'
|
import { VideoModel } from '../../../models/video/video'
|
||||||
import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
|
||||||
import { VideoCommentModel } from '../../../models/video/video-comment'
|
import { VideoCommentModel } from '../../../models/video/video-comment'
|
||||||
import { getVideoAbuseActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoViewActivityPubUrl } from '../url'
|
|
||||||
import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
|
import { broadcastToActors, broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
|
||||||
import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience'
|
import { audiencify, getActorsInvolvedInVideo, getAudience, getAudienceFromFollowersOf, getVideoCommentAudience } from '../audience'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
|
@ -25,20 +23,6 @@ async function sendCreateVideo (video: VideoModel, t: Transaction) {
|
||||||
return broadcastToFollowers(createActivity, byActor, [ byActor ], t)
|
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) {
|
async function sendCreateCacheFile (byActor: ActorModel, fileRedundancy: VideoRedundancyModel) {
|
||||||
logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
|
logger.info('Creating job to send file cache of %s.', fileRedundancy.url)
|
||||||
|
|
||||||
|
@ -91,37 +75,6 @@ async function sendCreateVideoComment (comment: VideoCommentModel, t: Transactio
|
||||||
return unicastTo(createActivity, byActor, comment.Video.VideoChannel.Account.Actor.sharedInboxUrl)
|
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 {
|
function buildCreateActivity (url: string, byActor: ActorModel, object: any, audience?: ActivityAudience): ActivityCreate {
|
||||||
if (!audience) audience = getAudience(byActor)
|
if (!audience) audience = getAudience(byActor)
|
||||||
|
|
||||||
|
@ -136,33 +89,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 {
|
export {
|
||||||
sendCreateVideo,
|
sendCreateVideo,
|
||||||
sendVideoAbuse,
|
|
||||||
buildCreateActivity,
|
buildCreateActivity,
|
||||||
sendCreateView,
|
|
||||||
sendCreateDislike,
|
|
||||||
buildDislikeActivity,
|
|
||||||
sendCreateVideoComment,
|
sendCreateVideoComment,
|
||||||
sendCreateCacheFile
|
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 {
|
import {
|
||||||
ActivityAnnounce,
|
ActivityAnnounce,
|
||||||
ActivityAudience,
|
ActivityAudience,
|
||||||
ActivityCreate,
|
ActivityCreate, ActivityDislike,
|
||||||
ActivityFollow,
|
ActivityFollow,
|
||||||
ActivityLike,
|
ActivityLike,
|
||||||
ActivityUndo
|
ActivityUndo
|
||||||
|
@ -13,13 +13,14 @@ import { VideoModel } from '../../../models/video/video'
|
||||||
import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
|
import { getActorFollowActivityPubUrl, getUndoActivityPubUrl, getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from '../url'
|
||||||
import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
|
import { broadcastToFollowers, sendVideoRelatedActivity, unicastTo } from './utils'
|
||||||
import { audiencify, getAudience } from '../audience'
|
import { audiencify, getAudience } from '../audience'
|
||||||
import { buildCreateActivity, buildDislikeActivity } from './send-create'
|
import { buildCreateActivity } from './send-create'
|
||||||
import { buildFollowActivity } from './send-follow'
|
import { buildFollowActivity } from './send-follow'
|
||||||
import { buildLikeActivity } from './send-like'
|
import { buildLikeActivity } from './send-like'
|
||||||
import { VideoShareModel } from '../../../models/video/video-share'
|
import { VideoShareModel } from '../../../models/video/video-share'
|
||||||
import { buildAnnounceWithVideoAudience } from './send-announce'
|
import { buildAnnounceWithVideoAudience } from './send-announce'
|
||||||
import { logger } from '../../../helpers/logger'
|
import { logger } from '../../../helpers/logger'
|
||||||
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
|
import { VideoRedundancyModel } from '../../../models/redundancy/video-redundancy'
|
||||||
|
import { buildDislikeActivity } from './send-dislike'
|
||||||
|
|
||||||
async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
|
async function sendUndoFollow (actorFollow: ActorFollowModel, t: Transaction) {
|
||||||
const me = actorFollow.ActorFollower
|
const me = actorFollow.ActorFollower
|
||||||
|
@ -65,9 +66,8 @@ async function sendUndoDislike (byActor: ActorModel, video: VideoModel, t: Trans
|
||||||
|
|
||||||
const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
|
const dislikeUrl = getVideoDislikeActivityPubUrl(byActor, video)
|
||||||
const dislikeActivity = buildDislikeActivity(dislikeUrl, 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) {
|
async function sendUndoCacheFile (byActor: ActorModel, redundancyModel: VideoRedundancyModel, t: Transaction) {
|
||||||
|
@ -94,7 +94,7 @@ export {
|
||||||
function undoActivityData (
|
function undoActivityData (
|
||||||
url: string,
|
url: string,
|
||||||
byActor: ActorModel,
|
byActor: ActorModel,
|
||||||
object: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
|
object: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce,
|
||||||
audience?: ActivityAudience
|
audience?: ActivityAudience
|
||||||
): ActivityUndo {
|
): ActivityUndo {
|
||||||
if (!audience) audience = getAudience(byActor)
|
if (!audience) audience = getAudience(byActor)
|
||||||
|
@ -114,7 +114,7 @@ async function sendUndoVideoRelatedActivity (options: {
|
||||||
byActor: ActorModel,
|
byActor: ActorModel,
|
||||||
video: VideoModel,
|
video: VideoModel,
|
||||||
url: string,
|
url: string,
|
||||||
activity: ActivityFollow | ActivityLike | ActivityCreate | ActivityAnnounce,
|
activity: ActivityFollow | ActivityLike | ActivityDislike | ActivityCreate | ActivityAnnounce,
|
||||||
transaction: Transaction
|
transaction: Transaction
|
||||||
}) {
|
}) {
|
||||||
const activityBuilder = (audience: ActivityAudience) => {
|
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 { Transaction } from 'sequelize'
|
||||||
import { AccountModel } from '../../models/account/account'
|
import { AccountModel } from '../../models/account/account'
|
||||||
import { VideoModel } from '../../models/video/video'
|
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 { VideoRateType } from '../../../shared/models/videos'
|
||||||
import * as Bluebird from 'bluebird'
|
import * as Bluebird from 'bluebird'
|
||||||
import { getOrCreateActorAndServerAndModel } from './actor'
|
import { getOrCreateActorAndServerAndModel } from './actor'
|
||||||
|
@ -12,6 +12,7 @@ import { doRequest } from '../../helpers/requests'
|
||||||
import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
|
import { checkUrlsSameHost, getAPId } from '../../helpers/activitypub'
|
||||||
import { ActorModel } from '../../models/activitypub/actor'
|
import { ActorModel } from '../../models/activitypub/actor'
|
||||||
import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url'
|
import { getVideoDislikeActivityPubUrl, getVideoLikeActivityPubUrl } from './url'
|
||||||
|
import { sendDislike } from './send/send-dislike'
|
||||||
|
|
||||||
async function createRates (ratesUrl: string[], video: VideoModel, rate: VideoRateType) {
|
async function createRates (ratesUrl: string[], video: VideoModel, rate: VideoRateType) {
|
||||||
let rateCounts = 0
|
let rateCounts = 0
|
||||||
|
@ -82,7 +83,7 @@ async function sendVideoRateChange (account: AccountModel,
|
||||||
// Like
|
// Like
|
||||||
if (likes > 0) await sendLike(actor, video, t)
|
if (likes > 0) await sendLike(actor, video, t)
|
||||||
// Dislike
|
// 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) {
|
function getRateUrl (rateType: VideoRateType, actor: ActorModel, video: VideoModel) {
|
||||||
|
|
Loading…
Reference in New Issue