Merge pull request #345 from robintown/unregistered-join-existing
Fix joining an existing room from UnregisteredView
This commit is contained in:
commit
7d44a1e979
1 changed files with 31 additions and 25 deletions
|
@ -43,6 +43,10 @@ export function UnauthenticatedView() {
|
||||||
useInteractiveRegistration();
|
useInteractiveRegistration();
|
||||||
const { execute, reset, recaptchaId } = useRecaptcha(recaptchaKey);
|
const { execute, reset, recaptchaId } = useRecaptcha(recaptchaKey);
|
||||||
|
|
||||||
|
const { modalState, modalProps } = useModalTriggerState();
|
||||||
|
const [onFinished, setOnFinished] = useState();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const onSubmit = useCallback(
|
const onSubmit = useCallback(
|
||||||
(e) => {
|
(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -63,40 +67,42 @@ export function UnauthenticatedView() {
|
||||||
recaptchaResponse,
|
recaptchaResponse,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const roomIdOrAlias = await createRoom(client, roomName, ptt);
|
|
||||||
|
let roomIdOrAlias;
|
||||||
|
try {
|
||||||
|
roomIdOrAlias = await createRoom(client, roomName, ptt);
|
||||||
|
} catch (error) {
|
||||||
|
if (error.errcode === "M_ROOM_IN_USE") {
|
||||||
|
setOnFinished(() => () => {
|
||||||
|
setClient(client, session);
|
||||||
|
const aliasLocalpart = roomAliasFromRoomName(roomName);
|
||||||
|
const [, serverName] = client.getUserId().split(":");
|
||||||
|
history.push(`/room/#${aliasLocalpart}:${serverName}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
modalState.open();
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Only consider the registration successful if we managed to create the room, too
|
// Only consider the registration successful if we managed to create the room, too
|
||||||
setClient(client, session);
|
setClient(client, session);
|
||||||
|
|
||||||
if (roomIdOrAlias) {
|
|
||||||
history.push(`/room/${roomIdOrAlias}`);
|
history.push(`/room/${roomIdOrAlias}`);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
submit().catch((error) => {
|
submit().catch((error) => {
|
||||||
if (error.errcode === "M_ROOM_IN_USE") {
|
|
||||||
setExistingRoomId(roomAliasFromRoomName(roomName));
|
|
||||||
setLoading(false);
|
|
||||||
setError(undefined);
|
|
||||||
modalState.open();
|
|
||||||
} else {
|
|
||||||
console.error(error);
|
console.error(error);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setError(error);
|
setError(error);
|
||||||
reset();
|
reset();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[register, reset, execute]
|
[register, reset, execute, history]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { modalState, modalProps } = useModalTriggerState();
|
|
||||||
const [existingRoomId, setExistingRoomId] = useState();
|
|
||||||
const history = useHistory();
|
|
||||||
const onJoinExistingRoom = useCallback(() => {
|
|
||||||
history.push(`/${existingRoomId}`);
|
|
||||||
}, [history, existingRoomId]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Header>
|
<Header>
|
||||||
|
@ -176,7 +182,7 @@ export function UnauthenticatedView() {
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
{modalState.isOpen && (
|
{modalState.isOpen && (
|
||||||
<JoinExistingCallModal onJoin={onJoinExistingRoom} {...modalProps} />
|
<JoinExistingCallModal onJoin={onFinished} {...modalProps} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue