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