2023-08-15 02:52:38 +09:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2023-09-15 14:28:29 +09:00
|
|
|
import type { GalleryLikesRepository } from '@/models/_.js';
|
2023-09-20 11:33:36 +09:00
|
|
|
import type { } from '@/models/Blocking.js';
|
|
|
|
|
import type { MiGalleryLike } from '@/models/GalleryLike.js';
|
2022-12-04 15:03:09 +09:00
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-08-08 20:13:05 +09:00
|
|
|
import { Packed } from '@/misc/json-schema.js';
|
2023-09-25 12:43:07 +09:00
|
|
|
import type { MiUser } from '@/models/User.js';
|
2023-07-19 11:27:50 +09:00
|
|
|
import { GalleryPostEntityService } from './GalleryPostEntityService.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class GalleryLikeEntityService {
|
|
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.galleryLikesRepository)
|
|
|
|
|
private galleryLikesRepository: GalleryLikesRepository,
|
|
|
|
|
|
|
|
|
|
private galleryPostEntityService: GalleryPostEntityService,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2022-09-18 03:27:08 +09:00
|
|
|
public async pack(
|
2023-08-26 08:42:29 +09:00
|
|
|
src: MiGalleryLike['id'] | MiGalleryLike,
|
|
|
|
|
me: { id: MiUser['id'] } | null | undefined,
|
2023-08-08 20:13:05 +09:00
|
|
|
) : Promise<Packed<'GalleryLike'>> {
|
2022-09-18 03:27:08 +09:00
|
|
|
const like = typeof src === 'object' ? src : await this.galleryLikesRepository.findOneByOrFail({ id: src });
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: like.id,
|
|
|
|
|
post: await this.galleryPostEntityService.pack(like.post ?? like.postId, me),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 15:03:09 +09:00
|
|
|
@bindThis
|
2023-08-08 20:13:05 +09:00
|
|
|
public async packMany(
|
2023-08-26 08:42:29 +09:00
|
|
|
likes: (MiGalleryLike['id'] | MiGalleryLike)[],
|
|
|
|
|
me: { id: MiUser['id'] } | null | undefined,
|
2023-08-08 20:13:05 +09:00
|
|
|
) : Promise<Packed<'GalleryLike'>[]> {
|
|
|
|
|
return (await Promise.allSettled(likes.map(x => this.pack(x, me))))
|
|
|
|
|
.filter(result => result.status === 'fulfilled')
|
|
|
|
|
.map(result => (result as PromiseFulfilledResult<Packed<'GalleryLike'>>).value);
|
2022-09-18 03:27:08 +09:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|