mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-26 12:21:03 +00:00
Merge branch 'feature/game-achievements' of github.com:hydralauncher/hydra into feature/cloud-sync
This commit is contained in:
@@ -51,7 +51,7 @@ const getAchievementLocalUser = async (shop: string, objectId: string) => {
|
||||
...achievementData,
|
||||
unlocked: false,
|
||||
unlockTime: null,
|
||||
icon: icongray,
|
||||
icongray: icongray,
|
||||
} as UserAchievement;
|
||||
})
|
||||
.sort((a, b) => {
|
||||
@@ -110,7 +110,7 @@ const getAchievementsRemoteUser = async (
|
||||
...achievementData,
|
||||
unlocked: false,
|
||||
unlockTime: null,
|
||||
icon: icongray,
|
||||
icongray: icongray,
|
||||
} as UserAchievement;
|
||||
})
|
||||
.sort((a, b) => {
|
||||
|
||||
@@ -50,6 +50,7 @@ import "./user/unblock-user";
|
||||
import "./user/get-user-friends";
|
||||
import "./user/get-user-stats";
|
||||
import "./user/report-user";
|
||||
import "./user/get-compared-unlocked-achievements";
|
||||
import "./profile/get-friend-requests";
|
||||
import "./profile/get-me";
|
||||
import "./profile/undo-friendship";
|
||||
|
||||
44
src/main/events/user/get-compared-unlocked-achievements.ts
Normal file
44
src/main/events/user/get-compared-unlocked-achievements.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import type { ComparedAchievements, GameShop } from "@types";
|
||||
import { registerEvent } from "../register-event";
|
||||
import { userPreferencesRepository } from "@main/repository";
|
||||
import { HydraApi } from "@main/services";
|
||||
|
||||
const getComparedUnlockedAchievements = async (
|
||||
_event: Electron.IpcMainInvokeEvent,
|
||||
objectId: string,
|
||||
shop: GameShop,
|
||||
userId: string
|
||||
) => {
|
||||
const userPreferences = await userPreferencesRepository.findOne({
|
||||
where: { id: 1 },
|
||||
});
|
||||
|
||||
return HydraApi.get<ComparedAchievements>(
|
||||
`/users/${userId}/games/achievements/compare`,
|
||||
{
|
||||
shop,
|
||||
objectId,
|
||||
language: userPreferences?.language || "en",
|
||||
}
|
||||
).then((achievements) => {
|
||||
const sortedAchievements = achievements.achievements.sort((a, b) => {
|
||||
if (a.otherUserStat.unlocked && !b.otherUserStat.unlocked) return -1;
|
||||
if (!a.otherUserStat.unlocked && b.otherUserStat.unlocked) return 1;
|
||||
if (a.otherUserStat.unlocked && b.otherUserStat.unlocked) {
|
||||
return b.otherUserStat.unlockTime! - a.otherUserStat.unlockTime!;
|
||||
}
|
||||
|
||||
return Number(a.hidden) - Number(b.hidden);
|
||||
});
|
||||
|
||||
return {
|
||||
...achievements,
|
||||
achievements: sortedAchievements,
|
||||
} as ComparedAchievements;
|
||||
});
|
||||
};
|
||||
|
||||
registerEvent(
|
||||
"getComparedUnlockedAchievements",
|
||||
getComparedUnlockedAchievements
|
||||
);
|
||||
Reference in New Issue
Block a user