From 85efc23c2547b965265cdee071855379958b8f01 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Mon, 10 Mar 2025 19:50:53 -0300 Subject: [PATCH] feat: friend request notification adjustments --- src/locales/en/translation.json | 7 +++++-- src/locales/pt-BR/translation.json | 8 +++++--- src/locales/pt-PT/translation.json | 8 +++++--- src/main/events/profile/sync-friend-requests.ts | 4 +++- src/main/services/notifications/index.ts | 15 ++++++++++++--- .../src/pages/settings/settings-general.tsx | 14 ++++++++++++++ src/types/level.types.ts | 1 + 7 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index fc64d010..6913491a 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -334,7 +334,8 @@ "import_theme": "Import theme", "import_theme_description": "You will import {{theme}} from the theme store", "error_importing_theme": "Error importing theme", - "theme_imported": "Theme imported successfully" + "theme_imported": "Theme imported successfully", + "enable_friend_request_notifications": "When a friend request is received" }, "notifications": { "download_complete": "Download complete", @@ -345,7 +346,9 @@ "new_update_available": "Version {{version}} available", "restart_to_install_update": "Restart Hydra to install the update", "notification_achievement_unlocked_title": "Achievement unlocked for {{game}}", - "notification_achievement_unlocked_body": "{{achievement}} and other {{count}} were unlocked" + "notification_achievement_unlocked_body": "{{achievement}} and other {{count}} were unlocked", + "new_friend_request_description": "You have received a new friend request", + "new_friend_request_title": "New friend request" }, "system_tray": { "open": "Open Hydra", diff --git a/src/locales/pt-BR/translation.json b/src/locales/pt-BR/translation.json index fc4dc84f..a1be48bf 100644 --- a/src/locales/pt-BR/translation.json +++ b/src/locales/pt-BR/translation.json @@ -31,7 +31,6 @@ }, "header": { "search": "Buscar jogos", - "catalogue": "Catálogo", "downloads": "Downloads", "search_results": "Resultados da busca", @@ -322,7 +321,8 @@ "import_theme": "Importar tema", "import_theme_description": "Você irá importar {{theme}} da loja de temas", "error_importing_theme": "Erro ao importar tema", - "theme_imported": "Tema importado com sucesso" + "theme_imported": "Tema importado com sucesso", + "enable_friend_request_notifications": "Quando um pedido de amizade é recebido" }, "notifications": { "download_complete": "Download concluído", @@ -331,7 +331,9 @@ "repack_count_one": "{{count}} novo repack", "repack_count_other": "{{count}} novos repacks", "new_update_available": "Versão {{version}} disponível", - "restart_to_install_update": "Reinicie o Hydra para instalar a nova versão" + "restart_to_install_update": "Reinicie o Hydra para instalar a nova versão", + "new_friend_request_title": "Novo pedido de amizade", + "new_friend_request_description": "Você recebeu um novo pedido de amizade" }, "system_tray": { "open": "Abrir Hydra", diff --git a/src/locales/pt-PT/translation.json b/src/locales/pt-PT/translation.json index 212c01d8..1a522a7e 100644 --- a/src/locales/pt-PT/translation.json +++ b/src/locales/pt-PT/translation.json @@ -30,7 +30,6 @@ }, "header": { "search": "Procurar jogos", - "catalogue": "Catálogo", "downloads": "Transferências", "search_results": "Resultados da pesquisa", @@ -250,7 +249,8 @@ "must_be_valid_url": "A fonte deve ser um URL válido", "blocked_users": "Utilizadores bloqueados", "user_unblocked": "Utilizador desbloqueado", - "enable_achievement_notifications": "Quando uma conquista é desbloqueada" + "enable_achievement_notifications": "Quando uma conquista é desbloqueada", + "enable_friend_request_notifications": "Quando um pedido de amizade é recebido" }, "notifications": { "download_complete": "Transferência concluída", @@ -259,7 +259,9 @@ "repack_count_one": "{{count}} novo repack", "repack_count_other": "{{count}} novos repacks", "new_update_available": "Versão {{version}} disponível", - "restart_to_install_update": "Reinicia o Hydra para instalar a nova versão" + "restart_to_install_update": "Reinicia o Hydra para instalar a nova versão", + "new_friend_request_title": "Novo pedido de amizade", + "new_friend_request_description": "Você recebeu um novo pedido de amizade" }, "system_tray": { "open": "Abrir o Hydra", diff --git a/src/main/events/profile/sync-friend-requests.ts b/src/main/events/profile/sync-friend-requests.ts index ca982c46..c5a37524 100644 --- a/src/main/events/profile/sync-friend-requests.ts +++ b/src/main/events/profile/sync-friend-requests.ts @@ -16,13 +16,15 @@ const syncFriendRequests = async (_event: Electron.IpcMainInvokeEvent) => { return HydraApi.get(`/profile/friend-requests/sync`) .then((res) => { if ( - syncState.friendsRequest && + syncState.friendsRequest != null && syncState.friendsRequest < res.friendRequestCount ) { publishNewFriendRequestNotification(); } syncState.friendsRequest = res.friendRequestCount; + + return res; }) .catch((err) => { if (err instanceof UserNotLoggedInError) { diff --git a/src/main/services/notifications/index.ts b/src/main/services/notifications/index.ts index 355bf61d..761270ce 100644 --- a/src/main/services/notifications/index.ts +++ b/src/main/services/notifications/index.ts @@ -81,15 +81,24 @@ export const publishNotificationUpdateReadyToInstall = async ( }; export const publishNewFriendRequestNotification = async () => { + const userPreferences = await db.get( + levelKeys.userPreferences, + { + valueEncoding: "json", + } + ); + + if (!userPreferences.friendRequestNotificationsEnabled) return; + new Notification({ - title: t("new_friend_request", { + title: t("new_friend_request_title", { ns: "notifications", }), - body: t("You have received a new friend request", { + body: t("new_friend_request_description", { ns: "notifications", }), icon: trayIcon, - }); + }).show(); }; export const publishCombinedNewAchievementNotification = async ( diff --git a/src/renderer/src/pages/settings/settings-general.tsx b/src/renderer/src/pages/settings/settings-general.tsx index b263c7fa..53019ab9 100644 --- a/src/renderer/src/pages/settings/settings-general.tsx +++ b/src/renderer/src/pages/settings/settings-general.tsx @@ -32,6 +32,7 @@ export function SettingsGeneral() { downloadNotificationsEnabled: false, repackUpdatesNotificationsEnabled: false, achievementNotificationsEnabled: false, + friendRequestNotificationsEnabled: false, language: "", customStyles: window.localStorage.getItem("customStyles") || "", @@ -82,6 +83,8 @@ export function SettingsGeneral() { userPreferences.repackUpdatesNotificationsEnabled ?? false, achievementNotificationsEnabled: userPreferences.achievementNotificationsEnabled ?? false, + friendRequestNotificationsEnabled: + userPreferences.friendRequestNotificationsEnabled ?? false, language: language ?? "en", })); } @@ -171,6 +174,17 @@ export function SettingsGeneral() { }) } /> + + + handleChange({ + friendRequestNotificationsEnabled: + !form.friendRequestNotificationsEnabled, + }) + } + /> ); } diff --git a/src/types/level.types.ts b/src/types/level.types.ts index 5c8d958b..b447ed48 100644 --- a/src/types/level.types.ts +++ b/src/types/level.types.ts @@ -82,4 +82,5 @@ export interface UserPreferences { downloadNotificationsEnabled?: boolean; repackUpdatesNotificationsEnabled?: boolean; achievementNotificationsEnabled?: boolean; + friendRequestNotificationsEnabled?: boolean; }