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