From 26ae2dfc0f494c377abd878c00044049fcd2bf37 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 22 Jan 2023 08:00:42 +0900 Subject: [PATCH] add achievement --- locales/ja-JP.yml | 3 +++ packages/backend/src/core/AchievementService.ts | 3 ++- .../src/server/api/endpoints/notes/favorites/create.ts | 6 ++++++ packages/frontend/src/scripts/achievements.ts | 6 ++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 898ae01e72..57296b9857 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1049,6 +1049,9 @@ _achievements: _noteFavorited1: title: "星をみるひと" description: "初めてノートをお気に入りに登録した" + _myNoteFavorited1: + title: "星が欲しい" + description: "自分のノートが他の人からお気に入りに登録された" _profileFilled: title: "準備万端" description: "プロフィール設定を行った" diff --git a/packages/backend/src/core/AchievementService.ts b/packages/backend/src/core/AchievementService.ts index 26dd356d36..be763e4629 100644 --- a/packages/backend/src/core/AchievementService.ts +++ b/packages/backend/src/core/AchievementService.ts @@ -44,6 +44,7 @@ const ACHIEVEMENT_TYPES = [ 'loggedInOnNewYearsDay', 'noteClipped1', 'noteFavorited1', + 'myNoteFavorited1', 'profileFilled', 'markedAsCat', 'following1', @@ -94,7 +95,7 @@ export class AchievementService { @bindThis public async create( userId: User['id'], - type: string, + type: typeof ACHIEVEMENT_TYPES[number], ): Promise { if (!ACHIEVEMENT_TYPES.includes(type)) return; diff --git a/packages/backend/src/server/api/endpoints/notes/favorites/create.ts b/packages/backend/src/server/api/endpoints/notes/favorites/create.ts index acf22a5ad4..e423f0f109 100644 --- a/packages/backend/src/server/api/endpoints/notes/favorites/create.ts +++ b/packages/backend/src/server/api/endpoints/notes/favorites/create.ts @@ -6,6 +6,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js'; import { GetterService } from '@/server/api/GetterService.js'; import { DI } from '@/di-symbols.js'; import { ApiError } from '../../../error.js'; +import { AchievementService } from '@/core/AchievementService.js'; export const meta = { tags: ['notes', 'favorites'], @@ -51,6 +52,7 @@ export default class extends Endpoint { private idService: IdService, private getterService: GetterService, + private achievementService: AchievementService, ) { super(meta, paramDef, async (ps, me) => { // Get favoritee @@ -76,6 +78,10 @@ export default class extends Endpoint { noteId: note.id, userId: me.id, }); + + if (note.userHost == null) { + this.achievementService.create(note.userId, 'myNoteFavorited1'); + } }); } } diff --git a/packages/frontend/src/scripts/achievements.ts b/packages/frontend/src/scripts/achievements.ts index c97358e880..f511fce3ea 100644 --- a/packages/frontend/src/scripts/achievements.ts +++ b/packages/frontend/src/scripts/achievements.ts @@ -40,6 +40,7 @@ export const ACHIEVEMENT_TYPES = [ 'loggedInOnNewYearsDay', 'noteClipped1', 'noteFavorited1', + 'myNoteFavorited1', 'profileFilled', 'markedAsCat', 'following1', @@ -240,6 +241,11 @@ export const ACHIEVEMENT_BADGES = { bg: null, frame: 'bronze', }, + 'myNoteFavorited1': { + img: '/fluent-emoji/1f320.png', + bg: null, + frame: 'silver', + }, 'profileFilled': { img: '/fluent-emoji/1f44c.png', bg: 'linear-gradient(0deg, rgb(187 183 59), rgb(255 143 77))',