feat: add option to disable friend starting game notification

This commit is contained in:
Zamitto
2025-05-19 07:23:46 -03:00
parent 73de69b5a6
commit e85d08422e
8 changed files with 36 additions and 14 deletions

View File

@@ -1,15 +1,25 @@
import type { FriendGameSession } from "@main/generated/envelope";
import { db, levelKeys } from "@main/level";
import { HydraApi } from "@main/services/hydra-api";
import { publishFriendStartedPlayingGameNotification } from "@main/services/notifications";
import { GameStats } from "@types";
import type { GameStats, UserPreferences, UserProfile } from "@types";
export const friendGameSessionEvent = async (payload: FriendGameSession) => {
const userPreferences = await db.get<string, UserPreferences | null>(
levelKeys.userPreferences,
{
valueEncoding: "json",
}
);
if (userPreferences?.friendStartGameNotificationsEnabled === false) return;
const [friend, gameStats] = await Promise.all([
HydraApi.get(`/users/${payload.friendId}`),
HydraApi.get<UserProfile>(`/users/${payload.friendId}`),
HydraApi.get<GameStats>(
`/games/stats?objectId=${payload.objectId}&shop=steam`
),
]);
]).catch(() => [null, null]);
if (friend && gameStats) {
publishFriendStartedPlayingGameNotification(friend, gameStats);