diff --git a/src/app/organisms/emoji-verification/EmojiVerification.jsx b/src/app/organisms/emoji-verification/EmojiVerification.jsx
index d1d3325..7d67e09 100644
--- a/src/app/organisms/emoji-verification/EmojiVerification.jsx
+++ b/src/app/organisms/emoji-verification/EmojiVerification.jsx
@@ -20,30 +20,14 @@ import CrossIC from '../../../../public/res/ic/outlined/cross.svg';
import { useStore } from '../../hooks/useStore';
import { accessSecretStorage } from '../settings/SecretStorageAccess';
-function EmojiVerificationContent({ request, requestClose }) {
+function EmojiVerificationContent({ data, requestClose }) {
const [sas, setSas] = useState(null);
const [process, setProcess] = useState(false);
+ const { request, targetDevice } = data;
const mx = initMatrix.matrixClient;
const mountStore = useStore();
- useEffect(() => {
- mountStore.setItem(true);
- const handleChange = () => {
- if (request.done || request.cancelled) requestClose();
- };
-
- if (request === null) return null;
- const req = request;
- req.on('change', handleChange);
- return () => {
- req.off('change', handleChange);
- if (!req.cancelled && !req.done) {
- req.cancel();
- }
- };
- }, [request]);
-
- const acceptRequest = async () => {
+ const beginVerification = async () => {
if (isCrossVerified(mx.deviceId) && !hasPrivateKey(getDefaultSSKey())) {
const keyData = await accessSecretStorage('Session verification');
if (!keyData) {
@@ -54,22 +38,12 @@ function EmojiVerificationContent({ request, requestClose }) {
setProcess(true);
await request.accept();
- let targetDevice;
- try {
- targetDevice = request.targetDevice;
- } catch {
- targetDevice = {
- userId: mx.getUserId(),
- deviceId: request.channel.devices[0],
- };
- }
-
const verifier = request.beginKeyVerification('m.sas.v1', targetDevice);
- const handleVerifier = (data) => {
+ const handleVerifier = (sasData) => {
verifier.off('show_sas', handleVerifier);
if (!mountStore.getItem()) return;
- setSas(data);
+ setSas(sasData);
setProcess(false);
};
verifier.on('show_sas', handleVerifier);
@@ -86,6 +60,26 @@ function EmojiVerificationContent({ request, requestClose }) {
setProcess(true);
};
+ useEffect(() => {
+ mountStore.setItem(true);
+ const handleChange = () => {
+ if (targetDevice && request.started) {
+ beginVerification();
+ }
+ if (request.done || request.cancelled) requestClose();
+ };
+
+ if (request === null) return null;
+ const req = request;
+ req.on('change', handleChange);
+ return () => {
+ req.off('change', handleChange);
+ if (!req.cancelled && !req.done) {
+ req.cancel();
+ }
+ };
+ }, [request]);
+
const renderWait = () => (
<>