mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
808 B
TypeScript
40 lines
808 B
TypeScript
/**
|
|
* 免打扰
|
|
*/
|
|
|
|
const KEY = 'plugin:com.msgbyte.notify/slientStorage';
|
|
|
|
const silentSet = new Set<string>(loadFromLocalstorage());
|
|
|
|
export function appendSilent(converseId: string) {
|
|
silentSet.add(converseId);
|
|
saveToLocalstorage();
|
|
}
|
|
|
|
export function removeSilent(converseId: string) {
|
|
silentSet.delete(converseId);
|
|
saveToLocalstorage();
|
|
}
|
|
|
|
export function hasSilent(converseId: string): boolean {
|
|
return silentSet.has(converseId);
|
|
}
|
|
|
|
function saveToLocalstorage() {
|
|
localStorage.setItem(KEY, JSON.stringify(Array.from(silentSet)));
|
|
}
|
|
|
|
function loadFromLocalstorage(): string[] {
|
|
try {
|
|
const arr = JSON.parse(localStorage.getItem(KEY));
|
|
if (Array.isArray(arr)) {
|
|
return arr;
|
|
} else {
|
|
return [];
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
return [];
|
|
}
|
|
}
|