Skip to content

Commit

Permalink
fix(backend): withCatsがフィルタされていない問題を修正 (yojo-art#485)
Browse files Browse the repository at this point in the history
* Fix:withCatsがフィルタされていない問題を修正 (yojo-art#323)

* del:test
  • Loading branch information
penginn-net authored Aug 21, 2024
1 parent 3daf8e5 commit 4b284a3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
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
29 changes: 28 additions & 1 deletion packages/backend/test/e2e/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ process.env.NODE_ENV = 'test';

import * as assert from 'assert';
import { WebSocket } from 'ws';
import { MiFollowing } from '@/models/Following.js';
import { api, createAppToken, initTestDb, port, post, signup, waitFire } from '../utils.js';
import type * as misskey from 'cherrypick-js';
import { MiFollowing } from '@/models/Following.js';

describe('Streaming', () => {
let Followings: any;
Expand Down 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

0 comments on commit 4b284a3

Please sign in to comment.