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

fix: includeSensitiveChannel not working for funout timeline #108

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
### Client

### Server
- Fix: includeSensitiveChannelがfunout timelineの範囲では機能しない問題

## 2023.11.1-kinel.2

Expand Down
7 changes: 4 additions & 3 deletions packages/backend/src/server/api/endpoints/users/notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const paramDef = {
untilDate: { type: 'integer' },
withFiles: { type: 'boolean', default: false },
excludeNsfw: { type: 'boolean', default: false },
includeSensitiveChannel: { type: 'boolean', default: false },
includeSensitiveChannel: { type: 'boolean' },
},
required: ['userId'],
} as const;
Expand All @@ -78,6 +78,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const sinceId = ps.sinceId ?? (ps.sinceDate ? this.idService.gen(ps.sinceDate!) : null);
const isRangeSpecified = untilId != null && sinceId != null;
const isSelf = me && (me.id === ps.userId);
const includeSensitiveChannel = ps.includeSensitiveChannel ?? isSelf;

if (isRangeSpecified || sinceId == null) {
const [
Expand Down Expand Up @@ -123,7 +124,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
}

if (note.channel?.isSensitive && !isSelf) return false;
if (note.channel?.isSensitive && !includeSensitiveChannel) return false;
if (note.visibility === 'specified' && (!me || (me.id !== note.userId && !note.visibleUserIds.some(v => v === me.id)))) return false;
if (note.visibility === 'followers' && !isFollowing && !isSelf) return false;

Expand Down Expand Up @@ -151,7 +152,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
.leftJoinAndSelect('renote.user', 'renoteUser');

if (ps.withChannelNotes) {
if (!ps.includeSensitiveChannel) query.andWhere(new Brackets(qb => {
if (!includeSensitiveChannel) query.andWhere(new Brackets(qb => {
qb.orWhere('note.channelId IS NULL');
qb.orWhere('channel.isSensitive = false');
}));
Expand Down
26 changes: 26 additions & 0 deletions packages/backend/test/e2e/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,32 @@ describe('Timelines', () => {
assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true);
});

test.concurrent('[withChannelNotes: true, includeSensitiveChannel: true] 他人が取得した場合もセンシティブチャンネル投稿が含まれる', async () => {
const [alice, bob] = await Promise.all([signup(), signup()]);

const channel = await api('/channels/create', { name: 'channel', isSensitive: true }, bob).then(x => x.body);
const bobNote = await post(bob, { text: 'hi', channelId: channel.id });

await waitForPushToTl();

const res = await api('/users/notes', { userId: bob.id, withChannelNotes: true, includeSensitiveChannel: true }, alice);

assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), true);
});

test.concurrent('[withChannelNotes: true, includeSensitiveChannel: false] 自分が取得したも場合センシティブチャンネル投稿が含まれない', async () => {
anatawa12 marked this conversation as resolved.
Show resolved Hide resolved
const [bob] = await Promise.all([signup()]);

const channel = await api('/channels/create', { name: 'channel', isSensitive: true }, bob).then(x => x.body);
const bobNote = await post(bob, { text: 'hi', channelId: channel.id });

await waitForPushToTl();

const res = await api('/users/notes', { userId: bob.id, withChannelNotes: true, includeSensitiveChannel: false }, bob);

assert.strictEqual(res.body.some((note: any) => note.id === bobNote.id), false);
});

test.concurrent('ミュートしているユーザーに関連する投稿が含まれない', async () => {
const [alice, bob, carol] = await Promise.all([signup(), signup(), signup()]);

Expand Down
Loading