Skip to content

Commit

Permalink
Formalize auto-accepting follow requests
Browse files Browse the repository at this point in the history
  • Loading branch information
RangerMauve committed Mar 20, 2024
1 parent fb1fb77 commit 13a632b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export const ActorInfoSchema = Type.Object({
actorUrl: Type.String(),
publicKeyId: Type.String(),
keypair: KeyPairSchema,
announce: Type.Boolean({ default: false })
announce: Type.Optional(Type.Boolean({ default: false })),
manuallyApprovesFollowers: Type.Optional(Type.Boolean({ default: false }))
})

export type ActorInfo = Static<typeof ActorInfoSchema>
Expand Down
8 changes: 4 additions & 4 deletions src/server/announcements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class Announcements {
outbox: `${actorInfo.actorUrl}outbox`,
publicKey: {
id: `${actorInfo.actorUrl}#main-key`,

owner: actorInfo.actorUrl,
publicKeyPem: actorInfo.keypair.publicKeyPem
}
Expand Down Expand Up @@ -79,7 +78,8 @@ export class Announcements {
privateKeyPem,
publicKeyPem
},
announce: false
announce: false,
manuallyApprovesFollowers: false
})
}
}
Expand Down Expand Up @@ -123,10 +123,10 @@ export class Announcements {
const actor = this.store
const activities = await actor.outbox.list()
const orderedItems = activities
// XXX: maybe `new Date()` doesn't correctly parse possible dates?
.filter(a => a.type !== 'Note')
// XXX: maybe `new Date()` doesn't correctly parse possible dates?
.map(a => ({ ...a, published: typeof a.published === 'string' ? new Date(a.published) : a.published }))
.sort((a, b) => +(b.published ?? 0) - +(a.published ?? 0))
.filter(a => a.type !== 'Note')
.map(a => a.id)
.filter((id): id is string => id !== undefined)

Expand Down
6 changes: 5 additions & 1 deletion src/server/apsystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,13 @@ export default class ActivityPubSystem {

const actorStore = this.store.forActor(fromActor)

const { manuallyApprovesFollowers } = await actorStore.getInfo()

await actorStore.inbox.add(activity)

if (activityType === 'Undo') {
if (activityType === 'Follow' && (manuallyApprovesFollowers !== true)) {
await this.approveActivity(fromActor, activityId)
} else if (activityType === 'Undo') {
await this.performUndo(fromActor, activity)
} else if (moderationState === BLOCKED) {
// TODO: Notify of blocks?
Expand Down

0 comments on commit 13a632b

Please sign in to comment.