| 1 | import { writable } from 'svelte/store'; |
| 2 | import { getAccountData } from './api'; |
| 3 | import { NO_MUTED_SPACES, parseMutedSpaces, type MutedSpaces } from './mute-model'; |
| 4 | |
| 5 | export const MUTED_SPACES_EVENT = 'dev.malice.muted_spaces'; |
| 6 | |
| 7 | export const mutedSpaces = writable<MutedSpaces>(NO_MUTED_SPACES); |
| 8 | |
| 9 | let loaded = false; |
| 10 | |
| 11 | export const mutedSpacesLoaded = () => loaded; |
| 12 | |
| 13 | export async function loadMutedSpaces(): Promise<void> { |
| 14 | try { |
| 15 | mutedSpaces.set(parseMutedSpaces(await getAccountData(MUTED_SPACES_EVENT))); |
| 16 | loaded = true; |
| 17 | } catch {} |
| 18 | } |
| 19 | |
| 20 | export function resetMutedSpaces(): void { |
| 21 | loaded = false; |
| 22 | mutedSpaces.set(NO_MUTED_SPACES); |
| 23 | } |