fix(timeline): withReplieswithFilesを両方設定できない問題を修正 (MisskeyIO#379)

`withFiles`の方が優先されるように
This commit is contained in:
まっちゃとーにゅ 2024-01-24 04:32:24 +09:00 committed by GitHub
parent ecb45acb62
commit fd0601bde4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 17 additions and 47 deletions

View file

@ -43,12 +43,6 @@ export const meta = {
code: 'STL_DISABLED', code: 'STL_DISABLED',
id: '620763f4-f621-4533-ab33-0577a1a3c342', id: '620763f4-f621-4533-ab33-0577a1a3c342',
}, },
bothWithRepliesAndWithFiles: {
message: 'Specifying both withReplies and withFiles is not supported',
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
id: 'dfaa3eb7-8002-4cb7-bcc4-1095df46656f'
},
}, },
} as const; } as const;
@ -99,8 +93,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.stlDisabled); throw new ApiError(meta.errors.stlDisabled);
} }
if (ps.withReplies && ps.withFiles) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
const serverSettings = await this.metaService.fetch(); const serverSettings = await this.metaService.fetch();
if (!serverSettings.enableFanoutTimeline) { if (!serverSettings.enableFanoutTimeline) {
@ -123,23 +115,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
} }
let timelineConfig: FanoutTimelineName[]; let timelineConfig: FanoutTimelineName[];
if (ps.withFiles) { if (ps.withFiles) {
timelineConfig = [ timelineConfig = [`homeTimelineWithFiles:${me.id}`, 'localTimelineWithFiles'];
`homeTimelineWithFiles:${me.id}`,
'localTimelineWithFiles',
];
} else if (ps.withReplies) { } else if (ps.withReplies) {
timelineConfig = [ timelineConfig = [`homeTimeline:${me.id}`, 'localTimeline', 'localTimelineWithReplies'];
`homeTimeline:${me.id}`,
'localTimeline',
'localTimelineWithReplies',
];
} else { } else {
timelineConfig = [ timelineConfig = [`homeTimeline:${me.id}`, 'localTimeline'];
`homeTimeline:${me.id}`,
'localTimeline',
];
} }
const redisTimeline = await this.fanoutTimelineEndpointService.timeline({ const redisTimeline = await this.fanoutTimelineEndpointService.timeline({

View file

@ -18,6 +18,7 @@ import { MetaService } from '@/core/MetaService.js';
import { MiLocalUser } from '@/models/User.js'; import { MiLocalUser } from '@/models/User.js';
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js'; import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { FanoutTimelineName } from "@/core/FanoutTimelineService.js";
export const meta = { export const meta = {
tags: ['notes'], tags: ['notes'],
@ -38,12 +39,6 @@ export const meta = {
code: 'LTL_DISABLED', code: 'LTL_DISABLED',
id: '45a6eb02-7695-4393-b023-dd3be9aaaefd', id: '45a6eb02-7695-4393-b023-dd3be9aaaefd',
}, },
bothWithRepliesAndWithFiles: {
message: 'Specifying both withReplies and withFiles is not supported',
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
id: 'dd9c8400-1cb5-4eef-8a31-200c5f933793',
},
}, },
} as const; } as const;
@ -87,8 +82,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
throw new ApiError(meta.errors.ltlDisabled); throw new ApiError(meta.errors.ltlDisabled);
} }
if (ps.withReplies && ps.withFiles) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
const serverSettings = await this.metaService.fetch(); const serverSettings = await this.metaService.fetch();
if (!serverSettings.enableFanoutTimeline) { if (!serverSettings.enableFanoutTimeline) {
@ -109,6 +102,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
return await this.noteEntityService.packMany(timeline, me); return await this.noteEntityService.packMany(timeline, me);
} }
let timelineConfig: FanoutTimelineName[];
if (ps.withFiles) {
timelineConfig = ['localTimelineWithFiles'];
} else if (ps.withReplies) {
timelineConfig = ['localTimeline', 'localTimelineWithReplies'];
} else if (me) {
timelineConfig = ['localTimeline', `localTimelineWithReplyTo:${me.id}`];
} else {
timelineConfig = ['localTimeline'];
}
const timeline = await this.fanoutTimelineEndpointService.timeline({ const timeline = await this.fanoutTimelineEndpointService.timeline({
untilId, untilId,
sinceId, sinceId,
@ -116,11 +120,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
allowPartial: ps.allowPartial, allowPartial: ps.allowPartial,
me, me,
useDbFallback: serverSettings.enableFanoutTimelineDbFallback, useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
redisTimelines: redisTimelines: timelineConfig,
ps.withFiles ? ['localTimelineWithFiles']
: ps.withReplies ? ['localTimeline', 'localTimelineWithReplies']
: me ? ['localTimeline', `localTimelineWithReplyTo:${me.id}`]
: ['localTimeline'],
alwaysIncludeMyNotes: true, alwaysIncludeMyNotes: true,
excludePureRenotes: !ps.withRenotes, excludePureRenotes: !ps.withRenotes,
dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({ dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({

View file

@ -16,7 +16,6 @@ import { MetaService } from '@/core/MetaService.js';
import { MiLocalUser } from '@/models/User.js'; import { MiLocalUser } from '@/models/User.js';
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js'; import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
import { FanoutTimelineName } from '@/core/FanoutTimelineService.js'; import { FanoutTimelineName } from '@/core/FanoutTimelineService.js';
import { ApiError } from '@/server/api/error.js';
export const meta = { export const meta = {
tags: ['users', 'notes'], tags: ['users', 'notes'],
@ -37,12 +36,6 @@ export const meta = {
code: 'NO_SUCH_USER', code: 'NO_SUCH_USER',
id: '27e494ba-2ac2-48e8-893b-10d4d8c2387b', id: '27e494ba-2ac2-48e8-893b-10d4d8c2387b',
}, },
bothWithRepliesAndWithFiles: {
message: 'Specifying both withReplies and withFiles is not supported',
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
id: '91c8cb9f-36ed-46e7-9ca2-7df96ed6e222',
},
}, },
} as const; } as const;
@ -84,8 +77,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const serverSettings = await this.metaService.fetch(); const serverSettings = await this.metaService.fetch();
if (ps.withReplies && ps.withFiles) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
// early return if me is blocked by requesting user // early return if me is blocked by requesting user
if (me != null) { if (me != null) {
const userIdsWhoBlockingMe = await this.cacheService.userBlockedCache.fetch(me.id); const userIdsWhoBlockingMe = await this.cacheService.userBlockedCache.fetch(me.id);

View file

@ -19,7 +19,6 @@ class GlobalTimelineChannel extends Channel {
public static shouldShare = false; public static shouldShare = false;
public static requireCredential = false as const; public static requireCredential = false as const;
private withRenotes: boolean; private withRenotes: boolean;
private withReplies: boolean;
private withFiles: boolean; private withFiles: boolean;
constructor( constructor(
@ -40,7 +39,6 @@ class GlobalTimelineChannel extends Channel {
if (!policies.gtlAvailable) return; if (!policies.gtlAvailable) return;
this.withRenotes = params.withRenotes ?? true; this.withRenotes = params.withRenotes ?? true;
this.withReplies = params.withReplies ?? false;
this.withFiles = params.withFiles ?? false; this.withFiles = params.withFiles ?? false;
// Subscribe events // Subscribe events
@ -60,7 +58,7 @@ class GlobalTimelineChannel extends Channel {
// 関係ない返信は除外 // 関係ない返信は除外
if (note.reply) { if (note.reply) {
const reply = note.reply; const reply = note.reply;
if ((this.following[note.userId]?.withReplies ?? false) || this.withReplies) { if ((this.following[note.userId]?.withReplies ?? false)) {
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く // 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return; if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return;
// 自分の見ることができないユーザーの visibility: specified な投稿への返信は弾く // 自分の見ることができないユーザーの visibility: specified な投稿への返信は弾く