Convert things to Typescript and re-use a generic component
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
b21e5ba10b
commit
14cee41360
9 changed files with 342 additions and 303 deletions
58
src/toasts/BulkUnverifiedSessionsToast.ts
Normal file
58
src/toasts/BulkUnverifiedSessionsToast.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { _t } from '../languageHandler';
|
||||
import dis from "../dispatcher/dispatcher";
|
||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||
import DeviceListener from '../DeviceListener';
|
||||
import GenericToast from "../components/views/toasts/GenericToast";
|
||||
import ToastStore from "../stores/ToastStore";
|
||||
|
||||
const TOAST_KEY = "reviewsessions";
|
||||
|
||||
export const showToast = (deviceIds: Set<string>) => {
|
||||
const onAccept = () => {
|
||||
DeviceListener.sharedInstance().dismissUnverifiedSessions(deviceIds);
|
||||
|
||||
dis.dispatch({
|
||||
action: 'view_user_info',
|
||||
userId: MatrixClientPeg.get().getUserId(),
|
||||
});
|
||||
};
|
||||
|
||||
const onReject = () => {
|
||||
DeviceListener.sharedInstance().dismissUnverifiedSessions(deviceIds);
|
||||
};
|
||||
|
||||
ToastStore.sharedInstance().addOrReplaceToast({
|
||||
key: TOAST_KEY,
|
||||
title: _t("Review where you’re logged in"),
|
||||
icon: "verification_warning",
|
||||
props: {
|
||||
description: _t("Verify all your sessions to ensure your account & messages are safe"),
|
||||
acceptLabel: _t("Review"),
|
||||
onAccept,
|
||||
rejectLabel: _t("Later"),
|
||||
onReject,
|
||||
},
|
||||
component: GenericToast,
|
||||
priority: 50,
|
||||
});
|
||||
};
|
||||
|
||||
export const hideToast = () => {
|
||||
ToastStore.sharedInstance().dismissToast(TOAST_KEY);
|
||||
};
|
106
src/toasts/SetupEncryptionToast.ts
Normal file
106
src/toasts/SetupEncryptionToast.ts
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import Modal from "../Modal";
|
||||
import * as sdk from "../index";
|
||||
import { _t } from "../languageHandler";
|
||||
import DeviceListener from "../DeviceListener";
|
||||
import SetupEncryptionDialog from "../components/views/dialogs/SetupEncryptionDialog";
|
||||
import { accessSecretStorage } from "../CrossSigningManager";
|
||||
import ToastStore from "../stores/ToastStore";
|
||||
import GenericToast from "../components/views/toasts/GenericToast";
|
||||
|
||||
const TOAST_KEY = "setupencryption";
|
||||
|
||||
const getTitle = (kind: Kind) => {
|
||||
switch (kind) {
|
||||
case Kind.SET_UP_ENCRYPTION:
|
||||
return _t("Set up encryption");
|
||||
case Kind.UPGRADE_ENCRYPTION:
|
||||
return _t("Encryption upgrade available");
|
||||
case Kind.VERIFY_THIS_SESSION:
|
||||
return _t("Verify this session");
|
||||
}
|
||||
};
|
||||
|
||||
const getSetupCaption = (kind: Kind) => {
|
||||
switch (kind) {
|
||||
case Kind.SET_UP_ENCRYPTION:
|
||||
return _t("Set up");
|
||||
case Kind.UPGRADE_ENCRYPTION:
|
||||
return _t("Upgrade");
|
||||
case Kind.VERIFY_THIS_SESSION:
|
||||
return _t("Verify");
|
||||
}
|
||||
};
|
||||
|
||||
const getDescription = (kind: Kind) => {
|
||||
switch (kind) {
|
||||
case Kind.SET_UP_ENCRYPTION:
|
||||
case Kind.UPGRADE_ENCRYPTION:
|
||||
return _t("Verify yourself & others to keep your chats safe");
|
||||
case Kind.VERIFY_THIS_SESSION:
|
||||
return _t("Other users may not trust it");
|
||||
}
|
||||
};
|
||||
|
||||
export enum Kind {
|
||||
SET_UP_ENCRYPTION = "set_up_encryption",
|
||||
UPGRADE_ENCRYPTION = "upgrade_encryption",
|
||||
VERIFY_THIS_SESSION = "verify_this_session",
|
||||
}
|
||||
|
||||
const onReject = () => {
|
||||
DeviceListener.sharedInstance().dismissEncryptionSetup();
|
||||
};
|
||||
|
||||
export const showToast = (kind: Kind) => {
|
||||
const onAccept = async () => {
|
||||
if (kind === Kind.VERIFY_THIS_SESSION) {
|
||||
Modal.createTrackedDialog("Verify session", "Verify session", SetupEncryptionDialog,
|
||||
{}, null, /* priority = */ false, /* static = */ true);
|
||||
} else {
|
||||
const Spinner = sdk.getComponent("elements.Spinner");
|
||||
const modal = Modal.createDialog(
|
||||
Spinner, null, "mx_Dialog_spinner", /* priority */ false, /* static */ true,
|
||||
);
|
||||
try {
|
||||
await accessSecretStorage();
|
||||
} finally {
|
||||
modal.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ToastStore.sharedInstance().addOrReplaceToast({
|
||||
key: TOAST_KEY,
|
||||
title: getTitle(kind),
|
||||
icon: "verification_warning",
|
||||
props: {
|
||||
description: getDescription(kind),
|
||||
acceptLabel: getSetupCaption(kind),
|
||||
onAccept,
|
||||
rejectLabel: _t("Later"),
|
||||
onReject,
|
||||
},
|
||||
component: GenericToast,
|
||||
priority: kind === Kind.VERIFY_THIS_SESSION ? 95 : 40,
|
||||
});
|
||||
};
|
||||
|
||||
export const hideToast = () => {
|
||||
ToastStore.sharedInstance().dismissToast(TOAST_KEY);
|
||||
};
|
70
src/toasts/UnverifiedSessionToast.ts
Normal file
70
src/toasts/UnverifiedSessionToast.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
Copyright 2020 The Matrix.org Foundation C.I.C.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { _t } from '../languageHandler';
|
||||
import { MatrixClientPeg } from '../MatrixClientPeg';
|
||||
import Modal from '../Modal';
|
||||
import DeviceListener from '../DeviceListener';
|
||||
import NewSessionReviewDialog from '../components/views/dialogs/NewSessionReviewDialog';
|
||||
import ToastStore from "../stores/ToastStore";
|
||||
import GenericToast from "../components/views/toasts/GenericToast";
|
||||
|
||||
function toastKey(deviceId: string) {
|
||||
return "unverified_session_" + deviceId;
|
||||
}
|
||||
|
||||
export const showToast = (deviceId: string) => {
|
||||
const cli = MatrixClientPeg.get();
|
||||
|
||||
const onAccept = () => {
|
||||
Modal.createTrackedDialog('New Session Review', 'Starting dialog', NewSessionReviewDialog, {
|
||||
userId: cli.getUserId(),
|
||||
device: cli.getStoredDevice(cli.getUserId(), deviceId),
|
||||
onFinished: (r) => {
|
||||
if (!r) {
|
||||
/* This'll come back false if the user clicks "this wasn't me" and saw a warning dialog */
|
||||
DeviceListener.sharedInstance().dismissUnverifiedSessions([deviceId]);
|
||||
}
|
||||
},
|
||||
}, null, /* priority = */ false, /* static = */ true);
|
||||
};
|
||||
|
||||
const onReject = () => {
|
||||
DeviceListener.sharedInstance().dismissUnverifiedSessions([deviceId]);
|
||||
};
|
||||
|
||||
const device = cli.getStoredDevice(cli.getUserId(), deviceId);
|
||||
|
||||
ToastStore.sharedInstance().addOrReplaceToast({
|
||||
key: toastKey(deviceId),
|
||||
title: _t("New login. Was this you?"),
|
||||
icon: "verification_warning",
|
||||
props: {
|
||||
description: _t(
|
||||
"Verify the new login accessing your account: %(name)s", { name: device.getDisplayName()}),
|
||||
acceptLabel: _t("Verify"),
|
||||
onAccept,
|
||||
rejectLabel: _t("Later"),
|
||||
onReject,
|
||||
},
|
||||
component: GenericToast,
|
||||
priority: 80,
|
||||
});
|
||||
};
|
||||
|
||||
export const hideToast = (deviceId: string) => {
|
||||
ToastStore.sharedInstance().dismissToast(deviceId);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue