Skip to content

Commit

Permalink
Merge pull request #153 from anatawa12/fix-blocked-notes-on-delay
Browse files Browse the repository at this point in the history
Fix blocked notes on delay
  • Loading branch information
anatawa12 authored Feb 21, 2024
2 parents f209b24 + 9a7a00c commit b2a9f70
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
-->

## 202x.x.x (unreleased)

### General
-

### Client
-

### Server
- Fix: 禁止ワード設定によってリモートの投稿がブロックされると、InboxキューにDelayed Jobとして残ってしまう問題を修正
- Fix: ローカルユーザーがまだ誰もフォローしていないリモートユーザーによる、通知を引き起こす可能性のある投稿を拒否すると、InboxキューにDelayed Jobとして残ってしまう問題を修正

## 2024.2.0-kinel.2

### Server
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ export class NoteCreateService implements OnApplicationShutdown {
private logger: Logger;
#shutdownController = new AbortController();

public static ContainsProhibitedWordsError = class extends Error {};

constructor(
@Inject(DI.config)
private config: Config,
Expand Down Expand Up @@ -271,7 +269,7 @@ export class NoteCreateService implements OnApplicationShutdown {
}

if (this.utilityService.isKeyWordIncluded(data.cw ?? data.text ?? '', meta.prohibitedWords)) {
throw new NoteCreateService.ContainsProhibitedWordsError();
throw new IdentifiableError('689ee33f-f97c-479a-ac49-1b9f8140af99', 'Note contains prohibited words');
}

const inSilencedInstance = this.utilityService.isSilencedHost(meta.silencedHosts, user.host);
Expand Down
11 changes: 10 additions & 1 deletion packages/backend/src/queue/processors/InboxProcessorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
import { LdSignatureService } from '@/core/activitypub/LdSignatureService.js';
import { ApInboxService } from '@/core/activitypub/ApInboxService.js';
import { bindThis } from '@/decorators.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { QueueLoggerService } from '../QueueLoggerService.js';
import type { InboxJobData } from '../types.js';

Expand Down Expand Up @@ -180,7 +181,15 @@ export class InboxProcessorService {
});

// アクティビティを処理
await this.apInboxService.performActivity(authUser.user, activity);
try {
await this.apInboxService.performActivity(authUser.user, activity);
} catch (e) {
if (e instanceof IdentifiableError) {
if (e.id === 'e11b3a16-f543-4885-8eb1-66cad131dbfd') return 'blocked mentions from unfamiliar user';
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') return 'blocked notes with prohibited words';
}
throw e;
}
return 'ok';
}
}
5 changes: 3 additions & 2 deletions packages/backend/src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DI } from '@/di-symbols.js';
import { isPureRenote } from '@/misc/is-pure-renote.js';
import { MetaService } from '@/core/MetaService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { ApiError } from '../../error.js';

export const meta = {
Expand Down Expand Up @@ -376,8 +377,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
};
} catch (e) {
// TODO: 他のErrorもここでキャッチしてエラーメッセージを当てるようにしたい
if (e instanceof NoteCreateService.ContainsProhibitedWordsError) {
throw new ApiError(meta.errors.containsProhibitedWords);
if (e instanceof IdentifiableError) {
if (e.id === '689ee33f-f97c-479a-ac49-1b9f8140af99') throw new ApiError(meta.errors.containsProhibitedWords);
}

throw e;
Expand Down

0 comments on commit b2a9f70

Please sign in to comment.