summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorsyuilo <4439005+syuilo@users.noreply.github.com>2025-08-26 13:34:41 +0900
committersyuilo <4439005+syuilo@users.noreply.github.com>2025-08-26 13:34:41 +0900
commitd6a1046361d3d38726f2a86588960c3614f72a9f (patch)
treed0a501710c36b8e9488e6756adc906c08447910b /packages/backend/src/core
parentrefactor and fix (diff)
downloadmisskey-d6a1046361d3d38726f2a86588960c3614f72a9f.tar.gz
misskey-d6a1046361d3d38726f2a86588960c3614f72a9f.tar.bz2
misskey-d6a1046361d3d38726f2a86588960c3614f72a9f.zip
refactor
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/entities/NoteReactionEntityService.ts50
1 files changed, 39 insertions, 11 deletions
diff --git a/packages/backend/src/core/entities/NoteReactionEntityService.ts b/packages/backend/src/core/entities/NoteReactionEntityService.ts
index 46ec13704c..54ce4d472a 100644
--- a/packages/backend/src/core/entities/NoteReactionEntityService.ts
+++ b/packages/backend/src/core/entities/NoteReactionEntityService.ts
@@ -49,15 +49,12 @@ export class NoteReactionEntityService implements OnModuleInit {
public async pack(
src: MiNoteReaction['id'] | MiNoteReaction,
me?: { id: MiUser['id'] } | null | undefined,
- options?: {
- withNote: boolean;
- },
+ options?: object,
hints?: {
packedUser?: Packed<'UserLite'>
},
): Promise<Packed<'NoteReaction'>> {
const opts = Object.assign({
- withNote: false,
}, options);
const reaction = typeof src === 'object' ? src : await this.noteReactionsRepository.findOneByOrFail({ id: src });
@@ -67,9 +64,6 @@ export class NoteReactionEntityService implements OnModuleInit {
createdAt: this.idService.parse(reaction.id).date.toISOString(),
user: hints?.packedUser ?? await this.userEntityService.pack(reaction.user ?? reaction.userId, me),
type: this.reactionService.convertLegacyReaction(reaction.reaction),
- ...(opts.withNote ? {
- note: await this.noteEntityService.pack(reaction.note ?? reaction.noteId, me),
- } : {}),
};
}
@@ -77,16 +71,50 @@ export class NoteReactionEntityService implements OnModuleInit {
public async packMany(
reactions: MiNoteReaction[],
me?: { id: MiUser['id'] } | null | undefined,
- options?: {
- withNote: boolean;
- },
+ options?: object,
): Promise<Packed<'NoteReaction'>[]> {
const opts = Object.assign({
- withNote: false,
}, options);
const _users = reactions.map(({ user, userId }) => user ?? userId);
const _userMap = await this.userEntityService.packMany(_users, me)
.then(users => new Map(users.map(u => [u.id, u])));
return Promise.all(reactions.map(reaction => this.pack(reaction, me, opts, { packedUser: _userMap.get(reaction.userId) })));
}
+
+ @bindThis
+ public async packWithNote(
+ src: MiNoteReaction['id'] | MiNoteReaction,
+ me?: { id: MiUser['id'] } | null | undefined,
+ options?: object,
+ hints?: {
+ packedUser?: Packed<'UserLite'>
+ },
+ ): Promise<Packed<'NoteReactionWithNote'>> {
+ const opts = Object.assign({
+ }, options);
+
+ const reaction = typeof src === 'object' ? src : await this.noteReactionsRepository.findOneByOrFail({ id: src });
+
+ return {
+ id: reaction.id,
+ createdAt: this.idService.parse(reaction.id).date.toISOString(),
+ user: hints?.packedUser ?? await this.userEntityService.pack(reaction.user ?? reaction.userId, me),
+ type: this.reactionService.convertLegacyReaction(reaction.reaction),
+ note: await this.noteEntityService.pack(reaction.note ?? reaction.noteId, me),
+ };
+ }
+
+ @bindThis
+ public async packManyWithNote(
+ reactions: MiNoteReaction[],
+ me?: { id: MiUser['id'] } | null | undefined,
+ options?: object,
+ ): Promise<Packed<'NoteReactionWithNote'>[]> {
+ const opts = Object.assign({
+ }, options);
+ const _users = reactions.map(({ user, userId }) => user ?? userId);
+ const _userMap = await this.userEntityService.packMany(_users, me)
+ .then(users => new Map(users.map(u => [u.id, u])));
+ return Promise.all(reactions.map(reaction => this.packWithNote(reaction, me, opts, { packedUser: _userMap.get(reaction.userId) })));
+ }
}