Correctly forward video related activities
This commit is contained in:
parent
3f9b33b02b
commit
9588d4f49b
|
@ -5,7 +5,7 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
||||||
import { VideoModel } from '../../../models/video/video'
|
import { VideoModel } from '../../../models/video/video'
|
||||||
import { VideoShareModel } from '../../../models/video/video-share'
|
import { VideoShareModel } from '../../../models/video/video-share'
|
||||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||||
import { forwardActivity } from '../send/utils'
|
import { forwardVideoRelatedActivity } from '../send/utils'
|
||||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||||
|
|
||||||
async function processAnnounceActivity (activity: ActivityAnnounce) {
|
async function processAnnounceActivity (activity: ActivityAnnounce) {
|
||||||
|
@ -58,7 +58,8 @@ async function shareVideo (actorAnnouncer: ActorModel, activity: ActivityAnnounc
|
||||||
if (video.isOwned() && created === true) {
|
if (video.isOwned() && created === true) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ actorAnnouncer ]
|
const exceptions = [ actorAnnouncer ]
|
||||||
await forwardActivity(activity, t, exceptions)
|
|
||||||
|
await forwardVideoRelatedActivity(activity, t, exceptions, video)
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined
|
return undefined
|
||||||
|
|
|
@ -9,10 +9,9 @@ import { ActorModel } from '../../../models/activitypub/actor'
|
||||||
import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
import { VideoAbuseModel } from '../../../models/video/video-abuse'
|
||||||
import { VideoCommentModel } from '../../../models/video/video-comment'
|
import { VideoCommentModel } from '../../../models/video/video-comment'
|
||||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||||
import { getActorsInvolvedInVideo } from '../audience'
|
|
||||||
import { resolveThread } from '../video-comments'
|
import { resolveThread } from '../video-comments'
|
||||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||||
import { forwardActivity } from '../send/utils'
|
import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
|
||||||
|
|
||||||
async function processCreateActivity (activity: ActivityCreate) {
|
async function processCreateActivity (activity: ActivityCreate) {
|
||||||
const activityObject = activity.object
|
const activityObject = activity.object
|
||||||
|
@ -87,7 +86,8 @@ async function createVideoDislike (byActor: ActorModel, activity: ActivityCreate
|
||||||
if (video.isOwned() && created === true) {
|
if (video.isOwned() && created === true) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
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
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
const exceptions = [ byActor ]
|
||||||
|
|
||||||
// Mastodon does not add our announces in audience, so we forward to them manually
|
await forwardVideoRelatedActivity(activity, t, exceptions, video)
|
||||||
const additionalActors = await getActorsInvolvedInVideo(video, t)
|
|
||||||
const additionalFollowerUrls = additionalActors.map(a => a.followersUrl)
|
|
||||||
|
|
||||||
await forwardActivity(activity, t, exceptions, additionalFollowerUrls)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,9 @@ import { sequelizeTypescript } from '../../../initializers'
|
||||||
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
import { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||||
import { ActorModel } from '../../../models/activitypub/actor'
|
import { ActorModel } from '../../../models/activitypub/actor'
|
||||||
import { getOrCreateActorAndServerAndModel } from '../actor'
|
import { getOrCreateActorAndServerAndModel } from '../actor'
|
||||||
import { forwardActivity } from '../send/utils'
|
import { forwardActivity, forwardVideoRelatedActivity } from '../send/utils'
|
||||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||||
|
import { getActorsInvolvedInVideo } from '../audience'
|
||||||
|
|
||||||
async function processLikeActivity (activity: ActivityLike) {
|
async function processLikeActivity (activity: ActivityLike) {
|
||||||
const actor = await getOrCreateActorAndServerAndModel(activity.actor)
|
const actor = await getOrCreateActorAndServerAndModel(activity.actor)
|
||||||
|
@ -54,7 +55,8 @@ async function createVideoLike (byActor: ActorModel, activity: ActivityLike) {
|
||||||
if (video.isOwned() && created === true) {
|
if (video.isOwned() && created === true) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byActor ]
|
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 { AccountVideoRateModel } from '../../../models/account/account-video-rate'
|
||||||
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'
|
||||||
import { forwardActivity } from '../send/utils'
|
import { forwardVideoRelatedActivity } from '../send/utils'
|
||||||
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
import { getOrCreateAccountAndVideoAndChannel } from '../videos'
|
||||||
import { VideoShareModel } from '../../../models/video/video-share'
|
import { VideoShareModel } from '../../../models/video/video-share'
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ async function undoLike (actorUrl: string, activity: ActivityUndo) {
|
||||||
if (video.isOwned()) {
|
if (video.isOwned()) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byAccount.Actor ]
|
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()) {
|
if (video.isOwned()) {
|
||||||
// Don't resend the activity to the sender
|
// Don't resend the activity to the sender
|
||||||
const exceptions = [ byAccount.Actor ]
|
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) {
|
function undoAnnounce (actorUrl: string, announceActivity: ActivityAnnounce) {
|
||||||
return sequelizeTypescript.transaction(async t => {
|
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)
|
const share = await VideoShareModel.loadByUrl(announceActivity.id, t)
|
||||||
if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`)
|
if (!share) throw new Error(`'Unknown video share ${announceActivity.id}.`)
|
||||||
|
|
||||||
await share.destroy({ transaction: t })
|
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 { ActorModel } from '../../../models/activitypub/actor'
|
||||||
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||||
import { JobQueue } from '../../job-queue'
|
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 (
|
async function forwardActivity (
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
|
@ -91,7 +106,8 @@ export {
|
||||||
broadcastToFollowers,
|
broadcastToFollowers,
|
||||||
unicastTo,
|
unicastTo,
|
||||||
forwardActivity,
|
forwardActivity,
|
||||||
broadcastToActors
|
broadcastToActors,
|
||||||
|
forwardVideoRelatedActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
|
@ -99,7 +99,7 @@ export class VideoShareModel extends Model<VideoShareModel> {
|
||||||
}
|
}
|
||||||
|
|
||||||
static loadByUrl (url: string, t: Sequelize.Transaction) {
|
static loadByUrl (url: string, t: Sequelize.Transaction) {
|
||||||
return VideoShareModel.scope(ScopeNames.WITH_ACTOR).findOne({
|
return VideoShareModel.scope(ScopeNames.FULL).findOne({
|
||||||
where: {
|
where: {
|
||||||
url
|
url
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue