mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-22 08:46:54 -06:00
Add reject processing for activitypub
This commit is contained in:
parent
cfe1efd200
commit
4bbc373f13
@ -1,6 +1,9 @@
|
|||||||
import * as validator from 'validator'
|
import * as validator from 'validator'
|
||||||
import { Activity, ActivityType } from '../../../../shared/models/activitypub'
|
import { Activity, ActivityType } from '../../../../shared/models/activitypub'
|
||||||
import { isActorAcceptActivityValid, isActorDeleteActivityValid, isActorFollowActivityValid, isActorUpdateActivityValid } from './actor'
|
import {
|
||||||
|
isActorAcceptActivityValid, isActorDeleteActivityValid, isActorFollowActivityValid, isActorRejectActivityValid,
|
||||||
|
isActorUpdateActivityValid
|
||||||
|
} from './actor'
|
||||||
import { isAnnounceActivityValid } from './announce'
|
import { isAnnounceActivityValid } from './announce'
|
||||||
import { isActivityPubUrlValid } from './misc'
|
import { isActivityPubUrlValid } from './misc'
|
||||||
import { isDislikeActivityValid, isLikeActivityValid } from './rate'
|
import { isDislikeActivityValid, isLikeActivityValid } from './rate'
|
||||||
@ -33,6 +36,7 @@ const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean
|
|||||||
Delete: checkDeleteActivity,
|
Delete: checkDeleteActivity,
|
||||||
Follow: checkFollowActivity,
|
Follow: checkFollowActivity,
|
||||||
Accept: checkAcceptActivity,
|
Accept: checkAcceptActivity,
|
||||||
|
Reject: checkRejectActivity,
|
||||||
Announce: checkAnnounceActivity,
|
Announce: checkAnnounceActivity,
|
||||||
Undo: checkUndoActivity,
|
Undo: checkUndoActivity,
|
||||||
Like: checkLikeActivity
|
Like: checkLikeActivity
|
||||||
@ -82,6 +86,10 @@ function checkAcceptActivity (activity: any) {
|
|||||||
return isActorAcceptActivityValid(activity)
|
return isActorAcceptActivityValid(activity)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkRejectActivity (activity: any) {
|
||||||
|
return isActorRejectActivityValid(activity)
|
||||||
|
}
|
||||||
|
|
||||||
function checkAnnounceActivity (activity: any) {
|
function checkAnnounceActivity (activity: any) {
|
||||||
return isAnnounceActivityValid(activity)
|
return isAnnounceActivityValid(activity)
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,10 @@ function isActorAcceptActivityValid (activity: any) {
|
|||||||
return isBaseActivityValid(activity, 'Accept')
|
return isBaseActivityValid(activity, 'Accept')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isActorRejectActivityValid (activity: any) {
|
||||||
|
return isBaseActivityValid(activity, 'Reject')
|
||||||
|
}
|
||||||
|
|
||||||
function isActorUpdateActivityValid (activity: any) {
|
function isActorUpdateActivityValid (activity: any) {
|
||||||
return isBaseActivityValid(activity, 'Update') &&
|
return isBaseActivityValid(activity, 'Update') &&
|
||||||
isActorObjectValid(activity.object)
|
isActorObjectValid(activity.object)
|
||||||
@ -97,6 +101,7 @@ export {
|
|||||||
isActorFollowersCountValid,
|
isActorFollowersCountValid,
|
||||||
isActorFollowActivityValid,
|
isActorFollowActivityValid,
|
||||||
isActorAcceptActivityValid,
|
isActorAcceptActivityValid,
|
||||||
|
isActorRejectActivityValid,
|
||||||
isActorDeleteActivityValid,
|
isActorDeleteActivityValid,
|
||||||
isActorUpdateActivityValid
|
isActorUpdateActivityValid
|
||||||
}
|
}
|
||||||
|
32
server/lib/activitypub/process/process-reject.ts
Normal file
32
server/lib/activitypub/process/process-reject.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import { ActivityReject } from '../../../../shared/models/activitypub/activity'
|
||||||
|
import { sequelizeTypescript } from '../../../initializers'
|
||||||
|
import { ActorModel } from '../../../models/activitypub/actor'
|
||||||
|
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
|
||||||
|
|
||||||
|
async function processRejectActivity (activity: ActivityReject, inboxActor?: ActorModel) {
|
||||||
|
if (inboxActor === undefined) throw new Error('Need to reject on explicit inbox.')
|
||||||
|
|
||||||
|
const targetActor = await ActorModel.loadByUrl(activity.actor)
|
||||||
|
|
||||||
|
return processReject(inboxActor, targetActor)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export {
|
||||||
|
processRejectActivity
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
async function processReject (actor: ActorModel, targetActor: ActorModel) {
|
||||||
|
return sequelizeTypescript.transaction(async t => {
|
||||||
|
const actorFollow = await ActorFollowModel.loadByActorAndTarget(actor.id, targetActor.id, t)
|
||||||
|
|
||||||
|
if (!actorFollow) throw new Error(`'Unknown actor follow ${actor.id} -> ${targetActor.id}.`)
|
||||||
|
|
||||||
|
await actorFollow.destroy({ transaction: t })
|
||||||
|
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
}
|
@ -7,6 +7,7 @@ import { processCreateActivity } from './process-create'
|
|||||||
import { processDeleteActivity } from './process-delete'
|
import { processDeleteActivity } from './process-delete'
|
||||||
import { processFollowActivity } from './process-follow'
|
import { processFollowActivity } from './process-follow'
|
||||||
import { processLikeActivity } from './process-like'
|
import { processLikeActivity } from './process-like'
|
||||||
|
import { processRejectActivity } from './process-reject'
|
||||||
import { processUndoActivity } from './process-undo'
|
import { processUndoActivity } from './process-undo'
|
||||||
import { processUpdateActivity } from './process-update'
|
import { processUpdateActivity } from './process-update'
|
||||||
|
|
||||||
@ -16,6 +17,7 @@ const processActivity: { [ P in ActivityType ]: (activity: Activity, inboxActor?
|
|||||||
Delete: processDeleteActivity,
|
Delete: processDeleteActivity,
|
||||||
Follow: processFollowActivity,
|
Follow: processFollowActivity,
|
||||||
Accept: processAcceptActivity,
|
Accept: processAcceptActivity,
|
||||||
|
Reject: processRejectActivity,
|
||||||
Announce: processAnnounceActivity,
|
Announce: processAnnounceActivity,
|
||||||
Undo: processUndoActivity,
|
Undo: processUndoActivity,
|
||||||
Like: processLikeActivity
|
Like: processLikeActivity
|
||||||
|
@ -8,9 +8,9 @@ import { ViewObject } from './objects/view-object'
|
|||||||
|
|
||||||
export type Activity = ActivityCreate | ActivityUpdate |
|
export type Activity = ActivityCreate | ActivityUpdate |
|
||||||
ActivityDelete | ActivityFollow | ActivityAccept | ActivityAnnounce |
|
ActivityDelete | ActivityFollow | ActivityAccept | ActivityAnnounce |
|
||||||
ActivityUndo | ActivityLike
|
ActivityUndo | ActivityLike | ActivityReject
|
||||||
|
|
||||||
export type ActivityType = 'Create' | 'Update' | 'Delete' | 'Follow' | 'Accept' | 'Announce' | 'Undo' | 'Like'
|
export type ActivityType = 'Create' | 'Update' | 'Delete' | 'Follow' | 'Accept' | 'Announce' | 'Undo' | 'Like' | 'Reject'
|
||||||
|
|
||||||
export interface ActivityAudience {
|
export interface ActivityAudience {
|
||||||
to: string[]
|
to: string[]
|
||||||
@ -52,6 +52,11 @@ export interface ActivityAccept extends BaseActivity {
|
|||||||
object: ActivityFollow
|
object: ActivityFollow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ActivityReject extends BaseActivity {
|
||||||
|
type: 'Reject'
|
||||||
|
object: ActivityFollow
|
||||||
|
}
|
||||||
|
|
||||||
export interface ActivityAnnounce extends BaseActivity {
|
export interface ActivityAnnounce extends BaseActivity {
|
||||||
type: 'Announce'
|
type: 'Announce'
|
||||||
object: ActivityCreate | string
|
object: ActivityCreate | string
|
||||||
|
Loading…
Reference in New Issue
Block a user