mirror of https://github.com/Chocobozzz/PeerTube
Correctly forward video related activities
parent
3f9b33b02b
commit
9588d4f49b
|
@ -5,7 +5,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
|||
import { VideoModel } from '../../../models/video/video'
|
||||
import { VideoShareModel } from '../../../models/video/video-share'
|
||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||
import { forwardActivity } from '../send/utils'
|
||||
import { forwardVideoRelatedActivity } from '../send/utils'
|
||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||
|
||||
async function processAnnounceActivity (activity: ActivityAnnounce) {
|
||||
|
@ -58,7 +58,8 @@ async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounc
|
|||
if (video.isOwned() && created === true) {
|
||||
// Don't resend the activity to the sender
|
||||
const exceptions = [ actorAnnouncer ]
|
||||
await forwardActivity(activity, t, exceptions)
|
||||
|
||||
await forwardVideoRelatedActivity(activity, t, exceptions, video)
|
||||
}
|
||||
|
||||
return undefined
|
||||
|
|
|
@ -9,10 +9,9 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
|||
import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
||||
import { VideoCommentModel } from '../../../models/video/video-comment'
|
||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||
import { getActorsInvolvedInVideo } from '../audience'
|
||||
import { resolveThread } from '../video-comments'
|
||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||
import { forwardActivity } from '../send/utils'
|
||||
import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
|
||||
|
||||
async function processCreateActivity (activity: ActivityCreate) {
|
||||
const activityObject = activity.object
|
||||
|
@ -87,7 +86,8 @@ async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate
|
|||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -190,11 +190,7 @@ async function createVideoComment (byActor: ActorModel, activity: ActivityCreate
|
|||
// 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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ import { sequelizeTypescript } from '../../../initializers'
|
|||
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||
import { forwardActivity } from '../send/utils'
|
||||
import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
|
||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||
import { getActorsInvolvedInVideo } from '../audience'
|
||||
|
||||
async function processLikeActivity (activity: ActivityLike) {
|
||||
const actor = await getOrCreateActorAndServerAndModel(activity.actor)
|
||||
|
@ -54,7 +55,8 @@ async function createVideoLike (byActor: ActorModel, activity: ActivityLike) {
|
|||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { AccountModel } from '../../../models/account/account'
|
|||
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { forwardActivity } from '../send/utils'
|
||||
import { forwardVideoRelatedActivity } from '../send/utils'
|
||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||
import { VideoShareModel } from '../../../models/video/video-share'
|
||||
|
||||
|
@ -67,7 +67,8 @@ async function undoLike (actorUrl: string, activity: ActivityUndo) {
|
|||
if (video.isOwned()) {
|
||||
// Don't resend the activity to the sender
|
||||
const exceptions = [ byAccount.Actor ]
|
||||
await forwardActivity(activity, t, exceptions)
|
||||
|
||||
await forwardVideoRelatedActivity(activity, t, exceptions, video)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -99,7 +100,8 @@ async function undoDislike (actorUrl: string, activity: ActivityUndo) {
|
|||
if (video.isOwned()) {
|
||||
// Don't resend the activity to the sender
|
||||
const exceptions = [ byAccount.Actor ]
|
||||
await forwardActivity(activity, t, exceptions)
|
||||
|
||||
await forwardVideoRelatedActivity(activity, t, exceptions, video)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -138,11 +140,19 @@ function processUndoAnnounce (actorUrl: string, announceActivity: ActivityAnnoun
|
|||
|
||||
function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) {
|
||||
return sequelizeTypescript.transaction(async t => {
|
||||
const byAccount = await AccountModel.loadByUrl(actorUrl, t)
|
||||
if (!byAccount) throw new Error('Unknown account ' + actorUrl)
|
||||
|
||||
const share = await VideoShareModel.loadByUrl(announceActivity.id, t)
|
||||
if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`)
|
||||
|
||||
await share.destroy({ transaction: t })
|
||||
|
||||
return undefined
|
||||
if (share.Video.isOwned()) {
|
||||
// Don't resend the activity to the sender
|
||||
const exceptions = [ byAccount.Actor ]
|
||||
|
||||
await forwardVideoRelatedActivity(announceActivity, t, exceptions, share.Video)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,6 +4,21 @@ import { logger } from '../../../helpers/logger'
|
|||
import { ActorModel } from '../../../models/activitypub/actor'
|
||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||
import { JobQueue } from '../../job-queue'
|
||||
import { VideoModel } from '../../../models/video/video'
|
||||
import { getActorsInvolvedInVideo } from '../audience'
|
||||
|
||||
async function forwardVideoRelatedActivity (
|
||||
activity: Activity,
|
||||
t: Transaction,
|
||||
followersException: ActorModel[] = [],
|
||||
video: VideoModel
|
||||
) {
|
||||
// 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)
|
||||
|
||||
return forwardActivity(activity, t, followersException, additionalFollowerUrls)
|
||||
}
|
||||
|
||||
async function forwardActivity (
|
||||
activity: Activity,
|
||||
|
@ -91,7 +106,8 @@ export {
|
|||
broadcastToFollowers,
|
||||
unicastTo,
|
||||
forwardActivity,
|
||||
broadcastToActors
|
||||
broadcastToActors,
|
||||
forwardVideoRelatedActivity
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
@ -99,7 +99,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
|||
}
|
||||
|
||||
static loadByUrl (url: string, t: Sequelize.Transaction) {
|
||||
return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
|
||||
return VideoShareModel.scope(ScopeNames.FULL).findOne({
|
||||
where: {
|
||||
url
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue