wip
This commit is contained in:
parent
c1be538ccf
commit
d7dfcb26d5
|
@ -16,6 +16,7 @@ import type { UsersRepository, NotesRepository, FollowingsRepository, PollsRepos
|
|||
import { bindThis } from '@/decorators.js';
|
||||
import { isNotNull } from '@/misc/is-not-null.js';
|
||||
import { DebounceLoader } from '@/misc/loader.js';
|
||||
import { IdService } from '@/core/IdService.js';
|
||||
import type { OnModuleInit } from '@nestjs/common';
|
||||
import type { CustomEmojiService } from '../CustomEmojiService.js';
|
||||
import type { ReactionService } from '../ReactionService.js';
|
||||
|
@ -28,6 +29,7 @@ export class NoteEntityService implements OnModuleInit {
|
|||
private driveFileEntityService: DriveFileEntityService;
|
||||
private customEmojiService: CustomEmojiService;
|
||||
private reactionService: ReactionService;
|
||||
private idService: IdService;
|
||||
private noteLoader = new DebounceLoader(this.findNoteOrFail);
|
||||
|
||||
constructor(
|
||||
|
@ -66,6 +68,7 @@ export class NoteEntityService implements OnModuleInit {
|
|||
this.driveFileEntityService = this.moduleRef.get('DriveFileEntityService');
|
||||
this.customEmojiService = this.moduleRef.get('CustomEmojiService');
|
||||
this.reactionService = this.moduleRef.get('ReactionService');
|
||||
this.idService = this.moduleRef.get('IdService');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
@ -167,11 +170,11 @@ export class NoteEntityService implements OnModuleInit {
|
|||
}
|
||||
|
||||
@bindThis
|
||||
private async populateMyReaction(note: MiNote, meId: MiUser['id'], _hint_?: {
|
||||
public async populateMyReaction(noteId: MiNote['id'], meId: MiUser['id'], _hint_?: {
|
||||
myReactions: Map<MiNote['id'], MiNoteReaction | null>;
|
||||
}) {
|
||||
if (_hint_?.myReactions) {
|
||||
const reaction = _hint_.myReactions.get(note.id);
|
||||
const reaction = _hint_.myReactions.get(noteId);
|
||||
if (reaction) {
|
||||
return this.reactionService.convertLegacyReaction(reaction.reaction);
|
||||
} else if (reaction === null) {
|
||||
|
@ -181,13 +184,13 @@ export class NoteEntityService implements OnModuleInit {
|
|||
}
|
||||
|
||||
// パフォーマンスのためノートが作成されてから2秒以上経っていない場合はリアクションを取得しない
|
||||
if (note.createdAt.getTime() + 2000 > Date.now()) {
|
||||
if (this.idService.parse(noteId).date.getTime() + 2000 > Date.now()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const reaction = await this.noteReactionsRepository.findOneBy({
|
||||
userId: meId,
|
||||
noteId: note.id,
|
||||
noteId: noteId,
|
||||
});
|
||||
|
||||
if (reaction) {
|
||||
|
@ -355,7 +358,7 @@ export class NoteEntityService implements OnModuleInit {
|
|||
poll: note.hasPoll ? this.populatePoll(note, meId) : undefined,
|
||||
|
||||
...(meId ? {
|
||||
myReaction: this.populateMyReaction(note, meId, options?._hint_),
|
||||
myReaction: this.populateMyReaction(note.id, meId, options?._hint_),
|
||||
} : {}),
|
||||
} : {}),
|
||||
});
|
||||
|
|
|
@ -45,9 +45,9 @@ class ChannelChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
|
@ -71,9 +71,9 @@ class GlobalTimelineChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
|
@ -50,9 +50,9 @@ class HashtagChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
|
@ -73,9 +73,9 @@ class HomeTimelineChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
|
@ -87,9 +87,9 @@ class HybridTimelineChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
|
@ -70,9 +70,9 @@ class LocalTimelineChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
|
@ -102,9 +102,9 @@ class UserListChannel extends Channel {
|
|||
|
||||
if (note.renote && !note.text && isUserRelated(note, this.userIdsWhoMeMutingRenotes)) return;
|
||||
|
||||
if (this.user && note.renote && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renote, this.user.id);
|
||||
note.renote.myReaction = myRenoteReaction;
|
||||
if (this.user && note.renoteId && !note.text) {
|
||||
const myRenoteReaction = await this.noteEntityService.populateMyReaction(note.renoteId, this.user.id);
|
||||
note.renote!.myReaction = myRenoteReaction;
|
||||
}
|
||||
|
||||
this.connection.cacheNote(note);
|
||||
|
|
Loading…
Reference in New Issue