-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * Update ja-JP.yml * wip * wip * Update MkAchievements.vue * wip * 🎨 * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
- Loading branch information
Showing
34 changed files
with
1,385 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class loggedInDates1674255666603 { | ||
name = 'loggedInDates1674255666603' | ||
|
||
async up(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "user_profile" ADD "loggedInDates" character varying(32) array NOT NULL DEFAULT '{}'`); | ||
} | ||
|
||
async down(queryRunner) { | ||
await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "loggedInDates"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import type { UserProfilesRepository, UsersRepository } from '@/models/index.js'; | ||
import type { User } from '@/models/entities/User.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import { bindThis } from '@/decorators.js'; | ||
import { CreateNotificationService } from '@/core/CreateNotificationService.js'; | ||
|
||
const ACHIEVEMENT_TYPES = [ | ||
'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', | ||
'noteClipped1', | ||
'noteFavorited1', | ||
'profileFilled', | ||
'markedAsCat', | ||
'following1', | ||
'following10', | ||
'following50', | ||
'following100', | ||
'following300', | ||
'followers1', | ||
'followers10', | ||
'followers50', | ||
'followers100', | ||
'followers300', | ||
'followers500', | ||
'followers1000', | ||
'collectAchievements30', | ||
'iLoveMisskey', | ||
'client30min', | ||
'noteDeletedWithin1min', | ||
'postedAtLateNight', | ||
'postedAt0min0sec', | ||
'selfQuote', | ||
'htl20npm', | ||
'driveFolderCircularReference', | ||
'reactWithoutRead', | ||
'clickedClickHere', | ||
'justPlainLucky', | ||
'setNameToSyuilo', | ||
'cookieClicked', | ||
'brainDiver', | ||
] as const; | ||
|
||
@Injectable() | ||
export class AchievementService { | ||
constructor( | ||
@Inject(DI.usersRepository) | ||
private usersRepository: UsersRepository, | ||
|
||
@Inject(DI.userProfilesRepository) | ||
private userProfilesRepository: UserProfilesRepository, | ||
|
||
private createNotificationService: CreateNotificationService, | ||
) { | ||
} | ||
|
||
@bindThis | ||
public async create( | ||
userId: User['id'], | ||
type: string, | ||
): 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, | ||
}], | ||
}); | ||
|
||
this.createNotificationService.createNotification(userId, 'achievementEarned', { | ||
achievement: type, | ||
}); | ||
} | ||
} |
Oops, something went wrong.