2023-07-27 05:31:52 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-01-21 04:14:55 +00:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2023-09-15 05:28:29 +00:00
|
|
|
import type { UserProfilesRepository } from '@/models/_.js';
|
2023-08-16 08:51:28 +00:00
|
|
|
import type { MiUser } from '@/models/entities/User.js';
|
2023-01-21 04:14:55 +00:00
|
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
import { bindThis } from '@/decorators.js';
|
2023-03-16 05:24:11 +00:00
|
|
|
import { NotificationService } from '@/core/NotificationService.js';
|
2023-01-21 04:14:55 +00:00
|
|
|
|
2023-02-09 02:46:08 +00:00
|
|
|
export const ACHIEVEMENT_TYPES = [
|
2023-01-21 04:14:55 +00:00
|
|
|
'notes1',
|
|
|
|
'notes10',
|
|
|
|
'notes100',
|
|
|
|
'notes500',
|
|
|
|
'notes1000',
|
|
|
|
'notes5000',
|
|
|
|
'notes10000',
|
|
|
|
'notes20000',
|
|
|
|
'notes30000',
|
|
|
|
'notes40000',
|
|
|
|
'notes50000',
|
|
|
|
'notes60000',
|
|
|
|
'notes70000',
|
|
|
|
'notes80000',
|
|
|
|
'notes90000',
|
|
|
|
'notes100000',
|
|
|
|
'login3',
|
|
|
|
'login7',
|
|
|
|
'login15',
|
|
|
|
'login30',
|
|
|
|
'login60',
|
|
|
|
'login100',
|
|
|
|
'login200',
|
|
|
|
'login300',
|
|
|
|
'login400',
|
|
|
|
'login500',
|
|
|
|
'login600',
|
|
|
|
'login700',
|
|
|
|
'login800',
|
|
|
|
'login900',
|
|
|
|
'login1000',
|
|
|
|
'passedSinceAccountCreated1',
|
|
|
|
'passedSinceAccountCreated2',
|
|
|
|
'passedSinceAccountCreated3',
|
|
|
|
'loggedInOnBirthday',
|
2023-01-21 07:06:49 +00:00
|
|
|
'loggedInOnNewYearsDay',
|
2023-01-21 04:14:55 +00:00
|
|
|
'noteClipped1',
|
|
|
|
'noteFavorited1',
|
2023-01-21 23:00:42 +00:00
|
|
|
'myNoteFavorited1',
|
2023-01-21 04:14:55 +00:00
|
|
|
'profileFilled',
|
|
|
|
'markedAsCat',
|
|
|
|
'following1',
|
|
|
|
'following10',
|
|
|
|
'following50',
|
|
|
|
'following100',
|
|
|
|
'following300',
|
|
|
|
'followers1',
|
|
|
|
'followers10',
|
|
|
|
'followers50',
|
|
|
|
'followers100',
|
|
|
|
'followers300',
|
|
|
|
'followers500',
|
|
|
|
'followers1000',
|
|
|
|
'collectAchievements30',
|
2023-01-21 07:06:49 +00:00
|
|
|
'viewAchievements3min',
|
2023-01-21 04:14:55 +00:00
|
|
|
'iLoveMisskey',
|
2023-01-22 11:22:38 +00:00
|
|
|
'foundTreasure',
|
2023-01-21 04:14:55 +00:00
|
|
|
'client30min',
|
2023-04-20 10:40:02 +00:00
|
|
|
'client60min',
|
2023-01-21 04:14:55 +00:00
|
|
|
'noteDeletedWithin1min',
|
|
|
|
'postedAtLateNight',
|
|
|
|
'postedAt0min0sec',
|
|
|
|
'selfQuote',
|
|
|
|
'htl20npm',
|
2023-01-22 11:30:56 +00:00
|
|
|
'viewInstanceChart',
|
2023-01-21 06:30:29 +00:00
|
|
|
'outputHelloWorldOnScratchpad',
|
|
|
|
'open3windows',
|
2023-01-21 04:14:55 +00:00
|
|
|
'driveFolderCircularReference',
|
|
|
|
'reactWithoutRead',
|
|
|
|
'clickedClickHere',
|
|
|
|
'justPlainLucky',
|
|
|
|
'setNameToSyuilo',
|
|
|
|
'cookieClicked',
|
|
|
|
'brainDiver',
|
2023-09-12 06:48:19 +00:00
|
|
|
'smashTestNotificationButton',
|
2023-01-21 04:14:55 +00:00
|
|
|
] as const;
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class AchievementService {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.userProfilesRepository)
|
|
|
|
private userProfilesRepository: UserProfilesRepository,
|
|
|
|
|
2023-03-16 05:24:11 +00:00
|
|
|
private notificationService: NotificationService,
|
2023-01-21 04:14:55 +00:00
|
|
|
) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@bindThis
|
|
|
|
public async create(
|
2023-08-16 08:51:28 +00:00
|
|
|
userId: MiUser['id'],
|
2023-01-21 23:00:42 +00:00
|
|
|
type: typeof ACHIEVEMENT_TYPES[number],
|
2023-01-21 04:14:55 +00:00
|
|
|
): Promise<void> {
|
|
|
|
if (!ACHIEVEMENT_TYPES.includes(type)) return;
|
|
|
|
|
|
|
|
const date = Date.now();
|
|
|
|
|
|
|
|
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: userId });
|
|
|
|
|
|
|
|
if (profile.achievements.some(a => a.name === type)) return;
|
|
|
|
|
|
|
|
await this.userProfilesRepository.update(userId, {
|
|
|
|
achievements: [...profile.achievements, {
|
|
|
|
name: type,
|
|
|
|
unlockedAt: date,
|
|
|
|
}],
|
|
|
|
});
|
|
|
|
|
2023-03-16 05:24:11 +00:00
|
|
|
this.notificationService.createNotification(userId, 'achievementEarned', {
|
2023-01-21 04:14:55 +00:00
|
|
|
achievement: type,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|