Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユーザーミュートにメンションが考慮されるように #14995

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
- Fix: アカウント削除のモデレーションログが動作していないのを修正 (#14996)
- Fix: リノートミュートが新規投稿通知に対して作用していなかった問題を修正
- Fix: セキュリティに関する修正
- Fix: ユーザーミュートにおいて、ノート内のメンションが考慮されていなかった問題を修正
- これにより、第三者から自分に対するノートを意図せず取り逃してしまう可能性があったため、通知欄ではメンションを考慮しないままになっています

### Misskey.js
- Fix: Stream初期化時、別途WebSocketを指定する場合の型定義を修正
Expand Down
18 changes: 17 additions & 1 deletion packages/backend/src/core/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,18 @@ export class QueryService {
}

@bindThis
public generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }, exclude?: { id: MiUser['id'] }): void {
public generateMutedUserQuery(q: SelectQueryBuilder<any>, me: { id: MiUser['id'] }, exclude?: { id: MiUser['id'] }, checkMentions = true): void {
const mutingQuery = this.mutingsRepository.createQueryBuilder('muting')
.select('muting.muteeId')
.where('muting.muterId = :muterId', { muterId: me.id });

const mutingArrayQuery = this.mutingsRepository.createQueryBuilder('muting')
.select('array_agg(muting.muteeId)', 'muting.muteeIdArray')
.where('muting.muterId = :muterId', { muterId: me.id });

if (exclude) {
mutingQuery.andWhere('muting.muteeId != :excludeId', { excludeId: exclude.id });
mutingArrayQuery.andWhere('muting.muteeId != :excludeId', { excludeId: exclude.id });
}

const mutingInstanceQuery = this.userProfilesRepository.createQueryBuilder('user_profile')
Expand Down Expand Up @@ -172,7 +177,18 @@ export class QueryService {
.orWhere(`NOT ((${ mutingInstanceQuery.getQuery() })::jsonb ? note.renoteUserHost)`);
}));

// 投稿に含まれるメンションの相手をミュートしていない
if (checkMentions) {
q.andWhere(new Brackets(qb => {
qb
.where('note.mentions IS NULL')
.orWhere(`NOT EXISTS (${ mutingQuery.getQuery() })`)
.orWhere(`NOT (note.mentions && (${ mutingArrayQuery.getQuery() }))`);
}));
}

q.setParameters(mutingQuery.getParameters());
q.setParameters(mutingArrayQuery.getParameters());
q.setParameters(mutingInstanceQuery.getParameters());
}

Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/misc/is-user-related.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function isUserRelated(note: any, userIds: Set<string>, ignoreAuthor = fa
return true;
}

if (note.mentions != null && note.mentions.filter((userId: string) => userId !== note.userId && userIds.has(userId)).length > 0) {
return true;
}

if (note.reply != null && note.reply.userId !== note.userId && userIds.has(note.reply.userId)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser');

this.queryService.generateVisibilityQuery(query, me);
this.queryService.generateMutedUserQuery(query, me);
this.queryService.generateMutedUserQuery(query, me, undefined, false); // 通知系ではメンションを確認しないようにする
this.queryService.generateMutedNoteThreadQuery(query, me);
this.queryService.generateBlockedUserQuery(query, me);

Expand Down
Loading