mirror of
https://github.com/BetterSEQTA/BetterSEQTA-Plus.git
synced 2026-12-06 19:56:45 +10:30
fix: minor fixes
This commit is contained in:
1 parent
7eac66b2b0
commit
b3b3763fc8
8 files changed
+65
-28
No files matched your search
@@ -2,7 +2,6 @@
|
||||
import { onMount } from "svelte";
|
||||
import { cloudAuth } from "@/seqta/utils/CloudAuth";
|
||||
import { ACCOUNTS_BASE } from "./constants";
|
||||
import { recordConsent } from "./rosterStore";
|
||||
import { registerOptIn } from "./syncOrchestrator";
|
||||
|
||||
interface Props {
|
||||
@@ -53,7 +52,7 @@
|
||||
error = reg.error ?? "Could not complete opt-in.";
|
||||
return;
|
||||
}
|
||||
await recordConsent();
|
||||
if (reg.error) error = reg.error;
|
||||
await onAccepted();
|
||||
onComplete();
|
||||
} catch (e) {
|
||||
|
||||
@@ -149,14 +149,13 @@ const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
||||
|
||||
const onUpdated = () => schedulePaint();
|
||||
window.addEventListener(CLASSMATES_UPDATED_EVENT, onUpdated);
|
||||
document.addEventListener(
|
||||
"click",
|
||||
(e) => {
|
||||
if ((e.target as HTMLElement).closest?.(".timetablepage .entry.class")) schedulePaint();
|
||||
},
|
||||
true,
|
||||
);
|
||||
api.settings.onChange("enabled", schedulePaint);
|
||||
|
||||
const onClassEntryClick = (e: Event) => {
|
||||
if ((e.target as HTMLElement).closest?.(".timetablepage .entry.class")) schedulePaint();
|
||||
};
|
||||
document.addEventListener("click", onClassEntryClick, true);
|
||||
|
||||
const { unregister: unregisterEnabled } = api.settings.onChange("enabled", schedulePaint);
|
||||
|
||||
const { unregister } = api.seqta.onMount(".timetablepage", handleTimetablePage);
|
||||
if ((await loadSession()).syncOptIn) scheduleClassmatesSyncIfNeeded();
|
||||
@@ -169,6 +168,8 @@ const timetableClassmatesPlugin: Plugin<typeof timetableClassmatesSettings> = {
|
||||
if (paintTimer) clearTimeout(paintTimer);
|
||||
if (pollTimer) clearInterval(pollTimer);
|
||||
window.removeEventListener(CLASSMATES_UPDATED_EVENT, onUpdated);
|
||||
document.removeEventListener("click", onClassEntryClick, true);
|
||||
unregisterEnabled();
|
||||
removeClassmateStacks();
|
||||
};
|
||||
},
|
||||
|
||||
@@ -126,12 +126,13 @@ export function openClassmatesRosterPopup(
|
||||
host.className = "whatsnewTextContainer bsplus-classmates-roster-popup";
|
||||
host.append(list);
|
||||
|
||||
const header = stringToHTML(/* html */ `
|
||||
<div class="whatsnewHeader">
|
||||
<h1>${title}</h1>
|
||||
<p>${peers.length} classmate${peers.length === 1 ? "" : "s"} in this class</p>
|
||||
</div>
|
||||
`).firstChild as HTMLElement;
|
||||
const header = document.createElement("div");
|
||||
header.className = "whatsnewHeader";
|
||||
const heading = document.createElement("h1");
|
||||
heading.textContent = title;
|
||||
const subtitle = document.createElement("p");
|
||||
subtitle.textContent = `${peers.length} classmate${peers.length === 1 ? "" : "s"} in this class`;
|
||||
header.append(heading, subtitle);
|
||||
|
||||
openPopup({
|
||||
header,
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { postSeqtaJson } from "./seqtaClient";
|
||||
import type { PeopleCache } from "./rosterStore";
|
||||
import { loadPeopleCache, savePeopleCache } from "./rosterStore";
|
||||
import {
|
||||
loadPeopleCache,
|
||||
loadPeopleCacheFetchedAt,
|
||||
savePeopleCache,
|
||||
savePeopleCacheFetchedAt,
|
||||
} from "./rosterStore";
|
||||
|
||||
const PEOPLE_TTL_MS = 24 * 60 * 60 * 1000;
|
||||
|
||||
@@ -12,8 +17,8 @@ type PeopleApiRow = {
|
||||
|
||||
export async function refreshPeopleCacheIfStale(): Promise<PeopleCache> {
|
||||
const existing = await loadPeopleCache();
|
||||
const any = Object.values(existing)[0];
|
||||
if (any && Date.now() - any.updatedAt < PEOPLE_TTL_MS) return existing;
|
||||
const fetchedAt = await loadPeopleCacheFetchedAt();
|
||||
if (fetchedAt != null && Date.now() - fetchedAt < PEOPLE_TTL_MS) return existing;
|
||||
|
||||
const data = await postSeqtaJson<{ payload?: PeopleApiRow[] }>(
|
||||
"/seqta/student/load/message/people",
|
||||
@@ -31,6 +36,7 @@ export async function refreshPeopleCacheIfStale(): Promise<PeopleCache> {
|
||||
};
|
||||
}
|
||||
await savePeopleCache(next);
|
||||
await savePeopleCacheFetchedAt(now);
|
||||
return next;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { TIMETABLE_CLASSMATES_CONSENT_VERSION } from "./constants";
|
||||
|
||||
const ROSTER_KEY = "classRosterIndex";
|
||||
const PEOPLE_CACHE_KEY = "peopleCache";
|
||||
const PEOPLE_CACHE_FETCHED_AT_KEY = "peopleCacheFetchedAt";
|
||||
const CI_MAP_KEY = "ciToClassKey";
|
||||
const ARCHIVED_KEY = "archivedMembers";
|
||||
const SESSION_KEY = "session";
|
||||
@@ -115,6 +116,19 @@ export async function savePeopleCache(cache: PeopleCache): Promise<void> {
|
||||
await store.setItem(PEOPLE_CACHE_KEY, cache);
|
||||
}
|
||||
|
||||
export async function loadPeopleCacheFetchedAt(): Promise<number | null> {
|
||||
const store = await scopedStore();
|
||||
if (!store) return null;
|
||||
const at = await store.getItem<number>(PEOPLE_CACHE_FETCHED_AT_KEY);
|
||||
return typeof at === "number" ? at : null;
|
||||
}
|
||||
|
||||
export async function savePeopleCacheFetchedAt(at: number): Promise<void> {
|
||||
const store = await scopedStore();
|
||||
if (!store) return;
|
||||
await store.setItem(PEOPLE_CACHE_FETCHED_AT_KEY, at);
|
||||
}
|
||||
|
||||
export async function loadCiToClassKey(): Promise<Record<string, string>> {
|
||||
const store = await scopedStore();
|
||||
if (!store) return {};
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
loadSession,
|
||||
notifyClassmatesUpdated,
|
||||
patchSession,
|
||||
recordConsent,
|
||||
resolveClassmatesScope,
|
||||
saveArchivedMembers,
|
||||
saveCiToClassKey,
|
||||
@@ -92,13 +93,17 @@ export async function registerOptIn(): Promise<{ ok: boolean; error?: string }>
|
||||
}
|
||||
const body = await optInIdentityDigest(instanceHost, cloudUserId);
|
||||
if (!body) return { ok: false, error: "Could not read your SEQTA login." };
|
||||
await recordConsent();
|
||||
const res = await putOptIn(body);
|
||||
if (!res.ok) return res;
|
||||
const scope = await resolveClassmatesScope();
|
||||
if (scope) await setScopeSyncOptIn(scope, true);
|
||||
await patchSession({ syncOptIn: true, showAvatars: true });
|
||||
const sync = await runTimetableClassmatesSync();
|
||||
return sync.ok ? res : { ok: false, error: sync.error ?? "Opt-in saved but initial sync failed." };
|
||||
if (!sync.ok) {
|
||||
return { ok: true, error: sync.error ?? "Opt-in saved but initial sync failed." };
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export async function revokeOptIn(): Promise<{ ok: boolean; error?: string }> {
|
||||
|
||||
@@ -47,8 +47,11 @@ async function fetchServerHash(userId: string): Promise<string | null> {
|
||||
try {
|
||||
const res = await fetch(`${ACCOUNTS_BASE}/api/user/pfp/${userId}/meta`);
|
||||
if (!res.ok) {
|
||||
noPfpMetaUntil.set(userId, Date.now() + NO_PFP_META_TTL_MS);
|
||||
return null;
|
||||
if (res.status === 404) {
|
||||
noPfpMetaUntil.set(userId, Date.now() + NO_PFP_META_TTL_MS);
|
||||
return null;
|
||||
}
|
||||
throw new Error(`pfp meta HTTP ${res.status}`);
|
||||
}
|
||||
const data = (await res.json()) as { pfpHash?: string | null };
|
||||
const hash = data.pfpHash ?? null;
|
||||
@@ -106,7 +109,14 @@ export async function resolveCloudPfp(
|
||||
return { src: URL.createObjectURL(localBlob), fromCache: true };
|
||||
}
|
||||
|
||||
serverHash = await fetchServerHash(userId);
|
||||
try {
|
||||
serverHash = await fetchServerHash(userId);
|
||||
} catch {
|
||||
if (localHash && localBlob instanceof Blob) {
|
||||
return { src: URL.createObjectURL(localBlob), fromCache: true };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!serverHash) {
|
||||
if (!localHash && !localBlob) return null;
|
||||
|
||||
@@ -21,15 +21,15 @@ export function setupSettingsButton() {
|
||||
});
|
||||
}
|
||||
|
||||
let openSettingsInFlight: Promise<void> | null = null;
|
||||
let openSettingsInFlight: { gen: number; promise: Promise<void> } | null = null;
|
||||
|
||||
export async function openSettingsPopup(): Promise<void> {
|
||||
if (isExtensionSettingsOpen()) return;
|
||||
if (openSettingsInFlight) return openSettingsInFlight;
|
||||
|
||||
const gen = getSettingsOpenGeneration();
|
||||
if (openSettingsInFlight?.gen === gen) return openSettingsInFlight.promise;
|
||||
|
||||
openSettingsInFlight = (async () => {
|
||||
const promise = (async () => {
|
||||
try {
|
||||
let host = document.getElementById("ExtensionPopup");
|
||||
if (!host) {
|
||||
@@ -45,9 +45,10 @@ export async function openSettingsPopup(): Promise<void> {
|
||||
host = document.getElementById("ExtensionPopup");
|
||||
if (host) animateSettingsOpen(host);
|
||||
} finally {
|
||||
openSettingsInFlight = null;
|
||||
if (openSettingsInFlight?.gen === gen) openSettingsInFlight = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return openSettingsInFlight;
|
||||
openSettingsInFlight = { gen, promise };
|
||||
return promise;
|
||||
}
|
||||
Reference in new issue
Block a user