import * as validator from 'validator'
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 { isActivityPubUrlValid } from './misc'
import { isDislikeActivityValid, isLikeActivityValid } from './rate'
Delete: checkDeleteActivity,
Follow: checkFollowActivity,
Accept: checkAcceptActivity,
+ Reject: checkRejectActivity,
Announce: checkAnnounceActivity,
Undo: checkUndoActivity,
Like: checkLikeActivity
return isActorAcceptActivityValid(activity)
}
+function checkRejectActivity (activity: any) {
+ return isActorRejectActivityValid(activity)
+}
+
function checkAnnounceActivity (activity: any) {
return isAnnounceActivityValid(activity)
}
return isBaseActivityValid(activity, 'Accept')
}
+function isActorRejectActivityValid (activity: any) {
+ return isBaseActivityValid(activity, 'Reject')
+}
+
function isActorUpdateActivityValid (activity: any) {
return isBaseActivityValid(activity, 'Update') &&
isActorObjectValid(activity.object)
isActorFollowersCountValid,
isActorFollowActivityValid,
isActorAcceptActivityValid,
+ isActorRejectActivityValid,
isActorDeleteActivityValid,
isActorUpdateActivityValid
}
--- /dev/null
+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
+ })
+}
import { processDeleteActivity } from './process-delete'
import { processFollowActivity } from './process-follow'
import { processLikeActivity } from './process-like'
+import { processRejectActivity } from './process-reject'
import { processUndoActivity } from './process-undo'
import { processUpdateActivity } from './process-update'
Delete: processDeleteActivity,
Follow: processFollowActivity,
Accept: processAcceptActivity,
+ Reject: processRejectActivity,
Announce: processAnnounceActivity,
Undo: processUndoActivity,
Like: processLikeActivity
export type Activity = ActivityCreate | ActivityUpdate |
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 {
to: string[]
object: ActivityFollow
}
+export interface ActivityReject extends BaseActivity {
+ type: 'Reject'
+ object: ActivityFollow
+}
+
export interface ActivityAnnounce extends BaseActivity {
type: 'Announce'
object: ActivityCreate | string