feat: add achievement notifications setting

This commit is contained in:
Zamitto 2024-10-13 22:37:36 -03:00
parent c24f6be1b7
commit 1d29bc3620
8 changed files with 60 additions and 10 deletions

View file

@ -1,4 +1,8 @@
import { gameAchievementRepository, gameRepository } from "@main/repository";
import {
gameAchievementRepository,
gameRepository,
userPreferencesRepository,
} from "@main/repository";
import type { GameShop, UnlockedAchievement } from "@types";
import { WindowManager } from "../window-manager";
import { HydraApi } from "../hydra-api";
@ -38,12 +42,15 @@ export const mergeAchievements = async (
if (!game) return;
const localGameAchievement = await gameAchievementRepository.findOne({
where: {
objectId,
shop,
},
});
const [localGameAchievement, userPreferences] = await Promise.all([
gameAchievementRepository.findOne({
where: {
objectId,
shop,
},
}),
userPreferencesRepository.findOne({ where: { id: 1 } }),
]);
const unlockedAchievements = JSON.parse(
localGameAchievement?.unlockedAchievements || "[]"
@ -64,7 +71,11 @@ export const mergeAchievements = async (
};
});
if (newAchievements.length && publishNotification) {
if (
newAchievements.length &&
publishNotification &&
userPreferences?.achievementNotificationsEnabled
) {
const achievementsInfo = newAchievements
.sort((a, b) => {
return a.unlockTime - b.unlockTime;