automatically accept if a locked account had accepted an old account

This commit is contained in:
Namekuji 2023-04-13 11:46:32 -04:00
parent 75c2c105fb
commit 71a2fbd232
2 changed files with 21 additions and 1 deletions

View file

@ -22,6 +22,7 @@ import { MetaService } from '@/core/MetaService.js';
import { CacheService } from '@/core/CacheService.js'; import { CacheService } from '@/core/CacheService.js';
import type { Config } from '@/config.js'; import type { Config } from '@/config.js';
import Logger from '../logger.js'; import Logger from '../logger.js';
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
const logger = new Logger('following/create'); const logger = new Logger('following/create');
@ -73,6 +74,7 @@ export class UserFollowingService implements OnModuleInit {
private federatedInstanceService: FederatedInstanceService, private federatedInstanceService: FederatedInstanceService,
private webhookService: WebhookService, private webhookService: WebhookService,
private apRendererService: ApRendererService, private apRendererService: ApRendererService,
private apPersonService: ApPersonService,
private perUserFollowingChart: PerUserFollowingChart, private perUserFollowingChart: PerUserFollowingChart,
private instanceChart: InstanceChart, private instanceChart: InstanceChart,
) { ) {
@ -137,6 +139,24 @@ export class UserFollowingService implements OnModuleInit {
if (followed) autoAccept = true; if (followed) autoAccept = true;
} }
// Automatically accept if the follower is an account who has moved and the locked followee had accepted the old account.
if (followee.isLocked && !autoAccept && follower.alsoKnownAs) {
for (const oldUri of follower.alsoKnownAs) {
try {
await this.apPersonService.updatePerson(oldUri);
const oldAccount = await this.apPersonService.resolvePerson(oldUri);
autoAccept = await this.followingsRepository.exist({
where: {
followeeId: followee.id,
followerId: oldAccount.id,
},
});
} catch {
/* skip if any error happens */
}
}
}
if (!autoAccept) { if (!autoAccept) {
await this.createFollowRequest(follower, followee, requestId); await this.createFollowRequest(follower, followee, requestId);
return; return;

View file

@ -217,7 +217,7 @@ export class ApPersonService implements OnModuleInit {
if (cached) return cached; if (cached) return cached;
// URIがこのサーバーを指しているならデータベースからフェッチ // URIがこのサーバーを指しているならデータベースからフェッチ
if (uri.startsWith(this.config.url + '/')) { if (uri.startsWith(`${this.config.url}/`)) {
const id = uri.split('/').pop(); const id = uri.split('/').pop();
const u = await this.usersRepository.findOneBy({ id }); const u = await this.usersRepository.findOneBy({ id });
if (u) this.cacheService.uriPersonCache.set(uri, u); if (u) this.cacheService.uriPersonCache.set(uri, u);