Loosen block restrictions
This commit is contained in:
parent
2991122668
commit
a851b94b01
10 changed files with 86 additions and 19 deletions
|
@ -13,6 +13,7 @@ import type { NotesRepository } from '@/models/_.js';
|
|||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||
import { FanoutTimelineName, FanoutTimelineService } from '@/core/FanoutTimelineService.js';
|
||||
import { isUserRelated } from '@/misc/is-user-related.js';
|
||||
import { isUserMentioned } from '@/misc/is-user-mentioned.js';
|
||||
import { isQuote, isRenote } from '@/misc/is-renote.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
import { isReply } from '@/misc/is-reply.js';
|
||||
|
@ -30,6 +31,7 @@ type TimelineOptions = {
|
|||
alwaysIncludeMyNotes?: boolean;
|
||||
ignoreAuthorFromBlock?: boolean;
|
||||
ignoreAuthorFromMute?: boolean;
|
||||
ignoreMentionsFromBlock?: boolean;
|
||||
excludeNoFiles?: boolean;
|
||||
excludeReplies?: boolean;
|
||||
excludeBots?: boolean;
|
||||
|
@ -106,17 +108,25 @@ export class FanoutTimelineEndpointService {
|
|||
userIdsWhoMeMuting,
|
||||
userIdsWhoMeMutingRenotes,
|
||||
userIdsWhoBlockingMe,
|
||||
userIdsWhoMeBlocking,
|
||||
userMutedInstances,
|
||||
] = await Promise.all([
|
||||
this.cacheService.userMutingsCache.fetch(ps.me.id),
|
||||
this.cacheService.renoteMutingsCache.fetch(ps.me.id),
|
||||
this.cacheService.userBlockedCache.fetch(ps.me.id),
|
||||
this.cacheService.userBlockingCache.fetch(ps.me.id),
|
||||
this.cacheService.userProfileCache.fetch(me.id).then(p => new Set(p.mutedInstances)),
|
||||
]);
|
||||
|
||||
const parentFilter = filter;
|
||||
filter = (note) => {
|
||||
if (isUserRelated(note, userIdsWhoBlockingMe, ps.ignoreAuthorFromBlock)) return false;
|
||||
if (isUserRelated(note, userIdsWhoMeBlocking, ps.ignoreAuthorFromBlock)) return false;
|
||||
const ignoreMentions = ps.ignoreMentionsFromBlock ?? ps.ignoreAuthorFromBlock;
|
||||
if (ignoreMentions) {
|
||||
if (isUserMentioned(note, userIdsWhoBlockingMe)) return false;
|
||||
if (isUserMentioned(note, userIdsWhoMeBlocking)) return false;
|
||||
}
|
||||
if (isUserRelated(note, userIdsWhoMeMuting, ps.ignoreAuthorFromMute)) return false;
|
||||
if (!ps.ignoreAuthorFromMute && isRenote(note) && !isQuote(note) && userIdsWhoMeMutingRenotes.has(note.userId)) return false;
|
||||
if (isInstanceMuted(note, userMutedInstances)) return false;
|
||||
|
|
|
@ -79,6 +79,7 @@ export class QueryService {
|
|||
.where('blocking.blockeeId = :blockeeId', { blockeeId: me.id });
|
||||
|
||||
const mentionQuery = `SELECT COUNT(*) FROM unnest(note.mentions) mention WHERE mention IN (${blockingQuery.getQuery()}) OR mention IN (${blockedQuery.getQuery()}) LIMIT 1`;
|
||||
const mentionMeQuery = `SELECT COUNT(*) FROM unnest(note.mentions) mention WHERE mention = :meId LIMIT 1`;
|
||||
|
||||
// 投稿の作者にブロックされていない かつ
|
||||
// 投稿の返信先の作者にブロックされていない かつ
|
||||
|
@ -98,7 +99,13 @@ export class QueryService {
|
|||
.orWhere(`note.renoteUserId NOT IN (${ blockedQuery.getQuery() })`)
|
||||
.orWhere(`note.renoteUserId NOT IN (${ blockingQuery.getQuery() })`);
|
||||
}))
|
||||
.andWhere(`(${mentionQuery}) = 0`);
|
||||
.andWhere(new Brackets(qb => {
|
||||
qb
|
||||
.where(`(${mentionQuery}) = 0`)
|
||||
.orWhere('note.userId = :meId', { meId: me.id })
|
||||
.orWhere('note.replyUserId = :meId', { meId: me.id })
|
||||
.orWhere(`(${mentionMeQuery}) = 1`, { meId: me.id });
|
||||
}));
|
||||
|
||||
q.setParameters(blockingQuery.getParameters());
|
||||
q.setParameters(blockedQuery.getParameters());
|
||||
|
|
|
@ -236,14 +236,17 @@ export class SearchService {
|
|||
const [
|
||||
userIdsWhoMeMuting,
|
||||
userIdsWhoBlockingMe,
|
||||
userIdsWhoMeBlocking,
|
||||
] = me ? await Promise.all([
|
||||
this.cacheService.userMutingsCache.fetch(me.id),
|
||||
this.cacheService.userBlockedCache.fetch(me.id),
|
||||
this.cacheService.userBlockingCache.fetch(me.id),
|
||||
]) : [new Set<string>(), new Set<string>()];
|
||||
const notes = (await this.notesRepository.findBy({
|
||||
id: In(res.hits.map(x => x.id)),
|
||||
})).filter(note => {
|
||||
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
||||
if (me && isUserRelated(note, userIdsWhoMeBlocking)) return false;
|
||||
if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;
|
||||
return true;
|
||||
});
|
||||
|
|
20
packages/backend/src/misc/is-user-mentioned.ts
Normal file
20
packages/backend/src/misc/is-user-mentioned.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
export function isUserMentioned(note: any, userIds: Set<string>): boolean {
|
||||
if (!note) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (note.mentions != null && note.mentions.some(mention => userIds.has(mention))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (note.renote != null && note.renote.mentions != null && note.renote.mentions.some(mention => userIds.has(mention))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -4,8 +4,6 @@
|
|||
*/
|
||||
|
||||
export function isUserRelated(note: any, userIds: Set<string>, ignoreAuthor = false): boolean {
|
||||
console.log(note);
|
||||
|
||||
if (!note) {
|
||||
return false;
|
||||
}
|
||||
|
@ -22,13 +20,5 @@ export function isUserRelated(note: any, userIds: Set<string>, ignoreAuthor = fa
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!ignoreAuthor && note.mentions != null && note.mentions.some(mention => userIds.has(mention))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ignoreAuthor && note.renote != null && note.renote.mentions != null && note.renote.mentions.some(mention => userIds.has(mention))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { GetterService } from '@/server/api/GetterService.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
@ -55,15 +57,23 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
private noteEntityService: NoteEntityService,
|
||||
private getterService: GetterService,
|
||||
private cacheService: CacheService,
|
||||
private roleService: RoleService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const note = await this.getterService.getNote(ps.noteId).catch(err => {
|
||||
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||
throw err;
|
||||
});
|
||||
const [userIdsWhoBlockingMe, userIdsWhoMeBlocking, isModerator, note] = await Promise.all([
|
||||
me != null && this.cacheService.userBlockedCache.fetch(me.id),
|
||||
me != null && this.cacheService.userBlockingCache.fetch(me.id),
|
||||
me != null && this.roleService.isModerator(me),
|
||||
this.getterService.getNote(ps.noteId).catch(err => {
|
||||
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote);
|
||||
throw err;
|
||||
}),
|
||||
]);
|
||||
|
||||
const conversation: MiNote[] = [];
|
||||
let i = 0;
|
||||
let length = 0;
|
||||
|
||||
const get = async (id: any) => {
|
||||
i++;
|
||||
|
@ -71,10 +81,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (p == null) return;
|
||||
|
||||
if (i > ps.offset!) {
|
||||
conversation.push(p);
|
||||
if (me == null ||
|
||||
isModerator ||
|
||||
!(userIdsWhoBlockingMe.has(p.userId) || userIdsWhoMeBlocking.has(p.userId))
|
||||
) {
|
||||
conversation.push(p);
|
||||
}
|
||||
|
||||
length += 1;
|
||||
}
|
||||
|
||||
if (conversation.length === ps.limit) {
|
||||
if (length === ps.limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { FeaturedService } from '@/core/FeaturedService.js';
|
||||
import { isUserRelated } from '@/misc/is-user-related.js';
|
||||
import { isUserMentioned } from '@/misc/is-user-mentioned.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
|
||||
export const meta = {
|
||||
|
@ -81,9 +82,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
const [
|
||||
userIdsWhoMeMuting,
|
||||
userIdsWhoBlockingMe,
|
||||
userIdsWhoMeBlocking,
|
||||
] = me ? await Promise.all([
|
||||
this.cacheService.userMutingsCache.fetch(me.id),
|
||||
this.cacheService.userBlockedCache.fetch(me.id),
|
||||
this.cacheService.userBlockingCache.fetch(me.id),
|
||||
]) : [new Set<string>(), new Set<string>()];
|
||||
|
||||
const query = this.notesRepository.createQueryBuilder('note')
|
||||
|
@ -97,8 +100,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
const notes = (await query.getMany()).filter(note => {
|
||||
if (me && isUserRelated(note, userIdsWhoBlockingMe)) return false;
|
||||
if (me && isUserRelated(note, userIdsWhoMeBlocking)) return false;
|
||||
if (me && isUserRelated(note, userIdsWhoMeMuting)) return false;
|
||||
|
||||
if (me && isUserMentioned(note, userIdsWhoBlockingMe)) return false;
|
||||
if (me && isUserMentioned(note, userIdsWhoMeBlocking)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import { FeaturedService } from '@/core/FeaturedService.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
import { isUserRelated } from '@/misc/is-user-related.js';
|
||||
import { isUserMentioned } from '@/misc/is-user-mentioned.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['notes'],
|
||||
|
@ -53,9 +54,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const userIdsWhoBlockingMe = me ? await this.cacheService.userBlockedCache.fetch(me.id) : new Set<string>();
|
||||
const userIdsWhoMeBlocking = me ? await this.cacheService.userBlockingCache.fetch(me.id) : new Set<string>();
|
||||
|
||||
// early return if me is blocked by requesting user
|
||||
if (userIdsWhoBlockingMe.has(ps.userId)) {
|
||||
if (userIdsWhoBlockingMe.has(ps.userId) || userIdsWhoMeBlocking.has(ps.userId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -90,6 +92,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (me && isUserRelated(note, userIdsWhoBlockingMe, false)) return false;
|
||||
if (me && isUserRelated(note, userIdsWhoMeMuting, true)) return false;
|
||||
|
||||
if (me && isUserMentioned(note, userIdsWhoBlockingMe)) return false;
|
||||
if (me && isUserMentioned(note, userIdsWhoMeBlocking)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import { CacheService } from '@/core/CacheService.js';
|
|||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { RoleService } from '@/core/RoleService.js';
|
||||
import { isUserRelated } from '@/misc/is-user-related.js';
|
||||
import { isUserMentioned } from '@/misc/is-user-mentioned.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
|
@ -77,6 +78,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const userIdsWhoBlockingMe = me ? await this.cacheService.userBlockedCache.fetch(me.id) : new Set<string>();
|
||||
const userIdsWhoMeBlocking = me ? await this.cacheService.userBlockingCache.fetch(me.id) : new Set<string>();
|
||||
const iAmModerator = me ? await this.roleService.isModerator(me) : false; // Moderators can see reactions of all users
|
||||
if (!iAmModerator) {
|
||||
const user = await this.cacheService.findUserById(ps.userId);
|
||||
|
@ -90,7 +92,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
}
|
||||
|
||||
// early return if me is blocked by requesting user
|
||||
if (userIdsWhoBlockingMe.has(ps.userId)) {
|
||||
if (userIdsWhoBlockingMe.has(ps.userId) || userIdsWhoMeBlocking.has(ps.userId)) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +113,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
if (me && isUserRelated(reaction.note, userIdsWhoBlockingMe)) return false;
|
||||
if (me && isUserRelated(reaction.note, userIdsWhoMeMuting)) return false;
|
||||
|
||||
if (me && isUserMentioned(note, userIdsWhoBlockingMe)) return false;
|
||||
if (me && isUserMentioned(note, userIdsWhoMeBlocking)) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
import { bindThis } from '@/decorators.js';
|
||||
import { isInstanceMuted } from '@/misc/is-instance-muted.js';
|
||||
import { isUserRelated } from '@/misc/is-user-related.js';
|
||||
import { isUserMentioned } from '@/misc/is-user-mentioned.js';
|
||||
import { isRenotePacked, isQuotePacked } from '@/misc/is-renote.js';
|
||||
import type { Packed } from '@/misc/json-schema.js';
|
||||
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
|
||||
|
@ -76,6 +77,8 @@ export default abstract class Channel {
|
|||
if (isUserRelated(note, this.userIdsWhoBlockingMe)) return true;
|
||||
if (isUserRelated(note, this.userIdsWhoMeBlocking)) return true;
|
||||
|
||||
if (isUserMentioned(note, this.userIdsWhoMeBlocking) && !isUserMentioned(note, [ this.user().id ])) return true;
|
||||
|
||||
// 流れてきたNoteがリノートをミュートしてるユーザが行ったもの
|
||||
if (isRenotePacked(note) && !isQuotePacked(note) && this.userIdsWhoMeMutingRenotes.has(note.user.id)) return true;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue