1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2025-01-21 17:23:56 +09:00

fix(backend): withCatsがフィルタされていない問題を修正 (#485)

* Fix:withCatsがフィルタされていない問題を修正 (#323)

* del:test
This commit is contained in:
pen 2024-08-21 09:36:39 +09:00 committed by GitHub
parent 3daf8e5cf3
commit 4b284a3ddf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 1 deletions

View File

@ -19,6 +19,7 @@ class GlobalTimelineChannel extends Channel {
public static requireCredential = false as const; public static requireCredential = false as const;
private withRenotes: boolean; private withRenotes: boolean;
private withFiles: boolean; private withFiles: boolean;
private withCats: boolean;
constructor( constructor(
private metaService: MetaService, private metaService: MetaService,
@ -39,6 +40,7 @@ class GlobalTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true); this.withRenotes = !!(params.withRenotes ?? true);
this.withFiles = !!(params.withFiles ?? false); this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);
// Subscribe events // Subscribe events
this.subscriber.on('notesStream', this.onNote); this.subscriber.on('notesStream', this.onNote);
@ -47,6 +49,7 @@ class GlobalTimelineChannel extends Channel {
@bindThis @bindThis
private async onNote(note: Packed<'Note'>) { private async onNote(note: Packed<'Note'>) {
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return; 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.visibility !== 'public') return;
if (note.channelId != null) return; if (note.channelId != null) return;

View File

@ -18,6 +18,7 @@ class HomeTimelineChannel extends Channel {
public static kind = 'read:account'; public static kind = 'read:account';
private withRenotes: boolean; private withRenotes: boolean;
private withFiles: boolean; private withFiles: boolean;
private withCats: boolean;
constructor( constructor(
private noteEntityService: NoteEntityService, private noteEntityService: NoteEntityService,
@ -33,6 +34,7 @@ class HomeTimelineChannel extends Channel {
public async init(params: JsonObject) { public async init(params: JsonObject) {
this.withRenotes = !!(params.withRenotes ?? true); this.withRenotes = !!(params.withRenotes ?? true);
this.withFiles = !!(params.withFiles ?? false); this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);
this.subscriber.on('notesStream', this.onNote); this.subscriber.on('notesStream', this.onNote);
} }
@ -42,6 +44,7 @@ class HomeTimelineChannel extends Channel {
const isMe = this.user!.id === note.userId; const isMe = this.user!.id === note.userId;
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return; 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 (note.channelId) {
if (!this.followingChannels.has(note.channelId)) return; if (!this.followingChannels.has(note.channelId)) return;

View File

@ -21,6 +21,7 @@ class HybridTimelineChannel extends Channel {
private withRenotes: boolean; private withRenotes: boolean;
private withReplies: boolean; private withReplies: boolean;
private withFiles: boolean; private withFiles: boolean;
private withCats: boolean;
constructor( constructor(
private metaService: MetaService, private metaService: MetaService,
@ -42,6 +43,7 @@ class HybridTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true); this.withRenotes = !!(params.withRenotes ?? true);
this.withReplies = !!(params.withReplies ?? false); this.withReplies = !!(params.withReplies ?? false);
this.withFiles = !!(params.withFiles ?? false); this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);
// Subscribe events // Subscribe events
this.subscriber.on('notesStream', this.onNote); this.subscriber.on('notesStream', this.onNote);
@ -52,6 +54,7 @@ class HybridTimelineChannel extends Channel {
const isMe = this.user!.id === note.userId; const isMe = this.user!.id === note.userId;
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return; if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return;
if (this.withCats && (note.user.isCat == null || note.user.isCat === false)) return;
// チャンネルの投稿ではなく、自分自身の投稿 または // チャンネルの投稿ではなく、自分自身の投稿 または
// チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または // チャンネルの投稿ではなく、その投稿のユーザーをフォローしている または

View File

@ -20,6 +20,7 @@ class LocalTimelineChannel extends Channel {
private withRenotes: boolean; private withRenotes: boolean;
private withReplies: boolean; private withReplies: boolean;
private withFiles: boolean; private withFiles: boolean;
private withCats: boolean;
constructor( constructor(
private metaService: MetaService, private metaService: MetaService,
@ -41,6 +42,7 @@ class LocalTimelineChannel extends Channel {
this.withRenotes = !!(params.withRenotes ?? true); this.withRenotes = !!(params.withRenotes ?? true);
this.withReplies = !!(params.withReplies ?? false); this.withReplies = !!(params.withReplies ?? false);
this.withFiles = !!(params.withFiles ?? false); this.withFiles = !!(params.withFiles ?? false);
this.withCats = !!(params.withCats ?? false);
// Subscribe events // Subscribe events
this.subscriber.on('notesStream', this.onNote); this.subscriber.on('notesStream', this.onNote);
@ -49,6 +51,7 @@ class LocalTimelineChannel extends Channel {
@bindThis @bindThis
private async onNote(note: Packed<'Note'>) { private async onNote(note: Packed<'Note'>) {
if (this.withFiles && (note.fileIds == null || note.fileIds.length === 0)) return; 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.user.host !== null) return;
if (note.visibility !== 'public') return; if (note.visibility !== 'public') return;

View File

@ -7,9 +7,9 @@ process.env.NODE_ENV = 'test';
import * as assert from 'assert'; import * as assert from 'assert';
import { WebSocket } from 'ws'; import { WebSocket } from 'ws';
import { MiFollowing } from '@/models/Following.js';
import { api, createAppToken, initTestDb, port, post, signup, waitFire } from '../utils.js'; import { api, createAppToken, initTestDb, port, post, signup, waitFire } from '../utils.js';
import type * as misskey from 'cherrypick-js'; import type * as misskey from 'cherrypick-js';
import { MiFollowing } from '@/models/Following.js';
describe('Streaming', () => { describe('Streaming', () => {
let Followings: any; let Followings: any;
@ -306,6 +306,33 @@ describe('Streaming', () => {
assert.strictEqual(fired, true); 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 () => { test('withReplies: true のとき自分のfollowers投稿に対するリプライが流れる', async () => {
const erinNote = await post(erin, { text: 'hi', visibility: 'followers' }); const erinNote = await post(erin, { text: 'hi', visibility: 'followers' });
const fired = await waitFire( const fired = await waitFire(