summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/gallery/posts
diff options
context:
space:
mode:
authorzyoshoka <107108195+zyoshoka@users.noreply.github.com>2023-11-26 10:05:56 +0900
committerGitHub <noreply@github.com>2023-11-26 10:05:56 +0900
commit2ee48ae04da540384214ff0d7c8df2dfb18c88fc (patch)
tree2a32f6298d23b610134b6bd0fc8414206c9ed0d1 /packages/backend/src/server/api/endpoints/gallery/posts
parentfix(backend): rename FunoutTimelineService to FanoutTimelineService (#12453) (diff)
downloadsharkey-2ee48ae04da540384214ff0d7c8df2dfb18c88fc.tar.gz
sharkey-2ee48ae04da540384214ff0d7c8df2dfb18c88fc.tar.bz2
sharkey-2ee48ae04da540384214ff0d7c8df2dfb18c88fc.zip
fix(backend): ギャラリーの人気の投稿の選出にidを用いるように (#12448)
Diffstat (limited to 'packages/backend/src/server/api/endpoints/gallery/posts')
-rw-r--r--packages/backend/src/server/api/endpoints/gallery/posts/like.ts7
-rw-r--r--packages/backend/src/server/api/endpoints/gallery/posts/unlike.ts10
2 files changed, 17 insertions, 0 deletions
diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/like.ts b/packages/backend/src/server/api/endpoints/gallery/posts/like.ts
index 561b2492ab..cc424261b4 100644
--- a/packages/backend/src/server/api/endpoints/gallery/posts/like.ts
+++ b/packages/backend/src/server/api/endpoints/gallery/posts/like.ts
@@ -6,6 +6,7 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { GalleryLikesRepository, GalleryPostsRepository } from '@/models/_.js';
+import { FeaturedService, GALLERY_POSTS_RANKING_WINDOW } from '@/core/FeaturedService.js';
import { IdService } from '@/core/IdService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js';
@@ -57,6 +58,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.galleryLikesRepository)
private galleryLikesRepository: GalleryLikesRepository,
+ private featuredService: FeaturedService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
@@ -88,6 +90,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
userId: me.id,
});
+ // ランキング更新
+ if (Date.now() - this.idService.parse(post.id).date.getTime() < GALLERY_POSTS_RANKING_WINDOW) {
+ await this.featuredService.updateGalleryPostsRanking(post.id, 1);
+ }
+
this.galleryPostsRepository.increment({ id: post.id }, 'likedCount', 1);
});
}
diff --git a/packages/backend/src/server/api/endpoints/gallery/posts/unlike.ts b/packages/backend/src/server/api/endpoints/gallery/posts/unlike.ts
index 832b62282f..caa4d45553 100644
--- a/packages/backend/src/server/api/endpoints/gallery/posts/unlike.ts
+++ b/packages/backend/src/server/api/endpoints/gallery/posts/unlike.ts
@@ -6,6 +6,8 @@
import { Inject, Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js';
import type { GalleryPostsRepository, GalleryLikesRepository } from '@/models/_.js';
+import { FeaturedService, GALLERY_POSTS_RANKING_WINDOW } from '@/core/FeaturedService.js';
+import { IdService } from '@/core/IdService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../../error.js';
@@ -49,6 +51,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
@Inject(DI.galleryLikesRepository)
private galleryLikesRepository: GalleryLikesRepository,
+
+ private featuredService: FeaturedService,
+ private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
const post = await this.galleryPostsRepository.findOneBy({ id: ps.postId });
@@ -68,6 +73,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
// Delete like
await this.galleryLikesRepository.delete(exist.id);
+ // ランキング更新
+ if (Date.now() - this.idService.parse(post.id).date.getTime() < GALLERY_POSTS_RANKING_WINDOW) {
+ await this.featuredService.updateGalleryPostsRanking(post.id, -1);
+ }
+
this.galleryPostsRepository.decrement({ id: post.id }, 'likedCount', 1);
});
}