From 5101684154d725b25d688c376e2c054e9b172552 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 19 Aug 2024 12:31:39 -0300 Subject: [PATCH] feat: add property --- src/main/events/user/get-user.ts | 46 +++++++++++++++----------------- src/types/index.ts | 1 + 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/main/events/user/get-user.ts b/src/main/events/user/get-user.ts index eb4f0619..bc4a58ad 100644 --- a/src/main/events/user/get-user.ts +++ b/src/main/events/user/get-user.ts @@ -1,7 +1,7 @@ import { registerEvent } from "../register-event"; import { HydraApi } from "@main/services"; import { steamGamesWorker } from "@main/workers"; -import { UserProfile } from "@types"; +import { UserGame, UserProfile } from "@types"; import { convertSteamGameToCatalogueEntry } from "../helpers/search-games"; import { getSteamAppAsset } from "@main/helpers"; import { getUserFriends } from "./get-user-friends"; @@ -20,35 +20,13 @@ const getUser = async ( const recentGames = await Promise.all( profile.recentGames.map(async (game) => { - const steamGame = await steamGamesWorker.run(Number(game.objectId), { - name: "getById", - }); - const iconUrl = steamGame?.clientIcon - ? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon) - : null; - - return { - ...game, - ...convertSteamGameToCatalogueEntry(steamGame), - iconUrl, - }; + return getSteamUserGame(game); }) ); const libraryGames = await Promise.all( profile.libraryGames.map(async (game) => { - const steamGame = await steamGamesWorker.run(Number(game.objectId), { - name: "getById", - }); - const iconUrl = steamGame?.clientIcon - ? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon) - : null; - - return { - ...game, - ...convertSteamGameToCatalogueEntry(steamGame), - iconUrl, - }; + return getSteamUserGame(game); }) ); @@ -58,10 +36,28 @@ const getUser = async ( recentGames, friends: friends.friends, totalFriends: friends.totalFriends, + currentGame: profile.currentGame + ? getSteamUserGame(profile.currentGame) + : null, }; } catch (err) { return null; } }; +const getSteamUserGame = async (game): Promise => { + const steamGame = await steamGamesWorker.run(Number(game.objectId), { + name: "getById", + }); + const iconUrl = steamGame?.clientIcon + ? getSteamAppAsset("icon", game.objectId, steamGame.clientIcon) + : null; + + return { + ...game, + ...convertSteamGameToCatalogueEntry(steamGame), + iconUrl, + }; +}; + registerEvent("getUser", getUser); diff --git a/src/types/index.ts b/src/types/index.ts index 46ab5421..d97433ae 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -318,6 +318,7 @@ export interface UserProfile { friends: UserFriend[]; totalFriends: number; relation: UserRelation | null; + currentGame: UserGame | null; } export interface UpdateProfileProps {