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