既存のものを使うように
This commit is contained in:
parent
ba661d930f
commit
0e7ab7500b
|
|
@ -28,7 +28,7 @@ import { MetaService } from '@/core/MetaService.js';
|
|||
import { CacheService } from '@/core/CacheService.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import { AccountMoveService } from '@/core/AccountMoveService.js';
|
||||
import { shouldSilenceInstance } from '@/misc/should-block-instance.js';
|
||||
import { UtilityService } from '@/core/UtilityService.js';
|
||||
import Logger from '../logger.js';
|
||||
|
||||
const logger = new Logger('following/create');
|
||||
|
|
@ -75,6 +75,7 @@ export class UserFollowingService implements OnModuleInit {
|
|||
private instancesRepository: InstancesRepository,
|
||||
|
||||
private cacheService: CacheService,
|
||||
private utilityService: UtilityService,
|
||||
private userEntityService: UserEntityService,
|
||||
private idService: IdService,
|
||||
private queueService: QueueService,
|
||||
|
|
@ -122,7 +123,6 @@ export class UserFollowingService implements OnModuleInit {
|
|||
}
|
||||
|
||||
const followeeProfile = await this.userProfilesRepository.findOneByOrFail({ userId: followee.id });
|
||||
|
||||
// フォロー対象が鍵アカウントである or
|
||||
// フォロワーがBotであり、フォロー対象がBotからのフォローに慎重である or
|
||||
// フォロワーがローカルユーザーであり、フォロー対象がリモートユーザーである or
|
||||
|
|
@ -132,7 +132,7 @@ export class UserFollowingService implements OnModuleInit {
|
|||
followee.isLocked ||
|
||||
(followeeProfile.carefulBot && follower.isBot) ||
|
||||
(this.userEntityService.isLocalUser(follower) && this.userEntityService.isRemoteUser(followee) && process.env.FORCE_FOLLOW_REMOTE_USER_FOR_TESTING !== 'true') ||
|
||||
( this.userEntityService.isLocalUser(followee) && this.userEntityService.isRemoteUser(follower) && await shouldSilenceInstance(follower.host, this.db))
|
||||
( this.userEntityService.isLocalUser(followee) && this.userEntityService.isRemoteUser(follower) && this.utilityService.isSilencedHost((await this.metaService.fetch()).silencedHosts, follower.host))
|
||||
) {
|
||||
let autoAccept = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@ export class UtilityService {
|
|||
return blockedHosts.some(x => `.${host.toLowerCase()}`.endsWith(`.${x}`));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public isSilencedHost(silencedHosts: string[], host: string | null): boolean {
|
||||
if (host == null) return false;
|
||||
return silencedHosts.some(x => `.${host.toLowerCase()}`.endsWith(`.${x}`));
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public extractDbHost(uri: string): string {
|
||||
const url = new URL(uri);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import type { Packed } from '@/misc/json-schema.js';
|
|||
import type { MiInstance } from '@/models/Instance.js';
|
||||
import { MetaService } from '@/core/MetaService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { shouldSilenceInstance } from '@/misc/should-block-instance.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { UtilityService } from '../UtilityService.js';
|
||||
|
||||
|
|
@ -48,7 +47,7 @@ export class InstanceEntityService {
|
|||
description: instance.description,
|
||||
maintainerName: instance.maintainerName,
|
||||
maintainerEmail: instance.maintainerEmail,
|
||||
isSilenced: await shouldSilenceInstance(instance.host, this.db),
|
||||
isSilenced: this.utilityService.isSilencedHost(meta.silencedHosts, instance.host),
|
||||
iconUrl: instance.iconUrl,
|
||||
faviconUrl: instance.faviconUrl,
|
||||
themeColor: instance.themeColor,
|
||||
|
|
|
|||
|
|
@ -1,40 +0,0 @@
|
|||
import { DataSource } from 'typeorm';
|
||||
import { MiMeta } from '@/models/Meta.js';
|
||||
|
||||
let cache: MiMeta;
|
||||
|
||||
export async function fetchMeta(noCache = false, db: DataSource): Promise<MiMeta> {
|
||||
if (!noCache && cache) return cache;
|
||||
|
||||
return await db.transaction(async (transactionalEntityManager) => {
|
||||
// New IDs are prioritized because multiple records may have been created due to past bugs.
|
||||
const metas = await transactionalEntityManager.find(MiMeta, {
|
||||
order: {
|
||||
id: 'DESC',
|
||||
},
|
||||
});
|
||||
|
||||
const meta = metas[0];
|
||||
|
||||
if (meta) {
|
||||
cache = meta;
|
||||
return meta;
|
||||
} else {
|
||||
// If fetchMeta is called at the same time when meta is empty, this part may be called at the same time, so use fail-safe upsert.
|
||||
const saved = await transactionalEntityManager
|
||||
.upsert(
|
||||
MiMeta,
|
||||
{
|
||||
id: 'x',
|
||||
},
|
||||
['id'],
|
||||
)
|
||||
.then((x) =>
|
||||
transactionalEntityManager.findOneByOrFail(MiMeta, x.identifiers[0]),
|
||||
);
|
||||
|
||||
cache = saved;
|
||||
return saved;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
import { DataSource } from 'typeorm';
|
||||
import { fetchMeta } from '@/misc/fetch-meta.js';
|
||||
import type { MiInstance } from '@/models/Instance.js';
|
||||
import type { MiMeta } from '@/models/Meta.js';
|
||||
|
||||
export async function shouldSilenceInstance(
|
||||
host: MiInstance['host'],
|
||||
db : DataSource,
|
||||
meta?: MiMeta,
|
||||
): Promise<boolean> {
|
||||
const { silencedHosts } = meta ?? (await fetchMeta(true, db));
|
||||
return silencedHosts.some(
|
||||
(limitedHost: string) => host === limitedHost || host.endsWith(`.${limitedHost}`),
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue