Skip to content

Commit fd0601b

Browse files
authored
fix(timeline): withReplieswithFilesを両方設定できない問題を修正 (#379)
`withFiles`の方が優先されるように
1 parent ecb45ac commit fd0601b

File tree

4 files changed

+17
-47
lines changed

4 files changed

+17
-47
lines changed

packages/backend/src/server/api/endpoints/notes/hybrid-timeline.ts

+3-22
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ export const meta = {
4343
code: 'STL_DISABLED',
4444
id: '620763f4-f621-4533-ab33-0577a1a3c342',
4545
},
46-
47-
bothWithRepliesAndWithFiles: {
48-
message: 'Specifying both withReplies and withFiles is not supported',
49-
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
50-
id: 'dfaa3eb7-8002-4cb7-bcc4-1095df46656f'
51-
},
5246
},
5347
} as const;
5448

@@ -99,8 +93,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
9993
throw new ApiError(meta.errors.stlDisabled);
10094
}
10195

102-
if (ps.withReplies && ps.withFiles) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
103-
10496
const serverSettings = await this.metaService.fetch();
10597

10698
if (!serverSettings.enableFanoutTimeline) {
@@ -123,23 +115,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
123115
}
124116

125117
let timelineConfig: FanoutTimelineName[];
126-
127118
if (ps.withFiles) {
128-
timelineConfig = [
129-
`homeTimelineWithFiles:${me.id}`,
130-
'localTimelineWithFiles',
131-
];
119+
timelineConfig = [`homeTimelineWithFiles:${me.id}`, 'localTimelineWithFiles'];
132120
} else if (ps.withReplies) {
133-
timelineConfig = [
134-
`homeTimeline:${me.id}`,
135-
'localTimeline',
136-
'localTimelineWithReplies',
137-
];
121+
timelineConfig = [`homeTimeline:${me.id}`, 'localTimeline', 'localTimelineWithReplies'];
138122
} else {
139-
timelineConfig = [
140-
`homeTimeline:${me.id}`,
141-
'localTimeline',
142-
];
123+
timelineConfig = [`homeTimeline:${me.id}`, 'localTimeline'];
143124
}
144125

145126
const redisTimeline = await this.fanoutTimelineEndpointService.timeline({

packages/backend/src/server/api/endpoints/notes/local-timeline.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { MetaService } from '@/core/MetaService.js';
1818
import { MiLocalUser } from '@/models/User.js';
1919
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
2020
import { ApiError } from '../../error.js';
21+
import { FanoutTimelineName } from "@/core/FanoutTimelineService.js";
2122

2223
export const meta = {
2324
tags: ['notes'],
@@ -38,12 +39,6 @@ export const meta = {
3839
code: 'LTL_DISABLED',
3940
id: '45a6eb02-7695-4393-b023-dd3be9aaaefd',
4041
},
41-
42-
bothWithRepliesAndWithFiles: {
43-
message: 'Specifying both withReplies and withFiles is not supported',
44-
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
45-
id: 'dd9c8400-1cb5-4eef-8a31-200c5f933793',
46-
},
4742
},
4843
} as const;
4944

@@ -87,8 +82,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
8782
throw new ApiError(meta.errors.ltlDisabled);
8883
}
8984

90-
if (ps.withReplies && ps.withFiles) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
91-
9285
const serverSettings = await this.metaService.fetch();
9386

9487
if (!serverSettings.enableFanoutTimeline) {
@@ -109,18 +102,25 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
109102
return await this.noteEntityService.packMany(timeline, me);
110103
}
111104

105+
let timelineConfig: FanoutTimelineName[];
106+
if (ps.withFiles) {
107+
timelineConfig = ['localTimelineWithFiles'];
108+
} else if (ps.withReplies) {
109+
timelineConfig = ['localTimeline', 'localTimelineWithReplies'];
110+
} else if (me) {
111+
timelineConfig = ['localTimeline', `localTimelineWithReplyTo:${me.id}`];
112+
} else {
113+
timelineConfig = ['localTimeline'];
114+
}
115+
112116
const timeline = await this.fanoutTimelineEndpointService.timeline({
113117
untilId,
114118
sinceId,
115119
limit: ps.limit,
116120
allowPartial: ps.allowPartial,
117121
me,
118122
useDbFallback: serverSettings.enableFanoutTimelineDbFallback,
119-
redisTimelines:
120-
ps.withFiles ? ['localTimelineWithFiles']
121-
: ps.withReplies ? ['localTimeline', 'localTimelineWithReplies']
122-
: me ? ['localTimeline', `localTimelineWithReplyTo:${me.id}`]
123-
: ['localTimeline'],
123+
redisTimelines: timelineConfig,
124124
alwaysIncludeMyNotes: true,
125125
excludePureRenotes: !ps.withRenotes,
126126
dbFallback: async (untilId, sinceId, limit) => await this.getFromDb({

packages/backend/src/server/api/endpoints/users/notes.ts

-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { MetaService } from '@/core/MetaService.js';
1616
import { MiLocalUser } from '@/models/User.js';
1717
import { FanoutTimelineEndpointService } from '@/core/FanoutTimelineEndpointService.js';
1818
import { FanoutTimelineName } from '@/core/FanoutTimelineService.js';
19-
import { ApiError } from '@/server/api/error.js';
2019

2120
export const meta = {
2221
tags: ['users', 'notes'],
@@ -37,12 +36,6 @@ export const meta = {
3736
code: 'NO_SUCH_USER',
3837
id: '27e494ba-2ac2-48e8-893b-10d4d8c2387b',
3938
},
40-
41-
bothWithRepliesAndWithFiles: {
42-
message: 'Specifying both withReplies and withFiles is not supported',
43-
code: 'BOTH_WITH_REPLIES_AND_WITH_FILES',
44-
id: '91c8cb9f-36ed-46e7-9ca2-7df96ed6e222',
45-
},
4639
},
4740
} as const;
4841

@@ -84,8 +77,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
8477

8578
const serverSettings = await this.metaService.fetch();
8679

87-
if (ps.withReplies && ps.withFiles) throw new ApiError(meta.errors.bothWithRepliesAndWithFiles);
88-
8980
// early return if me is blocked by requesting user
9081
if (me != null) {
9182
const userIdsWhoBlockingMe = await this.cacheService.userBlockedCache.fetch(me.id);

packages/backend/src/server/api/stream/channels/global-timeline.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class GlobalTimelineChannel extends Channel {
1919
public static shouldShare = false;
2020
public static requireCredential = false as const;
2121
private withRenotes: boolean;
22-
private withReplies: boolean;
2322
private withFiles: boolean;
2423

2524
constructor(
@@ -40,7 +39,6 @@ class GlobalTimelineChannel extends Channel {
4039
if (!policies.gtlAvailable) return;
4140

4241
this.withRenotes = params.withRenotes ?? true;
43-
this.withReplies = params.withReplies ?? false;
4442
this.withFiles = params.withFiles ?? false;
4543

4644
// Subscribe events
@@ -60,7 +58,7 @@ class GlobalTimelineChannel extends Channel {
6058
// 関係ない返信は除外
6159
if (note.reply) {
6260
const reply = note.reply;
63-
if ((this.following[note.userId]?.withReplies ?? false) || this.withReplies) {
61+
if ((this.following[note.userId]?.withReplies ?? false)) {
6462
// 自分のフォローしていないユーザーの visibility: followers な投稿への返信は弾く
6563
if (reply.visibility === 'followers' && !Object.hasOwn(this.following, reply.userId)) return;
6664
// 自分の見ることができないユーザーの visibility: specified な投稿への返信は弾く

0 commit comments

Comments
 (0)