pass NoteEntityService through Channel constructor instead of method args

This commit is contained in:
Hazelnoot 2025-02-25 20:52:14 -05:00
parent de3c9124cd
commit 019e60d9a4
18 changed files with 60 additions and 37 deletions

View file

@ -17,6 +17,7 @@ import type Connection from './Connection.js';
*/
// eslint-disable-next-line import/no-default-export
export default abstract class Channel {
protected readonly noteEntityService: NoteEntityService;
protected connection: Connection;
public id: string;
public abstract readonly chName: string;
@ -82,8 +83,10 @@ export default abstract class Channel {
}
constructor(id: string, connection: Connection) {
constructor(id: string, connection: Connection, noteEntityService: NoteEntityService) {
this.id = id;
this.connection = connection;
this.noteEntityService = noteEntityService;
}
public send(payload: { type: string, body: JsonValue }): void
@ -106,7 +109,7 @@ export default abstract class Channel {
public onMessage?(type: string, body: JsonValue): void;
public async assignMyReaction(note: Packed<'Note'>, noteEntityService: NoteEntityService): Promise<Packed<'Note'>> {
public async assignMyReaction(note: Packed<'Note'>): Promise<Packed<'Note'>> {
let changed = false;
// StreamingApiServerService creates a single EventEmitter per server process,
// so a new note arriving from redis gets de-serialised once per server process,
@ -116,7 +119,7 @@ export default abstract class Channel {
const clonedNote = { ...note };
if (this.user && isRenotePacked(note) && !isQuotePacked(note)) {
if (note.renote && Object.keys(note.renote.reactions).length > 0) {
const myReaction = await noteEntityService.populateMyReaction(note.renote, this.user.id);
const myReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
if (myReaction) {
changed = true;
clonedNote.renote = { ...note.renote };
@ -124,7 +127,7 @@ export default abstract class Channel {
}
}
if (note.renote?.reply && Object.keys(note.renote.reply.reactions).length > 0) {
const myReaction = await noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
const myReaction = await this.noteEntityService.populateMyReaction(note.renote.reply, this.user.id);
if (myReaction) {
changed = true;
clonedNote.renote = { ...note.renote };
@ -134,7 +137,7 @@ export default abstract class Channel {
}
}
if (this.user && note.reply && Object.keys(note.reply.reactions).length > 0) {
const myReaction = await noteEntityService.populateMyReaction(note.reply, this.user.id);
const myReaction = await this.noteEntityService.populateMyReaction(note.reply, this.user.id);
if (myReaction) {
changed = true;
clonedNote.reply = { ...note.reply };

View file

@ -6,6 +6,7 @@
import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import type { JsonObject } from '@/misc/json-value.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import Channel, { type MiChannelService } from '../channel.js';
class AdminChannel extends Channel {
@ -30,6 +31,7 @@ export class AdminChannelService implements MiChannelService<true> {
public readonly kind = AdminChannel.kind;
constructor(
private readonly noteEntityService: NoteEntityService,
) {
}
@ -38,6 +40,7 @@ export class AdminChannelService implements MiChannelService<true> {
return new AdminChannel(
id,
connection,
this.noteEntityService,
);
}
}

View file

@ -18,12 +18,12 @@ class AntennaChannel extends Channel {
private antennaId: string;
constructor(
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onEvent = this.onEvent.bind(this);
}

View file

@ -26,12 +26,12 @@ class BubbleTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
private roleService: RoleService,
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
}
@bindThis
@ -63,7 +63,7 @@ class BubbleTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
const clonedNote = await this.assignMyReaction(note);
this.connection.cacheNote(clonedNote);

View file

@ -20,12 +20,12 @@ class ChannelChannel extends Channel {
private withRenotes: boolean;
constructor(
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}

View file

@ -6,6 +6,7 @@
import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import type { JsonObject } from '@/misc/json-value.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import Channel, { type MiChannelService } from '../channel.js';
class DriveChannel extends Channel {
@ -30,6 +31,7 @@ export class DriveChannelService implements MiChannelService<true> {
public readonly kind = DriveChannel.kind;
constructor(
private readonly noteEntityService: NoteEntityService,
) {
}
@ -38,6 +40,7 @@ export class DriveChannelService implements MiChannelService<true> {
return new DriveChannel(
id,
connection,
this.noteEntityService,
);
}
}

View file

@ -24,12 +24,12 @@ class GlobalTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
private roleService: RoleService,
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}
@ -60,7 +60,7 @@ class GlobalTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
const clonedNote = await this.assignMyReaction(note);
this.connection.cacheNote(clonedNote);

View file

@ -19,12 +19,12 @@ class HashtagChannel extends Channel {
private q: string[][];
constructor(
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}

View file

@ -20,12 +20,12 @@ class HomeTimelineChannel extends Channel {
private withFiles: boolean;
constructor(
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}
@ -81,7 +81,7 @@ class HomeTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
const clonedNote = await this.assignMyReaction(note);
this.connection.cacheNote(clonedNote);

View file

@ -26,12 +26,12 @@ class HybridTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
private roleService: RoleService,
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}
@ -98,7 +98,7 @@ class HybridTimelineChannel extends Channel {
}
}
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
const clonedNote = await this.assignMyReaction(note);
this.connection.cacheNote(clonedNote);

View file

@ -25,12 +25,12 @@ class LocalTimelineChannel extends Channel {
constructor(
private metaService: MetaService,
private roleService: RoleService,
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}
@ -70,7 +70,7 @@ class LocalTimelineChannel extends Channel {
if (this.isNoteMutedOrBlocked(note)) return;
const clonedNote = await this.assignMyReaction(note, this.noteEntityService);
const clonedNote = await this.assignMyReaction(note);
this.connection.cacheNote(clonedNote);

View file

@ -17,12 +17,12 @@ class MainChannel extends Channel {
public static kind = 'read:account';
constructor(
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
}
@bindThis

View file

@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import { isJsonObject } from '@/misc/json-value.js';
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import Channel, { type MiChannelService } from '../channel.js';
const ev = new Xev();
@ -17,8 +18,8 @@ class QueueStatsChannel extends Channel {
public static shouldShare = true;
public static requireCredential = false as const;
constructor(id: string, connection: Channel['connection']) {
super(id, connection);
constructor(id: string, connection: Channel['connection'], noteEntityService: NoteEntityService) {
super(id, connection, noteEntityService);
//this.onStats = this.onStats.bind(this);
//this.onMessage = this.onMessage.bind(this);
}
@ -64,6 +65,7 @@ export class QueueStatsChannelService implements MiChannelService<false> {
public readonly kind = QueueStatsChannel.kind;
constructor(
private readonly noteEntityService: NoteEntityService,
) {
}
@ -72,6 +74,7 @@ export class QueueStatsChannelService implements MiChannelService<false> {
return new QueueStatsChannel(
id,
connection,
this.noteEntityService,
);
}
}

View file

@ -11,6 +11,7 @@ import { ReversiService } from '@/core/ReversiService.js';
import { ReversiGameEntityService } from '@/core/entities/ReversiGameEntityService.js';
import { isJsonObject } from '@/misc/json-value.js';
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import Channel, { type MiChannelService } from '../channel.js';
import { reversiUpdateKeys } from 'misskey-js';
@ -23,11 +24,12 @@ class ReversiGameChannel extends Channel {
constructor(
private reversiService: ReversiService,
private reversiGameEntityService: ReversiGameEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
}
@bindThis
@ -116,6 +118,7 @@ export class ReversiGameChannelService implements MiChannelService<false> {
constructor(
private reversiService: ReversiService,
private reversiGameEntityService: ReversiGameEntityService,
private noteEntityService: NoteEntityService,
) {
}
@ -124,6 +127,7 @@ export class ReversiGameChannelService implements MiChannelService<false> {
return new ReversiGameChannel(
this.reversiService,
this.reversiGameEntityService,
this.noteEntityService,
id,
connection,
);

View file

@ -6,6 +6,7 @@
import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import type { JsonObject } from '@/misc/json-value.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import Channel, { type MiChannelService } from '../channel.js';
class ReversiChannel extends Channel {
@ -17,8 +18,9 @@ class ReversiChannel extends Channel {
constructor(
id: string,
connection: Channel['connection'],
noteEntityService: NoteEntityService,
) {
super(id, connection);
super(id, connection, noteEntityService);
}
@bindThis
@ -40,6 +42,7 @@ export class ReversiChannelService implements MiChannelService<true> {
public readonly kind = ReversiChannel.kind;
constructor(
private readonly noteEntityService: NoteEntityService,
) {
}
@ -48,6 +51,7 @@ export class ReversiChannelService implements MiChannelService<true> {
return new ReversiChannel(
id,
connection,
this.noteEntityService,
);
}
}

View file

@ -18,13 +18,13 @@ class RoleTimelineChannel extends Channel {
private roleId: string;
constructor(
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
private roleservice: RoleService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.onNote = this.onNote.bind(this);
}

View file

@ -8,6 +8,7 @@ import { Injectable } from '@nestjs/common';
import { bindThis } from '@/decorators.js';
import { isJsonObject } from '@/misc/json-value.js';
import type { JsonObject, JsonValue } from '@/misc/json-value.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import Channel, { type MiChannelService } from '../channel.js';
const ev = new Xev();
@ -17,8 +18,8 @@ class ServerStatsChannel extends Channel {
public static shouldShare = true;
public static requireCredential = false as const;
constructor(id: string, connection: Channel['connection']) {
super(id, connection);
constructor(id: string, connection: Channel['connection'], noteEntityService: NoteEntityService) {
super(id, connection, noteEntityService);
//this.onStats = this.onStats.bind(this);
//this.onMessage = this.onMessage.bind(this);
}
@ -62,6 +63,7 @@ export class ServerStatsChannelService implements MiChannelService<false> {
public readonly kind = ServerStatsChannel.kind;
constructor(
private readonly noteEntityService: NoteEntityService,
) {
}
@ -70,6 +72,7 @@ export class ServerStatsChannelService implements MiChannelService<false> {
return new ServerStatsChannel(
id,
connection,
this.noteEntityService,
);
}
}

View file

@ -26,12 +26,12 @@ class UserListChannel extends Channel {
constructor(
private userListsRepository: UserListsRepository,
private userListMembershipsRepository: UserListMembershipsRepository,
private noteEntityService: NoteEntityService,
noteEntityService: NoteEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
super(id, connection, noteEntityService);
//this.updateListUsers = this.updateListUsers.bind(this);
//this.onNote = this.onNote.bind(this);
}