2023-07-27 05:31:52 +00:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 05:31:52 +00:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-09-17 18:27:08 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-10-03 11:26:11 +00:00
|
|
|
import type { MiUserListMembership, UserListMembershipsRepository, UserListsRepository } from '@/models/_.js';
|
2023-03-10 05:22:37 +00:00
|
|
|
import type { Packed } from '@/misc/json-schema.js';
|
2023-09-20 02:33:36 +00:00
|
|
|
import type { } from '@/models/Blocking.js';
|
|
|
|
import type { MiUserList } from '@/models/UserList.js';
|
2022-12-04 06:03:09 +00:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-10-16 01:45:22 +00:00
|
|
|
import { IdService } from '@/core/IdService.js';
|
2023-10-03 11:26:11 +00:00
|
|
|
import { UserEntityService } from './UserEntityService.js';
|
2022-09-17 18:27:08 +00:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class UserListEntityService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.userListsRepository)
|
|
|
|
private userListsRepository: UserListsRepository,
|
|
|
|
|
2023-10-03 11:26:11 +00:00
|
|
|
@Inject(DI.userListMembershipsRepository)
|
|
|
|
private userListMembershipsRepository: UserListMembershipsRepository,
|
|
|
|
|
|
|
|
private userEntityService: UserEntityService,
|
2023-10-16 01:45:22 +00:00
|
|
|
private idService: IdService,
|
2022-09-17 18:27:08 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
2022-12-04 06:03:09 +00:00
|
|
|
@bindThis
|
2022-09-17 18:27:08 +00:00
|
|
|
public async pack(
|
2023-08-16 08:51:28 +00:00
|
|
|
src: MiUserList['id'] | MiUserList,
|
2022-09-17 18:27:08 +00:00
|
|
|
): Promise<Packed<'UserList'>> {
|
|
|
|
const userList = typeof src === 'object' ? src : await this.userListsRepository.findOneByOrFail({ id: src });
|
|
|
|
|
2023-10-03 11:26:11 +00:00
|
|
|
const users = await this.userListMembershipsRepository.findBy({
|
2022-09-17 18:27:08 +00:00
|
|
|
userListId: userList.id,
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
id: userList.id,
|
2023-10-16 01:45:22 +00:00
|
|
|
createdAt: this.idService.parse(userList.id).date.toISOString(),
|
2022-09-17 18:27:08 +00:00
|
|
|
name: userList.name,
|
|
|
|
userIds: users.map(x => x.userId),
|
2023-05-19 01:06:12 +00:00
|
|
|
isPublic: userList.isPublic,
|
2022-09-17 18:27:08 +00:00
|
|
|
};
|
|
|
|
}
|
2023-10-03 11:26:11 +00:00
|
|
|
|
|
|
|
@bindThis
|
|
|
|
public async packMembershipsMany(
|
|
|
|
memberships: MiUserListMembership[],
|
|
|
|
) {
|
|
|
|
return Promise.all(memberships.map(async x => ({
|
|
|
|
id: x.id,
|
2023-10-16 01:45:22 +00:00
|
|
|
createdAt: this.idService.parse(x.id).date.toISOString(),
|
2023-10-03 11:26:11 +00:00
|
|
|
userId: x.userId,
|
|
|
|
user: await this.userEntityService.pack(x.userId),
|
|
|
|
withReplies: x.withReplies,
|
|
|
|
})));
|
|
|
|
}
|
2022-09-17 18:27:08 +00:00
|
|
|
}
|
|
|
|
|