2022-03-26 15:34:00 +09:00
|
|
|
import { db } from '@/db/postgre.js';
|
2022-02-27 11:07:39 +09:00
|
|
|
import { NoteReaction } from '@/models/entities/note-reaction.js';
|
|
|
|
import { Notes, Users } from '../index.js';
|
|
|
|
import { Packed } from '@/misc/schema.js';
|
|
|
|
import { convertLegacyReaction } from '@/misc/reaction-lib.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
2019-04-23 22:35:26 +09:00
|
|
|
|
2022-03-26 15:34:00 +09:00
|
|
|
export const NoteReactionRepository = db.getRepository(NoteReaction).extend({
|
|
|
|
async pack(
|
2019-04-07 21:50:36 +09:00
|
|
|
src: NoteReaction['id'] | NoteReaction,
|
2021-10-17 01:33:15 +09:00
|
|
|
me?: { id: User['id'] } | null | undefined,
|
|
|
|
options?: {
|
|
|
|
withNote: boolean;
|
|
|
|
},
|
2021-09-22 22:35:55 +09:00
|
|
|
): Promise<Packed<'NoteReaction'>> {
|
2021-10-17 01:33:15 +09:00
|
|
|
const opts = Object.assign({
|
|
|
|
withNote: false,
|
|
|
|
}, options);
|
|
|
|
|
2022-03-26 15:34:00 +09:00
|
|
|
const reaction = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
|
2019-04-07 21:50:36 +09:00
|
|
|
|
|
|
|
return {
|
|
|
|
id: reaction.id,
|
2019-04-23 22:35:26 +09:00
|
|
|
createdAt: reaction.createdAt.toISOString(),
|
2022-02-27 13:59:10 +09:00
|
|
|
user: await Users.pack(reaction.user ?? reaction.userId, me),
|
2020-01-30 04:37:25 +09:00
|
|
|
type: convertLegacyReaction(reaction.reaction),
|
2021-10-17 01:33:15 +09:00
|
|
|
...(opts.withNote ? {
|
2022-02-27 13:59:10 +09:00
|
|
|
note: await Notes.pack(reaction.note ?? reaction.noteId, me),
|
2021-12-09 23:58:30 +09:00
|
|
|
} : {}),
|
2019-04-07 21:50:36 +09:00
|
|
|
};
|
2022-03-26 15:34:00 +09:00
|
|
|
},
|
|
|
|
});
|