forked from FoundKeyGang/FoundKey
Merge pull request 'deliver Delete activities to all known instances' (#198) from deliver-delete-everyone into main
Reviewed-on: FoundKeyGang/FoundKey#198
This commit is contained in:
commit
811d5cd0d7
2 changed files with 49 additions and 6 deletions
|
@ -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')
|
||||||
|
// so we don't have to make our inboxes Set work as hard
|
||||||
|
.distinct(true)
|
||||||
|
// can't deliver to unknown shared inbox
|
||||||
|
.where('users.sharedInbox IS NOT NULL')
|
||||||
|
// don't deliver to ourselves
|
||||||
|
.andWhere('users.host IS NOT NULL')
|
||||||
|
.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" みたいな問い合わせにすればよりパフォーマンス向上できそう
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { User, ILocalUser, IRemoteUser } from '@/models/entities/user.js';
|
||||||
import { Note } from '@/models/entities/note.js';
|
import { Note } from '@/models/entities/note.js';
|
||||||
import { Notes, Users, Instances } from '@/models/index.js';
|
import { Notes, Users, Instances } from '@/models/index.js';
|
||||||
import { notesChart, perUserNotesChart, instanceChart } from '@/services/chart/index.js';
|
import { notesChart, perUserNotesChart, instanceChart } from '@/services/chart/index.js';
|
||||||
import { deliverToFollowers, deliverToUser } from '@/remote/activitypub/deliver-manager.js';
|
import DeliverManager from '@/remote/activitypub/deliver-manager.js';
|
||||||
import { countSameRenotes } from '@/misc/count-same-renotes.js';
|
import { countSameRenotes } from '@/misc/count-same-renotes.js';
|
||||||
import { isPureRenote } from '@/misc/renote.js';
|
import { isPureRenote } from '@/misc/renote.js';
|
||||||
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js';
|
||||||
|
@ -132,10 +132,22 @@ async function getMentionedRemoteUsers(note: Note): Promise<IRemoteUser[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deliverToConcerned(user: { id: ILocalUser['id']; host: null; }, note: Note, content: any) {
|
async function deliverToConcerned(user: { id: ILocalUser['id']; host: null; }, note: Note, content: any) {
|
||||||
deliverToFollowers(user, content);
|
const manager = new DeliverManager(user, content);
|
||||||
deliverToRelays(user, content);
|
|
||||||
const remoteUsers = await getMentionedRemoteUsers(note);
|
const remoteUsers = await getMentionedRemoteUsers(note);
|
||||||
for (const remoteUser of remoteUsers) {
|
for (const remoteUser of remoteUsers) {
|
||||||
deliverToUser(user, content, remoteUser);
|
manager.addDirectRecipe(remoteUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (['public', 'home', 'followers'].includes(note.visibility)) {
|
||||||
|
manager.addFollowersRecipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (['public', 'home'].includes(note.visibility)) {
|
||||||
|
manager.addEveryone();
|
||||||
|
}
|
||||||
|
|
||||||
|
await manager.execute();
|
||||||
|
|
||||||
|
deliverToRelays(user, content);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue