mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-06 17:11:55 +00:00
feat(mobx): migrate trusted links
This commit is contained in:
@@ -9,6 +9,7 @@ import { EmojiPack } from "../../components/common/Emoji";
|
||||
import Persistent from "../interfaces/Persistent";
|
||||
import Store from "../interfaces/Store";
|
||||
import SAudio, { SoundOptions } from "./helpers/SAudio";
|
||||
import SSecurity from "./helpers/SSecurity";
|
||||
import STheme from "./helpers/STheme";
|
||||
|
||||
interface ISettings {
|
||||
@@ -24,6 +25,8 @@ interface ISettings {
|
||||
"appearance:theme:font": Fonts;
|
||||
"appearance:theme:monoFont": MonospaceFonts;
|
||||
"appearance:theme:css": string;
|
||||
|
||||
"security:trustedOrigins": string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,6 +37,7 @@ export default class Settings implements Store, Persistent<ISettings> {
|
||||
|
||||
theme: STheme;
|
||||
sounds: SAudio;
|
||||
security: SSecurity;
|
||||
|
||||
/**
|
||||
* Construct new Settings store.
|
||||
@@ -44,6 +48,7 @@ export default class Settings implements Store, Persistent<ISettings> {
|
||||
|
||||
this.theme = new STheme(this);
|
||||
this.sounds = new SAudio(this);
|
||||
this.security = new SSecurity(this);
|
||||
}
|
||||
|
||||
get id() {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { makeAutoObservable, computed, action } from "mobx";
|
||||
|
||||
import call_join from "../../../assets/sounds/call_join.mp3";
|
||||
import call_leave from "../../../assets/sounds/call_leave.mp3";
|
||||
import message from "../../../assets/sounds/message.mp3";
|
||||
import outbound from "../../../assets/sounds/outbound.mp3";
|
||||
import Settings from "../Settings";
|
||||
import call_join from "./call_join.mp3";
|
||||
import call_leave from "./call_leave.mp3";
|
||||
import message from "./message.mp3";
|
||||
import outbound from "./outbound.mp3";
|
||||
|
||||
export type Sounds = "message" | "outbound" | "call_join" | "call_leave";
|
||||
|
||||
|
||||
33
src/mobx/stores/helpers/SSecurity.ts
Normal file
33
src/mobx/stores/helpers/SSecurity.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { makeAutoObservable, computed, action } from "mobx";
|
||||
|
||||
import Settings from "../Settings";
|
||||
|
||||
/**
|
||||
* Helper class for changing security options.
|
||||
*/
|
||||
export default class SSecurity {
|
||||
private settings: Settings;
|
||||
|
||||
/**
|
||||
* Construct a new security helper.
|
||||
* @param settings Settings parent class
|
||||
*/
|
||||
constructor(settings: Settings) {
|
||||
this.settings = settings;
|
||||
makeAutoObservable(this);
|
||||
}
|
||||
|
||||
@action addTrustedOrigin(origin: string) {
|
||||
this.settings.set("security:trustedOrigins", [
|
||||
...(this.settings.get("security:trustedOrigins") ?? []).filter(
|
||||
(x) => x !== origin,
|
||||
),
|
||||
origin,
|
||||
]);
|
||||
}
|
||||
|
||||
@computed isTrustedOrigin(origin: string) {
|
||||
console.log(this.settings.get("security:trustedOrigins"), origin);
|
||||
return this.settings.get("security:trustedOrigins")?.includes(origin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user