Skip to content

Commit

Permalink
Merge pull request #108 from anatawa12/fix-user-include-sensitive-cha…
Browse files Browse the repository at this point in the history
…nnel

fix: includeSensitiveChannel not working for funout timeline
  • Loading branch information
anatawa12 authored Nov 28, 2023
2 parents 223b4eb + a2f50ff commit 092881e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
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 () => {
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

0 comments on commit 092881e

Please sign in to comment.