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:withCatsがフィルタされていない問題を修正 #323

Merged
merged 9 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG_yojo.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- Fix:通知ポップアップにも通知削除ボタンが表示される

### Server
-
- Fix:withCats(ネコミミ付きのみのstreaming)がフィルタされていない問題を修正 [#323](https://github.com/yojo-art/cherrypick/pull/323)

### Misc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GlobalTimelineChannel extends Channel {
public static requireCredential = false as const;
private withRenotes: boolean;
private withFiles: boolean;
private withCats: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -39,6 +40,7 @@ class GlobalTimelineChannel extends Channel {

this.withRenotes = !!(params.withRenotes ?? true);
this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand All @@ -47,6 +49,7 @@ class GlobalTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (this.withCats && (note.user.isCat == null || note.user.isCat === false)) return;

if (note.visibility !== 'public') return;
if (note.channelId != null) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class HomeTimelineChannel extends Channel {
public static kind = 'read:account';
private withRenotes: boolean;
private withFiles: boolean;
private withCats: boolean;

constructor(
private noteEntityService: NoteEntityService,
Expand All @@ -33,6 +34,7 @@ class HomeTimelineChannel extends Channel {
public async init(params: JsonObject) {
this.withRenotes = !!(params.withRenotes ?? true);
this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);

this.subscriber.on('notesStream', this.onNote);
}
Expand All @@ -42,6 +44,7 @@ class HomeTimelineChannel extends Channel {
const isMe = this.user!.id === note.userId;

if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (this.withCats && (note.user.isCat == null || note.user.isCat === false)) return;

if (note.channelId) {
if (!this.followingChannels.has(note.channelId)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HybridTimelineChannel extends Channel {
private withRenotes: boolean;
private withReplies: boolean;
private withFiles: boolean;
private withCats: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -42,6 +43,7 @@ class HybridTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true);
this.withReplies = !!(params.withReplies ?? false);
this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand All @@ -52,6 +54,7 @@ class HybridTimelineChannel extends Channel {
const isMe = this.user!.id === note.userId;

if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (this.withCats && (note.user.isCat == null || note.user.isCat === false)) return;

// チャンネルの投稿ではなく、自分自身の投稿 または
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LocalTimelineChannel extends Channel {
private withRenotes: boolean;
private withReplies: boolean;
private withFiles: boolean;
private withCats: boolean;

constructor(
private metaService: MetaService,
Expand All @@ -41,6 +42,7 @@ class LocalTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true);
this.withReplies = !!(params.withReplies ?? false);
this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);

// Subscribe events
this.subscriber.on('notesStream', this.onNote);
Expand All @@ -49,6 +51,7 @@ class LocalTimelineChannel extends Channel {
@bindThis
private async onNote(note: Packed<'Note'>) {
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (this.withCats && (note.user.isCat == null || note.user.isCat === false)) return;

if (note.user.host !== null) return;
if (note.visibility !== 'public') return;
Expand Down
111 changes: 111 additions & 0 deletions packages/backend/test/e2e/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,33 @@ describe('Streaming', () => {
assert.strictEqual(fired, true);
});

test('withCats: true のときノートが流れる', async () => {
await api('i/update', {
isCat: true,
}, kyoko);
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'meow' }, kyoko), // cat kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, true);
await api('i/update', {
isCat: false,
}, kyoko);
});

test('withCats: true のときノートが流れない', async () => {
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'test' }, kyoko), // kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, false);
});
test('withReplies: true のとき自分のfollowers投稿に対するリプライが流れる', async () => {
const erinNote = await post(erin, { text: 'hi', visibility: 'followers' });
const fired = await waitFire(
Expand Down Expand Up @@ -401,6 +428,34 @@ describe('Streaming', () => {

assert.strictEqual(fired, false);
});

test('withCats: true のときノートが流れる', async () => {
await api('i/update', {
isCat: true,
}, kyoko);
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'meow' }, kyoko), // cat kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, true);
await api('i/update', {
isCat: false,
}, kyoko);
});

test('withCats: true のときノートが流れない', async () => {
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'test' }, kyoko), // kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, false);
});
});

describe('Hybrid Timeline', () => {
Expand Down Expand Up @@ -537,6 +592,34 @@ describe('Streaming', () => {

assert.strictEqual(fired, false);
});

test('withCats: true のときノートが流れる', async () => {
await api('i/update', {
isCat: true,
}, kyoko);
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'meow' }, kyoko), // cat kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, true);
await api('i/update', {
isCat: false,
}, kyoko);
});

test('withCats: true のときノートが流れない', async () => {
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'test' }, kyoko), // kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, false);
});
});

describe('Global Timeline', () => {
Expand Down Expand Up @@ -581,6 +664,34 @@ describe('Streaming', () => {

assert.strictEqual(fired, true);
});

test('withCats: true のときノートが流れる', async () => {
await api('i/update', {
isCat: true,
}, kyoko);
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'meow' }, kyoko), // cat kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, true);
await api('i/update', {
isCat: false,
}, kyoko);
});

test('withCats: true のときノートが流れない', async () => {
const fired = await waitFire(
ayano, 'homeTimeline', // ayano:home
() => api('notes/create', { text: 'test' }, kyoko), // kyoko note
msg => msg.type === 'note' && msg.body.userId === kyoko.id, // wait kyoko
{ withCats: true },
);

assert.strictEqual(fired, false);
});
});

describe('UserList Timeline', () => {
Expand Down
Loading