mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-23 11:08:13 +09:00
81c7db0744
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
41 lines
1.4 KiB
TypeScript
41 lines
1.4 KiB
TypeScript
import { EntityRepository, Repository } from 'typeorm';
|
|
import { MessagingMessage } from '@/models/entities/messaging-message';
|
|
import { Users, DriveFiles, UserGroups } from '../index';
|
|
import { Packed } from '@/misc/schema';
|
|
import { User } from '@/models/entities/user';
|
|
|
|
@EntityRepository(MessagingMessage)
|
|
export class MessagingMessageRepository extends Repository<MessagingMessage> {
|
|
public async pack(
|
|
src: MessagingMessage['id'] | MessagingMessage,
|
|
me?: { id: User['id'] } | null | undefined,
|
|
options?: {
|
|
populateRecipient?: boolean,
|
|
populateGroup?: boolean,
|
|
}
|
|
): Promise<Packed<'MessagingMessage'>> {
|
|
const opts = options || {
|
|
populateRecipient: true,
|
|
populateGroup: true,
|
|
};
|
|
|
|
const message = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
|
|
|
return {
|
|
id: message.id,
|
|
createdAt: message.createdAt.toISOString(),
|
|
text: message.text,
|
|
userId: message.userId,
|
|
user: await Users.pack(message.user || message.userId, me),
|
|
recipientId: message.recipientId,
|
|
recipient: message.recipientId && opts.populateRecipient ? await Users.pack(message.recipient || message.recipientId, me) : undefined,
|
|
groupId: message.groupId,
|
|
group: message.groupId && opts.populateGroup ? await UserGroups.pack(message.group || message.groupId) : undefined,
|
|
fileId: message.fileId,
|
|
file: message.fileId ? await DriveFiles.pack(message.fileId) : null,
|
|
isRead: message.isRead,
|
|
reads: message.reads,
|
|
};
|
|
}
|
|
}
|