Loosen block restrictions
This commit is contained in:
parent
2991122668
commit
a851b94b01
10 changed files with 86 additions and 19 deletions
|
@ -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