mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
feat(mobx): migrate trusted links
This commit is contained in:
@@ -15,7 +15,7 @@ import { useContext, useEffect, useMemo, useState } from "preact/hooks";
|
||||
import { internalSubscribe } from "../../lib/eventEmitter";
|
||||
import { determineLink } from "../../lib/links";
|
||||
|
||||
import { getState } from "../../redux";
|
||||
import { useApplicationState } from "../../mobx/State";
|
||||
|
||||
import { Action } from "../../components/ui/Modal";
|
||||
|
||||
@@ -132,6 +132,7 @@ interface Props {
|
||||
|
||||
export default function Intermediate(props: Props) {
|
||||
const [screen, openScreen] = useState<Screen>({ id: "none" });
|
||||
const settings = useApplicationState().settings;
|
||||
const history = useHistory();
|
||||
|
||||
const value = {
|
||||
@@ -154,10 +155,11 @@ export default function Intermediate(props: Props) {
|
||||
return true;
|
||||
}
|
||||
case "external": {
|
||||
const { trustedLinks } = getState();
|
||||
if (
|
||||
!trusted &&
|
||||
!trustedLinks.domains?.includes(link.url.hostname)
|
||||
!settings.security.isTrustedOrigin(
|
||||
link.url.hostname,
|
||||
)
|
||||
) {
|
||||
openScreen({
|
||||
id: "external_link_prompt",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Text } from "preact-i18n";
|
||||
|
||||
import { useApplicationState } from "../../../mobx/State";
|
||||
import { dispatch } from "../../../redux";
|
||||
|
||||
import Modal from "../../../components/ui/Modal";
|
||||
@@ -13,6 +14,7 @@ interface Props {
|
||||
|
||||
export function ExternalLinkModal({ onClose, link }: Props) {
|
||||
const { openLink } = useIntermediate();
|
||||
const settings = useApplicationState().settings;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
@@ -39,13 +41,10 @@ export function ExternalLinkModal({ onClose, link }: Props) {
|
||||
onClick: () => {
|
||||
try {
|
||||
const url = new URL(link);
|
||||
dispatch({
|
||||
type: "TRUSTED_LINKS_ADD_DOMAIN",
|
||||
domain: url.hostname,
|
||||
});
|
||||
settings.security.addTrustedOrigin(url.hostname);
|
||||
} catch (e) {}
|
||||
|
||||
openLink(link);
|
||||
openLink(link, true);
|
||||
onClose();
|
||||
},
|
||||
plain: true,
|
||||
|
||||
Reference in New Issue
Block a user