feat: friend request notification adjustments

This commit is contained in:
Zamitto
2025-03-10 19:50:53 -03:00
parent b344a1850a
commit 85efc23c25
7 changed files with 45 additions and 12 deletions

View File

@@ -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",

View File

@@ -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",

View File

@@ -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",

View File

@@ -16,13 +16,15 @@ const syncFriendRequests = async (_event: Electron.IpcMainInvokeEvent) => {
return HydraApi.get<FriendRequestSync>(`/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) {

View File

@@ -81,15 +81,24 @@ export const publishNotificationUpdateReadyToInstall = async (
};
export const publishNewFriendRequestNotification = async () => {
const userPreferences = await db.get<string, UserPreferences>(
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 (

View File

@@ -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() {
})
}
/>
<CheckboxField
label={t("enable_friend_request_notifications")}
checked={form.friendRequestNotificationsEnabled}
onChange={() =>
handleChange({
friendRequestNotificationsEnabled:
!form.friendRequestNotificationsEnabled,
})
}
/>
</div>
);
}

View File

@@ -82,4 +82,5 @@ export interface UserPreferences {
downloadNotificationsEnabled?: boolean;
repackUpdatesNotificationsEnabled?: boolean;
achievementNotificationsEnabled?: boolean;
friendRequestNotificationsEnabled?: boolean;
}