ActivityPub: allow all known shared inboxes to be addressed

This is oriented on this paragraph from the AP spec:

> Additionally, if an object is addressed to the Public special collection,
> a server MAY deliver that object to all known sharedInbox endpoints
> on the network.
This commit is contained in:
Johann150 2022-10-11 00:27:43 +02:00
parent 4e0f14c0db
commit 8920eeb86a
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -8,6 +8,10 @@ interface IRecipe {
type: string; type: string;
} }
interface IEveryoneRecipe extends IRecipe {
type: 'Everyone';
}
interface IFollowersRecipe extends IRecipe { interface IFollowersRecipe extends IRecipe {
type: 'Followers'; type: 'Followers';
} }
@ -17,6 +21,9 @@ interface IDirectRecipe extends IRecipe {
to: IRemoteUser; to: IRemoteUser;
} }
const isEveryone = (recipe: any): recipe is IEveryoneRecipe =>
recipe.type === 'Everyone';
const isFollowers = (recipe: any): recipe is IFollowersRecipe => const isFollowers = (recipe: any): recipe is IFollowersRecipe =>
recipe.type === 'Followers'; recipe.type === 'Followers';
@ -63,6 +70,13 @@ export default class DeliverManager {
this.addRecipe(recipe); this.addRecipe(recipe);
} }
/**
* Add recipe to send this activity to all known sharedInboxes
*/
public addEveryone() {
this.addRecipe({ type: 'Everyone' } as IEveryoneRecipe);
}
/** /**
* Add recipe * Add recipe
* @param recipe Recipe * @param recipe Recipe
@ -82,9 +96,26 @@ export default class DeliverManager {
/* /*
build inbox list build inbox list
Process follower recipes first to avoid duplication when processing Processing order matters to avoid duplication.
direct recipes later.
*/ */
if (this.recipes.some(r => isEveryone(r))) {
// deliver to all of known network
const sharedInboxes = await Users.createQueryBuilder('users')
.select('users.sharedInbox', 'sharedInbox')
// can't deliver to unknown shared inbox
.where('users.sharedInbox IS NOT NULL')
// don't deliver to ourselves
.andWhere('users.host IS NOT NULL')
// so we don't have to make our inboxes Set work as hard
.groupBy('users.sharedInbox')
.getRawMany();
for (const inbox of sharedInboxes) {
inboxes.add(inbox.sharedInbox);
}
}
if (this.recipes.some(r => isFollowers(r))) { if (this.recipes.some(r => isFollowers(r))) {
// followers deliver // followers deliver
// TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう // TODO: SELECT DISTINCT ON ("followerSharedInbox") "followerSharedInbox" みたいな問い合わせにすればよりパフォーマンス向上できそう