mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 10:49:28 +02:00
Correctly send Flag/Dislike/View activities
This commit is contained in:
parent
848f499def
commit
1e7eb25f6c
9 changed files with 138 additions and 89 deletions
|
@ -3,9 +3,7 @@ import { ActivityAudience, ActivityCreate } from '../../../../shared/models/acti
|
|||
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, fileRedundancy: VideoRedundancyModel) {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
|
@ -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 {
|
||||
sendCreateVideo,
|
||||
sendVideoAbuse,
|
||||
buildCreateActivity,
|
||||
sendCreateView,
|
||||
sendCreateDislike,
|
||||
buildDislikeActivity,
|
||||
sendCreateVideoComment,
|
||||
sendCreateCacheFile
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue