feat: Add session count to app badge (#575)

This commit is contained in:
lostb1t
2025-03-05 08:21:59 +01:00
committed by GitHub
parent 89eb0d7796
commit 5df021a836
5 changed files with 91 additions and 56 deletions

View File

@@ -3,6 +3,8 @@ import { apiAtom } from "@/providers/JellyfinProvider";
import { useAtom } from "jotai";
import { getSessionApi } from "@jellyfin/sdk/lib/utils/api/session-api";
import { userAtom } from "@/providers/JellyfinProvider";
import { Platform } from "react-native";
const Notifications = !Platform.isTV ? require("expo-notifications") : null;
export interface useSessionsProps {
refetchInterval: number;
@@ -22,9 +24,13 @@ export const useSessions = ({ refetchInterval = 5 * 1000, activeWithinSeconds =
const response = await getSessionApi(api).getSessions({
activeWithinSeconds: activeWithinSeconds,
});
return response.data
const result = response.data
.filter((s) => s.NowPlayingItem)
.sort((a, b) => (b.NowPlayingItem?.Name ?? "").localeCompare(a.NowPlayingItem?.Name ?? ""));
Notifications.setBadgeCountAsync(result.length);
return result
},
refetchInterval: refetchInterval,
});