Files
cobble/src/functions/backend/db/push/is-user-present.ts
T
tben dbfe48796b Make the app an installable PWA with phone layout and Web Push
Add a generated manifest, icon set, offline page and service worker that never caches authenticated HTML, plus install and update UI. Turn the rail into a drawer below md with container-query internals, dvh and safe-area handling, and reconnect the socket after visibility/network changes. Add Web Push subscriptions, presence-aware delivery, notification settings and tests.
2026-10-19 17:12:16 +01:00

25 lines
774 B
TypeScript

import BunSQLite from "@moduletrace/bun-sqlite";
import type { BUN_SQLITE_COBBLE_USER_PRESENCE } from "@/db/types/db";
import { AppData } from "@/src/data/app-data";
/**
* Whether the app is open for this user right now (any process), based on
* the socket keepalive. Push notifications are skipped while it is.
*/
export default async function isUserPresent({
user_id,
}: {
user_id: number | string;
}) {
const row = (
await BunSQLite.sql<BUN_SQLITE_COBBLE_USER_PRESENCE>({
sql: `SELECT last_seen_at FROM user_presence WHERE user_id = ? LIMIT 1`,
values: [user_id],
})
).payload?.[0];
if (!row?.last_seen_at) return false;
return Date.now() - Number(row.last_seen_at) <= AppData.PushPresenceWindowMs;
}