なんかもうめっちゃ変えた

This commit is contained in:
syuilo 2022-09-18 03:27:08 +09:00 committed by GitHub
parent d9ab03f086
commit b75184ec8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
946 changed files with 41219 additions and 28839 deletions

View file

@ -1,11 +1,14 @@
import Channel from '../channel.js';
import { Notes, Users } from '@/models/index.js';
import { Inject, Injectable } from '@nestjs/common';
import type { NotesRepository, UsersRepository } from '@/models/index.js';
import { isUserRelated } from '@/misc/is-user-related.js';
import { User } from '@/models/entities/user.js';
import { StreamMessages } from '../types.js';
import { Packed } from '@/misc/schema.js';
import type { User } from '@/models/entities/User.js';
import type { Packed } from '@/misc/schema.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import Channel from '../channel.js';
import type { StreamMessages } from '../types.js';
export default class extends Channel {
class ChannelChannel extends Channel {
public readonly chName = 'channel';
public static shouldShare = false;
public static requireCredential = false;
@ -13,7 +16,13 @@ export default class extends Channel {
private typers: Record<User['id'], Date> = {};
private emitTypersIntervalId: ReturnType<typeof setInterval>;
constructor(id: string, connection: Channel['connection']) {
constructor(
private noteEntityService: NoteEntityService,
private userEntityService: UserEntityService,
id: string,
connection: Channel['connection'],
) {
super(id, connection);
this.onNote = this.onNote.bind(this);
this.emitTypers = this.emitTypers.bind(this);
@ -33,13 +42,13 @@ export default class extends Channel {
// リプライなら再pack
if (note.replyId != null) {
note.reply = await Notes.pack(note.replyId, this.user, {
note.reply = await this.noteEntityService.pack(note.replyId, this.user, {
detail: true,
});
}
// Renoteなら再pack
if (note.renoteId != null) {
note.renote = await Notes.pack(note.renoteId, this.user, {
note.renote = await this.noteEntityService.pack(note.renoteId, this.user, {
detail: true,
});
}
@ -73,7 +82,7 @@ export default class extends Channel {
if (now.getTime() - date.getTime() > 5000) delete this.typers[userId];
}
const users = await Users.packMany(Object.keys(this.typers), null, { detail: false });
const users = await this.userEntityService.packMany(Object.keys(this.typers), null, { detail: false });
this.send({
type: 'typers',
@ -89,3 +98,24 @@ export default class extends Channel {
clearInterval(this.emitTypersIntervalId);
}
}
@Injectable()
export class ChannelChannelService {
public readonly shouldShare = ChannelChannel.shouldShare;
public readonly requireCredential = ChannelChannel.requireCredential;
constructor(
private noteEntityService: NoteEntityService,
private userEntityService: UserEntityService,
) {
}
public create(id: string, connection: Channel['connection']): ChannelChannel {
return new ChannelChannel(
this.noteEntityService,
this.userEntityService,
id,
connection,
);
}
}